Skip to content

Commit 92094a9

Browse files
ruby-oujoEvergreen Agent
authored andcommitted
Import wiredtiger: 99698d7a8bd6ea4e15a6c4da5cfecb6f169daba9 from branch mongodb-master
ref: 3d54dd43fb..99698d7a8b for: 7.2.0-rc0 WT-11721 Chunk cache metadata file management
1 parent 029c806 commit 92094a9

File tree

9 files changed

+139
-5
lines changed

9 files changed

+139
-5
lines changed

src/third_party/wiredtiger/dist/s_string.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ WideCharToMultiByte
424424
WinNT
425425
WiredTiger
426426
WiredTiger's
427+
WiredTigerCC
427428
WiredTigerCheckpoint
428429
WiredTigerChunkCache
429430
WiredTigerHS

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.git",
44
"branch": "mongodb-master",
5-
"commit": "3d54dd43fb29870da49300bf1777f98e83791619"
5+
"commit": "99698d7a8bd6ea4e15a6c4da5cfecb6f169daba9"
66
}

src/third_party/wiredtiger/src/block/block_open.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ __wt_desc_write(WT_SESSION_IMPL *session, WT_FH *fh, uint32_t allocsize)
328328
return (ret);
329329
}
330330

331+
/*
332+
* __file_is_wt_internal --
333+
* Check if a filename is one used by WiredTiger internal files.
334+
*/
335+
static bool
336+
__file_is_wt_internal(const char *name)
337+
{
338+
return (strcmp(name, WT_METAFILE) == 0 || strcmp(name, WT_HS_FILE) == 0 ||
339+
strcmp(name, WT_CC_METAFILE) == 0);
340+
}
341+
331342
/*
332343
* __desc_read --
333344
* Read and verify the file's metadata.
@@ -404,7 +415,7 @@ __desc_read(WT_SESSION_IMPL *session, uint32_t allocsize, WT_BLOCK *block)
404415
* file name, and is now frantically pounding their interrupt key.
405416
*/
406417
if (desc->magic != WT_BLOCK_MAGIC || !checksum_matched) {
407-
if (strcmp(block->name, WT_METAFILE) == 0 || strcmp(block->name, WT_HS_FILE) == 0)
418+
if (__file_is_wt_internal(block->name))
408419
WT_ERR_MSG(session, WT_TRY_SALVAGE,
409420
"%s is corrupted: calculated block checksum of %#" PRIx32
410421
" doesn't match expected checksum of %#" PRIx32,

src/third_party/wiredtiger/src/block_cache/block_chunkcache.c

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,75 @@
2020
#define WT_CHUNK_OFFSET(chunkcache, offset) \
2121
(wt_off_t)(((size_t)offset / (chunkcache)->chunk_size) * (chunkcache)->chunk_size)
2222

23+
/*
24+
* __chunkcache_create_metadata_file --
25+
* Create the table that will persistently track what chunk cache content is on disk.
26+
*/
27+
static int
28+
__chunkcache_create_metadata_file(
29+
WT_SESSION_IMPL *session, uint64_t capacity, unsigned int hashtable_size, size_t chunk_size)
30+
{
31+
char cfg[128];
32+
WT_RET(__wt_snprintf(cfg, sizeof(cfg),
33+
WT_CC_APP_META_FORMAT ",key_format=" WT_CC_KEY_FORMAT ",value_format=" WT_CC_VALUE_FORMAT,
34+
capacity, hashtable_size, chunk_size));
35+
36+
return (__wt_session_create(session, WT_CC_METAFILE_URI, cfg));
37+
}
38+
39+
/*
40+
* __chunkcache_get_metadata_config --
41+
* If present, retrieve the on-disk configuration for the chunk cache metadata file. The caller
42+
* must only use *config if *found is true. The caller is responsible for freeing the memory
43+
* allocated into *config.
44+
*/
45+
static int
46+
__chunkcache_get_metadata_config(WT_SESSION_IMPL *session, char **config)
47+
{
48+
WT_CURSOR *cursor;
49+
WT_DECL_RET;
50+
char *tmp;
51+
52+
*config = NULL;
53+
54+
WT_RET(__wt_metadata_cursor(session, &cursor));
55+
cursor->set_key(cursor, WT_CC_METAFILE_URI);
56+
WT_ERR(cursor->search(cursor));
57+
58+
WT_ERR(cursor->get_value(cursor, &tmp));
59+
WT_ERR(__wt_strdup(session, tmp, config));
60+
61+
err:
62+
WT_TRET(__wt_metadata_cursor_release(session, &cursor));
63+
return (ret);
64+
}
65+
66+
/*
67+
* __chunkcache_verify_metadata_config --
68+
* Check that the existing chunk cache configuration is compatible with our current
69+
* configuration (and ergo, whether we can reuse the chunk cache contents).
70+
*/
71+
static int
72+
__chunkcache_verify_metadata_config(WT_SESSION_IMPL *session, char *md_config, uint64_t capacity,
73+
unsigned int hashtable_size, size_t chunk_size)
74+
{
75+
WT_DECL_RET;
76+
char tmp[128];
77+
78+
WT_RET(
79+
__wt_snprintf(tmp, sizeof(tmp), WT_CC_APP_META_FORMAT, capacity, hashtable_size, chunk_size));
80+
81+
if (strstr(md_config, tmp) == NULL) {
82+
__wt_verbose_error(session, WT_VERB_CHUNKCACHE,
83+
"stored chunk cache config (%s) incompatible with runtime config (%s)", md_config, tmp);
84+
ret = -1;
85+
}
86+
87+
/* FIXME-WT-11723 Open the underlying table just to verify it exists. */
88+
89+
return (ret);
90+
}
91+
2392
/*
2493
* __chunkcache_bitmap_find_free --
2594
* Iterate through the bitmap to find a free chunk in the cache.
@@ -903,12 +972,13 @@ __wt_chunkcache_setup(WT_SESSION_IMPL *session, const char *cfg[])
903972
WT_CONFIG_ITEM cval;
904973
WT_DECL_RET;
905974
unsigned int cnt, i;
906-
char **pinned_objects;
975+
char *metadata_config, **pinned_objects;
907976
size_t mapped_size;
908977

909978
chunkcache = &S2C(session)->chunkcache;
910-
pinned_objects = NULL;
911979
cnt = 0;
980+
metadata_config = NULL;
981+
pinned_objects = NULL;
912982

913983
if (F_ISSET(chunkcache, WT_CHUNKCACHE_CONFIGURED))
914984
WT_RET_MSG(session, EINVAL, "chunk cache setup requested, but cache is already configured");
@@ -969,6 +1039,21 @@ __wt_chunkcache_setup(WT_SESSION_IMPL *session, const char *cfg[])
9691039
WT_RET(__wt_calloc(session,
9701040
WT_CHUNKCACHE_BITMAP_SIZE(chunkcache->capacity, chunkcache->chunk_size), sizeof(uint8_t),
9711041
&chunkcache->free_bitmap));
1042+
1043+
/* Retrieve the chunk cache metadata config, and ensure it matches our startup config. */
1044+
ret = __chunkcache_get_metadata_config(session, &metadata_config);
1045+
if (ret == WT_NOTFOUND) {
1046+
WT_RET(__chunkcache_create_metadata_file(
1047+
session, chunkcache->capacity, chunkcache->hashtable_size, chunkcache->chunk_size));
1048+
__wt_verbose(session, WT_VERB_CHUNKCACHE, "%s", "created chunkcache metadata file");
1049+
} else if (ret == 0) {
1050+
WT_RET(__chunkcache_verify_metadata_config(session, metadata_config,
1051+
chunkcache->capacity, chunkcache->hashtable_size, chunkcache->chunk_size));
1052+
__wt_verbose(session, WT_VERB_CHUNKCACHE, "%s", "reused chunkcache metadata file");
1053+
} else {
1054+
WT_RET(ret);
1055+
}
1056+
__wt_free(session, metadata_config);
9721057
}
9731058

9741059
WT_RET(__wt_config_gets(session, cfg, "chunk_cache.flushed_data_cache_insertion", &cval));
@@ -1032,6 +1117,28 @@ __wt_chunkcache_teardown(WT_SESSION_IMPL *session)
10321117
return (ret);
10331118
}
10341119

