]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
fixed sync() crap
authorsage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 4 Sep 2006 20:23:19 +0000 (20:23 +0000)
committersage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 4 Sep 2006 20:23:19 +0000 (20:23 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@842 29311d96-e01e-0410-9327-a35deaab8ce9

ceph/osd/Fake.h
ceph/osd/FakeStore.cc
ceph/osd/FakeStore.h
ceph/osd/ObjectStore.h

index d94e1c2b4ca28a407503c8012d4a168d28a6ec02..ba0056ff4d9ac28934b57cbe09e9b461dc70858e 100644 (file)
@@ -17,8 +17,6 @@
 
 #include "include/types.h"
 
-#include "common/Timer.h"
-
 #include <list>
 #include <set>
 #include <ext/hash_map>
@@ -28,9 +26,12 @@ using namespace __gnu_cxx;
 class FakeStoreCollections {
  private:
   Mutex faker_lock;
+  ObjectStore *store;
   hash_map<coll_t, set<object_t> > fakecollections;
 
  public:
+  FakeStoreCollections(ObjectStore *s) : store(s) {}
+
   // faked collections
   int list_collections(list<coll_t>& ls) {
        faker_lock.Lock();
@@ -49,7 +50,7 @@ class FakeStoreCollections {
                                                Context *onsafe=0) {
        faker_lock.Lock();
        fakecollections[c].size();
-       if (onsafe) g_timer.add_event_after(2.0,onsafe);
+       if (onsafe) store->sync(onsafe);
        faker_lock.Unlock();
        return 0;
   }
@@ -61,7 +62,7 @@ class FakeStoreCollections {
        if (fakecollections.count(c)) {
          fakecollections.erase(c);
          //fakecattr.erase(c);
-         if (onsafe) g_timer.add_event_after(2.0,onsafe);
+         if (onsafe) store->sync(onsafe);
        } else 
          r = -1;
        faker_lock.Unlock();
@@ -83,7 +84,7 @@ class FakeStoreCollections {
                                         Context *onsafe=0) {
        faker_lock.Lock();
        fakecollections[c].insert(o);
-       if (onsafe) g_timer.add_event_after(2.0,onsafe);
+       if (onsafe) store->sync(onsafe);
        faker_lock.Unlock();
        return 0;
   }
@@ -92,7 +93,7 @@ class FakeStoreCollections {
                                                Context *onsafe=0) {
        faker_lock.Lock();
        fakecollections[c].erase(o);
-       if (onsafe) g_timer.add_event_after(2.0,onsafe);
+       if (onsafe) store->sync(onsafe);
        faker_lock.Unlock();
        return 0;
   }
@@ -161,16 +162,19 @@ class FakeStoreAttrs {
   };
 
   Mutex faker_lock;
+  ObjectStore *store;
   hash_map<object_t, FakeAttrSet> fakeoattrs;
   hash_map<coll_t, FakeAttrSet> fakecattrs;
 
  public:
+  FakeStoreAttrs(ObjectStore *s) : store(s) {}
+
   int setattr(object_t oid, const char *name,
                          const void *value, size_t size,
                          Context *onsafe=0) {
        faker_lock.Lock();
        int r = fakeoattrs[oid].setattr(name, value, size);
-       if (onsafe) g_timer.add_event_after(2.0,onsafe);
+       if (onsafe) store->sync(onsafe);
        faker_lock.Unlock();
        return r;
   }
@@ -197,7 +201,7 @@ class FakeStoreAttrs {
                         Context *onsafe=0) {
        faker_lock.Lock();
        int r = fakeoattrs[oid].rmattr(name);
-       if (onsafe) g_timer.add_event_after(2.0,onsafe);
+       if (onsafe) store->sync(onsafe);
        faker_lock.Unlock();
        return r;
   }
@@ -214,7 +218,7 @@ class FakeStoreAttrs {
                                                 Context *onsafe=0) {
        faker_lock.Lock();
        int r = fakecattrs[c].setattr(name, value, size);
-       if (onsafe) g_timer.add_event_after(2.0,onsafe);
+       if (onsafe) store->sync(onsafe);
        faker_lock.Unlock();
        return r;
   }
@@ -222,7 +226,7 @@ class FakeStoreAttrs {
                                                Context *onsafe=0) {
        faker_lock.Lock();
        int r = fakecattrs[c].rmattr(name);
-       if (onsafe) g_timer.add_event_after(2.0,onsafe);
+       if (onsafe) store->sync(onsafe);
        faker_lock.Unlock();
        return r;
   }
index 74da0e63777de4e4a49aa6db68419648ac38d846..d9881dbf8d935e19ddf1058339d4c59dfefc52ce 100644 (file)
@@ -50,11 +50,6 @@ using namespace __gnu_cxx;
 
 
 
-FakeStore::FakeStore(char *base, int whoami) 
-{
-  this->basedir = base;
-  this->whoami = whoami;
-}
 
 
 int FakeStore::mount() 
@@ -79,14 +74,6 @@ int FakeStore::mount()
        return r;
   }
 
-  /*{
-       char name[80];
-       sprintf(name,"osd%d.fakestore.threadpool", whoami);
-       fsync_threadpool = new ThreadPool<FakeStore, pair<int,Context*> >(name, g_conf.fakestore_syncthreads, 
-                                                                                                                                         (void (*)(FakeStore*, pair<int,Context*>*))dofsync, 
-                                                                                                                                         this);
-                                                                                                                                         }*/
-
   // all okay.
   return 0;
 }
@@ -95,11 +82,6 @@ int FakeStore::umount()
 {
   dout(5) << "finalize" << endl;
 
-  // close collections db files
-  //close_collections();
-
-  //delete fsync_threadpool;
-
   if (g_conf.fakestore_dev) {
        char cmd[100];
        dout(0) << "umounting" << endl;
@@ -119,20 +101,9 @@ int FakeStore::statfs(struct statfs *buf)
   return ::statfs(mydir.c_str(), buf);
 }
 
-///////////
 
-/*void FakeStore::do_fsync(int fd, Context *c)
-{
-  ::fsync(fd);
-  ::close(fd);
-  dout(10) << "do_fsync finished on " << fd << " context " << c << endl;
-  c->finish(0);
-  delete c;
-}*/
 
 
-////
-
 void FakeStore::get_dir(string& dir) {
   char s[30];
   sprintf(s, "%d", whoami);
@@ -144,11 +115,6 @@ void FakeStore::get_oname(object_t oid, string& fn) {
   fn = basedir + "/" + s;
   //  dout(1) << "oname is " << fn << endl;
 }
-/*void FakeStore::get_collfn(coll_t c, string &fn) {
-  char s[100];
-  sprintf(s, "%d/%02llx/%016llx.co", whoami, HASH_FUNC(c), c);
-  fn = basedir + "/" + s;
-  }*/
 
 
 
@@ -189,7 +155,6 @@ int FakeStore::mkfs()
 
   dout(1) << "mkfs in " << mydir << endl;
 
-  //close_collections();
 
   // make sure my dir exists
   r = ::stat(mydir.c_str(), &st);
@@ -265,9 +230,7 @@ int FakeStore::remove(object_t oid, Context *onsafe)
   string fn;
   get_oname(oid,fn);
   int r = ::unlink(fn.c_str());
-  if (onsafe)
-       g_timer.add_event_after((float)g_conf.fakestore_fake_sync,
-                                                       onsafe);
+  if (onsafe) sync(onsafe);
   return r;
 }
 
@@ -278,9 +241,7 @@ int FakeStore::truncate(object_t oid, off_t size, Context *onsafe)
   string fn;
   get_oname(oid,fn);
   int r = ::truncate(fn.c_str(), size);
-  if (onsafe)
-       g_timer.add_event_after((float)g_conf.fakestore_fake_sync,
-                                                       onsafe);
+  if (onsafe) sync(onsafe);
   return r;
 }
 
@@ -319,56 +280,6 @@ int FakeStore::read(object_t oid,
   return got;
 }
 
-int FakeStore::write(object_t oid,
-                                        off_t offset, size_t len,
-                                        bufferlist& bl,
-                                        bool do_fsync) {
-  dout(20) << "write " << oid << " len " << len << " off " << offset << endl;
-
-  string fn;
-  get_oname(oid,fn);
-  
-  ::mknod(fn.c_str(), 0644, 0);  // in case it doesn't exist yet.
-
-  int flags = O_WRONLY;//|O_CREAT;
-  if (do_fsync && g_conf.fakestore_writesync) flags |= O_SYNC;
-  int fd = ::open(fn.c_str(), flags);
-  if (fd < 0) {
-       dout(1) << "write couldn't open " << fn.c_str() << " flags " << flags << " errno " << errno << " " << strerror(errno) << endl;
-       return fd;
-  }
-  ::flock(fd, LOCK_EX);    // lock for safety
-  //::fchmod(fd, 0664);
-  
-  // seek
-  off_t actual = lseek(fd, offset, SEEK_SET);
-  int did = 0;
-  assert(actual == offset);
-
-  // write buffers
-  for (list<bufferptr>::iterator it = bl.buffers().begin();
-          it != bl.buffers().end();
-          it++) {
-       int r = ::write(fd, (*it).c_str(), (*it).length());
-       if (r > 0)
-         did += r;
-       else {
-         dout(1) << "couldn't write to " << fn.c_str() << " len " << len << " off " << offset << " errno " << errno << " " << strerror(errno) << endl;
-       }
-  }
-  
-  if (did < 0) {
-       dout(1) << "couldn't write to " << fn.c_str() << " len " << len << " off " << offset << " errno " << errno << " " << strerror(errno) << endl;
-  }
-
-  // sync to to disk?
-  if (do_fsync && g_conf.fakestore_fsync) ::fsync(fd); // fsync or fdatasync?
-
-  ::flock(fd, LOCK_UN);
-  ::close(fd);
-  
-  return did;
-}
 
 int FakeStore::write(object_t oid, 
                                         off_t offset, size_t len,
@@ -415,139 +326,38 @@ int FakeStore::write(object_t oid,
   ::flock(fd, LOCK_UN);
 
   // schedule sync
-  if (onsafe) {
-       if (g_conf.fakestore_fake_sync) {
-         g_timer.add_event_after((float)g_conf.fakestore_fake_sync,
-                                                         onsafe);
-         ::close(fd);
-       } else { 
-         assert(0); //queue_fsync(fd, onsafe);
-       }
-  } else {
-       ::close(fd);
-  }
+  if (onsafe) sync(onsafe);
+
+  ::close(fd);
   
   return did;
 }
 
 
-
-// ------------------
-// attributes
-
-
-/*
-int FakeStore::setattr(object_t oid, const char *name,
-                                          void *value, size_t size)
-{
-  if (g_conf.fakestore_fakeattr) {
-       lock.Lock();
-       int r = fakeoattrs[oid].setattr(name, value, size);
-       lock.Unlock();
-       return r;
-  } else {
-       string fn;
-       get_oname(oid, fn);
-       int r = setxattr(fn.c_str(), name, value, size, 0);
-       if (r == -1) 
-         cerr << " errno is " << errno << " " << strerror(errno) << endl;
-       assert(r == 0);
-       return r;
-  }
-}
-
-
-int FakeStore::getattr(object_t oid, const char *name,
-                                          void *value, size_t size)
-{
-  if (g_conf.fakestore_fakeattr) {
-       lock.Lock();
-       int r = fakeoattrs[oid].getattr(name, value, size);
-       lock.Unlock();
-       return r;
-  } else {
-       string fn;
-       get_oname(oid, fn);
-       int r = getxattr(fn.c_str(), name, value, size);
-       //      assert(r == 0);
-       return r;
-  }
-}
-
-int FakeStore::listattr(object_t oid, char *attrs, size_t size)
-{
-  if (g_conf.fakestore_fakeattr) {
-       lock.Lock();
-       int r = fakeoattrs[oid].listattr(attrs,size);
-       lock.Unlock();
-       return r;
-  } else {
-       string fn;
-       get_oname(oid, fn);
-       return listxattr(fn.c_str(), attrs, size);
+class C_FakeSync : public Context {
+public:
+  Context *c;
+  int *n;
+  C_FakeSync(Context *c_, int *n_) : c(c_), n(n_) {
+       ++*n;
   }
-}
-*/
-
-
-
-// ------------------
-// collections
-
-// helpers
-
-
-/*
-int FakeStore::collection_setattr(coll_t cid, const char *name,
-                                                                 void *value, size_t size)
-{
-  int r;
-  lock.Lock();
-  if (!collections.is_open()) open_collections();
-  if (g_conf.fakestore_fakeattr) {
-       r = fakecattrs[cid].setattr(name, value, size);
-  } else {
-       string fn;
-       get_collfn(cid,fn);
-       r = setxattr(fn.c_str(), name, value, size, 0);
+  void finish(int r) {
+       c->finish(r);
+       --(*n);
+       //cout << "sync, " << *n << " still unsync" << endl;
   }
-  lock.Unlock();
-  return r;
-}
+};
 
-
-int FakeStore::collection_getattr(coll_t cid, const char *name,
-                                          void *value, size_t size)
+void FakeStore::sync(Context *onsafe)
 {
-  int r;
-  lock.Lock();
-  if (!collections.is_open()) open_collections();
-  if (g_conf.fakestore_fakeattr) {
-       r = fakecattrs[cid].getattr(name, value, size);
+  if (g_conf.fakestore_fake_sync) {
+       g_timer.add_event_after((float)g_conf.fakestore_fake_sync,
+                                                       new C_FakeSync(onsafe, &unsync));
+       
   } else {
-       string fn;
-       get_collfn(cid,fn);
-       r = getxattr(fn.c_str(), name, value, size);
+       assert(0); // der..no implemented anymore
   }
-  lock.Unlock();
-  return r;
 }
 
-int FakeStore::collection_listattr(coll_t cid, char *attrs, size_t size)
-{
-  int r;
-  lock.Lock();
-  if (!collections.is_open()) open_collections();
 
-  if (g_conf.fakestore_fakeattr) {
-       r = fakecattrs[cid].listattr(attrs,size);
-  } else {
-       string fn;
-       get_collfn(cid, fn);
-       r = listxattr(fn.c_str(), attrs, size);
-  }
-  lock.Unlock();
-  return r;
-}
 
-*/
index 09aa86b0192179b557d9342d93be4783a3118f94..141f5e8d4a94471d6dad46019676032001787441 100644 (file)
@@ -39,6 +39,8 @@ class FakeStore : public ObjectStore,
   string basedir;
   int whoami;
   
+  int unsync;
+
   Mutex lock;
 
   // fns
@@ -47,22 +49,14 @@ class FakeStore : public ObjectStore,
   void wipe_dir(string mydir);
 
 
-  /*
-  // async fsync
-  class ThreadPool<class FakeStore, pair<int, class Context*> >  *fsync_threadpool;
-  void queue_fsync(int fd, class Context *c) {
-       fsync_threadpool->put_op(new pair<int, class Context*>(fd,c));
-  }
  public:
-  void do_fsync(int fd, class Context *c);
-  static void dofsync(class FakeStore *f, pair<int, class Context*> *af) {
-       f->do_fsync(af->first, af->second);
-       delete af;
+  FakeStore(char *base, int whoami) : FakeStoreAttrs(this), FakeStoreCollections(this)
+  {
+       this->basedir = base;
+       this->whoami = whoami;
+       unsync = 0;
   }
-  */
 
- public:
-  FakeStore(char *base, int whoami);
 
   int mount();
   int umount();
@@ -79,15 +73,12 @@ class FakeStore : public ObjectStore,
   int read(object_t oid, 
                   off_t offset, size_t len,
                   bufferlist& bl);
-  int write(object_t oid,
-                       off_t offset, size_t len,
-                       bufferlist& bl,
-                       bool fsync);
   int write(object_t oid, 
                        off_t offset, size_t len,
                        bufferlist& bl, 
                        Context *onsafe);
 
+  void sync(Context *onsafe);
 };
 
 #endif
index ad5f82a6de54be6f2e2437f8cd1a0e9f97b81ac3..2777783a6c451b3b99a5d8b4b73b791ccfba8eda 100644 (file)
@@ -210,9 +210,6 @@ public:
        for (list<int>::iterator p = t.ops.begin();
                 p != t.ops.end();
                 p++) {
-         Context *last = 0;
-         if (p == t.ops.end()) last = onsafe;
-
          switch (*p) {
          case Transaction::OP_READ:
                {
@@ -252,7 +249,7 @@ public:
                  off_t offset = t.offsets.front(); t.offsets.pop_front();
                  size_t len = t.lengths.front(); t.lengths.pop_front();
                  bufferlist bl = t.bls.front(); t.bls.pop_front();
-                 write(oid, offset, len, bl, last);
+                 write(oid, offset, len, bl, 0);
                }
                break;
 
@@ -260,14 +257,14 @@ public:
                {
                  object_t oid = t.oids.front(); t.oids.pop_front();
                  off_t len = t.offsets.front(); t.offsets.pop_front();
-                 truncate(oid, len, last);
+                 truncate(oid, len, 0);
                }
                break;
 
          case Transaction::OP_REMOVE:
                {
                  object_t oid = t.oids.front(); t.oids.pop_front();
-                 remove(oid, last);
+                 remove(oid, 0);
                }
                break;
 
@@ -276,14 +273,14 @@ public:
                  object_t oid = t.oids.front(); t.oids.pop_front();
                  const char *attrname = t.attrnames.front(); t.attrnames.pop_front();
                  pair<const void*,int> attrval = t.attrvals.front(); t.attrvals.pop_front();
-                 setattr(oid, attrname, attrval.first, attrval.second, last);
+                 setattr(oid, attrname, attrval.first, attrval.second, 0);
                }
                break;
          case Transaction::OP_SETATTRS:
                {
                  object_t oid = t.oids.front(); t.oids.pop_front();
                  map<string,bufferptr> *pattrset = t.pattrsets.front(); t.pattrsets.pop_front();
-                 setattrs(oid, *pattrset, last);
+                 setattrs(oid, *pattrset, 0);
                }
                break;
 
@@ -291,21 +288,21 @@ public:
                {
                  object_t oid = t.oids.front(); t.oids.pop_front();
                  const char *attrname = t.attrnames.front(); t.attrnames.pop_front();
-                 rmattr(oid, attrname, last);
+                 rmattr(oid, attrname, 0);
                }
                break;
 
          case Transaction::OP_MKCOLL:
                {
                  coll_t cid = t.cids.front(); t.cids.pop_front();
-                 create_collection(cid, last);
+                 create_collection(cid, 0);
                }
                break;
 
          case Transaction::OP_RMCOLL:
                {
                  coll_t cid = t.cids.front(); t.cids.pop_front();
-                 destroy_collection(cid, last);
+                 destroy_collection(cid, 0);
                }
                break;
 
@@ -313,7 +310,7 @@ public:
                {
                  coll_t cid = t.cids.front(); t.cids.pop_front();
                  object_t oid = t.oids.front(); t.oids.pop_front();
-                 collection_add(cid, oid, last);
+                 collection_add(cid, oid, 0);
                }
                break;
 
@@ -321,7 +318,7 @@ public:
                {
                  coll_t cid = t.cids.front(); t.cids.pop_front();
                  object_t oid = t.oids.front(); t.oids.pop_front();
-                 collection_remove(cid, oid, last);
+                 collection_remove(cid, oid, 0);
                }
                break;
 
@@ -330,7 +327,7 @@ public:
                  coll_t cid = t.cids.front(); t.cids.pop_front();
                  const char *attrname = t.attrnames.front(); t.attrnames.pop_front();
                  pair<const void*,int> attrval = t.attrvals.front(); t.attrvals.pop_front();
-                 collection_setattr(cid, attrname, attrval.first, attrval.second, last);
+                 collection_setattr(cid, attrname, attrval.first, attrval.second, 0);
                }
                break;
 
@@ -338,7 +335,7 @@ public:
                {
                  coll_t cid = t.cids.front(); t.cids.pop_front();
                  const char *attrname = t.attrnames.front(); t.attrnames.pop_front();
-                 collection_rmattr(cid, attrname, last);
+                 collection_rmattr(cid, attrname, 0);
                }
                break;
 
@@ -348,6 +345,9 @@ public:
                assert(0);
          }
        }
+
+       if (onsafe) sync(onsafe);
+
        return 0;  // FIXME count errors
   }
 
@@ -427,8 +427,10 @@ public:
                                                                 void *value, size_t size) {return 0;} //= 0;
   virtual int collection_listattr(coll_t cid, char *attrs, size_t size) {return 0;} //= 0;
   
+  virtual void sync(Context *onsync) {};
   virtual void sync() {};
   
+  
   virtual void _fake_writes(bool b) {};
 
   virtual void _get_frag_stat(FragmentationStat& st) {};