]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
objectstore: create Transaction::iterator class
authorSage Weil <sage@newdream.net>
Tue, 13 Dec 2011 17:05:10 +0000 (09:05 -0800)
committerSage Weil <sage@newdream.net>
Tue, 13 Dec 2011 17:05:10 +0000 (09:05 -0800)
Remove iterator state from Transaction itself.

Signed-off-by: Sage Weil <sage@newdream.net>
src/os/FileStore.cc
src/os/ObjectStore.h

index 631201780761a34ac35842a7548270f9a3f0aba7..36696a893b8aa7cae1ceaa95a96e7db03be5909b 100644 (file)
@@ -2157,76 +2157,78 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
 
   bool idempotent = true;
 
-  while (t.have_op()) {
-    int op = t.get_op();
+  Transaction::iterator i = t.begin();
+
+  while (i.have_op()) {
+    int op = i.get_op();
     int r = 0;
     switch (op) {
     case Transaction::OP_NOP:
       break;
     case Transaction::OP_TOUCH:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
        r = _touch(cid, oid);
       }
       break;
       
     case Transaction::OP_WRITE:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       uint64_t off = t.get_length();
-       uint64_t len = t.get_length();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       uint64_t off = i.get_length();
+       uint64_t len = i.get_length();
        bufferlist bl;
-       t.get_bl(bl);
+       i.get_bl(bl);
        r = _write(cid, oid, off, len, bl);
       }
       break;
       
     case Transaction::OP_ZERO:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       uint64_t off = t.get_length();
-       uint64_t len = t.get_length();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       uint64_t off = i.get_length();
+       uint64_t len = i.get_length();
        r = _zero(cid, oid, off, len);
       }
       break;
       
     case Transaction::OP_TRIMCACHE:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       uint64_t off = t.get_length();
-       uint64_t len = t.get_length();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       uint64_t off = i.get_length();
+       uint64_t len = i.get_length();
        trim_from_cache(cid, oid, off, len);
       }
       break;
       
     case Transaction::OP_TRUNCATE:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       uint64_t off = t.get_length();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       uint64_t off = i.get_length();
        r = _truncate(cid, oid, off);
       }
       break;
       
     case Transaction::OP_REMOVE:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
        r = _remove(cid, oid);
       }
       break;
       
     case Transaction::OP_SETATTR:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       string name = t.get_attrname();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       string name = i.get_attrname();
        bufferlist bl;
-       t.get_bl(bl);
+       i.get_bl(bl);
        r = _setattr(cid, oid, name.c_str(), bl.c_str(), bl.length());
        if (r == -ENOSPC)
          dout(0) << " ENOSPC on setxattr on " << cid << "/" << oid
@@ -2236,29 +2238,29 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
       
     case Transaction::OP_SETATTRS:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
        map<string, bufferptr> aset;
-       t.get_attrset(aset);
+       i.get_attrset(aset);
        r = _setattrs(cid, oid, aset);
        if (r == -ENOSPC)
          dout(0) << " ENOSPC on setxattrs on " << cid << "/" << oid << dendl;
-    }
+      }
       break;
 
     case Transaction::OP_RMATTR:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       string name = t.get_attrname();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       string name = i.get_attrname();
        r = _rmattr(cid, oid, name.c_str());
       }
       break;
 
     case Transaction::OP_RMATTRS:
       {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
        r = _rmattrs(cid, oid);
       }
       break;
@@ -2267,9 +2269,9 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
       {
        idempotent = false;   // this operation is non-idempotent
 
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       hobject_t noid = t.get_oid();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       hobject_t noid = i.get_oid();
        r = _clone(cid, oid, noid);
       }
       break;
@@ -2278,11 +2280,11 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
       {
        idempotent = false;   // this operation is non-idempotent
 
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       hobject_t noid = t.get_oid();
-       uint64_t off = t.get_length();
-       uint64_t len = t.get_length();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       hobject_t noid = i.get_oid();
+       uint64_t off = i.get_length();
+       uint64_t len = i.get_length();
        r = _clone_range(cid, oid, noid, off, len, off);
       }
       break;
@@ -2291,12 +2293,12 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
       {
        idempotent = false;   // this operation is non-idempotent
 
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
-       hobject_t noid = t.get_oid();
-       uint64_t srcoff = t.get_length();
-       uint64_t len = t.get_length();
-       uint64_t dstoff = t.get_length();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
+       hobject_t noid = i.get_oid();
+       uint64_t srcoff = i.get_length();
+       uint64_t len = i.get_length();
+       uint64_t dstoff = i.get_length();
        r = _clone_range(cid, oid, noid, srcoff, len, dstoff);
       }
       break;
@@ -2305,7 +2307,7 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
       {
        // this operation is non-idempotent, but we tolerate replay below.
 
-       coll_t cid = t.get_cid();
+       coll_t cid = i.get_cid();
        r = _create_collection(cid);
       }
       break;
