Skip to content

Commit 07b4909

Browse files
lukechMongoDB Bot
authored and
MongoDB Bot
committed
Import wiredtiger: ce1f45b4908579eb3e9dd588ee6ed4267783fe13 from branch mongodb-8.1 (#36272)
GitOrigin-RevId: c441b67d7260844c1422bf259e23c054a33ee7d8
1 parent b95f197 commit 07b4909

File tree

11 files changed

+198
-35
lines changed

11 files changed

+198
-35
lines changed

src/third_party/wiredtiger/import.data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"vendor": "wiredtiger",
33
"github": "wiredtiger/wiredtiger",
44
"branch": "mongodb-8.1",
5-
"commit": "d6eda7a7e8b05772384c4cfe36b1c1d43344adfd"
5+
"commit": "ce1f45b4908579eb3e9dd588ee6ed4267783fe13"
66
}

src/third_party/wiredtiger/src/checkpoint/checkpoint_txn.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,15 @@ __checkpoint_db_internal(WT_SESSION_IMPL *session, const char *cfg[])
14311431
if (F_ISSET(&conn->log_mgr, WT_LOG_ENABLED))
14321432
WT_ERR(__wt_log_flush(session, WT_LOG_FSYNC));
14331433

1434+
/*
1435+
* Stress point to stop just before we sync the metadata file. Used to recreate log recovery
1436+
* scenarios with an incomplete checkpoint.
1437+
*/
1438+
WT_STAT_CONN_SET(session, checkpoint_stop_stress_active, 1);
1439+
/* Wait prior to flush the checkpoint stop log record. */
1440+
__checkpoint_timing_stress(session, WT_TIMING_STRESS_CHECKPOINT_STOP, &tsp);
1441+
WT_STAT_CONN_SET(session, checkpoint_stop_stress_active, 0);
1442+
14341443
/*
14351444
* Ensure that the metadata changes are durable before the checkpoint is resolved. Either
14361445
* checkpointing the metadata or syncing the log file works. Recovery relies on the checkpoint
@@ -1459,11 +1468,6 @@ __checkpoint_db_internal(WT_SESSION_IMPL *session, const char *cfg[])
14591468

14601469
__checkpoint_verbose_track(session, "metadata sync completed");
14611470

1462-
WT_STAT_CONN_SET(session, checkpoint_stop_stress_active, 1);
1463-
/* Wait prior to flush the checkpoint stop log record. */
1464-
__checkpoint_timing_stress(session, WT_TIMING_STRESS_CHECKPOINT_STOP, &tsp);
1465-
WT_STAT_CONN_SET(session, checkpoint_stop_stress_active, 0);
1466-
14671471
/*
14681472
* Now that the metadata is stable, re-open the metadata file for regular eviction by clearing
14691473
* the checkpoint_pinned flag.

src/third_party/wiredtiger/src/conn/conn_dhandle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ __conn_dhandle_config_set(WT_SESSION_IMPL *session)
4545
base = NULL;
4646
tmp = NULL;
4747

48+
/* We should never be looking at metadata before it's been recovered. */
49+
WT_ASSERT_ALWAYS(session, !F_ISSET(S2C(session), WT_CONN_RECOVERING_METADATA),
50+
"Assert failure: %s: attempt to open data handle during metadata recovery", session->name);
51+
4852
/*
4953
* Read the object's entry from the metadata file, we're done if we don't find one.
5054
*/