1120+
/*
1121+
* __wt_chunkcache_salvage --
1122+
* Remove any knowledge of any extant chunk cache metadata. We can always rebuild the cache
1123+
* later, so make no attempt at a "real" salvage.
1124+
*/
1125+
int
1126+
__wt_chunkcache_salvage(WT_SESSION_IMPL *session)
1127+
{
1128+
WT_DECL_RET;
1129+
const char *drop_cfg[] = {WT_CONFIG_BASE(session, WT_SESSION_drop), NULL};
1130+
1131+
/* Check that we're holding the schema lock (or take it) before doing a schema operation. */
1132+
if (FLD_ISSET(session->lock_flags, WT_SESSION_LOCKED_SCHEMA))
1133+
ret = __wt_schema_drop(session, WT_CC_METAFILE_URI, drop_cfg);
1134+
else
1135+
WT_WITH_SCHEMA_LOCK(session, ret = __wt_schema_drop(session, WT_CC_METAFILE_URI, drop_cfg));
1136+
1137+
if (ret == ENOENT)
1138+
return (0);
1139+
return (ret);
1140+
}
1141+
10351142
#ifdef HAVE_UNITTEST
10361143

10371144
int

src/third_party/wiredtiger/src/conn/conn_api.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2946,7 +2946,6 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler, const char *c
29462946
WT_ERR(__wt_verbose_config(session, cfg, false));
29472947
WT_ERR(__wt_timing_stress_config(session, cfg));
29482948
WT_ERR(__wt_blkcache_setup(session, cfg, false));
2949-
WT_ERR(__wt_chunkcache_setup(session, cfg));
29502949
WT_ERR(__wt_extra_diagnostics_config(session, cfg));
29512950
WT_ERR(__wt_conn_optrack_setup(session, cfg, false));
29522951
WT_ERR(__conn_session_size(session, cfg, &conn->session_size));
@@ -3156,6 +3155,9 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler, const char *c
31563155
wt_session = &session->iface;
31573156
WT_ERR(__wt_copy_and_sync(wt_session, WT_METAFILE, WT_METAFILE_SLVG));
31583157
WT_ERR(wt_session->salvage(wt_session, WT_METAFILE_URI, NULL));
3158+
3159+
/* Now that the metadata is usable, see if we need to erase the chunk cache. */
3160+
WT_ERR(__wt_chunkcache_salvage(session));
31593161
}
31603162

