diff --git a/fdbclient/DatabaseContext.h b/fdbclient/DatabaseContext.h index 7f8d93861d..a11be86862 100644 --- a/fdbclient/DatabaseContext.h +++ b/fdbclient/DatabaseContext.h @@ -25,7 +25,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbclient/KeyRangeMap.h" #include "fdbclient/MasterProxyInterface.h" -#include "fdbclient/PrivateKeySpace.h" +// #include "fdbclient/PrivateKeySpace.h" #include "fdbrpc/QueueModel.h" #include "fdbrpc/MultiInterface.h" #include "flow/TDMetric.actor.h" @@ -46,6 +46,7 @@ private: typedef MultiInterface> LocationInfo; typedef MultiInterface ProxyInfo; +class PrivateKeySpace; //forward declaration class DatabaseContext : public ReferenceCounted, public FastAllocated, NonCopyable { public: static DatabaseContext* allocateOnForeignThread() { @@ -203,7 +204,7 @@ public: double detailedHealthMetricsLastUpdated; UniqueOrderedOptionList transactionDefaults; - PrivateKeySpace privateKeySpace; + PrivateKeySpace* privateKeySpace; }; #endif diff --git a/fdbclient/PrivateKeySpace.actor.cpp b/fdbclient/PrivateKeySpace.actor.cpp index aa88a28345..f5ca2f3a22 100644 --- a/fdbclient/PrivateKeySpace.actor.cpp +++ b/fdbclient/PrivateKeySpace.actor.cpp @@ -4,7 +4,7 @@ namespace { ACTOR Future> getActor( PrivateKeySpace* pks, - ReadYourWritesTransaction* ryw, + Reference ryw, KeyRef key ) { // use getRange to workaround this @@ -26,7 +26,7 @@ ACTOR Future> getActor( // Seperate each part to make the code easy to understand and more compact ACTOR Future normalizeKeySelectorActor( const PrivateKeyRangeBaseImpl* pkrImpl, - ReadYourWritesTransaction* ryw, + Reference ryw, KeySelector* ks ) { ASSERT(!ks->orEqual); // should be removed before calling @@ -82,7 +82,7 @@ ACTOR Future normalizeKeySelectorActor( ACTOR Future> getRangeAggregationActor( PrivateKeySpace* pks, - ReadYourWritesTransaction* ryw, + Reference ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, @@ -177,7 +177,7 @@ ACTOR Future> getRangeAggregationActor( } // namespace end Future> PrivateKeySpace::getRange( - ReadYourWritesTransaction* ryw, + Reference ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, @@ -196,7 +196,7 @@ Future> PrivateKeySpace::getRange( } Future> PrivateKeySpace::get( - ReadYourWritesTransaction* ryw, + Reference ryw, const Key& key, bool snapshot) { diff --git a/fdbclient/PrivateKeySpace.h b/fdbclient/PrivateKeySpace.h index 64715d0811..8a6c3dff83 100644 --- a/fdbclient/PrivateKeySpace.h +++ b/fdbclient/PrivateKeySpace.h @@ -6,8 +6,9 @@ #include "flow/Arena.h" #include "fdbclient/FDBTypes.h" #include "fdbclient/KeyRangeMap.h" +#include "fdbclient/ReadYourWrites.h" -class ReadYourWritesTransaction; +// class ReadYourWritesTransaction; class PrivateKeyRangeBaseImpl { public: @@ -18,7 +19,7 @@ public: // virtual Future> getRange(ReadYourWritesTransaction* ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false) const = 0; // Each derived class only needs to implement this simple version of getRange - virtual Future> getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const = 0; + virtual Future> getRange(Reference ryw, KeyRangeRef kr) const = 0; explicit PrivateKeyRangeBaseImpl(KeyRef start, KeyRef end) { range = KeyRangeRef(range.arena(), KeyRangeRef(start, end)); @@ -39,9 +40,9 @@ protected: class PrivateKeySpace { public: - Future> get(ReadYourWritesTransaction* ryw, const Key& key, bool snapshot = false); + Future> get(Reference ryw, const Key& key, bool snapshot = false); - Future> getRange(ReadYourWritesTransaction* ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false); + Future> getRange(Reference ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false); PrivateKeySpace(KeyRef spaceStartKey = Key(), KeyRef spaceEndKey = allKeys.end) { // Default value is NULL, begin of KeyRangeMap is Key() diff --git a/fdbclient/ReadYourWrites.actor.cpp b/fdbclient/ReadYourWrites.actor.cpp index ef13f82b1a..e31c5cfdb3 100644 --- a/fdbclient/ReadYourWrites.actor.cpp +++ b/fdbclient/ReadYourWrites.actor.cpp @@ -21,6 +21,7 @@ #include "fdbclient/ReadYourWrites.h" #include "fdbclient/Atomic.h" #include "fdbclient/DatabaseContext.h" +#include "fdbclient/PrivateKeySpace.h" #include "fdbclient/StatusClient.h" #include "fdbclient/MonitorLeader.h" #include "flow/Util.h" @@ -1282,7 +1283,7 @@ Future< Standalone > ReadYourWritesTransaction::getRange( // start with simplest point, private key space are only allowed to query if both begin and end start with \xff\xff const KeyRef privateKeyPrefix = systemKeys.end; if (begin.getKey().startsWith(privateKeyPrefix) && end.getKey().startsWith(privateKeyPrefix)) - return getDatabase()->privateKeySpace.getRange(this, begin, end, limits, snapshot, reverse); + return getDatabase()->privateKeySpace->getRange(Reference(this), begin, end, limits, snapshot, reverse); if(checkUsedDuringCommit()) { return used_during_commit(); diff --git a/fdbrpc/FlowTests.actor.cpp b/fdbrpc/FlowTests.actor.cpp index a2238a7e92..87b094415d 100644 --- a/fdbrpc/FlowTests.actor.cpp +++ b/fdbrpc/FlowTests.actor.cpp @@ -1289,7 +1289,7 @@ public: return Key( prefix + format("%010d", idx)).withPrefix(range.begin); } - virtual Future> getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const override { + virtual Future> getRange(Reference ryw, KeyRangeRef kr) const override { int startIndex=0, endIndex= size; while (startIndex < size && kvs[startIndex].key < kr.begin) ++startIndex; @@ -1314,13 +1314,14 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") { pks.registerKeyRange(pkr1.getKeyRange(), &pkr1); pks.registerKeyRange(pkr2.getKeyRange(), &pkr2); pks.registerKeyRange(pkr3.getKeyRange(), &pkr3); + auto nullRef = Reference(); // get { - auto resultFuture = pks.get(NULL, LiteralStringRef("\xff\xff/cat/small0000000009")); + auto resultFuture = pks.get(nullRef, LiteralStringRef("\xff\xff/cat/small0000000009")); ASSERT(resultFuture.isReady()); auto result = resultFuture.getValue().get(); ASSERT(result == pkr1.getKeyValueForIndex(9).value); - auto emptyFuture = pks.get(NULL, LiteralStringRef("\xff\xff/cat/small0000000010")); + auto emptyFuture = pks.get(nullRef, LiteralStringRef("\xff\xff/cat/small0000000010")); ASSERT(emptyFuture.isReady()); auto emptyResult = emptyFuture.getValue(); ASSERT(!emptyResult.present()); @@ -1329,7 +1330,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") { { KeySelector start = KeySelectorRef(LiteralStringRef("\xff\xff/elepant"), false, -9); KeySelector end = KeySelectorRef(LiteralStringRef("\xff\xff/frog"), false, +11); - auto resultFuture = pks.getRange(NULL, start, end, GetRangeLimits()); + auto resultFuture = pks.getRange(nullRef, start, end, GetRangeLimits()); ASSERT(resultFuture.isReady()); auto result = resultFuture.getValue(); ASSERT(result.size() == 20); @@ -1340,7 +1341,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") { { KeySelector start = KeySelectorRef(pkr3.getKeyForIndex(999), true, -1110); KeySelector end = KeySelectorRef(pkr1.getKeyForIndex(0), false, +1112); - auto resultFuture = pks.getRange(NULL, start, end, GetRangeLimits()); + auto resultFuture = pks.getRange(nullRef, start, end, GetRangeLimits()); ASSERT(resultFuture.isReady()); auto result = resultFuture.getValue(); ASSERT(result.size() == 1110); @@ -1351,7 +1352,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") { { KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0); KeySelector end = KeySelectorRef(pkr3.getKeyForIndex(0), false, 0); - auto resultFuture = pks.getRange(NULL, start, end, GetRangeLimits(2)); + auto resultFuture = pks.getRange(nullRef, start, end, GetRangeLimits(2)); ASSERT(resultFuture.isReady()); auto result = resultFuture.getValue(); ASSERT(result.size() == 2); @@ -1362,7 +1363,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") { { KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0); KeySelector end = KeySelectorRef(pkr3.getKeyForIndex(0), false, 0); - auto resultFuture = pks.getRange(NULL, start, end, GetRangeLimits(10, 100)); + auto resultFuture = pks.getRange(nullRef, start, end, GetRangeLimits(10, 100)); ASSERT(resultFuture.isReady()); auto result = resultFuture.getValue(); int bytes = 0; @@ -1375,7 +1376,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") { { KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0); KeySelector end = KeySelectorRef(pkr3.getKeyForIndex(0), false, 0); - auto resultFuture = pks.getRange(NULL, start, end, GetRangeLimits(100), false, true); + auto resultFuture = pks.getRange(nullRef, start, end, GetRangeLimits(100), false, true); ASSERT(resultFuture.isReady()); auto result = resultFuture.getValue(); for (int i = 0; i < result.size(); ++i)