本文整理汇总了C++中WT_BM::read方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_BM::read方法的具体用法?C++ WT_BM::read怎么用?C++ WT_BM::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_BM
的用法示例。
在下文中一共展示了WT_BM::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*
* __wt_debug_addr --
* Read and dump a disk page in debugging mode, using an addr/size pair.
*/
int
__wt_debug_addr(WT_SESSION_IMPL *session,
const uint8_t *addr, size_t addr_size, const char *ofile)
{
WT_BM *bm;
WT_DECL_ITEM(buf);
WT_DECL_RET;
bm = S2BT(session)->bm;
WT_RET(__wt_scr_alloc(session, 1024, &buf));
WT_ERR(bm->read(bm, session, buf, addr, addr_size));
ret = __wt_debug_disk(session, buf->mem, ofile);
err: __wt_scr_free(session, &buf);
return (ret);
}
示例2:
/*
* __wt_bt_read --
* Read a cookie referenced block into a buffer.
*/
int
__wt_bt_read(WT_SESSION_IMPL *session,
WT_ITEM *buf, const uint8_t *addr, size_t addr_size)
{
WT_BM *bm;
WT_BTREE *btree;
WT_DECL_ITEM(tmp);
WT_DECL_RET;
const WT_PAGE_HEADER *dsk;
size_t result_len;
btree = S2BT(session);
bm = btree->bm;
/*
* If anticipating a compressed block, read into a scratch buffer and
* decompress into the caller's buffer. Else, read directly into the
* caller's buffer.
*/
if (btree->compressor == NULL) {
WT_RET(bm->read(bm, session, buf, addr, addr_size));
dsk = buf->data;
} else {
WT_RET(__wt_scr_alloc(session, 0, &tmp));
WT_ERR(bm->read(bm, session, tmp, addr, addr_size));
dsk = tmp->data;
}
/*
* If the block is compressed, copy the skipped bytes of the original
* image into place, then decompress.
*/
if (F_ISSET(dsk, WT_PAGE_COMPRESSED)) {
if (btree->compressor == NULL ||
btree->compressor->decompress == NULL)
WT_ERR_MSG(session, WT_ERROR,
"read compressed block where no compression engine "
"configured");
/*
* We're allocating the exact number of bytes we're expecting
* from decompression.
*/
WT_ERR(__wt_buf_initsize(session, buf, dsk->mem_size));
/*
* Note the source length is NOT the number of compressed bytes,
* it's the length of the block we just read (minus the skipped
* bytes). We don't store the number of compressed bytes: some
* compression engines need that length stored externally, they
* don't have markers in the stream to signal the end of the
* compressed bytes. Those engines must store the compressed
* byte length somehow, see the snappy compression extension for
* an example.
*/
memcpy(buf->mem, tmp->data, WT_BLOCK_COMPRESS_SKIP);
ret = btree->compressor->decompress(
btree->compressor, &session->iface,
(uint8_t *)tmp->data + WT_BLOCK_COMPRESS_SKIP,
tmp->size - WT_BLOCK_COMPRESS_SKIP,
(uint8_t *)buf->mem + WT_BLOCK_COMPRESS_SKIP,
dsk->mem_size - WT_BLOCK_COMPRESS_SKIP, &result_len);
/*
* If checksums were turned off because we're depending on the
* decompression to fail on any corrupted data, we'll end up
* here after corruption happens. If we're salvaging the file,
* it's OK, otherwise it's really, really bad.
*/
if (ret != 0 ||
result_len != dsk->mem_size - WT_BLOCK_COMPRESS_SKIP)
WT_ERR(
F_ISSET(btree, WT_BTREE_VERIFY) ||
F_ISSET(session, WT_SESSION_SALVAGE_CORRUPT_OK) ?
WT_ERROR :
__wt_illegal_value(session, btree->dhandle->name));
} else
if (btree->compressor == NULL)
buf->size = dsk->mem_size;
else
/*
* We guessed wrong: there was a compressor, but this
* block was not compressed, and now the page is in the
* wrong buffer and the buffer may be of the wrong size.
* This should be rare, but happens with small blocks
* that aren't worth compressing.
*/
WT_ERR(__wt_buf_set(
session, buf, tmp->data, dsk->mem_size));
/* If the handle is a verify handle, verify the physical page. */
if (F_ISSET(btree, WT_BTREE_VERIFY)) {
if (tmp == NULL)
WT_ERR(__wt_scr_alloc(session, 0, &tmp));
WT_ERR(bm->addr_string(bm, session, tmp, addr, addr_size));
WT_ERR(__wt_verify_dsk(session, (const char *)tmp->data, buf));
//.........这里部分代码省略.........
示例3: if
/*
* __wt_bt_read --
* Read a cookie referenced block into a buffer.
*/
int
__wt_bt_read(WT_SESSION_IMPL *session,
WT_ITEM *buf, const uint8_t *addr, size_t addr_size)
{
WT_BM *bm;
WT_BTREE *btree;
WT_DECL_ITEM(etmp);
WT_DECL_ITEM(tmp);
WT_DECL_RET;
WT_ENCRYPTOR *encryptor;
WT_ITEM *ip;
const WT_PAGE_HEADER *dsk;
const char *fail_msg;
size_t result_len;
btree = S2BT(session);
bm = btree->bm;
fail_msg = NULL; /* -Wuninitialized */
/*
* If anticipating a compressed or encrypted block, read into a scratch
* buffer and decompress into the caller's buffer. Else, read directly
* into the caller's buffer.
*/
if (btree->compressor == NULL && btree->kencryptor == NULL) {
WT_RET(bm->read(bm, session, buf, addr, addr_size));
dsk = buf->data;
ip = NULL;
} else {
WT_RET(__wt_scr_alloc(session, 0, &tmp));
WT_ERR(bm->read(bm, session, tmp, addr, addr_size));
dsk = tmp->data;
ip = tmp;
}
/*
* If the block is encrypted, copy the skipped bytes of the original
* image into place, then decrypt.
*/
if (F_ISSET(dsk, WT_PAGE_ENCRYPTED)) {
if (btree->kencryptor == NULL ||
(encryptor = btree->kencryptor->encryptor) == NULL ||
encryptor->decrypt == NULL) {
fail_msg =
"encrypted block in file for which no encryption "
"configured";
goto corrupt;
}
WT_ERR(__wt_scr_alloc(session, 0, &etmp));
if ((ret = __wt_decrypt(session,
encryptor, WT_BLOCK_ENCRYPT_SKIP, ip, etmp)) != 0) {
fail_msg = "block decryption failed";
goto corrupt;
}
ip = etmp;
dsk = ip->data;
} else if (btree->kencryptor != NULL) {
fail_msg =
"unencrypted block in file for which encryption configured";
goto corrupt;
}
if (F_ISSET(dsk, WT_PAGE_COMPRESSED)) {
if (btree->compressor == NULL ||
btree->compressor->decompress == NULL) {
fail_msg =
"compressed block in file for which no compression "
"configured";
goto corrupt;
}
/*
* Size the buffer based on the in-memory bytes we're expecting
* from decompression.
*/
WT_ERR(__wt_buf_initsize(session, buf, dsk->mem_size));
/*
* Note the source length is NOT the number of compressed bytes,
* it's the length of the block we just read (minus the skipped
* bytes). We don't store the number of compressed bytes: some
* compression engines need that length stored externally, they
* don't have markers in the stream to signal the end of the
* compressed bytes. Those engines must store the compressed
* byte length somehow, see the snappy compression extension for
* an example.
*/
memcpy(buf->mem, ip->data, WT_BLOCK_COMPRESS_SKIP);
ret = btree->compressor->decompress(
btree->compressor, &session->iface,
(uint8_t *)ip->data + WT_BLOCK_COMPRESS_SKIP,
tmp->size - WT_BLOCK_COMPRESS_SKIP,
(uint8_t *)buf->mem + WT_BLOCK_COMPRESS_SKIP,
dsk->mem_size - WT_BLOCK_COMPRESS_SKIP, &result_len);
//.........这里部分代码省略.........