summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/btree/bt_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/btree/bt_handle.c')
-rw-r--r--src/third_party/wiredtiger/src/btree/bt_handle.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/third_party/wiredtiger/src/btree/bt_handle.c b/src/third_party/wiredtiger/src/btree/bt_handle.c
index c1a8ab61054..0cc6b6eb25f 100644
--- a/src/third_party/wiredtiger/src/btree/bt_handle.c
+++ b/src/third_party/wiredtiger/src/btree/bt_handle.c
@@ -352,8 +352,6 @@ __btree_conf(WT_SESSION_IMPL *session, WT_CKPT *ckpt)
session, &btree->ovfl_lock, "btree overflow lock"));
WT_RET(__wt_spin_init(session, &btree->flush_lock, "btree flush lock"));
- __wt_stat_init_dsrc_stats(&btree->dhandle->stats);
-
btree->write_gen = ckpt->write_gen; /* Write generation */
btree->modified = 0; /* Clean */
@@ -385,12 +383,15 @@ int
__wt_btree_tree_open(
WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size)
{
+ WT_BM *bm;
WT_BTREE *btree;
+ WT_DECL_ITEM(tmp);
WT_DECL_RET;
WT_ITEM dsk;
WT_PAGE *page;
btree = S2BT(session);
+ bm = btree->bm;
/*
* A buffer into which we read a root page; don't use a scratch buffer,
@@ -399,12 +400,43 @@ __wt_btree_tree_open(
WT_CLEAR(dsk);
/*
- * Read the page, then build the in-memory version of the page. Clear
- * any local reference to an allocated copy of the disk image on return,
- * the page steals it.
+ * Read and verify the page (verify to catch encrypted objects we can't
+ * decrypt, where we read the object successfully but we can't decrypt
+ * it, and we want to fail gracefully).
+ *
+ * Create a printable version of the address to pass to verify.
+ */
+ WT_ERR(__wt_scr_alloc(session, 0, &tmp));
+ WT_ERR(bm->addr_string(bm, session, tmp, addr, addr_size));
+
+ F_SET(session, WT_SESSION_QUIET_CORRUPT_FILE);
+ if ((ret = __wt_bt_read(session, &dsk, addr, addr_size)) == 0)
+ ret = __wt_verify_dsk(session, tmp->data, &dsk);
+ F_CLR(session, WT_SESSION_QUIET_CORRUPT_FILE);
+ if (ret != 0)
+ __wt_err(session, ret,
+ "unable to read root page from %s", session->dhandle->name);
+ /*
+ * 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)) {
+ __wt_errx(session,
+ "WiredTiger has failed to open its metadata");
+ __wt_errx(session, "This may be due to the database"
+ " files being encrypted, being from an older"
+ " version or due to corruption on disk");
+ __wt_errx(session, "You should confirm that you have"
+ " opened the database with the correct options including"
+ " all encryption and compression options");
+ }
+ WT_ERR(ret);
+
+ /*
+ * Build the in-memory version of the page. Clear our local reference to
+ * the allocated copy of the disk image on return, the in-memory object
+ * steals it.
*/
- WT_ERR(__wt_bt_read(session, &dsk, addr, addr_size));
- WT_ERR(__wt_verify_dsk(session, (const char *)addr, &dsk));
WT_ERR(__wt_page_inmem(session, NULL, dsk.data, dsk.memsize,
WT_DATA_IN_ITEM(&dsk) ?
WT_PAGE_DISK_ALLOC : WT_PAGE_DISK_MAPPED, &page));
@@ -414,6 +446,8 @@ __wt_btree_tree_open(
__wt_root_ref_init(&btree->root, page, btree->type != BTREE_ROW);
err: __wt_buf_free(session, &dsk);
+ __wt_scr_free(session, &tmp);
+
return (ret);
}