diff options
Diffstat (limited to 'src/third_party/wiredtiger/src')
56 files changed, 975 insertions, 502 deletions
diff --git a/src/third_party/wiredtiger/src/block/block_map.c b/src/third_party/wiredtiger/src/block/block_map.c index 3d04a492269..b60623a37d8 100644 --- a/src/third_party/wiredtiger/src/block/block_map.c +++ b/src/third_party/wiredtiger/src/block/block_map.c @@ -20,6 +20,19 @@ __wt_block_map( *(void **)mapp = NULL; *maplenp = 0; +#ifdef WORDS_BIGENDIAN + /* + * The underlying objects are little-endian, mapping objects isn't + * currently supported on big-endian systems. + */ + WT_UNUSED(session); + WT_UNUSED(block); + WT_UNUSED(mappingcookie); +#else + /* Map support is configurable. */ + if (!S2C(session)->mmap) + return (0); + /* * Turn off mapping when verifying the file, because we can't perform * checksum validation of mapped segments, and verify has to checksum @@ -48,6 +61,7 @@ __wt_block_map( * Ignore errors, we'll read the file through the cache if map fails. */ (void)__wt_mmap(session, block->fh, mapp, maplenp, mappingcookie); +#endif return (0); } diff --git a/src/third_party/wiredtiger/src/block/block_mgr.c b/src/third_party/wiredtiger/src/block/block_mgr.c index 6e2dc775362..dceaae8bb99 100644 --- a/src/third_party/wiredtiger/src/block/block_mgr.c +++ b/src/third_party/wiredtiger/src/block/block_mgr.c @@ -69,18 +69,6 @@ __bm_checkpoint(WT_BM *bm, } /* - * __bm_sync -- - * Flush a file to disk. - */ -static int -__bm_sync(WT_BM *bm, WT_SESSION_IMPL *session, bool async) -{ - return (async ? - __wt_fsync_async(session, bm->block->fh) : - __wt_fsync(session, bm->block->fh)); -} - -/* * __bm_checkpoint_load -- * Load a checkpoint. */ @@ -89,10 +77,6 @@ __bm_checkpoint_load(WT_BM *bm, WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size, uint8_t *root_addr, size_t *root_addr_sizep, bool checkpoint) { - WT_CONNECTION_IMPL *conn; - - conn = S2C(session); - /* If not opening a checkpoint, we're opening the live system. */ bm->is_live = !checkpoint; WT_RET(__wt_block_checkpoint_load(session, bm->block, @@ -103,9 +87,8 @@ __bm_checkpoint_load(WT_BM *bm, WT_SESSION_IMPL *session, * Read-only objects are optionally mapped into memory instead * of being read into cache buffers. */ - if (conn->mmap) - WT_RET(__wt_block_map(session, bm->block, - &bm->map, &bm->maplen, &bm->mappingcookie)); + WT_RET(__wt_block_map(session, + bm->block, &bm->map, &bm->maplen, &bm->mappingcookie)); /* * If this handle is for a checkpoint, that is, read-only, there @@ -168,13 +151,13 @@ __bm_close(WT_BM *bm, WT_SESSION_IMPL *session) } /* - * __bm_compact_start -- - * Start a block manager compaction. + * __bm_compact_end -- + * End a block manager compaction. */ static int -__bm_compact_start(WT_BM *bm, WT_SESSION_IMPL *session) +__bm_compact_end(WT_BM *bm, WT_SESSION_IMPL *session) { - return (__wt_block_compact_start(session, bm->block)); + return (__wt_block_compact_end(session, bm->block)); } /* @@ -200,13 +183,13 @@ __bm_compact_skip(WT_BM *bm, WT_SESSION_IMPL *session, bool *skipp) } /* - * __bm_compact_end -- - * End a block manager compaction. + * __bm_compact_start -- + * Start a block manager compaction. */ static int -__bm_compact_end(WT_BM *bm, WT_SESSION_IMPL *session) +__bm_compact_start(WT_BM *bm, WT_SESSION_IMPL *session) { - return (__wt_block_compact_end(session, bm->block)); + return (__wt_block_compact_start(session, bm->block)); } /* @@ -233,36 +216,25 @@ __bm_is_mapped(WT_BM *bm, WT_SESSION_IMPL *session) } /* - * __bm_stat -- - * Block-manager statistics. - */ -static int -__bm_stat(WT_BM *bm, WT_SESSION_IMPL *session, WT_DSRC_STATS *stats) -{ - __wt_block_stat(session, bm->block, stats); - return (0); -} - -/* - * __bm_write -- - * Write a buffer into a block, returning the block's address cookie. + * __bm_salvage_end -- + * End a block manager salvage. */ static int -__bm_write(WT_BM *bm, WT_SESSION_IMPL *session, - WT_ITEM *buf, uint8_t *addr, size_t *addr_sizep, bool data_cksum) +__bm_salvage_end(WT_BM *bm, WT_SESSION_IMPL *session) { - return (__wt_block_write( - session, bm->block, buf, addr, addr_sizep, data_cksum)); + return (__wt_block_salvage_end(session, bm->block)); } /* - * __bm_write_size -- - * Return the buffer size required to write a block. + * __bm_salvage_next -- + * Return the next block from the file. */ static int -__bm_write_size(WT_BM *bm, WT_SESSION_IMPL *session, size_t *sizep) +__bm_salvage_next(WT_BM *bm, + WT_SESSION_IMPL *session, uint8_t *addr, size_t *addr_sizep, bool *eofp) { - return (__wt_block_write_size(session, bm->block, sizep)); + return (__wt_block_salvage_next( + session, bm->block, addr, addr_sizep, eofp)); } /* @@ -288,25 +260,47 @@ __bm_salvage_valid(WT_BM *bm, } /* - * __bm_salvage_next -- - * Return the next block from the file. + * __bm_stat -- + * Block-manager statistics. */ static int -__bm_salvage_next(WT_BM *bm, - WT_SESSION_IMPL *session, uint8_t *addr, size_t *addr_sizep, bool *eofp) +__bm_stat(WT_BM *bm, WT_SESSION_IMPL *session, WT_DSRC_STATS *stats) { - return (__wt_block_salvage_next( - session, bm->block, addr, addr_sizep, eofp)); + __wt_block_stat(session, bm->block, stats); + return (0); } /* - * __bm_salvage_end -- - * End a block manager salvage. + * __bm_sync -- + * Flush a file to disk. */ static int -__bm_salvage_end(WT_BM *bm, WT_SESSION_IMPL *session) +__bm_sync(WT_BM *bm, WT_SESSION_IMPL *session, bool async) { - return (__wt_block_salvage_end(session, bm->block)); + return (async ? + __wt_fsync_async(session, bm->block->fh) : + __wt_fsync(session, bm->block->fh)); +} + +/* + * __bm_verify_addr -- + * Verify an address. + */ +static int +__bm_verify_addr(WT_BM *bm, + WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size) +{ + return (__wt_block_verify_addr(session, bm->block, addr, addr_size)); +} + +/* + * __bm_verify_end -- + * End a block manager verify. + */ +static int +__bm_verify_end(WT_BM *bm, WT_SESSION_IMPL *session) +{ + return (__wt_block_verify_end(session, bm->block)); } /* @@ -321,24 +315,25 @@ __bm_verify_start(WT_BM *bm, } /* - * __bm_verify_addr -- - * Verify an address. + * __bm_write -- + * Write a buffer into a block, returning the block's address cookie. */ static int -__bm_verify_addr(WT_BM *bm, - WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size) +__bm_write(WT_BM *bm, WT_SESSION_IMPL *session, + WT_ITEM *buf, uint8_t *addr, size_t *addr_sizep, bool data_cksum) { - return (__wt_block_verify_addr(session, bm->block, addr, addr_size)); + return (__wt_block_write( + session, bm->block, buf, addr, addr_sizep, data_cksum)); } /* - * __bm_verify_end -- - * End a block manager verify. + * __bm_write_size -- + * Return the buffer size required to write a block. */ static int -__bm_verify_end(WT_BM *bm, WT_SESSION_IMPL *session) +__bm_write_size(WT_BM *bm, WT_SESSION_IMPL *session, size_t *sizep) { - return (__wt_block_verify_end(session, bm->block)); + return (__wt_block_write_size(session, bm->block, sizep)); } /* diff --git a/src/third_party/wiredtiger/src/block/block_open.c b/src/third_party/wiredtiger/src/block/block_open.c index dd0f3f0716a..d9b2f908737 100644 --- a/src/third_party/wiredtiger/src/block/block_open.c +++ b/src/third_party/wiredtiger/src/block/block_open.c @@ -296,15 +296,21 @@ __wt_desc_init(WT_SESSION_IMPL *session, WT_FH *fh, uint32_t allocsize) WT_RET(__wt_scr_alloc(session, allocsize, &buf)); memset(buf->mem, 0, allocsize); + /* + * Checksum a little-endian version of the header, and write everything + * in little-endian format. The checksum is (potentially) returned in a + * big-endian format, swap it into place in a separate step. + */ desc = buf->mem; desc->magic = WT_BLOCK_MAGIC; desc->majorv = WT_BLOCK_MAJOR_VERSION; desc->minorv = WT_BLOCK_MINOR_VERSION; - - /* Update the checksum. */ desc->cksum = 0; + __wt_block_desc_byteswap(desc); desc->cksum = __wt_cksum(desc, allocsize); - +#ifdef WORDS_BIGENDIAN + desc->cksum = __wt_bswap32(desc->cksum); +#endif ret = __wt_write(session, fh, (wt_off_t)0, (size_t)allocsize, desc); __wt_scr_free(session, &buf); @@ -321,7 +327,7 @@ __desc_read(WT_SESSION_IMPL *session, WT_BLOCK *block) WT_BLOCK_DESC *desc; WT_DECL_ITEM(buf); WT_DECL_RET; - uint32_t cksum; + uint32_t cksum_calculate, cksum_tmp; /* Use a scratch buffer to get correct alignment for direct I/O. */ WT_RET(__wt_scr_alloc(session, block->allocsize, &buf)); @@ -330,14 +336,19 @@ __desc_read(WT_SESSION_IMPL *session, WT_BLOCK *block) WT_ERR(__wt_read(session, block->fh, (wt_off_t)0, (size_t)block->allocsize, buf->mem)); + /* + * Handle little- and big-endian objects. Objects are written in little- + * endian format: save the header checksum, and calculate the checksum + * for the header in its little-endian form. Then, restore the header's + * checksum, and byte-swap the whole thing as necessary, leaving us with + * a calculated checksum that should match the checksum in the header. + */ desc = buf->mem; - WT_ERR(__wt_verbose(session, WT_VERB_BLOCK, - "%s: magic %" PRIu32 - ", major/minor: %" PRIu32 "/%" PRIu32 - ", checksum %#" PRIx32, - block->name, desc->magic, - desc->majorv, desc->minorv, - desc->cksum)); + cksum_tmp = desc->cksum; + desc->cksum = 0; + cksum_calculate = __wt_cksum(desc, block->allocsize); + desc->cksum = cksum_tmp; + __wt_block_desc_byteswap(desc); /* * We fail the open if the checksum fails, or the magic number is wrong @@ -348,10 +359,7 @@ __desc_read(WT_SESSION_IMPL *session, WT_BLOCK *block) * may have entered the wrong file name, and is now frantically pounding * their interrupt key. */ - cksum = desc->cksum; - desc->cksum = 0; - if (desc->magic != WT_BLOCK_MAGIC || - cksum != __wt_cksum(desc, block->allocsize)) + if (desc->magic != WT_BLOCK_MAGIC || desc->cksum != cksum_calculate) WT_ERR_MSG(session, WT_ERROR, "%s does not appear to be a WiredTiger file", block->name); @@ -365,6 +373,14 @@ __desc_read(WT_SESSION_IMPL *session, WT_BLOCK *block) WT_BLOCK_MAJOR_VERSION, WT_BLOCK_MINOR_VERSION, desc->majorv, desc->minorv); + WT_ERR(__wt_verbose(session, WT_VERB_BLOCK, + "%s: magic %" PRIu32 + ", major/minor: %" PRIu32 "/%" PRIu32 + ", checksum %#" PRIx32, + block->name, desc->magic, + desc->majorv, desc->minorv, + desc->cksum)); + err: __wt_scr_free(session, &buf); return (ret); } diff --git a/src/third_party/wiredtiger/src/block/block_read.c b/src/third_party/wiredtiger/src/block/block_read.c index 0e5911ecf2a..6e74d7a7793 100644 --- a/src/third_party/wiredtiger/src/block/block_read.c +++ b/src/third_party/wiredtiger/src/block/block_read.c @@ -139,6 +139,7 @@ __wt_block_read_off_blind( WT_RET(__wt_read( session, block->fh, offset, (size_t)block->allocsize, buf->mem)); blk = WT_BLOCK_HEADER_REF(buf->mem); + __wt_block_header_byteswap(blk); /* * Copy out the size and checksum (we're about to re-use the buffer), @@ -163,7 +164,7 @@ int __wt_block_read_off(WT_SESSION_IMPL *session, WT_BLOCK *block, WT_ITEM *buf, wt_off_t offset, uint32_t size, uint32_t cksum) { - WT_BLOCK_HEADER *blk; + WT_BLOCK_HEADER *blk, swap; size_t bufsize; uint32_t page_cksum; @@ -193,14 +194,26 @@ __wt_block_read_off(WT_SESSION_IMPL *session, WT_BLOCK *block, WT_RET(__wt_read(session, block->fh, offset, size, buf->mem)); buf->size = size; + /* + * We incrementally read through the structure before doing a checksum, + * do little- to big-endian handling early on, and then select from the + * original or swapped structure as needed. + */ blk = WT_BLOCK_HEADER_REF(buf->mem); - if (blk->cksum == cksum) { + __wt_block_header_byteswap_copy(blk, &swap); + if (swap.cksum == cksum) { blk->cksum = 0; page_cksum = __wt_cksum(buf->mem, - F_ISSET(blk, WT_BLOCK_DATA_CKSUM) ? + F_ISSET(&swap, WT_BLOCK_DATA_CKSUM) ? size : WT_BLOCK_COMPRESS_SKIP); - if (page_cksum == cksum) + if (page_cksum == cksum) { + /* + * Swap the page-header as needed; this doesn't belong + * here, but it's the best place to catch all callers. + */ + __wt_page_header_byteswap(buf->mem); return (0); + } if (!F_ISSET(session, WT_SESSION_QUIET_CORRUPT_FILE)) __wt_errx(session, @@ -216,7 +229,7 @@ __wt_block_read_off(WT_SESSION_IMPL *session, WT_BLOCK *block, "offset %" PRIuMAX ": block header checksum " "of %" PRIu32 " doesn't match expected checksum " "of %" PRIu32, - size, (uintmax_t)offset, blk->cksum, cksum); + size, (uintmax_t)offset, swap.cksum, cksum); /* Panic if a checksum fails during an ordinary read. */ return (block->verify || diff --git a/src/third_party/wiredtiger/src/block/block_slvg.c b/src/third_party/wiredtiger/src/block/block_slvg.c index ef22c727db4..a8cccd53023 100644 --- a/src/third_party/wiredtiger/src/block/block_slvg.c +++ b/src/third_party/wiredtiger/src/block/block_slvg.c @@ -126,6 +126,7 @@ __wt_block_salvage_next(WT_SESSION_IMPL *session, WT_ERR(__wt_read( session, fh, offset, (size_t)allocsize, tmp->mem)); blk = WT_BLOCK_HEADER_REF(tmp->mem); + __wt_block_header_byteswap(blk); size = blk->disk_size; cksum = blk->cksum; diff --git a/src/third_party/wiredtiger/src/block/block_write.c b/src/third_party/wiredtiger/src/block/block_write.c index 23f4d7650b9..4c6ac198fe4 100644 --- a/src/third_party/wiredtiger/src/block/block_write.c +++ b/src/third_party/wiredtiger/src/block/block_write.c @@ -203,11 +203,18 @@ __wt_block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block, WT_FH *fh; size_t align_size; wt_off_t offset; + uint32_t cksum; bool local_locked; blk = WT_BLOCK_HEADER_REF(buf->mem); fh = block->fh; + /* + * Swap the page-header as needed; this doesn't belong here, but it's + * the best place to catch all callers. + */ + __wt_page_header_byteswap(buf->mem); + /* Buffers should be aligned for writing. */ if (!F_ISSET(buf, WT_ITEM_ALIGNED)) { WT_ASSERT(session, F_ISSET(buf, WT_ITEM_ALIGNED)); @@ -255,13 +262,21 @@ __wt_block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block, * because they're not compressed, both to give salvage a quick test * of whether a block is useful and to give us a test so we don't lose * the first WT_BLOCK_COMPRESS_SKIP bytes without noticing. + * + * Checksum a little-endian version of the header, and write everything + * in little-endian format. The checksum is (potentially) returned in a + * big-endian format, swap it into place in a separate step. */ blk->flags = 0; if (data_cksum) F_SET(blk, WT_BLOCK_DATA_CKSUM); blk->cksum = 0; - blk->cksum = __wt_cksum( + __wt_block_header_byteswap(blk); + blk->cksum = cksum = __wt_cksum( buf->mem, data_cksum ? align_size : WT_BLOCK_COMPRESS_SKIP); +#ifdef WORDS_BIGENDIAN + blk->cksum = __wt_bswap32(blk->cksum); +#endif /* Pre-allocate some number of extension structures. */ WT_RET(__wt_block_ext_prealloc(session, 5)); @@ -325,11 +340,11 @@ __wt_block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block, WT_RET(__wt_verbose(session, WT_VERB_WRITE, "off %" PRIuMAX ", size %" PRIuMAX ", cksum %" PRIu32, - (uintmax_t)offset, (uintmax_t)align_size, blk->cksum)); + (uintmax_t)offset, (uintmax_t)align_size, cksum)); *offsetp = offset; *sizep = WT_STORE_SIZE(align_size); - *cksump = blk->cksum; + *cksump = cksum; - return (ret); + return (0); } diff --git a/src/third_party/wiredtiger/src/btree/bt_handle.c b/src/third_party/wiredtiger/src/btree/bt_handle.c index 7f0f37d95d6..2db3ca7d984 100644 --- a/src/third_party/wiredtiger/src/btree/bt_handle.c +++ b/src/third_party/wiredtiger/src/btree/bt_handle.c @@ -329,7 +329,7 @@ __btree_conf(WT_SESSION_IMPL *session, WT_CKPT *ckpt) * always inherit from the connection. */ WT_RET(__wt_config_gets(session, cfg, "encryption.name", &cval)); - if (WT_IS_METADATA(btree->dhandle) || cval.len == 0) + if (WT_IS_METADATA(session, btree->dhandle) || cval.len == 0) btree->kencryptor = conn->kencryptor; else if (WT_STRING_MATCH("none", cval.str, cval.len)) btree->kencryptor = NULL; @@ -420,7 +420,7 @@ __wt_btree_tree_open( * Failure to open metadata means that the database is unavailable. * Try to provide a helpful failure message. */ - if (ret != 0 && WT_IS_METADATA(session->dhandle)) { + if (ret != 0 && WT_IS_METADATA(session, session->dhandle)) { __wt_errx(session, "WiredTiger has failed to open its metadata"); __wt_errx(session, "This may be due to the database" diff --git a/src/third_party/wiredtiger/src/btree/bt_split.c b/src/third_party/wiredtiger/src/btree/bt_split.c index ac83a21ac6f..bd38451d5d1 100644 --- a/src/third_party/wiredtiger/src/btree/bt_split.c +++ b/src/third_party/wiredtiger/src/btree/bt_split.c @@ -875,16 +875,24 @@ __split_parent(WT_SESSION_IMPL *session, WT_REF *ref, WT_REF **ref_new, /* The split is complete and correct, ignore benign errors. */ complete = WT_ERR_IGNORE; - WT_ERR(__wt_verbose(session, WT_VERB_SPLIT, - "%p: %s %s" "split into parent %p, %" PRIu32 " -> %" PRIu32 - " (%s%" PRIu32 ")", - ref->page, ref->page == NULL ? - "unknown page type" : __wt_page_type_string(ref->page->type), - ref->page == NULL ? "reverse " : "", parent, - parent_entries, result_entries, - ref->page == NULL ? "-" : "+", - ref->page == NULL ? - parent_entries - result_entries : result_entries - parent_entries)); + /* + * !!! + * Swapping in the new page index released the page for eviction, we can + * no longer look inside the page. + */ + + if (ref->page == NULL) + WT_ERR(__wt_verbose(session, WT_VERB_SPLIT, + "%p: reverse split into parent %p, %" PRIu32 " -> %" PRIu32 + " (-%" PRIu32 ")", + ref->page, parent, parent_entries, result_entries, + parent_entries - result_entries)); + else + WT_ERR(__wt_verbose(session, WT_VERB_SPLIT, + "%p: split into parent %p, %" PRIu32 " -> %" PRIu32 + " (+%" PRIu32 ")", + ref->page, parent, parent_entries, result_entries, + result_entries - parent_entries)); /* * The new page index is in place, free the WT_REF we were splitting and @@ -935,8 +943,10 @@ __split_parent(WT_SESSION_IMPL *session, WT_REF *ref, WT_REF **ref_new, parent_decr += sizeof(WT_REF); } - /* We freed the reference that was split in the loop above. */ - ref = NULL; + /* + * !!! + * The original WT_REF has now been freed, we can no longer look at it. + */ /* * We can't free the previous page index, there may be threads using it. diff --git a/src/third_party/wiredtiger/src/btree/bt_walk.c b/src/third_party/wiredtiger/src/btree/bt_walk.c index 49a59b89552..55b11d7b2d1 100644 --- a/src/third_party/wiredtiger/src/btree/bt_walk.c +++ b/src/third_party/wiredtiger/src/btree/bt_walk.c @@ -89,11 +89,11 @@ __ref_is_leaf(WT_REF *ref) } /* - * __page_ascend -- + * __ref_ascend -- * Ascend the tree one level. */ -static void -__page_ascend(WT_SESSION_IMPL *session, +static inline void +__ref_ascend(WT_SESSION_IMPL *session, WT_REF **refp, WT_PAGE_INDEX **pindexp, uint32_t *slotp) { WT_REF *parent_ref, *ref; @@ -163,23 +163,20 @@ __page_ascend(WT_SESSION_IMPL *session, } /* - * __page_descend -- - * Descend the tree one level. + * __ref_descend_prev -- + * Descend the tree one level, during a previous-cursor walk. */ -static void -__page_descend(WT_SESSION_IMPL *session, - WT_PAGE *page, WT_PAGE_INDEX **pindexp, uint32_t *slotp, bool prev) +static inline void +__ref_descend_prev( + WT_SESSION_IMPL *session, WT_REF *ref, WT_PAGE_INDEX **pindexp) { WT_PAGE_INDEX *pindex; /* - * Ref is a child page into which we're descending, and on which we - * have a hazard pointer. + * We're passed a child page into which we're descending, and on which + * we have a hazard pointer. */ for (;; __wt_yield()) { - WT_INTL_INDEX_GET(session, page, pindex); - *slotp = prev ? pindex->entries - 1 : 0; - /* * There's a split race when a cursor moving backwards through * the tree descends the tree. If we're splitting an internal @@ -233,21 +230,41 @@ __page_descend(WT_SESSION_IMPL *session, * being split and part of its namespace moved. We have the * correct page and we don't have to move, all we have to do is * wait until the split page's page index is updated. - * - * No test is necessary for a next-cursor movement because we - * do right-hand splits on internal pages and the initial part - * of the page's namespace won't change as part of a split. - * Instead of testing the direction boolean, do the test the - * previous cursor movement requires in all cases, even though - * it will always succeed for a next-cursor movement. */ - if (pindex->index[*slotp]->home == page) + WT_INTL_INDEX_GET(session, ref->page, pindex); + if (pindex->index[pindex->entries - 1]->home == ref->page) break; } *pindexp = pindex; } /* + * __ref_initial_descent_prev -- + * Descend the tree one level, when setting up the initial cursor position + * for a previous-cursor walk. + */ +static inline bool +__ref_initial_descent_prev( + WT_SESSION_IMPL *session, WT_REF *ref, WT_PAGE_INDEX **pindexp) +{ + WT_PAGE_INDEX *pindex; + + /* + * We're passed a child page into which we're descending, and on which + * we have a hazard pointer. + * + * Acquire a page index for the child page and then confirm we haven't + * raced with a parent split. + */ + WT_INTL_INDEX_GET(session, ref->page, pindex); + if (__wt_split_descent_race(session, ref, *pindexp)) + return (false); + + *pindexp = pindex; + return (true); +} + +/* * __tree_walk_internal -- * Move to the next/previous page in the tree. */ @@ -259,11 +276,12 @@ __tree_walk_internal(WT_SESSION_IMPL *session, WT_DECL_RET; WT_PAGE_INDEX *pindex; WT_REF *couple, *couple_orig, *ref; - bool empty_internal, prev, skip; + bool empty_internal, initial_descent, prev, skip; uint32_t slot; btree = S2BT(session); - empty_internal = false; + pindex = NULL; + empty_internal = initial_descent = false; /* * Tree walks are special: they look inside page structures that splits @@ -323,22 +341,30 @@ __tree_walk_internal(WT_SESSION_IMPL *session, couple = couple_orig = ref = *refp; *refp = NULL; - /* If no page is active, begin a walk from the start of the tree. */ + /* If no page is active, begin a walk from the start/end of the tree. */ if (ref == NULL) { - ref = &btree->root; +restart: /* + * We can reach here with a NULL or root reference; the release + * function handles them internally, don't complicate this code + * by calling them out. + */ + WT_ERR(__wt_page_release(session, couple, flags)); + + couple = couple_orig = ref = &btree->root; if (ref->page == NULL) goto done; + + initial_descent = true; goto descend; } /* - * If the active page was the root, we've reached the walk's end. - * Release any hazard-pointer we're holding. + * If the active page was the root, we've reached the walk's end; we + * only get here if we've returned the root to our caller, so we're + * holding no hazard pointers. */ - if (__wt_ref_is_root(ref)) { - WT_ERR(__wt_page_release(session, couple, flags)); + if (__wt_ref_is_root(ref)) goto done; - } /* Figure out the current slot in the WT_REF array. */ __ref_index_slot(session, ref, &pindex, &slot); @@ -352,7 +378,7 @@ __tree_walk_internal(WT_SESSION_IMPL *session, while ((prev && slot == 0) || (!prev && slot == pindex->entries - 1)) { /* Ascend to the parent. */ - __page_ascend(session, &ref, &pindex, &slot); + __ref_ascend(session, &ref, &pindex, &slot); /* * If we got all the way through an internal page and @@ -521,16 +547,21 @@ __tree_walk_internal(WT_SESSION_IMPL *session, ret = 0; /* + * If a cursor is setting up at the end of the + * tree, we can't use our parent page's index, + * because it may have already split; restart + * the walk. + */ + if (prev && initial_descent) + goto restart; + + /* * If a new walk that never coupled from the * root to a new saved position in the tree, * restart the walk. */ - if (couple == &btree->root) { - ref = &btree->root; - if (ref->page == NULL) - goto done; - goto descend; - } + if (couple == &btree->root) + goto restart; /* * If restarting from some original position, @@ -561,10 +592,56 @@ __tree_walk_internal(WT_SESSION_IMPL *session, descend: couple = ref; empty_internal = true; - __page_descend( - session, ref->page, &pindex, &slot, prev); + /* + * There's a split race when a cursor is setting + * up at the end of the tree or moving backwards + * through the tree and descending a level. When + * splitting an internal page into its parent, + * we move the WT_REF structures and update the + * parent's page index before updating the split + * page's page index, and it's not an atomic + * update. A thread can read the parent page's + * replacement page index, then read the split + * page's original index, or the parent page's + * original and the split page's replacement. + * + * This isn't a problem for a cursor setting up + * at the start of the tree or moving forwards + * through the tree because we do right-hand + * splits on internal pages and the initial part + * of the split page's namespace won't change as + * part of a split. A thread reading the parent + * page's and split page's indexes will move to + * the same slot no matter what order of indexes + * are read. + * + * Handle a cursor setting up at the end of the + * tree or moving backwards through the tree. + */ + if (!prev) { + WT_INTL_INDEX_GET( + session, ref->page, pindex); + slot = 0; + } else if (initial_descent) { + if (!__ref_initial_descent_prev( + session, ref, &pindex)) + goto restart; + slot = pindex->entries - 1; + } else { + __ref_descend_prev( + session, ref, &pindex); + slot = pindex->entries - 1; + } } else { /* + * At the lowest tree level (considering a leaf + * page), turn off the initial-descent state. + * Descent race tests are different when moving + * through the tree vs. the initial descent. + */ + initial_descent = false; + + /* * Optionally skip leaf pages, the second half. * We didn't have an on-page cell to figure out * if it was a leaf page, we had to acquire the @@ -605,7 +682,7 @@ __wt_tree_walk(WT_SESSION_IMPL *session, WT_REF **refp, uint32_t flags) /* * __wt_tree_walk_count -- * Move to the next/previous page in the tree, tracking how many - * references were visited to get there. + * references were visited to get there. */ int __wt_tree_walk_count(WT_SESSION_IMPL *session, diff --git a/src/third_party/wiredtiger/src/btree/col_srch.c b/src/third_party/wiredtiger/src/btree/col_srch.c index cb5a227495f..3aa31044b82 100644 --- a/src/third_party/wiredtiger/src/btree/col_srch.c +++ b/src/third_party/wiredtiger/src/btree/col_srch.c @@ -137,12 +137,12 @@ restart_page: page = current->page; * If on the last slot (the key is larger than any key * on the page), check for an internal page split race. */ - if (parent_pindex != NULL && - __wt_split_intl_race( - session, current->home, parent_pindex)) { + if (__wt_split_descent_race( + session, current, parent_pindex)) { WT_RET(__wt_page_release(session, current, 0)); goto restart_root; } + goto descend; } diff --git a/src/third_party/wiredtiger/src/btree/row_srch.c b/src/third_party/wiredtiger/src/btree/row_srch.c index c06274cdb17..28c55a4ccd0 100644 --- a/src/third_party/wiredtiger/src/btree/row_srch.c +++ b/src/third_party/wiredtiger/src/btree/row_srch.c @@ -287,9 +287,26 @@ restart_page: page = current->page; WT_INTL_INDEX_GET(session, page, pindex); - /* Fast-path appends. */ + /* + * Fast-path appends. + * + * The 0th key on an internal page is a problem for a couple of + * reasons. First, we have to force the 0th key to sort less + * than any application key, so internal pages don't have to be + * updated if the application stores a new, "smallest" key in + * the tree. Second, reconciliation is aware of this and will + * store a byte of garbage in the 0th key, so the comparison of + * an application key and a 0th key is meaningless (but doing + * the comparison could still incorrectly modify our tracking + * of the leading bytes in each key that we can skip during the + * comparison). For these reasons, special-case the 0th key, and + * never pass it to a collator. + */ if (append_check) { descent = pindex->index[pindex->entries - 1]; + + if (pindex->entries == 1) + goto append; __wt_ref_key(page, descent, &item->data, &item->size); WT_ERR(__wt_compare( session, collator, srch_key, item, &cmp)); @@ -307,16 +324,8 @@ restart_page: page = current->page; * collation order), because doing the tests and error handling * inside the loop costs about 5%. * - * The 0th key on an internal page is a problem for a couple of - * reasons. First, we have to force the 0th key to sort less - * than any application key, so internal pages don't have to be - * updated if the application stores a new, "smallest" key in - * the tree. Second, reconciliation is aware of this and will - * store a byte of garbage in the 0th key, so the comparison of - * an application key and a 0th key is meaningless (but doing - * the comparison could still incorrectly modify our tracking - * of the leading bytes in each key that we can skip during the - * comparison). For these reasons, skip the 0th key. + * Reference the comment above about the 0th key: we continue to + * special-case it. */ base = 1; limit = pindex->entries - 1; @@ -409,9 +418,8 @@ restart_page: page = current->page; * page), check for an internal page split race. */ if (pindex->entries == base) { -append: if (parent_pindex != NULL && - __wt_split_intl_race( - session, current->home, parent_pindex)) { +append: if (__wt_split_descent_race( + session, current, parent_pindex)) { if ((ret = __wt_page_release( session, current, 0)) != 0) return (ret); diff --git a/src/third_party/wiredtiger/src/conn/conn_api.c b/src/third_party/wiredtiger/src/conn/conn_api.c index 2f62950a36e..27977de63b2 100644 --- a/src/third_party/wiredtiger/src/conn/conn_api.c +++ b/src/third_party/wiredtiger/src/conn/conn_api.c @@ -402,7 +402,7 @@ __wt_encryptor_config(WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cval, { WT_CONNECTION_IMPL *conn; WT_DECL_RET; - WT_ENCRYPTOR *encryptor; + WT_ENCRYPTOR *custom, *encryptor; WT_KEYED_ENCRYPTOR *kenc; WT_NAMED_ENCRYPTOR *nenc; uint64_t bucket, hash; @@ -440,12 +440,13 @@ __wt_encryptor_config(WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cval, WT_ERR(__wt_strndup(session, keyid->str, keyid->len, &kenc->keyid)); encryptor = nenc->encryptor; if (encryptor->customize != NULL) { + custom = NULL; WT_ERR(encryptor->customize(encryptor, &session->iface, - cfg_arg, &encryptor)); - if (encryptor == NULL) - encryptor = nenc->encryptor; - else + cfg_arg, &custom)); + if (custom != NULL) { kenc->owned = 1; + encryptor = custom; + } } WT_ERR(encryptor->sizing(encryptor, &session->iface, &kenc->size_const)); @@ -2065,6 +2066,8 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler, * DATABASE HOME, IT'S WHAT WE USE TO DECIDE IF WE'RE CREATING OR NOT. */ WT_ERR(__wt_turtle_init(session)); + + __wt_metadata_init(session); WT_ERR(__wt_metadata_cursor(session, NULL)); /* Start the worker threads and run recovery. */ diff --git a/src/third_party/wiredtiger/src/conn/conn_dhandle.c b/src/third_party/wiredtiger/src/conn/conn_dhandle.c index dedafc2b102..60136a71b99 100644 --- a/src/third_party/wiredtiger/src/conn/conn_dhandle.c +++ b/src/third_party/wiredtiger/src/conn/conn_dhandle.c @@ -421,7 +421,7 @@ __wt_conn_btree_apply(WT_SESSION_IMPL *session, (apply_checkpoints || dhandle->checkpoint == NULL) && WT_PREFIX_MATCH(dhandle->name, "file:") && - !WT_IS_METADATA(dhandle)) + !WT_IS_METADATA(session, dhandle)) WT_RET(__conn_btree_apply_internal( session, dhandle, func, cfg)); } @@ -644,7 +644,7 @@ __wt_conn_dhandle_discard_single( F_SET(S2C(session)->cache, WT_CACHE_CLEAR_WALKS); /* Try to remove the handle, protected by the data handle lock. */ - WT_WITH_HANDLE_LIST_LOCK(session, tret, + WT_WITH_HANDLE_LIST_LOCK(session, tret = __conn_dhandle_remove(session, final)); WT_TRET(tret); @@ -686,7 +686,7 @@ __wt_conn_dhandle_discard(WT_SESSION_IMPL *session) */ restart: TAILQ_FOREACH(dhandle, &conn->dhqh, q) { - if (WT_IS_METADATA(dhandle)) + if (WT_IS_METADATA(session, dhandle)) continue; WT_WITH_DHANDLE(session, dhandle, diff --git a/src/third_party/wiredtiger/src/conn/conn_log.c b/src/third_party/wiredtiger/src/conn/conn_log.c index ed226393fb0..60f46288072 100644 --- a/src/third_party/wiredtiger/src/conn/conn_log.c +++ b/src/third_party/wiredtiger/src/conn/conn_log.c @@ -180,9 +180,10 @@ __log_archive_once(WT_SESSION_IMPL *session, uint32_t backup_file) * disk and the checkpoint LSN. */ if (backup_file != 0) - min_lognum = WT_MIN(log->ckpt_lsn.file, backup_file); + min_lognum = WT_MIN(log->ckpt_lsn.l.file, backup_file); else - min_lognum = WT_MIN(log->ckpt_lsn.file, log->sync_lsn.file); + min_lognum = WT_MIN( + log->ckpt_lsn.l.file, log->sync_lsn.l.file); WT_RET(__wt_verbose(session, WT_VERB_LOG, "log_archive: archive to log number %" PRIu32, min_lognum)); @@ -218,8 +219,7 @@ __log_archive_once(WT_SESSION_IMPL *session, uint32_t backup_file) * Indicate what is our new earliest LSN. It is the start * of the log file containing the last checkpoint. */ - log->first_lsn.file = min_lognum; - log->first_lsn.offset = 0; + WT_SET_LSN(&log->first_lsn, min_lognum, 0); if (0) err: __wt_err(session, ret, "log archive server error"); @@ -317,7 +317,7 @@ __wt_log_truncate_files( backup_file = 0; if (cursor != NULL) backup_file = WT_CURSOR_BACKUP_ID(cursor); - WT_ASSERT(session, backup_file <= log->alloc_lsn.file); + WT_ASSERT(session, backup_file <= log->alloc_lsn.l.file); WT_RET(__wt_verbose(session, WT_VERB_LOG, "log_truncate_files: Archive once up to %" PRIu32, backup_file)); @@ -367,7 +367,7 @@ __log_file_server(void *arg) * could see mismatched settings. If we do, yield * until it is set. This should rarely happen. */ - while (log->log_close_lsn.file < filenum) + while (log->log_close_lsn.l.file < filenum) __wt_yield(); if (__wt_log_cmp( @@ -398,10 +398,10 @@ __log_file_server(void *arg) * actual data and has minimal pre-allocated * zeroed space. */ - WT_ERR(__wt_ftruncate( - session, close_fh, close_end_lsn.offset)); - close_end_lsn.file++; - close_end_lsn.offset = 0; + WT_ERR(__wt_ftruncate(session, + close_fh, close_end_lsn.l.offset)); + WT_SET_LSN(&close_end_lsn, + close_end_lsn.l.file + 1, 0); __wt_spin_lock(session, &log->log_sync_lock); locked = true; WT_ERR(__wt_close(session, &close_fh)); @@ -440,9 +440,9 @@ __log_file_server(void *arg) * this worker thread process that older file * immediately. */ - if ((log->sync_lsn.file < - log->bg_sync_lsn.file) || - (log->sync_lsn.file < min_lsn.file)) + if ((log->sync_lsn.l.file < + log->bg_sync_lsn.l.file) || + (log->sync_lsn.l.file < min_lsn.l.file)) continue; WT_ERR(__wt_fsync(session, log->log_fh)); __wt_spin_lock(session, &log->log_sync_lock); @@ -454,7 +454,8 @@ __log_file_server(void *arg) if (__wt_log_cmp( &log->sync_lsn, &min_lsn) <= 0) { WT_ASSERT(session, - min_lsn.file == log->sync_lsn.file); + min_lsn.l.file == + log->sync_lsn.l.file); log->sync_lsn = min_lsn; WT_ERR(__wt_cond_signal( session, log->log_sync_cond)); @@ -500,9 +501,9 @@ typedef struct { * Return comparison of a written slot pair by LSN. */ #define WT_WRLSN_ENTRY_CMP_LT(entry1, entry2) \ - ((entry1).lsn.file < (entry2).lsn.file || \ - ((entry1).lsn.file == (entry2).lsn.file && \ - (entry1).lsn.offset < (entry2).lsn.offset)) + ((entry1).lsn.l.file < (entry2).lsn.l.file || \ + ((entry1).lsn.l.file == (entry2).lsn.l.file && \ + (entry1).lsn.l.offset < (entry2).lsn.l.offset)) /* * __wt_log_wrlsn -- @@ -539,7 +540,7 @@ restart: save_i = i; slot = &log->slot_pool[i++]; WT_ASSERT(session, slot->slot_state != 0 || - slot->slot_release_lsn.file >= log->write_lsn.file); + slot->slot_release_lsn.l.file >= log->write_lsn.l.file); if (slot->slot_state != WT_LOG_SLOT_WRITTEN) continue; written[written_i].slot_index = save_i; @@ -629,9 +630,9 @@ restart: * the checkpoint LSN is close to the end of * the record. */ - if (slot->slot_start_lsn.offset != + if (slot->slot_start_lsn.l.offset != slot->slot_last_offset) - slot->slot_start_lsn.offset = + slot->slot_start_lsn.l.offset = slot->slot_last_offset; log->write_start_lsn = slot->slot_start_lsn; log->write_lsn = slot->slot_end_lsn; diff --git a/src/third_party/wiredtiger/src/conn/conn_stat.c b/src/third_party/wiredtiger/src/conn/conn_stat.c index 9edc6091b10..08ad105c725 100644 --- a/src/third_party/wiredtiger/src/conn/conn_stat.c +++ b/src/third_party/wiredtiger/src/conn/conn_stat.c @@ -340,7 +340,7 @@ __statlog_log_one(WT_SESSION_IMPL *session, WT_ITEM *path, WT_ITEM *tmp) * any that match the list of object sources. */ if (conn->stat_sources != NULL) { - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_conn_btree_apply( session, false, NULL, __statlog_apply, NULL)); WT_RET(ret); diff --git a/src/third_party/wiredtiger/src/conn/conn_sweep.c b/src/third_party/wiredtiger/src/conn/conn_sweep.c index a15aabdd6fe..7628076e605 100644 --- a/src/third_party/wiredtiger/src/conn/conn_sweep.c +++ b/src/third_party/wiredtiger/src/conn/conn_sweep.c @@ -26,7 +26,7 @@ __sweep_mark(WT_SESSION_IMPL *session, time_t now) conn = S2C(session); TAILQ_FOREACH(dhandle, &conn->dhqh, q) { - if (WT_IS_METADATA(dhandle)) + if (WT_IS_METADATA(session, dhandle)) continue; /* @@ -124,7 +124,7 @@ __sweep_expire(WT_SESSION_IMPL *session, time_t now) if (conn->open_btree_count < conn->sweep_handles_min) break; - if (WT_IS_METADATA(dhandle) || + if (WT_IS_METADATA(session, dhandle) || !F_ISSET(dhandle, WT_DHANDLE_OPEN) || dhandle->session_inuse != 0 || dhandle->timeofdeath == 0 || @@ -230,12 +230,12 @@ __sweep_remove_handles(WT_SESSION_IMPL *session) dhandle != NULL; dhandle = dhandle_next) { dhandle_next = TAILQ_NEXT(dhandle, q); - if (WT_IS_METADATA(dhandle)) + if (WT_IS_METADATA(session, dhandle)) continue; if (!WT_DHANDLE_CAN_DISCARD(dhandle)) continue; - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __sweep_remove_one(session, dhandle)); if (ret == 0) WT_STAT_FAST_CONN_INCR(session, dh_sweep_remove); diff --git a/src/third_party/wiredtiger/src/cursor/cur_backup.c b/src/third_party/wiredtiger/src/cursor/cur_backup.c index 6d5d68000ee..d7d74da48d4 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_backup.c +++ b/src/third_party/wiredtiger/src/cursor/cur_backup.c @@ -377,7 +377,7 @@ __backup_all(WT_SESSION_IMPL *session, WT_CURSOR_BACKUP *cb) WT_ERR(__wt_metadata_cursor_release(session, &cursor)); /* Build a list of the file objects that need to be copied. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, ret = + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_meta_btree_apply(session, __backup_list_all_append, NULL)); err: WT_TRET(__wt_metadata_cursor_release(session, &cursor)); diff --git a/src/third_party/wiredtiger/src/cursor/cur_log.c b/src/third_party/wiredtiger/src/cursor/cur_log.c index 35a2d00e6ec..3fcd8a86066 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_log.c +++ b/src/third_party/wiredtiger/src/cursor/cur_log.c @@ -187,13 +187,13 @@ __curlog_kv(WT_SESSION_IMPL *session, WT_CURSOR *cursor) if (FLD_ISSET(cursor->flags, WT_CURSTD_RAW)) { memset(&item, 0, sizeof(item)); WT_RET(wiredtiger_struct_size((WT_SESSION *)session, - &item.size, WT_LOGC_KEY_FORMAT, cl->cur_lsn->file, - cl->cur_lsn->offset, key_count)); + &item.size, WT_LOGC_KEY_FORMAT, cl->cur_lsn->l.file, + cl->cur_lsn->l.offset, key_count)); WT_RET(__wt_realloc(session, NULL, item.size, &cl->packed_key)); item.data = cl->packed_key; WT_RET(wiredtiger_struct_pack((WT_SESSION *)session, cl->packed_key, item.size, WT_LOGC_KEY_FORMAT, - cl->cur_lsn->file, cl->cur_lsn->offset, key_count)); + cl->cur_lsn->l.file, cl->cur_lsn->l.offset, key_count)); __wt_cursor_set_key(cursor, &item); WT_RET(wiredtiger_struct_size((WT_SESSION *)session, @@ -208,8 +208,8 @@ __curlog_kv(WT_SESSION_IMPL *session, WT_CURSOR *cursor) cl->opvalue)); __wt_cursor_set_value(cursor, &item); } else { - __wt_cursor_set_key(cursor, cl->cur_lsn->file, - cl->cur_lsn->offset, key_count); + __wt_cursor_set_key(cursor, cl->cur_lsn->l.file, + cl->cur_lsn->l.offset, key_count); __wt_cursor_set_value(cursor, cl->txnid, cl->rectype, optype, fileid, cl->opkey, cl->opvalue); } @@ -264,7 +264,7 @@ __curlog_search(WT_CURSOR *cursor) WT_DECL_RET; WT_LSN key; WT_SESSION_IMPL *session; - uint32_t counter; + uint32_t counter, key_file, key_offset; cl = (WT_CURSOR_LOG *)cursor; @@ -274,7 +274,8 @@ __curlog_search(WT_CURSOR *cursor) * !!! We are ignoring the counter and only searching based on the LSN. */ WT_ERR(__wt_cursor_get_key((WT_CURSOR *)cl, - &key.file, &key.offset, &counter)); + &key_file, &key_offset, &counter)); + WT_SET_LSN(&key, key_file, key_offset); ret = __wt_log_scan(session, &key, WT_LOGSCAN_ONE, __curlog_logrec, cl); if (ret == ENOENT) diff --git a/src/third_party/wiredtiger/src/docs/build-posix.dox b/src/third_party/wiredtiger/src/docs/build-posix.dox index f61b199bff2..4889bf931c9 100644 --- a/src/third_party/wiredtiger/src/docs/build-posix.dox +++ b/src/third_party/wiredtiger/src/docs/build-posix.dox @@ -116,10 +116,6 @@ The WiredTiger software supports some additional configuration options: Configure WiredTiger to sleep and wait for a debugger to attach on failure. <b>DO NOT</b> configure this option in production environments. -@par \c --enable-bzip2 -Configure WiredTiger for <a href="http://www.bzip.org/">bzip2</a> -compression; see @ref compression for more information. - @par \c --enable-diagnostic Configure WiredTiger to perform various run-time diagnostic tests. <b>DO NOT</b> configure this option in production environments. diff --git a/src/third_party/wiredtiger/src/docs/compression.dox b/src/third_party/wiredtiger/src/docs/compression.dox index 56715e20752..0be96835760 100644 --- a/src/third_party/wiredtiger/src/docs/compression.dox +++ b/src/third_party/wiredtiger/src/docs/compression.dox @@ -1,36 +1,7 @@ /*! @m_page{{c,java},compression,Compressors} This section explains how to configure WiredTiger's builtin support for -the bzip2, lz4, snappy and zlib compression engines. - -@section compression_bzip2 Using bzip2 compression - -To use the builtin support for -<a href="http://www.bzip.org/">Julian Seward's bzip2</a> -compression, first check that bzip2 is installed in include and library -directories searched by the compiler. Once bzip2 is installed, you can -enable bzip2 using the \c --enable-bzip2 option to configure. - -If bzip2 is installed in a location not normally searched by the -compiler toolchain, you'll need to modify the \c CPPFLAGS and \c LDFLAGS -to indicate these locations. For example, with the bzip2 includes and -libraries installed in \c /usr/local/include and \c /usr/local/lib, you -would run configure with the following additional arguments: - -@code ---enable-bzip2 CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/include" -@endcode - -When opening the WiredTiger database, load the bzip2 shared library as -an extension. For example, with the WiredTiger library installed in -\c /usr/local/lib, you would use the following extension: - -@snippet ex_all.c Configure bzip2 extension - -Finally, when creating the WiredTiger object, set \c block_compressor -to \c bzip2: - -@snippet ex_all.c Create a bzip2 compressed table +the lz4, snappy and zlib compression engines. @section compression_lz4 Using LZ4 compression diff --git a/src/third_party/wiredtiger/src/docs/upgrading.dox b/src/third_party/wiredtiger/src/docs/upgrading.dox index e0239919f0b..e4d85003a1e 100644 --- a/src/third_party/wiredtiger/src/docs/upgrading.dox +++ b/src/third_party/wiredtiger/src/docs/upgrading.dox @@ -27,6 +27,13 @@ reclaimed when the call returns. The performance of this API may differ from earlier releases. </dd> +<dt>Bzip2 compression support</dt> +<dd> +Support for the bzip2 compression/decompression engine has been removed +from the WiredTiger release; remaining compression engines include LZ4, +snappy and zlib. +</dd> + </dl><hr> @section version_270 Upgrading to Version 2.7.0 diff --git a/src/third_party/wiredtiger/src/docs/wtperf.dox b/src/third_party/wiredtiger/src/docs/wtperf.dox index 64e25978dd8..1f0d1533ac4 100644 --- a/src/third_party/wiredtiger/src/docs/wtperf.dox +++ b/src/third_party/wiredtiger/src/docs/wtperf.dox @@ -160,7 +160,7 @@ connection configuration string post-populate compact for LSM merging activity @par compression (string, default=none) compression extension. Allowed configuration values are: 'none', -'bzip', 'lz4', 'snappy', 'zlib' +'lz4', 'snappy', 'zlib' @par create (boolean, default=true) do population phase; false to use existing database @par database_count (unsigned int, default=1) diff --git a/src/third_party/wiredtiger/src/include/block.h b/src/third_party/wiredtiger/src/include/block.h index 27a140b73a4..10efd35086c 100644 --- a/src/third_party/wiredtiger/src/include/block.h +++ b/src/third_party/wiredtiger/src/include/block.h @@ -289,6 +289,23 @@ struct __wt_block_desc { #define WT_BLOCK_DESC_SIZE 16 /* + * __wt_block_desc_byteswap -- + * Handle big- and little-endian transformation of a description block. + */ +static inline void +__wt_block_desc_byteswap(WT_BLOCK_DESC *desc) +{ +#ifdef WORDS_BIGENDIAN + desc->magic = __wt_bswap32(desc->magic); + desc->majorv = __wt_bswap16(desc->majorv); + desc->minorv = __wt_bswap16(desc->minorv); + desc->cksum = __wt_bswap32(desc->cksum); +#else + WT_UNUSED(desc); +#endif +} + +/* * WT_BLOCK_HEADER -- * Blocks have a common header, a WT_PAGE_HEADER structure followed by a * block-manager specific structure: WT_BLOCK_HEADER is WiredTiger's default. @@ -331,6 +348,35 @@ struct __wt_block_header { #define WT_BLOCK_HEADER_SIZE 12 /* + * __wt_block_header_byteswap_copy -- + * Handle big- and little-endian transformation of a header block, + * copying from a source to a target. + */ +static inline void +__wt_block_header_byteswap_copy(WT_BLOCK_HEADER *from, WT_BLOCK_HEADER *to) +{ + *to = *from; +#ifdef WORDS_BIGENDIAN + to->disk_size = __wt_bswap32(from->disk_size); + to->cksum = __wt_bswap32(from->cksum); +#endif +} + +/* + * __wt_block_header_byteswap -- + * Handle big- and little-endian transformation of a header block. + */ +static inline void +__wt_block_header_byteswap(WT_BLOCK_HEADER *blk) +{ +#ifdef WORDS_BIGENDIAN + __wt_block_header_byteswap_copy(blk, blk); +#else + WT_UNUSED(blk); +#endif +} + +/* * WT_BLOCK_HEADER_BYTE * WT_BLOCK_HEADER_BYTE_SIZE -- * The first usable data byte on the block (past the combined headers). diff --git a/src/third_party/wiredtiger/src/include/btmem.h b/src/third_party/wiredtiger/src/include/btmem.h index cfbd87f0cae..ee495c52fc8 100644 --- a/src/third_party/wiredtiger/src/include/btmem.h +++ b/src/third_party/wiredtiger/src/include/btmem.h @@ -62,6 +62,23 @@ struct __wt_page_header { #define WT_PAGE_HEADER_SIZE 28 /* + * __wt_page_header_byteswap -- + * Handle big- and little-endian transformation of a page header. + */ +static inline void +__wt_page_header_byteswap(WT_PAGE_HEADER *dsk) +{ +#ifdef WORDS_BIGENDIAN + dsk->recno = __wt_bswap64(dsk->recno); + dsk->write_gen = __wt_bswap64(dsk->write_gen); + dsk->mem_size = __wt_bswap32(dsk->mem_size); + dsk->u.entries = __wt_bswap32(dsk->u.entries); +#else + WT_UNUSED(dsk); +#endif +} + +/* * The block-manager specific information immediately follows the WT_PAGE_HEADER * structure. */ diff --git a/src/third_party/wiredtiger/src/include/btree.i b/src/third_party/wiredtiger/src/include/btree.i index 94111397abd..b4b4d7f25a2 100644 --- a/src/third_party/wiredtiger/src/include/btree.i +++ b/src/third_party/wiredtiger/src/include/btree.i @@ -1294,19 +1294,19 @@ __wt_page_swap_func( bool acquired; /* - * In rare cases when walking the tree, we try to swap to the same - * page. Fast-path that to avoid thinking about error handling. - */ - if (held == want) - return (0); - - /* * This function is here to simplify the error handling during hazard * pointer coupling so we never leave a hazard pointer dangling. The * assumption is we're holding a hazard pointer on "held", and want to * acquire a hazard pointer on "want", releasing the hazard pointer on * "held" when we're done. + * + * When walking the tree, we sometimes swap to the same page. Fast-path + * that to avoid thinking about error handling. */ + if (held == want) + return (0); + + /* Get the wanted page. */ ret = __wt_page_in_func(session, want, flags #ifdef HAVE_DIAGNOSTIC , file, line @@ -1446,15 +1446,19 @@ __wt_btree_lsm_over_size(WT_SESSION_IMPL *session, uint64_t maxsize) } /* - * __wt_split_intl_race -- + * __wt_split_descent_race -- * Return if we raced with an internal page split when descending the tree. */ static inline bool -__wt_split_intl_race( - WT_SESSION_IMPL *session, WT_PAGE *parent, WT_PAGE_INDEX *saved_pindex) +__wt_split_descent_race( + WT_SESSION_IMPL *session, WT_REF *ref, WT_PAGE_INDEX *saved_pindex) { WT_PAGE_INDEX *pindex; + /* No test when starting the descent (there's no home to check). */ + if (__wt_ref_is_root(ref)) + return (false); + /* * A place to hang this comment... * @@ -1509,6 +1513,6 @@ __wt_split_intl_race( * content the split page retains after the split, and we ignore this * race. */ - WT_INTL_INDEX_GET(session, parent, pindex); + WT_INTL_INDEX_GET(session, ref->home, pindex); return (pindex != saved_pindex); } diff --git a/src/third_party/wiredtiger/src/include/connection.h b/src/third_party/wiredtiger/src/include/connection.h index 5d61f9456b3..88797e83ad6 100644 --- a/src/third_party/wiredtiger/src/include/connection.h +++ b/src/third_party/wiredtiger/src/include/connection.h @@ -364,6 +364,7 @@ struct __wt_connection_impl { uint32_t txn_logsync; /* Log sync configuration */ WT_SESSION_IMPL *meta_ckpt_session;/* Metadata checkpoint session */ + uint64_t meta_uri_hash; /* Metadata file name hash */ WT_SESSION_IMPL *sweep_session; /* Handle sweep session */ wt_thread_t sweep_tid; /* Handle sweep thread */ diff --git a/src/third_party/wiredtiger/src/include/extern.h b/src/third_party/wiredtiger/src/include/extern.h index b71f4b12486..1999ff6b732 100644 --- a/src/third_party/wiredtiger/src/include/extern.h +++ b/src/third_party/wiredtiger/src/include/extern.h @@ -455,6 +455,7 @@ extern int __wt_ext_metadata_search(WT_EXTENSION_API *wt_api, WT_SESSION *wt_ses extern int __wt_ext_metadata_update(WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, const char *key, const char *value); extern int __wt_metadata_get_ckptlist( WT_SESSION *session, const char *name, WT_CKPT **ckptbasep); extern void __wt_metadata_free_ckptlist(WT_SESSION *session, WT_CKPT *ckptbase); +extern void __wt_metadata_init(WT_SESSION_IMPL *session); extern int __wt_metadata_cursor_open( WT_SESSION_IMPL *session, const char *config, WT_CURSOR **cursorp); extern int __wt_metadata_cursor(WT_SESSION_IMPL *session, WT_CURSOR **cursorp); extern int __wt_metadata_cursor_release(WT_SESSION_IMPL *session, WT_CURSOR **cursorp); diff --git a/src/third_party/wiredtiger/src/include/log.h b/src/third_party/wiredtiger/src/include/log.h index 577f6a888a3..0e676d47b66 100644 --- a/src/third_party/wiredtiger/src/include/log.h +++ b/src/third_party/wiredtiger/src/include/log.h @@ -6,6 +6,23 @@ * See the file LICENSE for redistribution information. */ +/* + * WT_LSN -- + * A log sequence number, representing a position in the transaction log. + */ +union __wt_lsn { + struct { +#ifdef WORDS_BIGENDIAN + uint32_t file; + uint32_t offset; +#else + uint32_t offset; + uint32_t file; +#endif + } l; + uint64_t file_offset; +}; + #define WT_LOG_FILENAME "WiredTigerLog" /* Log file name */ #define WT_LOG_PREPNAME "WiredTigerPreplog" /* Log pre-allocated name */ #define WT_LOG_TMPNAME "WiredTigerTmplog" /* Log temporary name */ @@ -13,32 +30,33 @@ /* Logging subsystem declarations. */ #define WT_LOG_ALIGN 128 -#define WT_INIT_LSN(l) do { \ - (l)->file = 1; \ - (l)->offset = 0; \ -} while (0) +/* + * Atomically set the two components of the LSN. + */ +#define WT_SET_LSN(l, f, o) (l)->file_offset = (((uint64_t)(f) << 32) + (o)) -#define WT_MAX_LSN(l) do { \ - (l)->file = UINT32_MAX; \ - (l)->offset = INT64_MAX; \ -} while (0) +#define WT_INIT_LSN(l) WT_SET_LSN((l), 1, 0) -#define WT_ZERO_LSN(l) do { \ - (l)->file = 0; \ - (l)->offset = 0; \ -} while (0) +#define WT_MAX_LSN(l) WT_SET_LSN((l), UINT32_MAX, INT32_MAX) -#define WT_IS_INIT_LSN(l) \ - ((l)->file == 1 && (l)->offset == 0) -#define WT_IS_MAX_LSN(l) \ - ((l)->file == UINT32_MAX && (l)->offset == INT64_MAX) +#define WT_ZERO_LSN(l) WT_SET_LSN((l), 0, 0) + +/* + * Initialize LSN is (1,0). We only need to shift the 1 for comparison. + */ +#define WT_IS_INIT_LSN(l) ((l)->file_offset == ((uint64_t)1 << 32)) +/* + * XXX Original tested INT32_MAX. + */ +#define WT_IS_MAX_LSN(lsn) \ + ((lsn)->l.file == UINT32_MAX && (lsn)->l.offset == INT32_MAX) /* * Both of the macros below need to change if the content of __wt_lsn * ever changes. The value is the following: * txnid, record type, operation type, file id, operation key, operation value */ -#define WT_LOGC_KEY_FORMAT WT_UNCHECKED_STRING(IqI) +#define WT_LOGC_KEY_FORMAT WT_UNCHECKED_STRING(III) #define WT_LOGC_VALUE_FORMAT WT_UNCHECKED_STRING(qIIIuu) #define WT_LOG_SKIP_HEADER(data) \ @@ -253,6 +271,24 @@ struct __wt_log_record { }; /* + * __wt_log_record_byteswap -- + * Handle big- and little-endian transformation of the log record + * header block. + */ +static inline void +__wt_log_record_byteswap(WT_LOG_RECORD *record) +{ +#ifdef WORDS_BIGENDIAN + record->len = __wt_bswap32(record->len); + record->checksum = __wt_bswap32(record->checksum); + record->flags = __wt_bswap16(record->flags); + record->mem_len = __wt_bswap32(record->mem_len); +#else + WT_UNUSED(record); +#endif +} + +/* * WT_LOG_DESC -- * The log file's description. */ @@ -267,6 +303,24 @@ struct __wt_log_desc { }; /* + * __wt_log_desc_byteswap -- + * Handle big- and little-endian transformation of the log file + * description block. + */ +static inline void +__wt_log_desc_byteswap(WT_LOG_DESC *desc) +{ +#ifdef WORDS_BIGENDIAN + desc->log_magic = __wt_bswap32(desc->log_magic); + desc->majorv = __wt_bswap16(desc->majorv); + desc->minorv = __wt_bswap16(desc->minorv); + desc->log_size = __wt_bswap64(desc->log_size); +#else + WT_UNUSED(desc); +#endif +} + +/* * Flags for __wt_txn_op_printlog. */ #define WT_TXN_PRINTLOG_HEX 0x0001 /* Add hex output */ diff --git a/src/third_party/wiredtiger/src/include/log.i b/src/third_party/wiredtiger/src/include/log.i index fcdbc72c388..9e6c36291f7 100644 --- a/src/third_party/wiredtiger/src/include/log.i +++ b/src/third_party/wiredtiger/src/include/log.i @@ -16,25 +16,14 @@ static inline int __wt_log_cmp(WT_LSN *lsn1, WT_LSN *lsn2); static inline int __wt_log_cmp(WT_LSN *lsn1, WT_LSN *lsn2) { - WT_LSN l1, l2; + uint64_t l1, l2; /* * Read LSNs into local variables so that we only read each field * once and all comparisons are on the same values. */ - l1 = *(volatile WT_LSN *)lsn1; - l2 = *(volatile WT_LSN *)lsn2; + l1 = ((volatile WT_LSN *)lsn1)->file_offset; + l2 = ((volatile WT_LSN *)lsn2)->file_offset; - /* - * If the file numbers are different we don't need to compare the - * offset. - */ - if (l1.file != l2.file) - return (l1.file < l2.file ? -1 : 1); - /* - * If the file numbers are the same, compare the offset. - */ - if (l1.offset != l2.offset) - return (l1.offset < l2.offset ? -1 : 1); - return (0); + return (l1 < l2 ? -1 : (l1 > l2 ? 1 : 0)); } diff --git a/src/third_party/wiredtiger/src/include/meta.h b/src/third_party/wiredtiger/src/include/meta.h index e29ec4202dc..d61022c0c44 100644 --- a/src/third_party/wiredtiger/src/include/meta.h +++ b/src/third_party/wiredtiger/src/include/meta.h @@ -30,9 +30,8 @@ * against the metafile URI. The validity is checked on connection open * when diagnostic is enabled. */ -#define WT_METAFILE_NAME_HASH 1045034099109282882LLU /* Metadata file hash */ -#define WT_IS_METADATA(dh) \ - ((dh)->name_hash == WT_METAFILE_NAME_HASH && \ +#define WT_IS_METADATA(session, dh) \ + ((dh)->name_hash == S2C(session)->meta_uri_hash && \ strcmp((dh)->name, WT_METAFILE_URI) == 0) #define WT_METAFILE_ID 0 /* Metadata file ID */ diff --git a/src/third_party/wiredtiger/src/include/misc.h b/src/third_party/wiredtiger/src/include/misc.h index 78997661851..5dadb1b1484 100644 --- a/src/third_party/wiredtiger/src/include/misc.h +++ b/src/third_party/wiredtiger/src/include/misc.h @@ -48,6 +48,9 @@ #define WT_ALIGN(n, v) \ ((((uintmax_t)(n)) + ((v) - 1)) & ~(((uintmax_t)(v)) - 1)) +#define WT_ALIGN_NEAREST(n, v) \ + ((((uintmax_t)(n)) + ((v) / 2)) & ~(((uintmax_t)(v)) - 1)) + /* Min, max. */ #define WT_MIN(a, b) ((a) < (b) ? (a) : (b)) #define WT_MAX(a, b) ((a) < (b) ? (b) : (a)) diff --git a/src/third_party/wiredtiger/src/include/schema.h b/src/third_party/wiredtiger/src/include/schema.h index 88a3a39f8b3..a51030870c1 100644 --- a/src/third_party/wiredtiger/src/include/schema.h +++ b/src/third_party/wiredtiger/src/include/schema.h @@ -79,27 +79,37 @@ struct __wt_table { #define WT_COLGROUPS(t) WT_MAX((t)->ncolgroups, 1) /* + * WT_WITH_LOCK_WAIT -- + * Wait for a lock, perform an operation, drop the lock. + */ +#define WT_WITH_LOCK_WAIT(session, lock, flag, op) do { \ + if (F_ISSET(session, (flag))) { \ + op; \ + } else { \ + __wt_spin_lock(session, (lock)); \ + F_SET(session, (flag)); \ + op; \ + F_CLR(session, (flag)); \ + __wt_spin_unlock(session, (lock)); \ + } \ +} while (0) + +/* * WT_WITH_LOCK -- * Acquire a lock, perform an operation, drop the lock. */ #define WT_WITH_LOCK(session, ret, lock, flag, op) do { \ ret = 0; \ - if (F_ISSET(session, (flag))) { \ - op; \ - } else if (F_ISSET(session, WT_SESSION_LOCK_NO_WAIT)) { \ + if (!F_ISSET(session, (flag)) && \ + F_ISSET(session, WT_SESSION_LOCK_NO_WAIT)) { \ if ((ret = __wt_spin_trylock(session, (lock))) == 0) { \ F_SET(session, (flag)); \ op; \ F_CLR(session, (flag)); \ __wt_spin_unlock(session, (lock)); \ } \ - } else { \ - __wt_spin_lock(session, (lock)); \ - F_SET(session, (flag)); \ - op; \ - F_CLR(session, (flag)); \ - __wt_spin_unlock(session, (lock)); \ - } \ + } else \ + WT_WITH_LOCK_WAIT(session, lock, flag, op); \ } while (0) /* @@ -113,10 +123,15 @@ struct __wt_table { /* * WT_WITH_HANDLE_LIST_LOCK -- * Acquire the data handle list lock, perform an operation, drop the lock. + * + * Note: always waits because some operations need the handle list lock to + * discard handles, and we only expect it to be held across short + * operations. */ -#define WT_WITH_HANDLE_LIST_LOCK(session, ret, op) \ - WT_WITH_LOCK(session, ret, \ +#define WT_WITH_HANDLE_LIST_LOCK(session, op) \ + WT_WITH_LOCK_WAIT(session, \ &S2C(session)->dhandle_lock, WT_SESSION_LOCKED_HANDLE_LIST, op) + /* * WT_WITH_SCHEMA_LOCK -- * Acquire the schema lock, perform an operation, drop the lock. diff --git a/src/third_party/wiredtiger/src/include/swap.h b/src/third_party/wiredtiger/src/include/swap.h new file mode 100644 index 00000000000..2040ca88a77 --- /dev/null +++ b/src/third_party/wiredtiger/src/include/swap.h @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2014-2016 MongoDB, Inc. + * Copyright (c) 2008-2014 WiredTiger, Inc. + * All rights reserved. + * + * See the file LICENSE for redistribution information. + */ + +#if defined(_MSC_VER) && (_MSC_VER >= 1300) +#include <stdlib.h> +#define __wt_bswap16(v) _byteswap_ushort(v) +#define __wt_bswap32(v) _byteswap_ulong(v) +#define __wt_bswap64(v) _byteswap_uint64(v) +#elif defined(__clang__) && \ + defined(__clang_major__) && defined(__clang_minor__) && \ + (__clang_major__ >= 3) && (__clang_minor__ >= 1) +#if __has_builtin(__builtin_bswap16) +#define __wt_bswap16(v) __builtin_bswap16(v) +#endif +#if __has_builtin(__builtin_bswap32) +#define __wt_bswap32(v) __builtin_bswap32(v) +#endif +#if __has_builtin(__builtin_bswap64) +#define __wt_bswap64(v) __builtin_bswap64(v) +#endif +#elif defined(__GNUC__) && (__GNUC__ >= 4) +#if __GNUC__ >= 4 && defined(__GNUC_MINOR__) && __GNUC_MINOR__ >= 3 +#define __wt_bswap32(v) __builtin_bswap32(v) +#define __wt_bswap64(v) __builtin_bswap64(v) +#endif +#if __GNUC__ >= 4 && defined(__GNUC_MINOR__) && __GNUC_MINOR__ >= 8 +#define __wt_bswap16(v) __builtin_bswap16(v) +#endif +#elif defined(__sun) +#include <sys/byteorder.h> +#define __wt_bswap16(v) BSWAP_16(v) +#define __wt_bswap32(v) BSWAP_32(v) +#define __wt_bswap64(v) BSWAP_64(v) +#endif + +#if !defined(__wt_bswap64) +/* + * __wt_bswap64 -- + * 64-bit unsigned little-endian to/from big-endian value. + */ +static inline uint64_t +__wt_bswap64(uint64_t v) +{ + return ( + ((v << 56) & 0xff00000000000000UL) | + ((v << 40) & 0x00ff000000000000UL) | + ((v << 24) & 0x0000ff0000000000UL) | + ((v << 8) & 0x000000ff00000000UL) | + ((v >> 8) & 0x00000000ff000000UL) | + ((v >> 24) & 0x0000000000ff0000UL) | + ((v >> 40) & 0x000000000000ff00UL) | + ((v >> 56) & 0x00000000000000ffUL) + ); +} +#endif + +#if !defined(__wt_bswap32) +/* + * __wt_bswap32 -- + * 32-bit unsigned little-endian to/from big-endian value. + */ +static inline uint32_t +__wt_bswap32(uint32_t v) +{ + return ( + ((v << 24) & 0xff000000) | + ((v << 8) & 0x00ff0000) | + ((v >> 8) & 0x0000ff00) | + ((v >> 24) & 0x000000ff) + ); +} +#endif + +#if !defined(__wt_bswap16) +/* + * __wt_bswap16 -- + * 16-bit unsigned little-endian to/from big-endian value. + */ +static inline uint16_t +__wt_bswap16(uint16_t v) +{ + return ( + ((v << 8) & 0xff00) | + ((v >> 8) & 0x00ff) + ); +} +#endif diff --git a/src/third_party/wiredtiger/src/include/wiredtiger.in b/src/third_party/wiredtiger/src/include/wiredtiger.in index 676f95d9b05..767c176b53f 100644 --- a/src/third_party/wiredtiger/src/include/wiredtiger.in +++ b/src/third_party/wiredtiger/src/include/wiredtiger.in @@ -72,7 +72,6 @@ struct __wt_event_handler; typedef struct __wt_event_handler WT_EVENT_HANDLER; struct __wt_extension_api; typedef struct __wt_extension_api WT_EXTENSION_API; struct __wt_extractor; typedef struct __wt_extractor WT_EXTRACTOR; struct __wt_item; typedef struct __wt_item WT_ITEM; -struct __wt_lsn; typedef struct __wt_lsn WT_LSN; struct __wt_session; typedef struct __wt_session WT_SESSION; #if defined(SWIGJAVA) @@ -126,22 +125,6 @@ struct __wt_item { #endif }; -/* - * We rely on this structure being aligned at 64 bits by the compiler, - * if we were paranoid we could add an unused field to ensure the padding - * is correct. - * - * NOTE: If you change the contents of this structure you must also update - * the macros in log.h. - */ -/*! - * A log sequence number, representing a position in the transaction log. - */ -struct __wt_lsn { - uint32_t file; /*!< Log file number */ - wt_off_t offset; /*!< Log file offset */ -}; - /*! * The maximum packed size of a 64-bit integer. The ::wiredtiger_struct_pack * function will pack single long integers into at most this many bytes. @@ -1006,9 +989,9 @@ struct __wt_session { * @config{block_compressor, configure a compressor for file blocks. * Permitted values are \c "none" or custom compression engine name * created with WT_CONNECTION::add_compressor. If WiredTiger has - * builtin support for \c "bzip2"\, \c "snappy"\, \c "lz4" or \c "zlib" - * compression\, these names are also available. See @ref compression - * for more information., a string; default \c none.} + * builtin support for \c "snappy"\, \c "lz4" or \c "zlib" compression\, + * these names are also available. See @ref compression for more + * information., a string; default \c none.} * @config{cache_resident, do not ever evict the object's pages from * cache. Not compatible with LSM tables; see @ref * tuning_cache_resident for more information., a boolean flag; default @@ -1839,9 +1822,9 @@ struct __wt_connection { * @config{ compressor, configure a compressor * for log records. Permitted values are \c "none" or custom * compression engine name created with WT_CONNECTION::add_compressor. - * If WiredTiger has builtin support for \c "bzip2"\, \c "snappy"\, \c - * "lz4" or \c "zlib" compression\, these names are also available. See - * @ref compression for more information., a string; default \c none.} + * If WiredTiger has builtin support for \c "snappy"\, \c "lz4" or \c + * "zlib" compression\, these names are also available. See @ref + * compression for more information., a string; default \c none.} * @config{ enabled, enable logging subsystem., a * boolean flag; default \c false.} * @config{ file_max, the maximum size of log @@ -2308,11 +2291,11 @@ struct __wt_connection { * @config{ compressor, configure a compressor for log * records. Permitted values are \c "none" or custom compression engine name * created with WT_CONNECTION::add_compressor. If WiredTiger has builtin - * support for \c "bzip2"\, \c "snappy"\, \c "lz4" or \c "zlib" compression\, - * these names are also available. See @ref compression for more information., - * a string; default \c none.} - * @config{ enabled, enable - * logging subsystem., a boolean flag; default \c false.} + * support for \c "snappy"\, \c "lz4" or \c "zlib" compression\, these names are + * also available. See @ref compression for more information., a string; + * default \c none.} + * @config{ enabled, enable logging + * subsystem., a boolean flag; default \c false.} * @config{ file_max, the maximum size of log files., an * integer between 100KB and 2GB; default \c 100MB.} * @config{ path, the path to a directory into which the diff --git a/src/third_party/wiredtiger/src/include/wt_internal.h b/src/third_party/wiredtiger/src/include/wt_internal.h index 54b5dfd19f4..4533c8cbca0 100644 --- a/src/third_party/wiredtiger/src/include/wt_internal.h +++ b/src/third_party/wiredtiger/src/include/wt_internal.h @@ -6,6 +6,9 @@ * See the file LICENSE for redistribution information. */ +#ifndef __WT_INTERNAL_H +#define __WT_INTERNAL_H + #if defined(__cplusplus) extern "C" { #endif @@ -284,6 +287,8 @@ struct __wt_txn_state; typedef struct __wt_txn_state WT_TXN_STATE; struct __wt_update; typedef struct __wt_update WT_UPDATE; +union __wt_lsn; + typedef union __wt_lsn WT_LSN; union __wt_rand_state; typedef union __wt_rand_state WT_RAND_STATE; /* @@ -302,6 +307,7 @@ union __wt_rand_state; #include "msvc.h" #endif #include "hardware.h" +#include "swap.h" #include "queue.h" @@ -324,8 +330,8 @@ union __wt_rand_state; #include "btmem.h" #include "btree.h" #include "cache.h" -#include "config.h" #include "compact.h" +#include "config.h" #include "cursor.h" #include "dlh.h" #include "error.h" @@ -365,3 +371,4 @@ union __wt_rand_state; #if defined(__cplusplus) } #endif +#endif /* !__WT_INTERNAL_H */ diff --git a/src/third_party/wiredtiger/src/log/log.c b/src/third_party/wiredtiger/src/log/log.c index 3bf04d025d8..ce2d7191491 100644 --- a/src/third_party/wiredtiger/src/log/log.c +++ b/src/third_party/wiredtiger/src/log/log.c @@ -105,7 +105,7 @@ __wt_log_force_sync(WT_SESSION_IMPL *session, WT_LSN *min_lsn) * LSN has moved into a later log file and there should be a * log file ready to close. */ - while (log->sync_lsn.file < min_lsn->file) { + while (log->sync_lsn.l.file < min_lsn->l.file) { WT_ERR(__wt_cond_signal(session, S2C(session)->log_file_cond)); WT_ERR(__wt_cond_wait(session, log->log_sync_cond, 10000)); @@ -116,10 +116,11 @@ __wt_log_force_sync(WT_SESSION_IMPL *session, WT_LSN *min_lsn) * Sync the directory if the log file entry hasn't been written * into the directory. */ - if (log->sync_dir_lsn.file < min_lsn->file) { + if (log->sync_dir_lsn.l.file < min_lsn->l.file) { WT_ERR(__wt_verbose(session, WT_VERB_LOG, "log_force_sync: sync directory %s to LSN %d/%lu", - log->log_dir_fh->name, min_lsn->file, min_lsn->offset)); + log->log_dir_fh->name, + min_lsn->l.file, min_lsn->l.offset)); WT_ERR(__wt_directory_sync_fh(session, log->log_dir_fh)); log->sync_dir_lsn = *min_lsn; WT_STAT_FAST_CONN_INCR(session, log_sync_dir); @@ -130,7 +131,7 @@ __wt_log_force_sync(WT_SESSION_IMPL *session, WT_LSN *min_lsn) if (__wt_log_cmp(&log->sync_lsn, min_lsn) < 0) { WT_ERR(__wt_verbose(session, WT_VERB_LOG, "log_force_sync: sync %s to LSN %d/%lu", - log->log_fh->name, min_lsn->file, min_lsn->offset)); + log->log_fh->name, min_lsn->l.file, min_lsn->l.offset)); WT_ERR(__wt_fsync(session, log->log_fh)); log->sync_lsn = *min_lsn; WT_STAT_FAST_CONN_INCR(session, log_sync); @@ -174,7 +175,7 @@ __wt_log_needs_recovery(WT_SESSION_IMPL *session, WT_LSN *ckp_lsn, bool *recp) * we can skip recovery. */ WT_RET(__wt_curlog_open(session, "log:", NULL, &c)); - c->set_key(c, ckp_lsn->file, ckp_lsn->offset, 0); + c->set_key(c, ckp_lsn->l.file, ckp_lsn->l.offset, 0); if ((ret = c->search(c)) == 0) { while ((ret = c->next(c)) == 0) { /* @@ -278,7 +279,7 @@ __wt_log_get_all_files(WT_SESSION_IMPL *session, /* Filter out any files that are below the checkpoint LSN. */ for (max = 0, i = 0; i < count; ) { WT_ERR(__wt_log_extract_lognum(session, files[i], &id)); - if (active_only && id < log->ckpt_lsn.file) { + if (active_only && id < log->ckpt_lsn.l.file) { __wt_free(session, files[i]); files[i] = files[count - 1]; files[--count] = NULL; @@ -459,8 +460,8 @@ __log_size_fit(WT_SESSION_IMPL *session, WT_LSN *lsn, uint64_t recsize) conn = S2C(session); log = conn->log; - return (lsn->offset == WT_LOG_FIRST_RECORD || - lsn->offset + (wt_off_t)recsize < conn->log_file_max); + return (lsn->l.offset == WT_LOG_FIRST_RECORD || + lsn->l.offset + (wt_off_t)recsize < conn->log_file_max); } /* @@ -536,9 +537,7 @@ __log_fill(WT_SESSION_IMPL *session, WT_MYSLOT *myslot, bool force, WT_ITEM *record, WT_LSN *lsnp) { WT_DECL_RET; - WT_LOG_RECORD *logrec; - logrec = (WT_LOG_RECORD *)record->mem; /* * Call __wt_write or copy into the buffer. For now the offset is the * real byte offset. If the offset becomes a unit of WT_LOG_ALIGN this @@ -547,19 +546,19 @@ __log_fill(WT_SESSION_IMPL *session, */ if (!force && !F_ISSET(myslot, WT_MYSLOT_UNBUFFERED)) memcpy((char *)myslot->slot->slot_buf.mem + myslot->offset, - logrec, logrec->len); + record->mem, record->size); else /* * If this is a force or unbuffered write, write it now. */ WT_ERR(__wt_write(session, myslot->slot->slot_fh, myslot->offset + myslot->slot->slot_start_offset, - (size_t)logrec->len, (void *)logrec)); + record->size, record->mem)); - WT_STAT_FAST_CONN_INCRV(session, log_bytes_written, logrec->len); + WT_STAT_FAST_CONN_INCRV(session, log_bytes_written, record->size); if (lsnp != NULL) { *lsnp = myslot->slot->slot_start_lsn; - lsnp->offset += (wt_off_t)myslot->offset; + lsnp->l.offset += (uint32_t)myslot->offset; } err: if (ret != 0 && myslot->slot->slot_error == 0) @@ -596,19 +595,31 @@ __log_file_header( WT_ASSERT(session, sizeof(WT_LOG_DESC) < log->allocsize); WT_RET(__wt_scr_alloc(session, log->allocsize, &buf)); memset(buf->mem, 0, log->allocsize); + buf->size = log->allocsize; + logrec = (WT_LOG_RECORD *)buf->mem; desc = (WT_LOG_DESC *)logrec->record; desc->log_magic = WT_LOG_MAGIC; desc->majorv = WT_LOG_MAJOR_VERSION; desc->minorv = WT_LOG_MINOR_VERSION; desc->log_size = (uint64_t)conn->log_file_max; + __wt_log_desc_byteswap(desc); /* * Now that the record is set up, initialize the record header. + * + * Checksum a little-endian version of the header, and write everything + * in little-endian format. The checksum is (potentially) returned in a + * big-endian format, swap it into place in a separate step. */ logrec->len = log->allocsize; logrec->checksum = 0; + __wt_log_record_byteswap(logrec); logrec->checksum = __wt_cksum(logrec, log->allocsize); +#ifdef WORDS_BIGENDIAN + logrec->checksum = __wt_bswap32(logrec->checksum); +#endif + WT_CLEAR(tmp); memset(&myslot, 0, sizeof(myslot)); myslot.slot = &tmp; @@ -624,7 +635,7 @@ __log_file_header( tmp.slot_fh = fh; } else { WT_ASSERT(session, fh == NULL); - WT_ERR(__wt_log_acquire(session, logrec->len, &tmp)); + WT_ERR(__wt_log_acquire(session, log->allocsize, &tmp)); } WT_ERR(__log_fill(session, &myslot, true, buf, NULL)); /* @@ -673,7 +684,9 @@ __log_openfile(WT_SESSION_IMPL *session, memset(buf->mem, 0, allocsize); WT_ERR(__wt_read(session, *fh, 0, allocsize, buf->mem)); logrec = (WT_LOG_RECORD *)buf->mem; + __wt_log_record_byteswap(logrec); desc = (WT_LOG_DESC *)logrec->record; + __wt_log_desc_byteswap(desc); if (desc->log_magic != WT_LOG_MAGIC) WT_PANIC_RET(session, WT_ERROR, "log file %s corrupted: Bad magic number %" PRIu32, @@ -829,8 +842,7 @@ __log_newfile(WT_SESSION_IMPL *session, bool conn_open, bool *created) * We need to setup the LSNs. Set the end LSN and alloc LSN to * the end of the header. */ - log->alloc_lsn.file = log->fileid; - log->alloc_lsn.offset = WT_LOG_FIRST_RECORD; + WT_SET_LSN(&log->alloc_lsn, log->fileid, WT_LOG_FIRST_RECORD); end_lsn = log->alloc_lsn; /* @@ -890,7 +902,7 @@ __wt_log_acquire(WT_SESSION_IMPL *session, uint64_t recsize, WT_LOGSLOT *slot) * Pre-allocate on the first real write into the log file, if it * was just created (i.e. not pre-allocated). */ - if (log->alloc_lsn.offset == WT_LOG_FIRST_RECORD && created_log) + if (log->alloc_lsn.l.offset == WT_LOG_FIRST_RECORD && created_log) WT_RET(__log_prealloc(session, log->log_fh)); /* * Initialize the slot for activation. @@ -931,8 +943,9 @@ __log_truncate(WT_SESSION_IMPL *session, /* * Truncate the log file to the given LSN. */ - WT_ERR(__log_openfile(session, false, &log_fh, file_prefix, lsn->file)); - WT_ERR(__wt_ftruncate(session, log_fh, lsn->offset)); + WT_ERR(__log_openfile(session, + false, &log_fh, file_prefix, lsn->l.file)); + WT_ERR(__wt_ftruncate(session, log_fh, lsn->l.offset)); WT_ERR(__wt_fsync(session, log_fh)); WT_ERR(__wt_close(session, &log_fh)); @@ -946,7 +959,8 @@ __log_truncate(WT_SESSION_IMPL *session, WT_LOG_FILENAME, &logfiles, &logcount)); for (i = 0; i < logcount; i++) { WT_ERR(__wt_log_extract_lognum(session, logfiles[i], &lognum)); - if (lognum > lsn->file && lognum < log->trunc_lsn.file) { + if (lognum > lsn->l.file && + lognum < log->trunc_lsn.l.file) { WT_ERR(__log_openfile(session, false, &log_fh, file_prefix, lognum)); /* @@ -1111,10 +1125,8 @@ __wt_log_open(WT_SESSION_IMPL *session) if (firstlog == UINT32_MAX) { WT_ASSERT(session, logcount == 0); WT_INIT_LSN(&log->first_lsn); - } else { - log->first_lsn.file = firstlog; - log->first_lsn.offset = 0; - } + } else + WT_SET_LSN(&log->first_lsn, firstlog, 0); /* * Start logging at the beginning of the next log file, no matter @@ -1346,7 +1358,7 @@ __wt_log_release(WT_SESSION_IMPL *session, WT_LOGSLOT *slot, bool *freep) * sync operations. The most recent one will set the LSN to the * beginning of our file. */ - if (log->sync_lsn.file < slot->slot_end_lsn.file || + if (log->sync_lsn.l.file < slot->slot_end_lsn.l.file || __wt_spin_trylock(session, &log->log_sync_lock) != 0) { WT_ERR(__wt_cond_wait( session, log->log_sync_cond, 10000)); @@ -1366,12 +1378,12 @@ __wt_log_release(WT_SESSION_IMPL *session, WT_LOGSLOT *slot, bool *freep) * now if needed. */ if (F_ISSET(slot, WT_SLOT_SYNC_DIR) && - (log->sync_dir_lsn.file < sync_lsn.file)) { + (log->sync_dir_lsn.l.file < sync_lsn.l.file)) { WT_ASSERT(session, log->log_dir_fh != NULL); WT_ERR(__wt_verbose(session, WT_VERB_LOG, - "log_release: sync directory %s to LSN %d/%lu", + "log_release: sync directory %s to LSN %u/%lu", log->log_dir_fh->name, - sync_lsn.file, sync_lsn.offset)); + sync_lsn.l.file, sync_lsn.l.offset)); WT_ERR(__wt_directory_sync_fh( session, log->log_dir_fh)); log->sync_dir_lsn = sync_lsn; @@ -1384,8 +1396,9 @@ __wt_log_release(WT_SESSION_IMPL *session, WT_LOGSLOT *slot, bool *freep) if (F_ISSET(slot, WT_SLOT_SYNC) && __wt_log_cmp(&log->sync_lsn, &slot->slot_end_lsn) < 0) { WT_ERR(__wt_verbose(session, WT_VERB_LOG, - "log_release: sync log %s to LSN %d/%lu", - log->log_fh->name, sync_lsn.file, sync_lsn.offset)); + "log_release: sync log %s to LSN %u/%lu", + log->log_fh->name, + sync_lsn.l.file, sync_lsn.l.offset)); WT_STAT_FAST_CONN_INCR(session, log_sync); WT_ERR(__wt_fsync(session, log->log_fh)); log->sync_lsn = sync_lsn; @@ -1426,10 +1439,11 @@ __wt_log_scan(WT_SESSION_IMPL *session, WT_LSN *lsnp, uint32_t flags, WT_LOG_RECORD *logrec; WT_LSN end_lsn, next_lsn, rd_lsn, start_lsn; wt_off_t log_size; - uint32_t allocsize, cksum, firstlog, lastlog, lognum, rdup_len, reclen; + uint32_t allocsize, firstlog, lastlog, lognum, rdup_len, reclen; + uint32_t cksum_calculate, cksum_tmp; u_int i, logcount; int firstrecord; - bool eol; + bool eol, partial_record; char **logfiles; conn = S2C(session); @@ -1449,8 +1463,8 @@ __wt_log_scan(WT_SESSION_IMPL *session, WT_LSN *lsnp, uint32_t flags, if (LF_ISSET(WT_LOGSCAN_RECOVER)) WT_RET(__wt_verbose(session, WT_VERB_LOG, - "__wt_log_scan truncating to %u/%" PRIuMAX, - log->trunc_lsn.file, (uintmax_t)log->trunc_lsn.offset)); + "__wt_log_scan truncating to %u/%u", + log->trunc_lsn.l.file, log->trunc_lsn.l.offset)); if (log != NULL) { allocsize = log->allocsize; @@ -1468,8 +1482,8 @@ __wt_log_scan(WT_SESSION_IMPL *session, WT_LSN *lsnp, uint32_t flags, "choose either a start LSN or a start flag"); /* Offsets must be on allocation boundaries. */ - if (lsnp->offset % allocsize != 0 || - lsnp->file > log->fileid) + if (lsnp->l.offset % allocsize != 0 || + lsnp->l.file > log->fileid) return (WT_NOTFOUND); /* @@ -1509,14 +1523,13 @@ __wt_log_scan(WT_SESSION_IMPL *session, WT_LSN *lsnp, uint32_t flags, lastlog = WT_MAX(lastlog, lognum); firstlog = WT_MIN(firstlog, lognum); } - start_lsn.file = firstlog; - end_lsn.file = lastlog; - start_lsn.offset = end_lsn.offset = 0; + WT_SET_LSN(&start_lsn, firstlog, 0); + WT_SET_LSN(&end_lsn, lastlog, 0); __wt_log_files_free(session, logfiles, logcount); logfiles = NULL; } WT_ERR(__log_openfile( - session, false, &log_fh, WT_LOG_FILENAME, start_lsn.file)); + session, false, &log_fh, WT_LOG_FILENAME, start_lsn.l.file)); WT_ERR(__wt_filesize(session, log_fh, &log_size)); rd_lsn = start_lsn; @@ -1524,8 +1537,17 @@ __wt_log_scan(WT_SESSION_IMPL *session, WT_LSN *lsnp, uint32_t flags, WT_ERR(__wt_scr_alloc(session, 0, &decryptitem)); WT_ERR(__wt_scr_alloc(session, 0, &uncitem)); for (;;) { - if (rd_lsn.offset + allocsize > log_size) { + if (rd_lsn.l.offset + allocsize > log_size) { advance: + if (rd_lsn.l.offset == log_size) + partial_record = false; + else + /* + * See if there is anything non-zero at the + * end of this log file. + */ + WT_ERR(__log_has_hole(session, log_fh, + rd_lsn.l.offset, &partial_record)); /* * If we read the last record, go to the next file. */ @@ -1538,16 +1560,24 @@ advance: if (LF_ISSET(WT_LOGSCAN_RECOVER)) WT_ERR(__log_truncate(session, &rd_lsn, WT_LOG_FILENAME, 1)); - rd_lsn.file++; - rd_lsn.offset = 0; + /* + * If we had a partial record, we'll want to break + * now after closing and truncating. Although for now + * log_truncate does not modify the LSN passed in, + * this code does not assume it is unmodified after that + * call which is why it uses the boolean set earlier. + */ + if (partial_record) + break; + WT_SET_LSN(&rd_lsn, rd_lsn.l.file + 1, 0); /* * Avoid an error message when we reach end of log * by checking here. */ - if (rd_lsn.file > end_lsn.file) + if (rd_lsn.l.file > end_lsn.l.file) break; WT_ERR(__log_openfile(session, - false, &log_fh, WT_LOG_FILENAME, rd_lsn.file)); + false, &log_fh, WT_LOG_FILENAME, rd_lsn.l.file)); WT_ERR(__wt_filesize(session, log_fh, &log_size)); eol = false; continue; @@ -1557,14 +1587,16 @@ advance: */ WT_ASSERT(session, buf->memsize >= allocsize); WT_ERR(__wt_read(session, - log_fh, rd_lsn.offset, (size_t)allocsize, buf->mem)); + log_fh, rd_lsn.l.offset, (size_t)allocsize, buf->mem)); /* - * First 4 bytes is the real record length. See if we - * need to read more than the allocation size. We expect - * that we rarely will have to read more. Most log records - * will be fairly small. + * See if we need to read more than the allocation size. We + * expect that we rarely will have to read more. Most log + * records will be fairly small. */ - reclen = *(uint32_t *)buf->mem; + reclen = ((WT_LOG_RECORD *)buf->mem)->len; +#ifdef WORDS_BIGENDIAN + reclen = __wt_bswap32(reclen); +#endif /* * Log files are pre-allocated. We need to detect the * difference between a hole in the file (where this location @@ -1578,7 +1610,7 @@ advance: */ if (reclen == 0) { WT_ERR(__log_has_hole( - session, log_fh, rd_lsn.offset, &eol)); + session, log_fh, rd_lsn.l.offset, &eol)); if (eol) /* Found a hole. This LSN is the end. */ break; @@ -1590,28 +1622,40 @@ advance: if (reclen > allocsize) { /* * The log file end could be the middle of this - * log record. + * log record. If we have a partially written record + * then this is considered the end of the log. */ - if (rd_lsn.offset + rdup_len > log_size) - goto advance; + if (rd_lsn.l.offset + rdup_len > log_size) { + eol = true; + break; + } /* * We need to round up and read in the full padded * record, especially for direct I/O. */ WT_ERR(__wt_buf_grow(session, buf, rdup_len)); - WT_ERR(__wt_read(session, - log_fh, rd_lsn.offset, (size_t)rdup_len, buf->mem)); + WT_ERR(__wt_read(session, log_fh, + rd_lsn.l.offset, (size_t)rdup_len, buf->mem)); WT_STAT_FAST_CONN_INCR(session, log_scan_rereads); } /* * We read in the record, verify checksum. + * + * Handle little- and big-endian objects. Objects are written + * in little-endian format: save the header checksum, and + * calculate the checksum for the header in its little-endian + * form. Then, restore the header's checksum, and byte-swap + * the whole thing as necessary, leaving us with a calculated + * checksum that should match the checksum in the header. */ buf->size = reclen; logrec = (WT_LOG_RECORD *)buf->mem; - cksum = logrec->checksum; + cksum_tmp = logrec->checksum; logrec->checksum = 0; - logrec->checksum = __wt_cksum(logrec, logrec->len); - if (logrec->checksum != cksum) { + cksum_calculate = __wt_cksum(logrec, reclen); + logrec->checksum = cksum_tmp; + __wt_log_record_byteswap(logrec); + if (logrec->checksum != cksum_calculate) { /* * A checksum mismatch means we have reached the end of * the useful part of the log. This should be found on @@ -1636,8 +1680,8 @@ advance: */ WT_STAT_FAST_CONN_INCR(session, log_scan_records); next_lsn = rd_lsn; - next_lsn.offset += (wt_off_t)rdup_len; - if (rd_lsn.offset != 0) { + next_lsn.l.offset += rdup_len; + if (rd_lsn.l.offset != 0) { /* * We need to manage the different buffers here. * Buf is the buffer this function uses to read from @@ -1890,10 +1934,19 @@ __log_write_internal(WT_SESSION_IMPL *session, WT_ITEM *record, WT_LSN *lsnp, rdup_len - record->size); record->size = rdup_len; } + /* + * Checksum a little-endian version of the header, and write everything + * in little-endian format. The checksum is (potentially) returned in a + * big-endian format, swap it into place in a separate step. + */ logrec = (WT_LOG_RECORD *)record->mem; logrec->len = (uint32_t)record->size; logrec->checksum = 0; + __wt_log_record_byteswap(logrec); logrec->checksum = __wt_cksum(logrec, record->size); +#ifdef WORDS_BIGENDIAN + logrec->checksum = __wt_bswap32(logrec->checksum); +#endif WT_STAT_FAST_CONN_INCR(session, log_writes); @@ -2061,7 +2114,8 @@ __wt_log_flush(WT_SESSION_IMPL *session, uint32_t flags) WT_RET(__wt_log_flush_lsn(session, &lsn, false)); WT_RET(__wt_verbose(session, WT_VERB_LOG, - "log_flush: flags %d LSN %d/%lu", flags, lsn.file, lsn.offset)); + "log_flush: flags %d LSN %u/%lu", + flags, lsn.l.file, lsn.l.offset)); /* * If the user wants write-no-sync, there is nothing more to do. * If the user wants background sync, set the LSN and we're done. diff --git a/src/third_party/wiredtiger/src/log/log_slot.c b/src/third_party/wiredtiger/src/log/log_slot.c index 760e8888de6..2844516e78f 100644 --- a/src/third_party/wiredtiger/src/log/log_slot.c +++ b/src/third_party/wiredtiger/src/log/log_slot.c @@ -31,8 +31,8 @@ __wt_log_slot_activate(WT_SESSION_IMPL *session, WT_LOGSLOT *slot) * are reset when the slot is freed. See log_slot_free. */ slot->slot_start_lsn = slot->slot_end_lsn = log->alloc_lsn; - slot->slot_start_offset = log->alloc_lsn.offset; - slot->slot_last_offset = log->alloc_lsn.offset; + slot->slot_start_offset = log->alloc_lsn.l.offset; + slot->slot_last_offset = log->alloc_lsn.l.offset; slot->slot_fh = log->log_fh; slot->slot_error = 0; slot->slot_unbuffered = 0; @@ -96,14 +96,15 @@ retry: slot->slot_end_lsn = slot->slot_start_lsn; end_offset = WT_LOG_SLOT_JOINED_BUFFERED(old_state) + slot->slot_unbuffered; - slot->slot_end_lsn.offset += (wt_off_t)end_offset; + slot->slot_end_lsn.l.offset += end_offset; WT_STAT_FAST_CONN_INCRV(session, log_slot_consolidated, end_offset); /* * XXX Would like to change so one piece of code advances the LSN. */ log->alloc_lsn = slot->slot_end_lsn; - WT_ASSERT(session, log->alloc_lsn.file >= log->write_lsn.file); + WT_ASSERT(session, + log->alloc_lsn.l.file >= log->write_lsn.l.file); return (0); } diff --git a/src/third_party/wiredtiger/src/lsm/lsm_cursor.c b/src/third_party/wiredtiger/src/lsm/lsm_cursor.c index 1bb9a7238fe..f76b2bfd9ac 100644 --- a/src/third_party/wiredtiger/src/lsm/lsm_cursor.c +++ b/src/third_party/wiredtiger/src/lsm/lsm_cursor.c @@ -1543,7 +1543,7 @@ __wt_clsm_open(WT_SESSION_IMPL *session, bulk = cval.val != 0; /* Get the LSM tree. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, uri, bulk, &lsm_tree)); /* * Check whether the exclusive open for a bulk load succeeded, and diff --git a/src/third_party/wiredtiger/src/lsm/lsm_stat.c b/src/third_party/wiredtiger/src/lsm/lsm_stat.c index c147cf5774a..76e2ca6185e 100644 --- a/src/third_party/wiredtiger/src/lsm/lsm_stat.c +++ b/src/third_party/wiredtiger/src/lsm/lsm_stat.c @@ -33,7 +33,7 @@ __curstat_lsm_init( "checkpoint=" WT_CHECKPOINT, NULL, NULL }; locked = false; - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, uri, false, &lsm_tree)); WT_RET(ret); WT_ERR(__wt_scr_alloc(session, 0, &uribuf)); diff --git a/src/third_party/wiredtiger/src/lsm/lsm_tree.c b/src/third_party/wiredtiger/src/lsm/lsm_tree.c index ff6e66fd1a1..ab18e41a2f5 100644 --- a/src/third_party/wiredtiger/src/lsm/lsm_tree.c +++ b/src/third_party/wiredtiger/src/lsm/lsm_tree.c @@ -315,7 +315,7 @@ __wt_lsm_tree_create(WT_SESSION_IMPL *session, char *tmpconfig; /* If the tree is open, it already exists. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, uri, false, &lsm_tree)); if (ret == 0) { __wt_lsm_tree_release(session, lsm_tree); @@ -447,7 +447,7 @@ __wt_lsm_tree_create(WT_SESSION_IMPL *session, * tracking macros handle cleaning up on failure. */ if (ret == 0) - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __lsm_tree_open(session, uri, true, &lsm_tree)); if (ret == 0) __wt_lsm_tree_release(session, lsm_tree); @@ -961,7 +961,7 @@ __wt_lsm_tree_drop( locked = false; /* Get the LSM tree. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, name, true, &lsm_tree)); WT_RET(ret); @@ -997,7 +997,7 @@ __wt_lsm_tree_drop( err: if (locked) WT_TRET(__wt_lsm_tree_writeunlock(session, lsm_tree)); - WT_WITH_HANDLE_LIST_LOCK(session, tret, + WT_WITH_HANDLE_LIST_LOCK(session, tret = __lsm_tree_discard(session, lsm_tree, false)); WT_TRET(tret); return (ret); @@ -1023,7 +1023,7 @@ __wt_lsm_tree_rename(WT_SESSION_IMPL *session, locked = false; /* Get the LSM tree. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, olduri, true, &lsm_tree)); WT_RET(ret); @@ -1073,7 +1073,7 @@ err: if (locked) * Discard this LSM tree structure. The first operation on the renamed * tree will create a new one. */ - WT_WITH_HANDLE_LIST_LOCK(session, tret, + WT_WITH_HANDLE_LIST_LOCK(session, tret = __lsm_tree_discard(session, lsm_tree, false)); WT_TRET(tret); return (ret); @@ -1098,7 +1098,7 @@ __wt_lsm_tree_truncate( locked = false; /* Get the LSM tree. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, name, true, &lsm_tree)); WT_RET(ret); @@ -1137,7 +1137,7 @@ err: if (locked) * the last good version of the metadata will be used, resulting * in a valid (not truncated) tree. */ - WT_WITH_HANDLE_LIST_LOCK(session, tret, + WT_WITH_HANDLE_LIST_LOCK(session, tret = __lsm_tree_discard(session, lsm_tree, false)); WT_TRET(tret); } @@ -1237,7 +1237,7 @@ __wt_lsm_compact(WT_SESSION_IMPL *session, const char *name, bool *skipp) /* Tell __wt_schema_worker not to look inside the LSM tree. */ *skipp = true; - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, name, false, &lsm_tree)); WT_RET(ret); @@ -1435,7 +1435,7 @@ __wt_lsm_tree_worker(WT_SESSION_IMPL *session, locked = false; exclusive = FLD_ISSET(open_flags, WT_DHANDLE_EXCLUSIVE); - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_lsm_tree_get(session, uri, exclusive, &lsm_tree)); WT_RET(ret); diff --git a/src/third_party/wiredtiger/src/lsm/lsm_work_unit.c b/src/third_party/wiredtiger/src/lsm/lsm_work_unit.c index 4faa25967ad..d5d81df6785 100644 --- a/src/third_party/wiredtiger/src/lsm/lsm_work_unit.c +++ b/src/third_party/wiredtiger/src/lsm/lsm_work_unit.c @@ -272,7 +272,7 @@ __wt_lsm_checkpoint_chunk(WT_SESSION_IMPL *session, if (F_ISSET(chunk, WT_LSM_CHUNK_ONDISK) && !F_ISSET(chunk, WT_LSM_CHUNK_STABLE) && !chunk->evicted) { - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __lsm_discard_handle(session, chunk->uri, NULL)); if (ret == 0) chunk->evicted = 1; @@ -506,7 +506,7 @@ __lsm_drop_file(WT_SESSION_IMPL *session, const char *uri) * * This will fail with EBUSY if the file is still in use. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __lsm_discard_handle(session, uri, WT_CHECKPOINT)); WT_RET(ret); diff --git a/src/third_party/wiredtiger/src/meta/meta_ckpt.c b/src/third_party/wiredtiger/src/meta/meta_ckpt.c index f7da8525639..df4cd2cb4d6 100644 --- a/src/third_party/wiredtiger/src/meta/meta_ckpt.c +++ b/src/third_party/wiredtiger/src/meta/meta_ckpt.c @@ -451,7 +451,7 @@ __wt_meta_ckptlist_set(WT_SESSION_IMPL *session, if (ckptlsn != NULL) WT_ERR(__wt_buf_catfmt(session, buf, ",checkpoint_lsn=(%" PRIu32 ",%" PRIuMAX ")", - ckptlsn->file, (uintmax_t)ckptlsn->offset)); + ckptlsn->l.file, (uintmax_t)ckptlsn->l.offset)); WT_ERR(__ckpt_set(session, fname, buf->mem)); err: __wt_scr_free(session, &buf); diff --git a/src/third_party/wiredtiger/src/meta/meta_table.c b/src/third_party/wiredtiger/src/meta/meta_table.c index 9938cb07a5c..61cc009c983 100644 --- a/src/third_party/wiredtiger/src/meta/meta_table.c +++ b/src/third_party/wiredtiger/src/meta/meta_table.c @@ -9,6 +9,18 @@ #include "wt_internal.h" /* + * __wt_metadata_init -- + * Metadata initialization. + */ +void +__wt_metadata_init(WT_SESSION_IMPL *session) +{ + /* We cache the metadata file's URI hash for fast detection. */ + S2C(session)->meta_uri_hash = + __wt_hash_city64(WT_METAFILE_URI, strlen(WT_METAFILE_URI)); +} + +/* * __metadata_turtle -- * Return if a key's value should be taken from the turtle file. */ diff --git a/src/third_party/wiredtiger/src/reconcile/rec_write.c b/src/third_party/wiredtiger/src/reconcile/rec_write.c index 332449027a9..c25d7b5e493 100644 --- a/src/third_party/wiredtiger/src/reconcile/rec_write.c +++ b/src/third_party/wiredtiger/src/reconcile/rec_write.c @@ -1889,15 +1889,18 @@ __wt_split_page_size(WT_BTREE *btree, uint32_t maxpagesize) * we don't waste space when we write). */ a = maxpagesize; /* Don't overflow. */ - split_size = (uint32_t) - WT_ALIGN((a * (u_int)btree->split_pct) / 100, btree->allocsize); + split_size = (uint32_t)WT_ALIGN_NEAREST( + (a * (u_int)btree->split_pct) / 100, btree->allocsize); /* - * If the result of that calculation is the same as the allocation unit - * (that happens if the maximum size is the same size as an allocation - * unit, use a percentage of the maximum page size). + * Respect the configured split percentage if the calculated split + * size is either zero or a full page. The user has either configured + * an allocation size that matches the page size, or a split + * percentage that is close to zero or one hundred. Rounding is going + * to provide a worse outcome than having a split point that doesn't + * fall on an allocation size boundary in those cases. */ - if (split_size == btree->allocsize) + if (split_size == 0 || split_size == maxpagesize) split_size = (uint32_t)((a * (u_int)btree->split_pct) / 100); return (split_size); @@ -3286,6 +3289,17 @@ supd_check_complete: } } + bnd->entries = r->entries; + /* Output a verbose message if we create a page without many entries */ + if (WT_VERBOSE_ISSET(session, WT_VERB_SPLIT) && r->entries < 6) + WT_ERR(__wt_verbose(session, WT_VERB_SPLIT, + "Reconciliation creating a page with %" PRIu32 + " entries, memory footprint %" PRIu64 + ", page count %" PRIu32 ", %s, split state: %d\n", + r->entries, r->page->memory_footprint, r->bnd_next, + F_ISSET(r, WT_EVICTING) ? "evict" : "checkpoint", + r->bnd_state)); + WT_ERR(__wt_bt_write(session, buf, addr, &addr_size, false, bnd->already_compressed)); WT_ERR(__wt_strndup(session, addr, addr_size, &bnd->addr.addr)); diff --git a/src/third_party/wiredtiger/src/schema/schema_create.c b/src/third_party/wiredtiger/src/schema/schema_create.c index 8cdcbbcad54..9b3b76b62de 100644 --- a/src/third_party/wiredtiger/src/schema/schema_create.c +++ b/src/third_party/wiredtiger/src/schema/schema_create.c @@ -275,15 +275,11 @@ __create_colgroup(WT_SESSION_IMPL *session, WT_ERR(__wt_schema_create(session, source, sourceconf)); WT_ERR(__wt_config_collapse(session, cfg, &cgconf)); - if (exists) { - if (strcmp(cgconf, origconf) != 0) - WT_ERR_MSG(session, EINVAL, - "%s: does not match existing configuration", name); - goto err; - } - WT_ERR(__wt_metadata_insert(session, name, cgconf)); - WT_ERR(__wt_schema_open_colgroups(session, table)); + if (!exists) { + WT_ERR(__wt_metadata_insert(session, name, cgconf)); + WT_ERR(__wt_schema_open_colgroups(session, table)); + } err: __wt_free(session, cgconf); __wt_free(session, sourceconf); @@ -539,19 +535,17 @@ __create_index(WT_SESSION_IMPL *session, cfg[1] = sourceconf; cfg[2] = confbuf.data; WT_ERR(__wt_config_collapse(session, cfg, &idxconf)); - if (exists) { - if (strcmp(idxconf, origconf) != 0) - WT_ERR_MSG(session, EINVAL, - "%s: does not match existing configuration", name); - goto err; - } - WT_ERR(__wt_metadata_insert(session, name, idxconf)); - /* Make sure that the configuration is valid. */ - WT_ERR(__wt_schema_open_index( - session, table, idxname, strlen(idxname), &idx)); - if (!exists) + if (!exists) { + WT_ERR(__wt_metadata_insert(session, name, idxconf)); + + /* Make sure that the configuration is valid. */ + WT_ERR(__wt_schema_open_index( + session, table, idxname, strlen(idxname), &idx)); + + /* If there is data in the table, fill the index. */ WT_ERR(__fill_index(session, table, idx)); + } err: __wt_free(session, idxconf); __wt_free(session, origconf); @@ -611,23 +605,21 @@ __create_table(WT_SESSION_IMPL *session, WT_ERR_NOTFOUND_OK(ret); WT_ERR(__wt_config_collapse(session, cfg, &tableconf)); - if (exists) { - if (strcmp(tableconf, table->config) != 0) - WT_ERR_MSG(session, EINVAL, - "%s: does not match existing configuration", name); - goto err; - } - WT_ERR(__wt_metadata_insert(session, name, tableconf)); - /* Attempt to open the table now to catch any errors. */ - WT_ERR(__wt_schema_get_table( - session, tablename, strlen(tablename), true, &table)); + if (!exists) { + WT_ERR(__wt_metadata_insert(session, name, tableconf)); + + /* Attempt to open the table now to catch any errors. */ + WT_ERR(__wt_schema_get_table( + session, tablename, strlen(tablename), true, &table)); - if (ncolgroups == 0) { - cgsize = strlen("colgroup:") + strlen(tablename) + 1; - WT_ERR(__wt_calloc_def(session, cgsize, &cgname)); - snprintf(cgname, cgsize, "colgroup:%s", tablename); - WT_ERR(__create_colgroup(session, cgname, exclusive, config)); + if (ncolgroups == 0) { + cgsize = strlen("colgroup:") + strlen(tablename) + 1; + WT_ERR(__wt_calloc_def(session, cgsize, &cgname)); + snprintf(cgname, cgsize, "colgroup:%s", tablename); + WT_ERR(__create_colgroup( + session, cgname, exclusive, config)); + } } if (0) { diff --git a/src/third_party/wiredtiger/src/schema/schema_drop.c b/src/third_party/wiredtiger/src/schema/schema_drop.c index 6ac76930c9a..ead8cc45c62 100644 --- a/src/third_party/wiredtiger/src/schema/schema_drop.c +++ b/src/third_party/wiredtiger/src/schema/schema_drop.c @@ -29,7 +29,7 @@ __drop_file( return (EINVAL); /* Close all btree handles associated with this file. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_conn_dhandle_close_all(session, uri, force)); WT_RET(ret); diff --git a/src/third_party/wiredtiger/src/schema/schema_rename.c b/src/third_party/wiredtiger/src/schema/schema_rename.c index 4ec126394dd..21402ed9332 100644 --- a/src/third_party/wiredtiger/src/schema/schema_rename.c +++ b/src/third_party/wiredtiger/src/schema/schema_rename.c @@ -30,7 +30,7 @@ __rename_file( return (EINVAL); /* Close any btree handles in the file. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_conn_dhandle_close_all(session, uri, false)); WT_ERR(ret); diff --git a/src/third_party/wiredtiger/src/schema/schema_worker.c b/src/third_party/wiredtiger/src/schema/schema_worker.c index a2fe5244c4d..b5ee3bb7f7d 100644 --- a/src/third_party/wiredtiger/src/schema/schema_worker.c +++ b/src/third_party/wiredtiger/src/schema/schema_worker.c @@ -49,7 +49,7 @@ __wt_schema_worker(WT_SESSION_IMPL *session, * any open file handles, including checkpoints. */ if (FLD_ISSET(open_flags, WT_DHANDLE_EXCLUSIVE)) { - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_conn_dhandle_close_all( session, uri, false)); WT_ERR(ret); @@ -63,7 +63,7 @@ __wt_schema_worker(WT_SESSION_IMPL *session, } else if (ret == EBUSY) { WT_ASSERT(session, !FLD_ISSET( open_flags, WT_DHANDLE_EXCLUSIVE)); - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_conn_btree_apply_single_ckpt( session, uri, file_func, cfg)); } diff --git a/src/third_party/wiredtiger/src/session/session_dhandle.c b/src/third_party/wiredtiger/src/session/session_dhandle.c index 1ac758c0cee..1ee3342442c 100644 --- a/src/third_party/wiredtiger/src/session/session_dhandle.c +++ b/src/third_party/wiredtiger/src/session/session_dhandle.c @@ -72,7 +72,8 @@ __session_find_dhandle(WT_SESSION_IMPL *session, bucket = __wt_hash_city64(uri, strlen(uri)) % WT_HASH_ARRAY_SIZE; retry: TAILQ_FOREACH(dhandle_cache, &session->dhhash[bucket], hashq) { dhandle = dhandle_cache->dhandle; - if (WT_DHANDLE_INACTIVE(dhandle) && !WT_IS_METADATA(dhandle)) { + if (WT_DHANDLE_INACTIVE(dhandle) && + !WT_IS_METADATA(session, dhandle)) { __session_discard_dhandle(session, dhandle_cache); /* We deleted our entry, retry from the start. */ goto retry; @@ -407,7 +408,7 @@ __session_dhandle_sweep(WT_SESSION_IMPL *session) difftime(now, dhandle->timeofdeath) > conn->sweep_idle_time))) { WT_STAT_FAST_CONN_INCR(session, dh_session_handles); - WT_ASSERT(session, !WT_IS_METADATA(dhandle)); + WT_ASSERT(session, !WT_IS_METADATA(session, dhandle)); __session_discard_dhandle(session, dhandle_cache); } dhandle_cache = dhandle_cache_next; @@ -453,7 +454,7 @@ __session_get_dhandle( * We didn't find a match in the session cache, search the shared * handle list and cache the handle we find. */ - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __session_find_shared_dhandle(session, uri, checkpoint)); if (ret == 0) ret = __session_add_dhandle(session, NULL); @@ -510,7 +511,7 @@ __wt_session_get_btree(WT_SESSION_IMPL *session, WT_RET(__wt_writeunlock(session, dhandle->rwlock)); WT_WITH_SCHEMA_LOCK(session, ret, - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_session_get_btree( session, uri, checkpoint, cfg, flags))); diff --git a/src/third_party/wiredtiger/src/support/crypto.c b/src/third_party/wiredtiger/src/support/crypto.c index 1049621fb44..ab94ec2c829 100644 --- a/src/third_party/wiredtiger/src/support/crypto.c +++ b/src/third_party/wiredtiger/src/support/crypto.c @@ -21,8 +21,12 @@ __wt_decrypt(WT_SESSION_IMPL *session, uint32_t encrypt_len; uint8_t *dst, *src; - encrypt_len = WT_STORE_SIZE(*((uint32_t *) - ((uint8_t *)in->data + skip))); + encrypt_len = + WT_STORE_SIZE(*((uint32_t *)((uint8_t *)in->data + skip))); +#ifdef WORDS_BIGENDIAN + encrypt_len = __wt_bswap32(encrypt_len); +#endif + if (encrypt_len > in->size) WT_RET_MSG(session, WT_ERROR, "corrupted encrypted item: padded size less than " @@ -104,6 +108,9 @@ __wt_encrypt(WT_SESSION_IMPL *session, * decryption side. */ *unpadded_lenp = WT_STORE_SIZE(result_len); +#ifdef WORDS_BIGENDIAN + *unpadded_lenp = __wt_bswap32(*unpadded_lenp); +#endif /* * Copy in the skipped header bytes, set the final data size. */ diff --git a/src/third_party/wiredtiger/src/support/global.c b/src/third_party/wiredtiger/src/support/global.c index 0234455b6ce..e0d5bafeaa8 100644 --- a/src/third_party/wiredtiger/src/support/global.c +++ b/src/third_party/wiredtiger/src/support/global.c @@ -12,6 +12,35 @@ WT_PROCESS __wt_process; /* Per-process structure */ static int __wt_pthread_once_failed; /* If initialization failed */ /* + * __wt_endian_check -- + * Check the build matches the machine. + */ +static int +__wt_endian_check(void) +{ + uint64_t v; + bool big; + const char *e; + + v = 1; + big = *((uint8_t *)&v) == 0; + +#ifdef WORDS_BIGENDIAN + if (big) + return (0); + e = "big-endian"; +#else + if (!big) + return (0); + e = "little-endian"; +#endif + fprintf(stderr, + "This is a %s build of the WiredTiger data engine, incompatible " + "with this system\n", e); + return (EINVAL); +} + +/* * __wt_global_once -- * Global initialization, run once. */ @@ -31,10 +60,6 @@ __wt_global_once(void) TAILQ_INIT(&__wt_process.connqh); #ifdef HAVE_DIAGNOSTIC - /* Verify the pre-computed metadata hash. */ - WT_ASSERT(NULL, WT_METAFILE_NAME_HASH == - __wt_hash_city64(WT_METAFILE_URI, strlen(WT_METAFILE_URI))); - /* Load debugging code the compiler might optimize out. */ (void)__wt_breakpoint(); #endif @@ -50,6 +75,9 @@ __wt_library_init(void) static bool first = true; WT_DECL_RET; + /* Check the build matches the machine. */ + WT_RET(__wt_endian_check()); + /* * Do per-process initialization once, before anything else, but only * once. I don't know how heavy-weight the function (pthread_once, in diff --git a/src/third_party/wiredtiger/src/support/hash_city.c b/src/third_party/wiredtiger/src/support/hash_city.c index 5780cd7b459..7a700aa809c 100644 --- a/src/third_party/wiredtiger/src/support/hash_city.c +++ b/src/third_party/wiredtiger/src/support/hash_city.c @@ -57,7 +57,6 @@ * compromising on hash quality. */ -#include <string.h> #include "wt_internal.h" /* @@ -86,33 +85,60 @@ static uint32_t UNALIGNED_LOAD32(const char *p) { return (result); } -#if !defined(WORDS_BIGENDIAN) +#ifdef _MSC_VER -#define uint32_in_expected_order(x) (x) -#define uint64_in_expected_order(x) (x) +#include <stdlib.h> +#define bswap_32(x) _byteswap_ulong(x) +#define bswap_64(x) _byteswap_uint64(x) -#else +#elif defined(__APPLE__) -#ifdef __APPLE__ -/* Mac OS X / Darwin features */ +// Mac OS X / Darwin features #include <libkern/OSByteOrder.h> #define bswap_32(x) OSSwapInt32(x) #define bswap_64(x) OSSwapInt64(x) -#elif defined(__sun) +#elif defined(__sun) || defined(sun) #include <sys/byteorder.h> -#define bswap_32 BSWAP_32 -#define bswap_64 BSWAP_64 +#define bswap_32(x) BSWAP_32(x) +#define bswap_64(x) BSWAP_64(x) + +#elif defined(__FreeBSD__) + +#include <sys/endian.h> +#define bswap_32(x) bswap32(x) +#define bswap_64(x) bswap64(x) + +#elif defined(__OpenBSD__) + +#include <sys/types.h> +#define bswap_32(x) swap32(x) +#define bswap_64(x) swap64(x) + +#elif defined(__NetBSD__) + +#include <sys/types.h> +#include <machine/bswap.h> +#if defined(__BSWAP_RENAME) && !defined(__bswap_32) +#define bswap_32(x) bswap32(x) +#define bswap_64(x) bswap64(x) +#endif #else -#include <byteswap.h> + +#define bswap_32(x) __wt_bswap32(x) +#define bswap_64(x) __wt_bswap64(x) + #endif +#ifdef WORDS_BIGENDIAN #define uint32_in_expected_order(x) (bswap_32(x)) #define uint64_in_expected_order(x) (bswap_64(x)) - -#endif /* WORDS_BIGENDIAN */ +#else +#define uint32_in_expected_order(x) (x) +#define uint64_in_expected_order(x) (x) +#endif static uint64_t Fetch64(const char *p) { return uint64_in_expected_order(UNALIGNED_LOAD64(p)); diff --git a/src/third_party/wiredtiger/src/support/hash_fnv.c b/src/third_party/wiredtiger/src/support/hash_fnv.c index 35e7e5f3a73..83dd2574099 100644 --- a/src/third_party/wiredtiger/src/support/hash_fnv.c +++ b/src/third_party/wiredtiger/src/support/hash_fnv.c @@ -83,7 +83,6 @@ * Share and Enjoy! :-) */ -#include <stdlib.h> #include "wt_internal.h" /* diff --git a/src/third_party/wiredtiger/src/txn/txn_ckpt.c b/src/third_party/wiredtiger/src/txn/txn_ckpt.c index 7d4d4d5c27c..6a2c1eef826 100644 --- a/src/third_party/wiredtiger/src/txn/txn_ckpt.c +++ b/src/third_party/wiredtiger/src/txn/txn_ckpt.c @@ -184,7 +184,7 @@ __checkpoint_apply(WT_SESSION_IMPL *session, const char *cfg[], session->ckpt_handle[i].dhandle, ret = (*op)(session, cfg)); else - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __wt_conn_btree_apply_single(session, session->ckpt_handle[i].name, NULL, op, cfg)); WT_RET(ret); @@ -387,7 +387,7 @@ __txn_checkpoint(WT_SESSION_IMPL *session, const char *cfg[]) */ WT_WITH_SCHEMA_LOCK(session, ret, WT_WITH_TABLE_LOCK(session, ret, - WT_WITH_HANDLE_LIST_LOCK(session, ret, + WT_WITH_HANDLE_LIST_LOCK(session, ret = __checkpoint_apply_all( session, cfg, __wt_checkpoint_list, NULL)))); WT_ERR(ret); @@ -812,7 +812,7 @@ __checkpoint_worker(WT_SESSION_IMPL *session, * - On connection close when we know there can't be any races. */ WT_ASSERT(session, !need_tracking || - WT_IS_METADATA(dhandle) || WT_META_TRACKING(session)); + WT_IS_METADATA(session, dhandle) || WT_META_TRACKING(session)); /* * Set the checkpoint LSN to the maximum LSN so that if logging is @@ -1135,7 +1135,7 @@ fake: /* * recovery and open a checkpoint that isn't yet durable. */ if (F_ISSET(conn, WT_CONN_CKPT_SYNC) && - (WT_IS_METADATA(dhandle) || + (WT_IS_METADATA(session, dhandle) || !F_ISSET(&session->txn, WT_TXN_RUNNING))) WT_ERR(__wt_checkpoint_sync(session, NULL)); diff --git a/src/third_party/wiredtiger/src/txn/txn_log.c b/src/third_party/wiredtiger/src/txn/txn_log.c index 4c4a7fb3132..37a6e0b3711 100644 --- a/src/third_party/wiredtiger/src/txn/txn_log.c +++ b/src/third_party/wiredtiger/src/txn/txn_log.c @@ -266,14 +266,16 @@ __wt_txn_checkpoint_logread( WT_LSN *ckpt_lsn) { WT_ITEM ckpt_snapshot; + uint32_t ckpt_file, ckpt_offset; u_int ckpt_nsnapshot; - const char *fmt = WT_UNCHECKED_STRING(IQIU); + const char *fmt = WT_UNCHECKED_STRING(IIIU); WT_RET(__wt_struct_unpack(session, *pp, WT_PTRDIFF(end, *pp), fmt, - &ckpt_lsn->file, &ckpt_lsn->offset, + &ckpt_file, &ckpt_offset, &ckpt_nsnapshot, &ckpt_snapshot)); WT_UNUSED(ckpt_nsnapshot); WT_UNUSED(ckpt_snapshot); + WT_SET_LSN(ckpt_lsn, ckpt_file, ckpt_offset); *pp = end; return (0); } @@ -294,7 +296,7 @@ __wt_txn_checkpoint_log( uint8_t *end, *p; size_t recsize; uint32_t i, rectype = WT_LOGREC_CHECKPOINT; - const char *fmt = WT_UNCHECKED_STRING(IIQIU); + const char *fmt = WT_UNCHECKED_STRING(IIIIU); txn = &session->txn; ckpt_lsn = &txn->ckpt_lsn; @@ -350,13 +352,13 @@ __wt_txn_checkpoint_log( /* Write the checkpoint log record. */ WT_ERR(__wt_struct_size(session, &recsize, fmt, - rectype, ckpt_lsn->file, ckpt_lsn->offset, + rectype, ckpt_lsn->l.file, ckpt_lsn->l.offset, txn->ckpt_nsnapshot, ckpt_snapshot)); WT_ERR(__wt_logrec_alloc(session, recsize, &logrec)); WT_ERR(__wt_struct_pack(session, (uint8_t *)logrec->data + logrec->size, recsize, fmt, - rectype, ckpt_lsn->file, ckpt_lsn->offset, + rectype, ckpt_lsn->l.file, ckpt_lsn->l.offset, txn->ckpt_nsnapshot, ckpt_snapshot)); logrec->size += (uint32_t)recsize; WT_ERR(__wt_log_write(session, logrec, lsnp, @@ -465,12 +467,11 @@ __txn_printlog(WT_SESSION_IMPL *session, { FILE *out; WT_LOG_RECORD *logrec; - WT_LSN ckpt_lsn; WT_TXN_PRINTLOG_ARGS *args; const uint8_t *end, *p; const char *msg; uint64_t txnid; - uint32_t fileid, rectype; + uint32_t fileid, lsnfile, lsnoffset, rectype; int32_t start; bool compressed; @@ -490,8 +491,8 @@ __txn_printlog(WT_SESSION_IMPL *session, WT_RET(__wt_fprintf(out, ",\n")); WT_RET(__wt_fprintf(out, - " { \"lsn\" : [%" PRIu32 ",%" PRId64 "],\n", - lsnp->file, lsnp->offset)); + " { \"lsn\" : [%" PRIu32 ",%" PRIu32 "],\n", + lsnp->l.file, lsnp->l.offset)); WT_RET(__wt_fprintf(out, " \"hdr_flags\" : \"%s\",\n", compressed ? "compressed" : "")); WT_RET(__wt_fprintf(out, @@ -503,11 +504,11 @@ __txn_printlog(WT_SESSION_IMPL *session, switch (rectype) { case WT_LOGREC_CHECKPOINT: WT_RET(__wt_struct_unpack(session, p, WT_PTRDIFF(end, p), - WT_UNCHECKED_STRING(IQ), &ckpt_lsn.file, &ckpt_lsn.offset)); + WT_UNCHECKED_STRING(II), &lsnfile, &lsnoffset)); WT_RET(__wt_fprintf(out, " \"type\" : \"checkpoint\",\n")); WT_RET(__wt_fprintf(out, - " \"ckpt_lsn\" : [%" PRIu32 ",%" PRId64 "]\n", - ckpt_lsn.file, ckpt_lsn.offset)); + " \"ckpt_lsn\" : [%" PRIu32 ",%" PRIu32 "]\n", + lsnfile, lsnoffset)); break; case WT_LOGREC_COMMIT: diff --git a/src/third_party/wiredtiger/src/txn/txn_recover.c b/src/third_party/wiredtiger/src/txn/txn_recover.c index 8051d059d7e..e6bd8a8d755 100644 --- a/src/third_party/wiredtiger/src/txn/txn_recover.c +++ b/src/third_party/wiredtiger/src/txn/txn_recover.c @@ -91,9 +91,9 @@ __recovery_cursor(WT_SESSION_IMPL *session, WT_RECOVERY *r, WT_ERR(__recovery_cursor( \ (session), (r), (lsnp), (fileid), false, (cp))); \ WT_ERR(__wt_verbose((session), WT_VERB_RECOVERY, \ - "%s op %d to file %d at LSN %u/%" PRIuMAX, \ + "%s op %d to file %d at LSN %u/%u", \ (cursor == NULL) ? "Skipping" : "Applying", \ - optype, fileid, lsnp->file, (uintmax_t)lsnp->offset)); \ + optype, fileid, lsnp->l.file, lsnp->l.offset)); \ if (cursor == NULL) \ break @@ -303,8 +303,7 @@ __recovery_setup_file(WT_RECOVERY *r, const char *uri, const char *config) { WT_CONFIG_ITEM cval; WT_LSN lsn; - intmax_t offset; - uint32_t fileid; + uint32_t fileid, lsnfile, lsnoffset; WT_RET(__wt_config_getones(r->session, config, "id", &cval)); fileid = (uint32_t)cval.val; @@ -326,8 +325,8 @@ __recovery_setup_file(WT_RECOVERY *r, const char *uri, const char *config) if (cval.type != WT_CONFIG_ITEM_STRUCT) WT_INIT_LSN(&lsn); else if (sscanf(cval.str, - "(%" SCNu32 ",%" SCNdMAX ")", &lsn.file, &offset) == 2) - lsn.offset = offset; + "(%" SCNu32 ",%" SCNu32 ")", &lsnfile, &lsnoffset) == 2) + WT_SET_LSN(&lsn, lsnfile, lsnoffset); else WT_RET_MSG(r->session, EINVAL, "Failed to parse checkpoint LSN '%.*s'", @@ -335,8 +334,8 @@ __recovery_setup_file(WT_RECOVERY *r, const char *uri, const char *config) r->files[fileid].ckpt_lsn = lsn; WT_RET(__wt_verbose(r->session, WT_VERB_RECOVERY, - "Recovering %s with id %u @ (%" PRIu32 ", %" PRIu64 ")", - uri, fileid, lsn.file, lsn.offset)); + "Recovering %s with id %u @ (%" PRIu32 ", %" PRIu32 ")", + uri, fileid, lsn.l.file, lsn.l.offset)); return (0); @@ -485,8 +484,8 @@ __wt_txn_recover(WT_SESSION_IMPL *session) */ r.metadata_only = false; WT_ERR(__wt_verbose(session, WT_VERB_RECOVERY, - "Main recovery loop: starting at %u/%" PRIuMAX, - r.ckpt_lsn.file, (uintmax_t)r.ckpt_lsn.offset)); + "Main recovery loop: starting at %u/%u", + r.ckpt_lsn.l.file, r.ckpt_lsn.l.offset)); WT_ERR(__wt_log_needs_recovery(session, &r.ckpt_lsn, &needs_rec)); /* * Check if the database was shut down cleanly. If not |