31613163
/* Initialize connection values from stored metadata. */

src/third_party/wiredtiger/src/conn/conn_open.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ __wt_connection_workers(WT_SESSION_IMPL *session, const char *cfg[])
227227
/* Initialize metadata tracking, required before creating tables. */
228228
WT_RET(__wt_meta_track_init(session));
229229

230+
/* Can create a table, so must be done after metadata tracking. */
231+
WT_RET(__wt_chunkcache_setup(session, cfg));
232+
230233
/*
231234
* Create the history store file. This will only actually create it on a clean upgrade or when
232235
* creating a new database.

src/third_party/wiredtiger/src/include/block_chunkcache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
/* WiredTiger's chunk cache. Locally caches chunks of remote objects. */
1010

11+
#define WT_CC_KEY_FORMAT WT_UNCHECKED_STRING(SLq)
12+
#define WT_CC_VALUE_FORMAT WT_UNCHECKED_STRING(QQ)
13+
#define WT_CC_APP_META_FORMAT \
14+
"app_metadata=\"version=1,capacity=%" PRIu64 ",buckets=%u,chunk_size=%" WT_SIZET_FMT "\""
15+
1116
struct __wt_chunkcache_hashid {
1217
const char *objectname;
1318
uint32_t objectid;

src/third_party/wiredtiger/src/include/extern.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ extern int __wt_chunkcache_reconfig(WT_SESSION_IMPL *session, const char **cfg)
411411
WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
412412
extern int __wt_chunkcache_remove(WT_SESSION_IMPL *session, WT_BLOCK *block, uint32_t objectid,
413413
wt_off_t offset, uint32_t size) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
414+
extern int __wt_chunkcache_salvage(WT_SESSION_IMPL *session)
415+
WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
414416
extern int __wt_chunkcache_setup(WT_SESSION_IMPL *session, const char *cfg[])
415417
WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result));
416418
extern int __wt_chunkcache_teardown(WT_SESSION_IMPL *session)

src/third_party/wiredtiger/src/include/meta.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#define WT_HS_FILE "WiredTigerHS.wt" /* History store table */
3535
#define WT_HS_URI "file:WiredTigerHS.wt" /* History store table URI */
3636

37+
#define WT_CC_METAFILE "WiredTigerCC.wt" /* Chunk cache metadata table */
38+
#define WT_CC_METAFILE_URI "file:WiredTigerCC.wt" /* Chunk cache metadata table URI */
39+
3740
#define WT_SYSTEM_PREFIX "system:" /* System URI prefix */
3841
#define WT_SYSTEM_CKPT_TS "checkpoint_timestamp" /* Checkpoint timestamp name */
3942
#define WT_SYSTEM_CKPT_URI "system:checkpoint" /* Checkpoint timestamp URI */

0 commit comments

Comments
 (0)