diff options
author | Hari Babu Kommi <haribabu.kommi@mongodb.com> | 2023-05-11 08:04:14 +1000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-10 23:17:33 +0000 |
commit | 497c3b74b396b687193f7ddc116193d5018e0a41 (patch) | |
tree | 821910633e3c83fea8e490672185009c042f554e /src/third_party | |
parent | f3db294c92d4a6f400d2b1843bb06969ffd67aca (diff) | |
download | mongo-497c3b74b396b687193f7ddc116193d5018e0a41.tar.gz |
Import wiredtiger: 1cd2b3c7c9d0b1f5cdd68a0957017eeaecb0dfaf from branch mongodb-master
ref: 56efc96369..1cd2b3c7c9
for: 7.1.0-rc0
WT-10108 Add a data structure encapsulating user level truncate context
Diffstat (limited to 'src/third_party')
-rw-r--r-- | src/third_party/wiredtiger/import.data | 2 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/btree/bt_cursor.c | 12 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/cursor/cur_hs.c | 17 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/cursor/cur_table.c | 6 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/include/extern.h | 14 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/include/truncate.h | 26 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/include/wt_internal.h | 3 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/schema/schema_truncate.c | 31 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/session/session_api.c | 23 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/txn/txn_log.c | 37 |
10 files changed, 119 insertions, 52 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index cb04755a53f..f10d8e5f618 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": "56efc96369f5062bcc5ae2fda84eb0d737a09c99" + "commit": "1cd2b3c7c9d0b1f5cdd68a0957017eeaecb0dfaf" } diff --git a/src/third_party/wiredtiger/src/btree/bt_cursor.c b/src/third_party/wiredtiger/src/btree/bt_cursor.c index 2795ae79740..eb18cb5e333 100644 --- a/src/third_party/wiredtiger/src/btree/bt_cursor.c +++ b/src/third_party/wiredtiger/src/btree/bt_cursor.c @@ -2146,17 +2146,19 @@ err: * Discard a cursor range from the tree. */ int -__wt_btcur_range_truncate(WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop, WT_ITEM *orig_start_key, - WT_ITEM *orig_stop_key, bool local_start) +__wt_btcur_range_truncate(WT_TRUNCATE_INFO *trunc_info) { WT_BTREE *btree; + WT_CURSOR_BTREE *start, *stop; WT_DECL_RET; WT_SESSION_IMPL *session; bool logging; - btree = CUR2BT(start); - session = CUR2S(start); + session = trunc_info->session; + btree = CUR2BT(trunc_info->start); logging = __wt_log_op(session); + start = (WT_CURSOR_BTREE *)trunc_info->start; + stop = (WT_CURSOR_BTREE *)trunc_info->stop; WT_STAT_DATA_INCR(session, cursor_truncate); @@ -2191,7 +2193,7 @@ __wt_btcur_range_truncate(WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop, WT_ITEM * disabling writing of the in-memory remove records to disk. */ if (logging) - WT_RET(__wt_txn_truncate_log(session, orig_start_key, orig_stop_key, local_start)); + WT_RET(__wt_txn_truncate_log(trunc_info)); switch (btree->type) { case BTREE_COL_FIX: diff --git a/src/third_party/wiredtiger/src/cursor/cur_hs.c b/src/third_party/wiredtiger/src/cursor/cur_hs.c index a2ea52ccf68..5a85a5cc2ce 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_hs.c +++ b/src/third_party/wiredtiger/src/cursor/cur_hs.c @@ -1181,20 +1181,21 @@ err: * Discard a cursor range from the history store tree. */ static int -__curhs_range_truncate(WT_CURSOR *start, WT_CURSOR *stop) +__curhs_range_truncate(WT_TRUNCATE_INFO *trunc_info) { WT_CURSOR *start_file_cursor, *stop_file_cursor; WT_SESSION_IMPL *session; - session = CUR2S(start); - start_file_cursor = ((WT_CURSOR_HS *)start)->file_cursor; - stop_file_cursor = stop != NULL ? ((WT_CURSOR_HS *)stop)->file_cursor : NULL; + session = trunc_info->session; + start_file_cursor = ((WT_CURSOR_HS *)trunc_info->start)->file_cursor; + stop_file_cursor = NULL; WT_STAT_DATA_INCR(session, cursor_truncate); WT_ASSERT(session, F_ISSET(start_file_cursor, WT_CURSTD_KEY_INT)); WT_RET(__wt_cursor_localkey(start_file_cursor)); - if (stop != NULL) { + if (F_ISSET(trunc_info, WT_TRUNC_EXPLICIT_STOP)) { + stop_file_cursor = ((WT_CURSOR_HS *)trunc_info->stop)->file_cursor; WT_ASSERT(session, F_ISSET(stop_file_cursor, WT_CURSTD_KEY_INT)); WT_RET(__wt_cursor_localkey(stop_file_cursor)); } @@ -1210,15 +1211,15 @@ __curhs_range_truncate(WT_CURSOR *start, WT_CURSOR *stop) * Discard a cursor range from the history store tree. */ int -__wt_curhs_range_truncate(WT_CURSOR *start, WT_CURSOR *stop) +__wt_curhs_range_truncate(WT_TRUNCATE_INFO *trunc_info) { WT_CURSOR *start_file_cursor; WT_DECL_RET; - start_file_cursor = ((WT_CURSOR_HS *)start)->file_cursor; + start_file_cursor = ((WT_CURSOR_HS *)trunc_info->start)->file_cursor; WT_WITH_BTREE( - CUR2S(start), CUR2BT(start_file_cursor), ret = __curhs_range_truncate(start, stop)); + trunc_info->session, CUR2BT(start_file_cursor), ret = __curhs_range_truncate(trunc_info)); return (ret); } diff --git a/src/third_party/wiredtiger/src/cursor/cur_table.c b/src/third_party/wiredtiger/src/cursor/cur_table.c index c132c76fd56..3b27bd35165 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_table.c +++ b/src/third_party/wiredtiger/src/cursor/cur_table.c @@ -748,10 +748,10 @@ err: * Truncate of a cursor range, table implementation. */ int -__wt_table_range_truncate(WT_CURSOR_TABLE *start, WT_CURSOR_TABLE *stop) +__wt_table_range_truncate(WT_TRUNCATE_INFO *trunc_info) { WT_CURSOR *wt_start, *wt_stop; - WT_CURSOR_TABLE *ctable; + WT_CURSOR_TABLE *ctable, *start, *stop; WT_DECL_ITEM(key); WT_DECL_RET; WT_ITEM raw; @@ -759,6 +759,8 @@ __wt_table_range_truncate(WT_CURSOR_TABLE *start, WT_CURSOR_TABLE *stop) u_int i; int cmp; + start = (WT_CURSOR_TABLE *)trunc_info->start; + stop = (WT_CURSOR_TABLE *)trunc_info->stop; ctable = (start != NULL) ? start : stop; session = CUR2S(ctable); wt_start = start == NULL ? NULL : &start->iface; diff --git a/src/third_party/wiredtiger/src/include/extern.h b/src/third_party/wiredtiger/src/include/extern.h index a3ffa3efdf8..4fa14f94f2a 100644 --- a/src/third_party/wiredtiger/src/include/extern.h +++ b/src/third_party/wiredtiger/src/include/extern.h @@ -287,8 +287,7 @@ extern int __wt_btcur_next_random(WT_CURSOR_BTREE *cbt) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_btcur_prev(WT_CURSOR_BTREE *cbt, bool truncating) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); -extern int __wt_btcur_range_truncate(WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop, - WT_ITEM *orig_start_key, WT_ITEM *orig_stop_key, bool local_start) +extern int __wt_btcur_range_truncate(WT_TRUNCATE_INFO *trunc_info) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_btcur_remove(WT_CURSOR_BTREE *cbt, bool positioned) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); @@ -556,7 +555,7 @@ extern int __wt_curhs_cache(WT_SESSION_IMPL *session) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_curhs_open(WT_SESSION_IMPL *session, WT_CURSOR *owner, WT_CURSOR **cursorp) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); -extern int __wt_curhs_range_truncate(WT_CURSOR *start, WT_CURSOR *stop) +extern int __wt_curhs_range_truncate(WT_TRUNCATE_INFO *trunc_info) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_curhs_search_near_after(WT_SESSION_IMPL *session, WT_CURSOR *cursor) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); @@ -1421,8 +1420,7 @@ extern int __wt_schema_project_out(WT_SESSION_IMPL *session, WT_CURSOR **cp, con extern int __wt_schema_project_slice(WT_SESSION_IMPL *session, WT_CURSOR **cp, const char *proj_arg, bool key_only, const char *vformat, WT_ITEM *value) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); -extern int __wt_schema_range_truncate(WT_SESSION_IMPL *session, WT_CURSOR *start, WT_CURSOR *stop, - WT_ITEM *orig_start_key, WT_ITEM *orig_stop_key, bool local_start) +extern int __wt_schema_range_truncate(WT_TRUNCATE_INFO *trunc_info) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_schema_release_table(WT_SESSION_IMPL *session, WT_TABLE **tablep) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); @@ -1554,7 +1552,7 @@ extern int __wt_sync_obsolete_cleanup(WT_SESSION_IMPL *session, WT_REF *parent) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_table_check(WT_SESSION_IMPL *session, WT_TABLE *table) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); -extern int __wt_table_range_truncate(WT_CURSOR_TABLE *start, WT_CURSOR_TABLE *stop) +extern int __wt_table_range_truncate(WT_TRUNCATE_INFO *trunc_info) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_thread_group_create(WT_SESSION_IMPL *session, WT_THREAD_GROUP *group, const char *name, uint32_t min, uint32_t max, uint32_t flags, @@ -1693,8 +1691,8 @@ extern int __wt_txn_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[], b WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_txn_set_timestamp_uint(WT_SESSION_IMPL *session, WT_TS_TXN_TYPE which, wt_timestamp_t ts) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); -extern int __wt_txn_truncate_log(WT_SESSION_IMPL *session, WT_ITEM *orig_start_key, - WT_ITEM *orig_stop_key, bool local_start) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); +extern int __wt_txn_truncate_log(WT_TRUNCATE_INFO *trunc_info) + WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_txn_ts_log(WT_SESSION_IMPL *session) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); extern int __wt_txn_update_oldest(WT_SESSION_IMPL *session, uint32_t flags) diff --git a/src/third_party/wiredtiger/src/include/truncate.h b/src/third_party/wiredtiger/src/include/truncate.h new file mode 100644 index 00000000000..ee00e4f163e --- /dev/null +++ b/src/third_party/wiredtiger/src/include/truncate.h @@ -0,0 +1,26 @@ +/*- + * Copyright (c) 2014-present MongoDB, Inc. + * Copyright (c) 2008-2014 WiredTiger, Inc. + * All rights reserved. + * + * See the file LICENSE for redistribution information. + */ + +/* + * WT_TRUNCATE_INFO + * A set of context associated with a range truncate operation. + */ +struct __wt_truncate_info { + WT_SESSION_IMPL *session; + const char *uri; + WT_CURSOR *start; + WT_CURSOR *stop; + WT_ITEM *orig_start_key; + WT_ITEM *orig_stop_key; + +/* AUTOMATIC FLAG VALUE GENERATION START 0 */ +#define WT_TRUNC_EXPLICIT_START 0x1u +#define WT_TRUNC_EXPLICIT_STOP 0x2u + /* AUTOMATIC FLAG VALUE GENERATION STOP 32 */ + uint32_t flags; +}; diff --git a/src/third_party/wiredtiger/src/include/wt_internal.h b/src/third_party/wiredtiger/src/include/wt_internal.h index 3e78cec2b26..9e3d11e75af 100644 --- a/src/third_party/wiredtiger/src/include/wt_internal.h +++ b/src/third_party/wiredtiger/src/include/wt_internal.h @@ -367,6 +367,8 @@ struct __wt_time_aggregate; typedef struct __wt_time_aggregate WT_TIME_AGGREGATE; struct __wt_time_window; typedef struct __wt_time_window WT_TIME_WINDOW; +struct __wt_truncate_info; +typedef struct __wt_truncate_info WT_TRUNCATE_INFO; struct __wt_txn; typedef struct __wt_txn WT_TXN; struct __wt_txn_global; @@ -462,6 +464,7 @@ typedef uint64_t wt_timestamp_t; #include "schema.h" #include "thread_group.h" #include "tiered.h" +#include "truncate.h" #include "txn.h" #include "verbose.h" diff --git a/src/third_party/wiredtiger/src/schema/schema_truncate.c b/src/third_party/wiredtiger/src/schema/schema_truncate.c index 3b1cfcfd1e2..3393a9834e0 100644 --- a/src/third_party/wiredtiger/src/schema/schema_truncate.c +++ b/src/third_party/wiredtiger/src/schema/schema_truncate.c @@ -126,7 +126,10 @@ __wt_schema_truncate(WT_SESSION_IMPL *session, const char *uri, const char *cfg[ /* * __wt_range_truncate -- - * Truncate of a cursor range, default implementation. + * Truncate of a cursor range, default implementation. This truncate takes explicit cursors + * rather than a truncate information structure since it is used to implement truncate for + * column groups within a complex table, and those use different cursors than the API level + * truncate tracks. */ int __wt_range_truncate(WT_CURSOR *start, WT_CURSOR *stop) @@ -156,30 +159,30 @@ __wt_range_truncate(WT_CURSOR *start, WT_CURSOR *stop) * WT_SESSION::truncate with a range. */ int -__wt_schema_range_truncate(WT_SESSION_IMPL *session, WT_CURSOR *start, WT_CURSOR *stop, - WT_ITEM *orig_start_key, WT_ITEM *orig_stop_key, bool local_start) +__wt_schema_range_truncate(WT_TRUNCATE_INFO *trunc_info) { WT_DATA_SOURCE *dsrc; WT_DECL_RET; + WT_SESSION_IMPL *session; const char *uri; - uri = start->internal_uri; + session = trunc_info->session; + uri = trunc_info->uri; if (WT_STREQ(uri, WT_HS_URI)) - ret = __wt_curhs_range_truncate(start, stop); + ret = __wt_curhs_range_truncate(trunc_info); else if (WT_PREFIX_MATCH(uri, "file:")) { - WT_ERR(__cursor_needkey(start)); - if (stop != NULL) - WT_ERR(__cursor_needkey(stop)); - WT_WITH_BTREE(session, CUR2BT(start), - ret = __wt_btcur_range_truncate((WT_CURSOR_BTREE *)start, (WT_CURSOR_BTREE *)stop, - orig_start_key, orig_stop_key, local_start)); + WT_ERR(__cursor_needkey(trunc_info->start)); + if (F_ISSET(trunc_info, WT_TRUNC_EXPLICIT_STOP)) + WT_ERR(__cursor_needkey(trunc_info->stop)); + WT_WITH_BTREE( + session, CUR2BT(trunc_info->start), ret = __wt_btcur_range_truncate(trunc_info)); } else if (WT_PREFIX_MATCH(uri, "table:")) - ret = __wt_table_range_truncate((WT_CURSOR_TABLE *)start, (WT_CURSOR_TABLE *)stop); + ret = __wt_table_range_truncate(trunc_info); else if ((dsrc = __wt_schema_get_source(session, uri)) != NULL && dsrc->range_truncate != NULL) - ret = dsrc->range_truncate(dsrc, &session->iface, start, stop); + ret = dsrc->range_truncate(dsrc, &session->iface, trunc_info->start, trunc_info->stop); else - ret = __wt_range_truncate(start, stop); + ret = __wt_range_truncate(trunc_info->start, trunc_info->stop); err: return (ret); } diff --git a/src/third_party/wiredtiger/src/session/session_api.c b/src/third_party/wiredtiger/src/session/session_api.c index 5466f037dbb..2c5cc0f2cc3 100644 --- a/src/third_party/wiredtiger/src/session/session_api.c +++ b/src/third_party/wiredtiger/src/session/session_api.c @@ -1487,11 +1487,20 @@ __wt_session_range_truncate( WT_DECL_ITEM(orig_stop_key); WT_DECL_RET; WT_ITEM start_key, stop_key; + WT_TRUNCATE_INFO *trunc_info, _trunc_info; int cmp; bool local_start; orig_start_key = orig_stop_key = NULL; local_start = false; + + /* Setup the truncate information structure */ + trunc_info = &_trunc_info; + memset(trunc_info, 0, sizeof(*trunc_info)); + if (uri == NULL && start != NULL) + F_SET(trunc_info, WT_TRUNC_EXPLICIT_START); + if (uri == NULL && stop != NULL) + F_SET(trunc_info, WT_TRUNC_EXPLICIT_STOP); if (uri != NULL) { WT_ASSERT(session, WT_BTREE_PREFIX(uri)); /* @@ -1598,8 +1607,18 @@ __wt_session_range_truncate( goto done; } - WT_ERR( - __wt_schema_range_truncate(session, start, stop, orig_start_key, orig_stop_key, local_start)); + /* + * Now that the truncate is setup and ready regardless of how the API was called, populate our + * truncate information cookie. + */ + trunc_info->session = session; + trunc_info->uri = uri != NULL ? uri : start->internal_uri; + trunc_info->start = start; + trunc_info->stop = stop; + trunc_info->orig_start_key = orig_start_key; + trunc_info->orig_stop_key = orig_stop_key; + + WT_ERR(__wt_schema_range_truncate(trunc_info)); done: err: diff --git a/src/third_party/wiredtiger/src/txn/txn_log.c b/src/third_party/wiredtiger/src/txn/txn_log.c index 0f3be66851c..8548a1543ab 100644 --- a/src/third_party/wiredtiger/src/txn/txn_log.c +++ b/src/third_party/wiredtiger/src/txn/txn_log.c @@ -571,14 +571,15 @@ err: * Begin truncating a range of a file. */ int -__wt_txn_truncate_log( - WT_SESSION_IMPL *session, WT_ITEM *orig_start_key, WT_ITEM *orig_stop_key, bool local_start) +__wt_txn_truncate_log(WT_TRUNCATE_INFO *trunc_info) { WT_BTREE *btree; WT_ITEM *item; + WT_SESSION_IMPL *session; WT_TXN_OP *op; uint64_t start_recno, stop_recno; + session = trunc_info->session; btree = S2BT(session); start_recno = WT_RECNO_OOB; stop_recno = WT_RECNO_OOB; @@ -594,28 +595,40 @@ __wt_txn_truncate_log( * If the user provided a start cursor key (i.e. local_start is false) then use the original * key provided. */ - if (!local_start && orig_start_key != NULL) { + if (F_ISSET(trunc_info, WT_TRUNC_EXPLICIT_START)) { + WT_ASSERT_ALWAYS(session, trunc_info->orig_start_key != NULL, + "Truncate log operation with explicit range start has empty original key."); op->u.truncate_row.mode = WT_TXN_TRUNC_START; item = &op->u.truncate_row.start; - WT_RET(__wt_buf_set(session, item, orig_start_key->data, orig_start_key->size)); + WT_RET(__wt_buf_set( + session, item, trunc_info->orig_start_key->data, trunc_info->orig_start_key->size)); } - if (orig_stop_key != NULL) { + if (F_ISSET(trunc_info, WT_TRUNC_EXPLICIT_STOP)) { + WT_ASSERT_ALWAYS(session, trunc_info->orig_stop_key != NULL, + "Truncate log operation with explicit range stop has empty original key."); op->u.truncate_row.mode = (op->u.truncate_row.mode == WT_TXN_TRUNC_ALL) ? WT_TXN_TRUNC_STOP : WT_TXN_TRUNC_BOTH; item = &op->u.truncate_row.stop; - WT_RET(__wt_buf_set(session, item, orig_stop_key->data, orig_stop_key->size)); + WT_RET(__wt_buf_set( + session, item, trunc_info->orig_stop_key->data, trunc_info->orig_stop_key->size)); } } else { /* * If the user provided cursors, unpack the original keys that were saved in the cursor's * lower_bound field. */ - if (!local_start && orig_start_key != NULL) - WT_RET(__wt_struct_unpack( - session, orig_start_key->data, orig_start_key->size, "q", &start_recno)); - if (orig_stop_key != NULL) - WT_RET(__wt_struct_unpack( - session, orig_stop_key->data, orig_stop_key->size, "q", &stop_recno)); + if (F_ISSET(trunc_info, WT_TRUNC_EXPLICIT_START)) { + WT_ASSERT_ALWAYS(session, trunc_info->orig_start_key != NULL, + "Truncate log operation with explicit range start has empty original key."); + WT_RET(__wt_struct_unpack(session, trunc_info->orig_start_key->data, + trunc_info->orig_start_key->size, "q", &start_recno)); + } + if (F_ISSET(trunc_info, WT_TRUNC_EXPLICIT_STOP)) { + WT_ASSERT_ALWAYS(session, trunc_info->orig_stop_key != NULL, + "Truncate log operation with explicit range stop has empty original key."); + WT_RET(__wt_struct_unpack(session, trunc_info->orig_stop_key->data, + trunc_info->orig_stop_key->size, "q", &stop_recno)); + } op->type = WT_TXN_OP_TRUNCATE_COL; op->u.truncate_col.start = start_recno; |