]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
omap: add sync method to ObjectMap
authorSage Weil <sage.weil@dreamhost.com>
Thu, 8 Mar 2012 00:38:29 +0000 (16:38 -0800)
committerSage Weil <sage@newdream.net>
Sat, 10 Mar 2012 00:32:23 +0000 (16:32 -0800)
Signed-off-by: Samuel Just <rexludorum@gmail.com>
src/os/DBObjectMap.cc
src/os/DBObjectMap.h
src/os/KeyValueDB.h
src/os/LevelDBStore.h
src/os/ObjectMap.h

index 7364e2c160caa664809b1ee33098abf906cd0ffd..059e73a0c1ee9e866efdd10294ad0d918c9b0816 100644 (file)
@@ -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<string, bufferlist> 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);
 }
 
 
index 605e6034a633acee0d433c1ec30e6d8cfef10284..81ae96c09ea96dc1dceb7c43396982375388a886 100644 (file)
@@ -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);
index 0c7fd54868648ab2972ecb7ec774ea41ca0a8641..789bb0992cd107dd355d940cbe89c6db90f04d50 100644 (file)
@@ -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(
index f93244ec4febc9b6461b4a5cfb2f6d95caf71ffc..d62a40415535ba3a075558a973780245e4882a84 100644 (file)
@@ -59,6 +59,15 @@ public:
     return s.ok() ? 0 : -1;
   }
 
+  int submit_transaction_sync(KeyValueDB::Transaction t) {
+    LevelDBTransactionImpl * _t =
+      static_cast<LevelDBTransactionImpl *>(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<string> &key,
index 361d99210cb8480f5b69f301de8a0021f9f108fc..9627a03ea79e8e8c95de90dae0c890d2e49e6dd8 100644 (file)
@@ -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 {