diff options
author | Keith Bostic <keith@wiredtiger.com> | 2012-05-14 11:17:13 +0000 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2012-05-14 11:17:13 +0000 |
commit | 0657ba347e54cd0934135a343c47e72b071aacb6 (patch) | |
tree | 7ddcc64a8bfb2913af89e473b937b84cd211946c /src/session/session_salvage.c | |
parent | c854a4c43645d2f0ad48bdc39f1b6a4d190195c7 (diff) | |
download | mongo-0657ba347e54cd0934135a343c47e72b071aacb6.tar.gz |
Move the snapshot code out of the btree engine and up into the session
layer (makes the layering better, but still not right).
Diffstat (limited to 'src/session/session_salvage.c')
-rw-r--r-- | src/session/session_salvage.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/session/session_salvage.c b/src/session/session_salvage.c new file mode 100644 index 00000000000..046557c71d6 --- /dev/null +++ b/src/session/session_salvage.c @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2008-2012 WiredTiger, Inc. + * All rights reserved. + * + * See the file LICENSE for redistribution information. + */ + +#include "wt_internal.h" + +/* + * __wt_salvage -- + * Salvage a single file. + */ +int +__wt_salvage(WT_SESSION_IMPL *session, const char *cfg[]) +{ + WT_BTREE *btree; + WT_DECL_RET; + WT_SNAPSHOT snapbase[2]; + + btree = session->btree; + + /* + * XXX + * The salvage process reads and discards previous snapshot blocks, so + * the underlying block manager has to ignore any previous snapshot + * entries when creating a new snapshot, in other words, we can't use + * the metadata snapshot list, it has all of those snapshots listed and + * we don't care about them. Build a clean snapshot array and use it + * instead. + * + * Don't first clear the metadata snapshot list and call the snapshot + * get routine: a crash between clearing the metadata snapshot list and + * creating a new snapshot list would look like a create or open of a + * file without a snapshot from which to roll-forward, and the contents + * of the file would be discarded. + */ + memset(snapbase, 0, sizeof(snapbase)); + + WT_RET(__wt_strdup(session, WT_INTERNAL_SNAPSHOT, &snapbase[0].name)); + F_SET(&snapbase[0], WT_SNAP_ADD); + + WT_ERR(__wt_bt_salvage(session, snapbase, cfg)); + + /* + * If no snapshot was created, well, it's probably bad news, but there + * is nothing to do but clear any recorded snapshots for the file. If + * a snapshot was created, life is good, replace any recorded snapshots + * with the new one. + */ + if (snapbase[0].raw.data == NULL) + WT_ERR(__wt_meta_snapshot_clear(session, btree->name)); + else + WT_ERR(__wt_meta_snaplist_set(session, btree->name, snapbase)); + +err: __wt_free(session, snapbase[0].name); + return (0); +} |