summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2017-03-27 09:44:45 -0400
committersueloverso <sue@mongodb.com>2017-03-27 09:44:45 -0400
commita5b3166ab7bcdb365b60686246b8e5624efeca84 (patch)
treee9470b0d551ba6d47efd723d4321c82d283d253b
parente36d8cdb2748ad5b6713b824bbe7be0c8f11c14d (diff)
downloadmongo-a5b3166ab7bcdb365b60686246b8e5624efeca84.tar.gz
SERVER-28168 Cannot start or repair mongodb after unexpected shutdown. (#3353)
Panic if there's an error in reading/writing from/to the turtle file, there's no point in continuing. This change avoids user confusion when the turtle file is corrupted or zero'd out by the filesystem.
-rw-r--r--src/meta/meta_turtle.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/meta/meta_turtle.c b/src/meta/meta_turtle.c
index 66e34c728f2..5a089471059 100644
--- a/src/meta/meta_turtle.c
+++ b/src/meta/meta_turtle.c
@@ -242,7 +242,7 @@ __wt_turtle_read(WT_SESSION_IMPL *session, const char *key, char **valuep)
WT_DECL_ITEM(buf);
WT_DECL_RET;
WT_FSTREAM *fs;
- bool exist, match;
+ bool exist;
*valuep = NULL;
@@ -258,22 +258,19 @@ __wt_turtle_read(WT_SESSION_IMPL *session, const char *key, char **valuep)
__metadata_config(session, valuep) : WT_NOTFOUND);
WT_RET(__wt_fopen(session, WT_METADATA_TURTLE, 0, WT_STREAM_READ, &fs));
- /* Search for the key. */
WT_ERR(__wt_scr_alloc(session, 512, &buf));
- for (match = false;;) {
+
+ /* Search for the key. */
+ do {
WT_ERR(__wt_getline(session, fs, buf));
if (buf->size == 0)
WT_ERR(WT_NOTFOUND);
- if (strcmp(key, buf->data) == 0)
- match = true;
+ } while (strcmp(key, buf->data) != 0);
- /* Key matched: read the subsequent line for the value. */
- WT_ERR(__wt_getline(session, fs, buf));
- if (buf->size == 0)
- WT_ERR(__wt_illegal_value(session, WT_METADATA_TURTLE));
- if (match)
- break;
- }
+ /* Key matched: read the subsequent line for the value. */
+ WT_ERR(__wt_getline(session, fs, buf));
+ if (buf->size == 0)
+ WT_ERR(WT_NOTFOUND);
/* Copy the value for the caller. */
WT_ERR(__wt_strdup(session, buf->data, valuep));
@@ -283,7 +280,12 @@ err: WT_TRET(__wt_fclose(session, &fs));
if (ret != 0)
__wt_free(session, *valuep);
- return (ret);
+
+ /*
+ * A file error or a missing key/value pair in the turtle file means
+ * something has gone horribly wrong -- we're done.
+ */
+ return (ret == 0 ? 0 : __wt_illegal_value(session, WT_METADATA_TURTLE));
}
/*
@@ -322,5 +324,9 @@ __wt_turtle_update(WT_SESSION_IMPL *session, const char *key, const char *value)
err: WT_TRET(__wt_fclose(session, &fs));
WT_TRET(__wt_remove_if_exists(session, WT_METADATA_TURTLE_SET, false));
- return (ret);
+ /*
+ * An error updating the turtle file means something has gone horribly
+ * wrong -- we're done.
+ */
+ return (ret == 0 ? 0 : __wt_illegal_value(session, WT_METADATA_TURTLE));
}