src/third_party/wiredtiger/src/cursor/cur_hs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ __wt_curhs_cache(WT_SESSION_IMPL *session)
7373
* Make sure this session has a cached history store cursor, otherwise we can deadlock with a
7474
* session wanting exclusive access to a handle: that session will have a handle list write lock
7575
* and will be waiting on eviction to drain, we'll be inside eviction waiting on a handle list
76-
* read lock to open a history store cursor.
76+
* read lock to open a history store cursor. If we are recovering metadata, we aren't ready to
77+
* open the history store, and we can't deadlock because we are single threaded.
7778
*
7879
* The test for the no-reconciliation flag is necessary because the session may already be doing
7980
* history store operations and if we open/close the existing history store cursor, we can
@@ -89,7 +90,8 @@ __wt_curhs_cache(WT_SESSION_IMPL *session)
8990
*
9091
* FIXME-WT-6037: This isn't reasonable and needs a better fix.
9192
*/
92-
if (F_ISSET(conn, WT_CONN_IN_MEMORY) || F_ISSET(session, WT_SESSION_NO_RECONCILE) ||
93+
if (F_ISSET(conn, WT_CONN_IN_MEMORY | WT_CONN_RECOVERING_METADATA) ||
94+
F_ISSET(session, WT_SESSION_NO_RECONCILE) ||
9395
(session->dhandle != NULL && WT_IS_METADATA(S2BT(session)->dhandle)) ||
9496
session == conn->default_session)
9597
return (0);

src/third_party/wiredtiger/src/evict/evict_inline.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,11 @@ __wt_evict_app_assist_worker_check(
633633
if (didworkp != NULL)
634634
*didworkp = false;
635635

636+
/* It is not safe to proceed if the eviction server threads aren't setup yet. */
637+
WT_CONNECTION_IMPL *conn = S2C(session);
638+
if (!__wt_atomic_loadbool(&conn->evict_server_running))
639+
return (0);
640+
636641
/* Eviction causes reconciliation. So don't evict if we can't reconcile */
637642
if (F_ISSET(session, WT_SESSION_NO_RECONCILE))
638643
return (0);
@@ -655,9 +660,8 @@ __wt_evict_app_assist_worker_check(
655660
return (0);
656661

657662
/* Setting cache_max_wait_us to 1 effectively means "disable eviction when possible" */
658-
uint64_t cache_max_wait_us = session->cache_max_wait_us != 0 ?
659-
session->cache_max_wait_us :
660-
S2C(session)->evict->cache_max_wait_us;
663+
uint64_t cache_max_wait_us =
664+
session->cache_max_wait_us != 0 ? session->cache_max_wait_us : conn->evict->cache_max_wait_us;
661665
if (cache_max_wait_us == 1)
662666
return (0);
663667

@@ -667,7 +671,7 @@ __wt_evict_app_assist_worker_check(
667671
* evict what we can. Otherwise, we are at a transaction boundary and we can work harder to make
668672
* sure there is free space in the cache.
669673
*/
670-
WT_TXN_GLOBAL *txn_global = &S2C(session)->txn_global;
674+
WT_TXN_GLOBAL *txn_global = &conn->txn_global;
671675
WT_TXN_SHARED *txn_shared = WT_SESSION_TXN_SHARED(session);
672676
busy = busy || __wt_atomic_loadv64(&txn_shared->id) != WT_TXN_NONE ||
673677
session->hazards.num_active > 0 ||
@@ -687,7 +691,7 @@ __wt_evict_app_assist_worker_check(
687691
return (0);
688692

689693
/* In memory configurations don't block when the cache is full. */
690-
if (F_ISSET(S2C(session), WT_CONN_IN_MEMORY))
694+
if (F_ISSET(conn, WT_CONN_IN_MEMORY))
691695
return (0);
692696

693697
/*
@@ -704,6 +708,13 @@ __wt_evict_app_assist_worker_check(
704708
if (!__wt_evict_needed(session, busy, readonly, &pct_full))
705709
return (0);
706710

711+
/*
712+
* If the caller is holding shared resources, only evict if the cache is at any of its eviction
713+
* targets.
714+
*/
715+
if (busy && pct_full < 100.0)
716+
return (0);
717+
707718
/* Last check if application wants to prevent the thread from evicting. */
708719
if (!__evict_check_user_ok_with_eviction(session, interruptible))
709720
return (0);
@@ -715,7 +726,7 @@ __wt_evict_app_assist_worker_check(
715726
if (didworkp != NULL)
716727
*didworkp = true;
717728

718-
return (__wti_evict_app_assist_worker(session, busy, readonly, interruptible, pct_full));
729+
return (__wti_evict_app_assist_worker(session, busy, readonly, interruptible));
719730
}
720731

721732
/*

src/third_party/wiredtiger/src/evict/evict_lru.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ __evict_page(WT_SESSION_IMPL *session, bool is_server)
28152815
*/
28162816
int
28172817
__wti_evict_app_assist_worker(
2818-
WT_SESSION_IMPL *session, bool busy, bool readonly, bool interruptible, double pct_full)
2818+
WT_SESSION_IMPL *session, bool busy, bool readonly, bool interruptible)
28192819
{
28202820
WT_DECL_RET;
28212821
WT_TRACK_OP_DECL;
@@ -2835,18 +2835,11 @@ __wti_evict_app_assist_worker(
28352835
* Before we enter the eviction generation, make sure this session has a cached history store
28362836
* cursor, otherwise we can deadlock with a session wanting exclusive access to a handle: that
28372837
* session will have a handle list write lock and will be waiting on eviction to drain, we'll be
2838-
* inside eviction waiting on a handle list read lock to open a history store cursor.
2838+
* inside eviction waiting on a handle list read lock to open a history store cursor. The
2839+
* eviction server should be started at this point so it is safe to open the history store.
28392840
*/
28402841
WT_ERR(__wt_curhs_cache(session));
28412842

2842-
/*
2843-
* It is not safe to proceed if the eviction server threads aren't setup yet. Also, if the
2844-
* caller is holding shared resources, only evict if the cache is at any of its eviction
2845-
* targets.
2846-
*/
2847-
if (!__wt_atomic_loadbool(&conn->evict_server_running) || (busy && pct_full < 100.0))
2848-
goto done;
2849-
28502843
/* Wake the eviction server if we need to do work. */
28512844
__wt_evict_server_wake(session);
28522845

@@ -2907,6 +2900,7 @@ __wti_evict_app_assist_worker(
29072900
uint64_t max_progress = busy ? 5 : 20;
29082901

29092902
/* See if eviction is still needed. */
2903+
double pct_full;
29102904
if (!__wt_evict_needed(session, busy, readonly, &pct_full) ||
29112905
(pct_full < 100.0 &&
29122906
(__wt_atomic_loadv64(&evict->eviction_progress) > initial_progress + max_progress)))
@@ -2962,7 +2956,6 @@ __wti_evict_app_assist_worker(
29622956
}
29632957
}
29642958

2965-
done:
29662959
WT_TRACK_OP_END(session);
29672960

29682961
return (ret);

src/third_party/wiredtiger/src/evict/evict_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct __wti_evict_queue {
5050
/* DO NOT EDIT: automatically built by prototypes.py: BEGIN */
5151

5252
extern int __wti_evict_app_assist_worker(WT_SESSION_IMPL *session, bool busy, bool readonly,
53-
bool interruptible, double pct_full) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
53+
bool interruptible) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
5454
extern void __wti_evict_list_clear_page(WT_SESSION_IMPL *session, WT_REF *ref);
5555
static WT_INLINE bool __wti_evict_hs_dirty(WT_SESSION_IMPL *session)
5656
WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));

src/third_party/wiredtiger/src/include/connection.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,12 @@ struct __wt_connection_impl {
813813
#define WT_CONN_READY 0x00800000u
814814
#define WT_CONN_RECONFIGURING 0x01000000u
815815
#define WT_CONN_RECOVERING 0x02000000u
816-
#define WT_CONN_RECOVERY_COMPLETE 0x04000000u
817-
#define WT_CONN_RTS_THREAD_RUN 0x08000000u
818-
#define WT_CONN_SALVAGE 0x10000000u
819-
#define WT_CONN_TIERED_FIRST_FLUSH 0x20000000u
820-
#define WT_CONN_WAS_BACKUP 0x40000000u
816+
#define WT_CONN_RECOVERING_METADATA 0x04000000u
817+
#define WT_CONN_RECOVERY_COMPLETE 0x08000000u
818+
#define WT_CONN_RTS_THREAD_RUN 0x10000000u
819+
#define WT_CONN_SALVAGE 0x20000000u
820+
#define WT_CONN_TIERED_FIRST_FLUSH 0x40000000u
821+
#define WT_CONN_WAS_BACKUP 0x80000000u
821822
/* AUTOMATIC FLAG VALUE GENERATION STOP 32 */
822823
wt_shared uint32_t flags;
823824
};

src/third_party/wiredtiger/src/txn/txn_recover.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,13 @@ __wt_txn_recover(WT_SESSION_IMPL *session, const char *cfg[])
10161016
r.metadata_only = true;
10171017
r.backup_only = false;
10181018
}
1019+
1020+
/*
1021+
* Start metadata recovery. Don't allow any Btree files to be opened, they depend on metadata
1022+
* that might be modified during recovery.
1023+
*/
1024+
F_SET(conn, WT_CONN_RECOVERING_METADATA);
1025+
10191026
/*
10201027
* If this is a read-only connection, check if the checkpoint LSN in the metadata file is up to
10211028
* date, indicating a clean shutdown.
@@ -1036,6 +1043,9 @@ __wt_txn_recover(WT_SESSION_IMPL *session, const char *cfg[])
10361043
ret = __wt_log_scan(
10371044
session, &metafile->ckpt_lsn, NULL, WT_LOGSCAN_RECOVER_METADATA, __txn_log_recover, &r);
10381045
}
1046+
/* We're finished with metadata recovery, so allow other data files to be opened. */
1047+
F_CLR(conn, WT_CONN_RECOVERING_METADATA);
1048+
10391049
if (F_ISSET(conn, WT_CONN_SALVAGE))
10401050
ret = 0;
10411051
/* We need to do some work after recovering backup information. Do that now. */

src/third_party/wiredtiger/test/catch2/sub_level_error/unit/test_sub_level_error_rollback.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ TEST_CASE("Test functions for error handling in rollback workflows",
3333
SECTION(
3434
"Test WT_CACHE_OVERFLOW in __wti_evict_app_assist_worker - not safe to proceed with eviction")
3535
{
36+
3637
// If the eviction server isn't running, then the threads have not been set up yet and it's
3738
// not safe to evict.
38-
CHECK(__wti_evict_app_assist_worker(session_impl, false, false, true, 100) == 0);
39+
CHECK(__wt_evict_app_assist_worker_check(session_impl, false, false, true, NULL) == 0);
3940
check_error_info(err_info, 0, WT_NONE, WT_ERROR_INFO_SUCCESS);
4041

4142
// Set the eviction server as running.
4243
conn_impl->evict_server_running = true;
4344
// The eviction sever is running, but the application is busy and the cache is less than 100
4445
// percent full.
45-
CHECK(__wti_evict_app_assist_worker(session_impl, true, false, true, 99) == 0);
46+
conn_impl->cache_size = 10 * 1024 * 1024;
47+
conn_impl->cache->bytes_inmem = 9 * 1024 * 1024;
48+
CHECK(__wt_evict_app_assist_worker_check(session_impl, true, false, true, NULL) == 0);
4649
check_error_info(err_info, 0, WT_NONE, WT_ERROR_INFO_SUCCESS);
4750
}
4851

@@ -59,7 +62,7 @@ TEST_CASE("Test functions for error handling in rollback workflows",
5962
// Set transaction's update amount to 1 and ID to be equal to the oldest transaction ID.
6063
session_impl->txn->mod_count = 1;
6164
WT_SESSION_TXN_SHARED(session_impl)->id = S2C(session)->txn_global.oldest_id;
62-
CHECK(__wti_evict_app_assist_worker(session_impl, false, false, true, 100) == WT_ROLLBACK);
65+
CHECK(__wti_evict_app_assist_worker(session_impl, false, false, true) == WT_ROLLBACK);
6366
check_error_info(err_info, WT_ROLLBACK, WT_OLDEST_FOR_EVICTION,
6467
"Transaction has the oldest pinned transaction ID");
6568

@@ -84,7 +87,7 @@ TEST_CASE("Test functions for error handling in rollback workflows",
8487
cursor->set_key(cursor, "key");
8588
cursor->set_value(cursor, "value");
8689

87-
CHECK(__wti_evict_app_assist_worker(session_impl, false, false, true, 100) == WT_ROLLBACK);
90+
CHECK(__wti_evict_app_assist_worker(session_impl, false, false, true) == WT_ROLLBACK);
8891
check_error_info(err_info, WT_ROLLBACK, WT_CACHE_OVERFLOW, "Cache capacity has overflown");
8992

9093
// Drop the table.

0 commit comments

Comments
 (0)