diff options
author | Susan LoVerso <sue@wiredtiger.com> | 2014-08-13 11:24:30 -0400 |
---|---|---|
committer | Susan LoVerso <sue@wiredtiger.com> | 2014-08-13 11:24:30 -0400 |
commit | d7571147874104ffe0f01bfec251326a3ec6c3df (patch) | |
tree | 49c2d660aae393cc112aff2476da29c5b3a6cac4 /api | |
parent | df0d6f8d46dbf356f18e81451f15672d6f21a867 (diff) | |
download | mongo-d7571147874104ffe0f01bfec251326a3ec6c3df.tar.gz |
Add Replay phase to LiveBackup and add to test program.
Diffstat (limited to 'api')
-rw-r--r-- | api/leveldb/hyper_wt.cc | 22 | ||||
-rw-r--r-- | api/leveldb/leveldb_test.cc | 26 |
2 files changed, 46 insertions, 2 deletions
diff --git a/api/leveldb/hyper_wt.cc b/api/leveldb/hyper_wt.cc index 5b532495049..fcbcab5b77e 100644 --- a/api/leveldb/hyper_wt.cc +++ b/api/leveldb/hyper_wt.cc @@ -326,8 +326,26 @@ DbImpl::LiveBackup(const Slice& name) ret = 0; if ((t_ret = cursor->close(cursor)) != 0 && ret == 0) ret = t_ret; - // Does this now require walking the log with a ReplayIterator - // to apply all the operations onto the backup table? + + // We only copied file contents that are on-disk. + // At this point we want to use a ReplayIterator to + // apply any in-memory operations. + DB* db; + leveldb::Options options; + ReplayIteratorImpl *iter = new ReplayIteratorImpl(context); + Status s = Open(options, backup, &db); + assert(s.ok()); + + while (iter->Valid()) { + if (iter->HasValue()) + s = db->Put(leveldb::WriteOptions(), + iter->key(), iter->value()); + else + s = db->Delete(leveldb::WriteOptions(), iter->key()); + iter->Next(); + } + delete iter; + delete db; return (WiredTigerErrorToStatus(ret)); } diff --git a/api/leveldb/leveldb_test.cc b/api/leveldb/leveldb_test.cc index 0835273ff1f..c9c219d3a75 100644 --- a/api/leveldb/leveldb_test.cc +++ b/api/leveldb/leveldb_test.cc @@ -39,8 +39,16 @@ extern "C" int main() { assert(s.ok()); s = db->Put(leveldb::WriteOptions(), "key", "value"); + s = db->Put(leveldb::WriteOptions(), "key2", "value2"); + s = db->Put(leveldb::WriteOptions(), "key3", "value3"); + s = db->Put(leveldb::WriteOptions(), "key4", "value4"); assert(s.ok()); +#ifdef HAVE_HYPERLEVELDB + s = db->LiveBackup("test"); +#endif + + // Read through the main database leveldb::ReadOptions read_options; read_options.snapshot = db->GetSnapshot(); leveldb::Iterator* iter = db->NewIterator(read_options); @@ -53,5 +61,23 @@ extern "C" int main() { delete db; +#ifdef HAVE_HYPERLEVELDB + // Read through the backup database + leveldb::DB* db_bkup; + options.create_if_missing = false; + s = leveldb::DB::Open(options, "WTLDB_HOME/backup-test", &db_bkup); + read_options.snapshot = db_bkup->GetSnapshot(); + iter = db_bkup->NewIterator(read_options); + cout << "Backup:" << endl; + for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { + cout << iter->key().ToString() << ": " << iter->value().ToString() << endl; + } + + delete iter; + db_bkup->ReleaseSnapshot(read_options.snapshot); + + delete db_bkup; +#endif + return (0); } |