From c9550c59ad870d4ce043dc1c6eb3bf1510b0c733 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 7 Mar 2012 16:38:29 -0800 Subject: [PATCH] omap: add sync method to ObjectMap Signed-off-by: Samuel Just --- src/os/DBObjectMap.cc | 8 ++++++-- src/os/DBObjectMap.h | 5 ++++- src/os/KeyValueDB.h | 3 +++ src/os/LevelDBStore.h | 9 +++++++++ src/os/ObjectMap.h | 3 +++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/os/DBObjectMap.cc b/src/os/DBObjectMap.cc index 7364e2c160caa..059e73a0c1ee9 100644 --- a/src/os/DBObjectMap.cc +++ b/src/os/DBObjectMap.cc @@ -802,7 +802,11 @@ int DBObjectMap::init() { return 0; } -int DBObjectMap::write_state() { +int DBObjectMap::sync() { + return write_state(true); +} + +int DBObjectMap::write_state(bool sync) { dout(20) << "dbobjectmap: seq is " << next_seq << dendl; KeyValueDB::Transaction t = db->get_transaction(); State state; @@ -812,7 +816,7 @@ int DBObjectMap::write_state() { map to_write; to_write[GLOBAL_STATE_KEY] = bl; t->set(SYS_PREFIX, to_write); - return db->submit_transaction(t); + return sync ? db->submit_transaction_sync(t) : db->submit_transaction(t); } diff --git a/src/os/DBObjectMap.h b/src/os/DBObjectMap.h index 605e6034a633a..81ae96c09ea96 100644 --- a/src/os/DBObjectMap.h +++ b/src/os/DBObjectMap.h @@ -155,6 +155,9 @@ public: /// Consistency check, debug, there must be no parallel writes bool check(std::ostream &out); + /// Ensure that all previous operations are durable + int sync(); + ObjectMapIterator get_iterator(const hobject_t &hoid, CollectionIndex::IndexedPath path); @@ -383,7 +386,7 @@ private: KeyValueDB::Transaction t); /// Writes out State (mainly next_seq) - int write_state(); + int write_state(bool sync = false); /// 0 if the complete set now contains all of key space, < 0 on error, 1 else int need_parent(DBObjectMapIterator iter); diff --git a/src/os/KeyValueDB.h b/src/os/KeyValueDB.h index 0c7fd54868648..789bb0992cd10 100644 --- a/src/os/KeyValueDB.h +++ b/src/os/KeyValueDB.h @@ -42,6 +42,9 @@ public: virtual Transaction get_transaction() = 0; virtual int submit_transaction(Transaction) = 0; + virtual int submit_transaction_sync(Transaction t) { + return submit_transaction(t); + } /// Retrieve Keys virtual int get( diff --git a/src/os/LevelDBStore.h b/src/os/LevelDBStore.h index f93244ec4febc..d62a40415535b 100644 --- a/src/os/LevelDBStore.h +++ b/src/os/LevelDBStore.h @@ -59,6 +59,15 @@ public: return s.ok() ? 0 : -1; } + int submit_transaction_sync(KeyValueDB::Transaction t) { + LevelDBTransactionImpl * _t = + static_cast(t.get()); + leveldb::WriteOptions options; + options.sync = true; + leveldb::Status s = db->Write(options, &(_t->bat)); + return s.ok() ? 0 : -1; + } + int get( const string &prefix, const std::set &key, diff --git a/src/os/ObjectMap.h b/src/os/ObjectMap.h index 361d99210cb84..9627a03ea79e8 100644 --- a/src/os/ObjectMap.h +++ b/src/os/ObjectMap.h @@ -109,6 +109,9 @@ public: CollectionIndex::IndexedPath target_path ///< [in] path to target ) { return 0; } + /// Ensure all previous writes are durable + virtual int sync() { return 0; } + virtual bool check(std::ostream &out) { return true; } class ObjectMapIteratorImpl { -- 2.39.5