summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Dachary <loic@dachary.org>2013-08-12 16:47:42 +0200
committerLoic Dachary <loic@dachary.org>2013-08-22 02:10:58 +0200
commit7e85c6320c212c383ed000639f2133423cd3d40f (patch)
treea4f4512dc2eebd2c7d707b0a143bbbf50f087288
parent1688fb48428afe59b3c5bdb1cd6c716c80580f47 (diff)
downloadceph-7e85c6320c212c383ed000639f2133423cd3d40f.tar.gz
ReplicatedPG: ObjectContext is made compatible with SharedPtrRegistry
When creating a new object SharedPtrRegistry::lookup_or_create uses the default ObjectContext constructor with no argument. The existing ObjectContext constructor is modified to have no argument and the initialization that was previously done within the constructor is done by the caller (that only happens three times). The ObjectContext::get method is removed: its only purpose is to increment the ref. The ObjectContext::registered data member is removed as well as all the associated assert() The ObjectContext::destructor_callback data member Context is added and called by the destructor. It will allow the caller to perform additional cleanup, if necessary. All ObjectContext * data members are replaced with shared_ptr. http://tracker.ceph.com/issues/5510 refs #5510 Signed-off-by: Loic Dachary <loic@dachary.org>
-rw-r--r--src/osd/osd_types.h29
-rw-r--r--src/test/test_osd_types.cc9
2 files changed, 22 insertions, 16 deletions
diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h
index 3cafdc2b035..6cdacc9902c 100644
--- a/src/osd/osd_types.h
+++ b/src/osd/osd_types.h
@@ -2001,6 +2001,8 @@ struct ObjectState {
object_info_t oi;
bool exists;
+ ObjectState() : exists(false) {}
+
ObjectState(const object_info_t &oi_, bool exists_)
: oi(oi_), exists(exists_) {}
};
@@ -2022,13 +2024,18 @@ struct SnapSetContext {
* etc., because we don't send writes down to disk until after
* replicas ack.
*/
+
+struct ObjectContext;
+
+typedef std::tr1::shared_ptr<ObjectContext> ObjectContextRef;
+
struct ObjectContext {
- int ref;
- bool registered;
ObjectState obs;
SnapSetContext *ssc; // may be null
+ Context *destructor_callback;
+
private:
Mutex lock;
public:
@@ -2036,20 +2043,22 @@ public:
int unstable_writes, readers, writers_waiting, readers_waiting;
// set if writes for this object are blocked on another objects recovery
- ObjectContext *blocked_by; // object blocking our writes
- set<ObjectContext*> blocking; // objects whose writes we block
+ ObjectContextRef blocked_by; // object blocking our writes
+ set<ObjectContextRef> blocking; // objects whose writes we block
// any entity in obs.oi.watchers MUST be in either watchers or unconnected_watchers.
map<pair<uint64_t, entity_name_t>, WatchRef> watchers;
- ObjectContext(const object_info_t &oi_, bool exists_, SnapSetContext *ssc_)
- : ref(0), registered(false), obs(oi_, exists_), ssc(ssc_),
+ ObjectContext()
+ : ssc(NULL),
+ destructor_callback(0),
lock("ReplicatedPG::ObjectContext::lock"),
- unstable_writes(0), readers(0), writers_waiting(0), readers_waiting(0),
- blocked_by(0) {}
-
- void get() { ++ref; }
+ unstable_writes(0), readers(0), writers_waiting(0), readers_waiting(0) {}
+ ~ObjectContext() {
+ if (destructor_callback)
+ destructor_callback->complete(0);
+ }
// do simple synchronous mutual exclusion, for now. now waitqueues or anything fancy.
void ondisk_write_lock() {
lock.Lock();
diff --git a/src/test/test_osd_types.cc b/src/test/test_osd_types.cc
index 730a8ffdc5d..e07c9e06592 100644
--- a/src/test/test_osd_types.cc
+++ b/src/test/test_osd_types.cc
@@ -1008,8 +1008,7 @@ protected:
TEST_F(ObjectContextTest, read_write_lock)
{
{
- object_info_t oi;
- ObjectContext obc(oi, false, NULL);
+ ObjectContext obc;
//
// write_lock
@@ -1044,8 +1043,7 @@ TEST_F(ObjectContextTest, read_write_lock)
useconds_t delay = 0;
{
- object_info_t oi;
- ObjectContext obc(oi, false, NULL);
+ ObjectContext obc;
//
// write_lock
@@ -1102,8 +1100,7 @@ TEST_F(ObjectContextTest, read_write_lock)
}
{
- object_info_t oi;
- ObjectContext obc(oi, false, NULL);
+ ObjectContext obc;
//
// read_lock