@@ -2314,42 +2316,42 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
       {
        // this operation is non-idempotent, but we tolerate replay below.
 
-       coll_t cid = t.get_cid();
+       coll_t cid = i.get_cid();
        r = _destroy_collection(cid);
       }
       break;
 
     case Transaction::OP_COLL_ADD:
       {
-       coll_t ocid = t.get_cid();
-       coll_t ncid = t.get_cid();
-       hobject_t oid = t.get_oid();
+       coll_t ocid = i.get_cid();
+       coll_t ncid = i.get_cid();
+       hobject_t oid = i.get_oid();
        r = _collection_add(ocid, ncid, oid);
       }
       break;
 
     case Transaction::OP_COLL_REMOVE:
        {
-       coll_t cid = t.get_cid();
-       hobject_t oid = t.get_oid();
+       coll_t cid = i.get_cid();
+       hobject_t oid = i.get_oid();
        r = _collection_remove(cid, oid);
        }
       break;
 
     case Transaction::OP_COLL_SETATTR:
       {
-       coll_t cid = t.get_cid();
-       string name = t.get_attrname();
+       coll_t cid = i.get_cid();
+       string name = i.get_attrname();
        bufferlist bl;
-       t.get_bl(bl);
+       i.get_bl(bl);
        r = _collection_setattr(cid, name.c_str(), bl.c_str(), bl.length());
       }
       break;
 
     case Transaction::OP_COLL_RMATTR:
       {
-       coll_t cid = t.get_cid();
-       string name = t.get_attrname();
+       coll_t cid = i.get_cid();
+       string name = i.get_attrname();
        r = _collection_rmattr(cid, name.c_str());
       }
       break;
@@ -2362,8 +2364,8 @@ unsigned FileStore::_do_transaction(Transaction& t, uint64_t op_seq)
       {
        idempotent = false;   // this operation is non-idempotent
        
-       coll_t cid(t.get_cid());
-       coll_t ncid(t.get_cid());
+       coll_t cid(i.get_cid());
+       coll_t ncid(i.get_cid());
        r = _collection_rename(cid, ncid);
       }
       break;
index 1c3f737bce54b2ff373c7abb8a1e32004b36d5a9..ae8c04b70092f8a6655d2e9ec2628dd6ae3dcb49 100644 (file)
@@ -207,65 +207,67 @@ public:
       return !ops;
     }
 
-    bool have_op() {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      return !p.end();
-    }
     int get_num_ops() {
       return ops;
     }
-    int get_op() {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      __u32 op;
-      ::decode(op, p);
-      return op;
-    }
-    void get_bl(bufferlist& bl) {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      ::decode(bl, p);
-    }
-    hobject_t get_oid() {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      hobject_t hoid;
-      if (sobject_encoding) {
-       sobject_t soid;
-       ::decode(soid, p);
-       hoid.snap = soid.snap;
-       hoid.oid = soid.oid;
-      } else {
-       ::decode(hoid, p);
+
+    // ---- iterator ----
+    class iterator {
+      bufferlist::iterator p;
+      bool sobject_encoding;
+
+      iterator(Transaction *t)
+       : p(t->tbl.begin()),
+         sobject_encoding(t->sobject_encoding) {}
+
+      friend class Transaction;
+
+    public:
+      bool have_op() {
+       return !p.end();
+      }
+      int get_op() {
+       __u32 op;
+       ::decode(op, p);
+       return op;
+      }
+      void get_bl(bufferlist& bl) {
+       ::decode(bl, p);
       }
-      return hoid;
-    }
-    coll_t get_cid() {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      coll_t c;
-      ::decode(c, p);
-      return c;
-    }
-    uint64_t get_length() {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      uint64_t len;
-      ::decode(len, p);
-      return len;
-    }
-    string get_attrname() {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      string s;
-      ::decode(s, p);
-      return s;
-    }
-    void get_attrset(map<string,bufferptr>& aset) {
-      if (p.get_off() == 0)
-       p = tbl.begin();
-      ::decode(aset, p);
+      hobject_t get_oid() {
+       hobject_t hoid;
+       if (sobject_encoding) {
+         sobject_t soid;
+         ::decode(soid, p);
+         hoid.snap = soid.snap;
+         hoid.oid = soid.oid;
+       } else {
+         ::decode(hoid, p);
+       }
+       return hoid;
+      }
+      coll_t get_cid() {
+       coll_t c;
+       ::decode(c, p);
+       return c;
+      }
+      uint64_t get_length() {
+       uint64_t len;
+       ::decode(len, p);
+       return len;
+      }
+      string get_attrname() {
+       string s;
+       ::decode(s, p);
+       return s;
+      }
+      void get_attrset(map<string,bufferptr>& aset) {
+       ::decode(aset, p);
+      }
+    };
+
+    iterator begin() {
+      return iterator(this);
     }
 
     // -----------------------------