diff options
author | Will Korteland <will.korteland@mongodb.com> | 2022-04-29 04:01:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-29 04:41:56 +0000 |
commit | 8a3dc0b3d84b06c74ebeea4fa0bd3bbda7df060a (patch) | |
tree | 1f82bfea049c9c1b34aae4742543a19043449dcc | |
parent | dfe78f293480782ff9afccbf712d3b61819158ae (diff) | |
download | mongo-8a3dc0b3d84b06c74ebeea4fa0bd3bbda7df060a.tar.gz |
Import wiredtiger: c2c06e9771f4006cb69b96dc30e0a36105a0578a from branch mongodb-master
ref: 1b1eef9191..c2c06e9771
for: 6.1.0-rc0
WT-9208 add cursor method to allow applications to detect checkpoint cursor mismatch
20 files changed, 86 insertions, 16 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index 5817b4944f5..32c238cf171 100644 --- a/src/third_party/wiredtiger/import.data +++ b/src/third_party/wiredtiger/import.data @@ -2,5 +2,5 @@ "vendor": "wiredtiger", "github": "wiredtiger/wiredtiger.git", "branch": "mongodb-master", - "commit": "1b1eef9191b429fd2b75a66c1d50a9384e857b0d" + "commit": "c2c06e9771f4006cb69b96dc30e0a36105a0578a" } diff --git a/src/third_party/wiredtiger/src/cursor/cur_backup.c b/src/third_party/wiredtiger/src/cursor/cur_backup.c index 9965da89fe3..6732875c085 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_backup.c +++ b/src/third_party/wiredtiger/src/cursor/cur_backup.c @@ -272,6 +272,7 @@ __wt_curbackup_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *other, __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curbackup_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_BACKUP *cb, *othercb; diff --git a/src/third_party/wiredtiger/src/cursor/cur_config.c b/src/third_party/wiredtiger/src/cursor/cur_config.c index 0fbf1066b27..a37ce8ef6ec 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_config.c +++ b/src/third_party/wiredtiger/src/cursor/cur_config.c @@ -54,6 +54,7 @@ __wt_curconfig_open( __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curconfig_close); WT_CURSOR_CONFIG *cconfig; WT_CURSOR *cursor; diff --git a/src/third_party/wiredtiger/src/cursor/cur_ds.c b/src/third_party/wiredtiger/src/cursor/cur_ds.c index c3e28dd5f59..ecc666ee3a1 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_ds.c +++ b/src/third_party/wiredtiger/src/cursor/cur_ds.c @@ -428,6 +428,7 @@ __wt_curds_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, con __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curds_close); /* close */ WT_CONFIG_ITEM cval, metadata; WT_CURSOR *cursor, *source; diff --git a/src/third_party/wiredtiger/src/cursor/cur_dump.c b/src/third_party/wiredtiger/src/cursor/cur_dump.c index 64e273f801b..257f40c2f43 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_dump.c +++ b/src/third_party/wiredtiger/src/cursor/cur_dump.c @@ -399,6 +399,7 @@ __wt_curdump_create(WT_CURSOR *child, WT_CURSOR *owner, WT_CURSOR **cursorp) __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curdump_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_DUMP *cdump; diff --git a/src/third_party/wiredtiger/src/cursor/cur_file.c b/src/third_party/wiredtiger/src/cursor/cur_file.c index 09c8506e59b..310c8d4c442 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_file.c +++ b/src/third_party/wiredtiger/src/cursor/cur_file.c @@ -93,6 +93,20 @@ __curfile_check_cbt_txn(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt) } /* + * __wt_cursor_checkpoint_id -- + * Return the checkpoint ID for checkpoint cursors, otherwise 0. + */ +uint64_t +__wt_cursor_checkpoint_id(WT_CURSOR *cursor) +{ + WT_CURSOR_BTREE *cbt; + + cbt = (WT_CURSOR_BTREE *)cursor; + + return (cbt->checkpoint_id); +} + +/* * __curfile_compare -- * WT_CURSOR->compare method for the btree cursor type. */ @@ -843,6 +857,9 @@ __curfile_setup_checkpoint(WT_CURSOR_BTREE *cbt, const char *cfg[], WT_DATA_HAND */ cbt->checkpoint_write_gen = ckpt_snapshot->snapshot_write_gen; + /* Remember the checkpoint ID so it can be returned to the application. */ + cbt->checkpoint_id = ckpt_snapshot->ckpt_id; + /* * Override the read timestamp if explicitly provided. Otherwise it's the stable timestamp from * the checkpoint. Replace it in the snapshot info if necessary. @@ -919,6 +936,7 @@ __curfile_create(WT_SESSION_IMPL *session, WT_CURSOR *owner, const char *cfg[], __wt_cursor_largest_key, /* largest_key */ __curfile_cache, /* cache */ __curfile_reopen, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curfile_close); /* close */ WT_BTREE *btree; WT_CONFIG_ITEM cval; @@ -1126,6 +1144,7 @@ __wt_curfile_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, c * and furthermore any internally opened history store cursors come through here, so this case * does matter.) */ + ckpt_snapshot.ckpt_id = 0; ckpt_snapshot.oldest_ts = WT_TS_NONE; ckpt_snapshot.stable_ts = WT_TS_NONE; ckpt_snapshot.snapshot_write_gen = 0; diff --git a/src/third_party/wiredtiger/src/cursor/cur_hs.c b/src/third_party/wiredtiger/src/cursor/cur_hs.c index 4f99e78f3d5..02266339b1f 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_hs.c +++ b/src/third_party/wiredtiger/src/cursor/cur_hs.c @@ -1135,6 +1135,7 @@ __wt_curhs_open(WT_SESSION_IMPL *session, WT_CURSOR *owner, WT_CURSOR **cursorp) __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curhs_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_HS *hs_cursor; diff --git a/src/third_party/wiredtiger/src/cursor/cur_index.c b/src/third_party/wiredtiger/src/cursor/cur_index.c index 8e74e0e7e02..ef4703524af 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_index.c +++ b/src/third_party/wiredtiger/src/cursor/cur_index.c @@ -456,6 +456,7 @@ __wt_curindex_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curindex_close); /* close */ WT_CURSOR_INDEX *cindex; WT_CURSOR *cursor; diff --git a/src/third_party/wiredtiger/src/cursor/cur_join.c b/src/third_party/wiredtiger/src/cursor/cur_join.c index b721fe9d0ee..292149b6c86 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_join.c +++ b/src/third_party/wiredtiger/src/cursor/cur_join.c @@ -579,6 +579,7 @@ __curjoin_entry_member( __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __wt_cursor_notsup); /* close */ WT_DECL_RET; WT_INDEX *idx; @@ -1226,6 +1227,7 @@ __wt_curjoin_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, c __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curjoin_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_JOIN *cjoin; diff --git a/src/third_party/wiredtiger/src/cursor/cur_log.c b/src/third_party/wiredtiger/src/cursor/cur_log.c index ebd65ebe426..cb217665681 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_log.c +++ b/src/third_party/wiredtiger/src/cursor/cur_log.c @@ -343,6 +343,7 @@ __wt_curlog_open(WT_SESSION_IMPL *session, const char *uri, const char *cfg[], W __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curlog_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_LOG *cl; diff --git a/src/third_party/wiredtiger/src/cursor/cur_metadata.c b/src/third_party/wiredtiger/src/cursor/cur_metadata.c index f0b04128704..36ef6fd2e1b 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_metadata.c +++ b/src/third_party/wiredtiger/src/cursor/cur_metadata.c @@ -578,6 +578,7 @@ __wt_curmetadata_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owne __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curmetadata_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_METADATA *mdc; diff --git a/src/third_party/wiredtiger/src/cursor/cur_stat.c b/src/third_party/wiredtiger/src/cursor/cur_stat.c index ef8be97bc40..126ee552683 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_stat.c +++ b/src/third_party/wiredtiger/src/cursor/cur_stat.c @@ -611,6 +611,7 @@ __wt_curstat_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *other, c __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curstat_close); /* close */ WT_CONFIG_ITEM cval, sval; WT_CURSOR *cursor; diff --git a/src/third_party/wiredtiger/src/cursor/cur_table.c b/src/third_party/wiredtiger/src/cursor/cur_table.c index 3f6d53db4ae..0fe18bdfd3c 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_table.c +++ b/src/third_party/wiredtiger/src/cursor/cur_table.c @@ -105,6 +105,7 @@ __wt_apply_single_idx(WT_SESSION_IMPL *session, WT_INDEX *idx, WT_CURSOR *cur, __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __wt_cursor_notsup); /* close */ WT_CURSOR_EXTRACTOR extract_cursor; WT_DECL_RET; @@ -992,6 +993,7 @@ __wt_curtable_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, __curtable_largest_key, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curtable_close); /* close */ WT_CONFIG_ITEM cval; WT_CURSOR *cursor; diff --git a/src/third_party/wiredtiger/src/cursor/cur_version.c b/src/third_party/wiredtiger/src/cursor/cur_version.c index 4088a8dec0d..e70fa3ce25a 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_version.c +++ b/src/third_party/wiredtiger/src/cursor/cur_version.c @@ -606,6 +606,7 @@ __wt_curversion_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __curversion_close); /* close */ WT_CURSOR *cursor; diff --git a/src/third_party/wiredtiger/src/include/cursor.h b/src/third_party/wiredtiger/src/include/cursor.h index c2f533dcd61..d51db10de8f 100644 --- a/src/third_party/wiredtiger/src/include/cursor.h +++ b/src/third_party/wiredtiger/src/include/cursor.h @@ -14,25 +14,25 @@ */ #define WT_CURSOR_STATIC_INIT(n, get_key, get_value, set_key, set_value, compare, equals, next, \ prev, reset, search, search_near, insert, modify, update, remove, reserve, reconfigure, \ - largest_key, cache, reopen, close) \ + largest_key, cache, reopen, checkpoint_id, close) \ static const WT_CURSOR n = { \ NULL, /* session */ \ NULL, /* uri */ \ NULL, /* key_format */ \ NULL, /* value_format */ \ get_key, get_value, set_key, set_value, compare, equals, next, prev, reset, search, \ - search_near, insert, modify, update, remove, reserve, close, largest_key, reconfigure, \ - cache, reopen, 0, /* uri_hash */ \ - {NULL, NULL}, /* TAILQ_ENTRY q */ \ - 0, /* recno key */ \ - {0}, /* recno raw buffer */ \ - NULL, /* json_private */ \ - NULL, /* lang_private */ \ - {NULL, 0, NULL, 0, 0}, /* WT_ITEM key */ \ - {NULL, 0, NULL, 0, 0}, /* WT_ITEM value */ \ - 0, /* int saved_err */ \ - NULL, /* internal_uri */ \ - 0 /* uint32_t flags */ \ + search_near, insert, modify, update, remove, reserve, checkpoint_id, close, largest_key, \ + reconfigure, cache, reopen, 0, /* uri_hash */ \ + {NULL, NULL}, /* TAILQ_ENTRY q */ \ + 0, /* recno key */ \ + {0}, /* recno raw buffer */ \ + NULL, /* json_private */ \ + NULL, /* lang_private */ \ + {NULL, 0, NULL, 0, 0}, /* WT_ITEM key */ \ + {NULL, 0, NULL, 0, 0}, /* WT_ITEM value */ \ + 0, /* int saved_err */ \ + NULL, /* internal_uri */ \ + 0 /* uint32_t flags */ \ } struct __wt_cursor_backup { @@ -200,12 +200,15 @@ struct __wt_cursor_btree { * Bits used by checkpoint cursor: a private transaction, used to provide the proper read * snapshot; a reference to the corresponding history store checkpoint, which keeps it from * disappearing under us if it's unnamed and also tracks its identity for use in history store - * accesses; and a write generation, used to override the tree's base write generation in the - * unpacking cleanup code. + * accesses; a write generation, used to override the tree's base write generation in the + * unpacking cleanup code; and a checkpoint ID, which is available to applications through an + * undocumented interface to allow them to open cursors on multiple files and check if they got + * the same checkpoint in all of them. */ WT_TXN *checkpoint_txn; WT_DATA_HANDLE *checkpoint_hs_dhandle; uint64_t checkpoint_write_gen; + uint64_t checkpoint_id; /* * Fixed-length column-store items are a single byte, and it's simpler and cheaper to allocate diff --git a/src/third_party/wiredtiger/src/include/extern.h b/src/third_party/wiredtiger/src/include/extern.h index 3840811a32d..7a3faa8ea62 100644 --- a/src/third_party/wiredtiger/src/include/extern.h +++ b/src/third_party/wiredtiger/src/include/extern.h @@ -1675,6 +1675,8 @@ extern uint32_t __wt_rduppo2(uint32_t n, uint32_t po2) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern uint32_t __wt_split_page_size(int split_pct, uint32_t maxpagesize, uint32_t allocsize) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); +extern uint64_t __wt_cursor_checkpoint_id(WT_CURSOR *cursor) + WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern uint64_t __wt_gen(WT_SESSION_IMPL *session, int which) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern uint64_t __wt_hash_city64(const void *s, size_t len) diff --git a/src/third_party/wiredtiger/src/include/meta.h b/src/third_party/wiredtiger/src/include/meta.h index 39c4b36e36e..23ae4f59799 100644 --- a/src/third_party/wiredtiger/src/include/meta.h +++ b/src/third_party/wiredtiger/src/include/meta.h @@ -176,6 +176,7 @@ struct __wt_ckpt { * Snapshot and timestamp information associated with a checkpoint. */ struct __wt_ckpt_snapshot { + uint64_t ckpt_id; uint64_t oldest_ts; uint64_t stable_ts; uint64_t snapshot_write_gen; diff --git a/src/third_party/wiredtiger/src/include/wiredtiger.in b/src/third_party/wiredtiger/src/include/wiredtiger.in index 332d23e1683..f27e0e79d94 100644 --- a/src/third_party/wiredtiger/src/include/wiredtiger.in +++ b/src/third_party/wiredtiger/src/include/wiredtiger.in @@ -617,6 +617,20 @@ struct __wt_cursor { int __F(reserve)(WT_CURSOR *cursor); /*! @} */ +#ifndef DOXYGEN + /*! + * If the cursor is opened on a checkpoint, return a unique identifier for the checkpoint; + * otherwise return 0. + * + * This allows applications to confirm that checkpoint cursors opened on default checkpoints + * in different objects reference the same database checkpoint. + * + * @param cursor the cursor handle + * @errors + */ + uint64_t __F(checkpoint_id)(WT_CURSOR *cursor); +#endif + /*! * Close the cursor. * diff --git a/src/third_party/wiredtiger/src/lsm/lsm_cursor.c b/src/third_party/wiredtiger/src/lsm/lsm_cursor.c index 3cb9a9bf46e..b28977bc0d0 100644 --- a/src/third_party/wiredtiger/src/lsm/lsm_cursor.c +++ b/src/third_party/wiredtiger/src/lsm/lsm_cursor.c @@ -1693,6 +1693,7 @@ __wt_clsm_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, cons __wt_cursor_notsup, /* largest_key */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ __wt_clsm_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_LSM *clsm; diff --git a/src/third_party/wiredtiger/src/session/session_dhandle.c b/src/third_party/wiredtiger/src/session/session_dhandle.c index 5c0ce47dc97..bd6baab55a4 100644 --- a/src/third_party/wiredtiger/src/session/session_dhandle.c +++ b/src/third_party/wiredtiger/src/session/session_dhandle.c @@ -372,6 +372,7 @@ __wt_session_get_btree_ckpt(WT_SESSION_IMPL *session, const char *uri, const cha if (hs_dhandlep != NULL) *hs_dhandlep = NULL; if (ckpt_snapshot != NULL) { + ckpt_snapshot->ckpt_id = 0; ckpt_snapshot->oldest_ts = WT_TS_NONE; ckpt_snapshot->stable_ts = WT_TS_NONE; ckpt_snapshot->snapshot_write_gen = 0; @@ -534,6 +535,21 @@ __wt_session_get_btree_ckpt(WT_SESSION_IMPL *session, const char *uri, const cha if (ds_time > snapshot_time || hs_time > snapshot_time || stable_time > snapshot_time || oldest_time > snapshot_time) ret = __wt_set_return(session, EBUSY); + + /* + * Return the snapshot's wall time as the (global) checkpoint ID. The ID is a 64-bit + * value of unspecified semantics such that if you open the same checkpoint name and get + * different IDs, the cursors you got are looking at different versions of that + * checkpoint, which usually isn't what you want. Test code uses this to check whether a + * collection of checkpoint cursors they opened on different files all came from the + * same global checkpoint or not. This is the same problem as checking if the history + * store checkpoint and data store checkpoint match, so the wall time is the right thing + * to use for it. Note that it will be 0 for all checkpoints from before this run; + * however, it is impossible to open the same checkpoint name twice and get two + * different checkpoints from before the current database run, since the newer one must + * have just been created. + */ + ckpt_snapshot->ckpt_id = snapshot_time; } if (ret == 0) { |