Fix bug: change RYW* to Reference<RYW>

This commit is contained in:
chaoguang 2020-03-02 19:02:35 -08:00
parent 7f28719229
commit 146191e411
5 changed files with 24 additions and 20 deletions

View File

@ -25,7 +25,7 @@
#include "fdbclient/NativeAPI.actor.h" #include "fdbclient/NativeAPI.actor.h"
#include "fdbclient/KeyRangeMap.h" #include "fdbclient/KeyRangeMap.h"
#include "fdbclient/MasterProxyInterface.h" #include "fdbclient/MasterProxyInterface.h"
#include "fdbclient/PrivateKeySpace.h" // #include "fdbclient/PrivateKeySpace.h"
#include "fdbrpc/QueueModel.h" #include "fdbrpc/QueueModel.h"
#include "fdbrpc/MultiInterface.h" #include "fdbrpc/MultiInterface.h"
#include "flow/TDMetric.actor.h" #include "flow/TDMetric.actor.h"
@ -46,6 +46,7 @@ private:
typedef MultiInterface<ReferencedInterface<StorageServerInterface>> LocationInfo; typedef MultiInterface<ReferencedInterface<StorageServerInterface>> LocationInfo;
typedef MultiInterface<MasterProxyInterface> ProxyInfo; typedef MultiInterface<MasterProxyInterface> ProxyInfo;
class PrivateKeySpace; //forward declaration
class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAllocated<DatabaseContext>, NonCopyable { class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAllocated<DatabaseContext>, NonCopyable {
public: public:
static DatabaseContext* allocateOnForeignThread() { static DatabaseContext* allocateOnForeignThread() {
@ -203,7 +204,7 @@ public:
double detailedHealthMetricsLastUpdated; double detailedHealthMetricsLastUpdated;
UniqueOrderedOptionList<FDBTransactionOptions> transactionDefaults; UniqueOrderedOptionList<FDBTransactionOptions> transactionDefaults;
PrivateKeySpace privateKeySpace; PrivateKeySpace* privateKeySpace;
}; };
#endif #endif

View File

@ -4,7 +4,7 @@
namespace { namespace {
ACTOR Future<Optional<Value>> getActor( ACTOR Future<Optional<Value>> getActor(
PrivateKeySpace* pks, PrivateKeySpace* pks,
ReadYourWritesTransaction* ryw, Reference<ReadYourWritesTransaction> ryw,
KeyRef key ) KeyRef key )
{ {
// use getRange to workaround this // use getRange to workaround this
@ -26,7 +26,7 @@ ACTOR Future<Optional<Value>> getActor(
// Seperate each part to make the code easy to understand and more compact // Seperate each part to make the code easy to understand and more compact
ACTOR Future<Void> normalizeKeySelectorActor( ACTOR Future<Void> normalizeKeySelectorActor(
const PrivateKeyRangeBaseImpl* pkrImpl, const PrivateKeyRangeBaseImpl* pkrImpl,
ReadYourWritesTransaction* ryw, Reference<ReadYourWritesTransaction> ryw,
KeySelector* ks ) KeySelector* ks )
{ {
ASSERT(!ks->orEqual); // should be removed before calling ASSERT(!ks->orEqual); // should be removed before calling
@ -82,7 +82,7 @@ ACTOR Future<Void> normalizeKeySelectorActor(
ACTOR Future<Standalone<RangeResultRef>> getRangeAggregationActor( ACTOR Future<Standalone<RangeResultRef>> getRangeAggregationActor(
PrivateKeySpace* pks, PrivateKeySpace* pks,
ReadYourWritesTransaction* ryw, Reference<ReadYourWritesTransaction> ryw,
KeySelector begin, KeySelector begin,
KeySelector end, KeySelector end,
GetRangeLimits limits, GetRangeLimits limits,
@ -177,7 +177,7 @@ ACTOR Future<Standalone<RangeResultRef>> getRangeAggregationActor(
} // namespace end } // namespace end
Future<Standalone<RangeResultRef>> PrivateKeySpace::getRange( Future<Standalone<RangeResultRef>> PrivateKeySpace::getRange(
ReadYourWritesTransaction* ryw, Reference<ReadYourWritesTransaction> ryw,
KeySelector begin, KeySelector begin,
KeySelector end, KeySelector end,
GetRangeLimits limits, GetRangeLimits limits,
@ -196,7 +196,7 @@ Future<Standalone<RangeResultRef>> PrivateKeySpace::getRange(
} }
Future<Optional<Value>> PrivateKeySpace::get( Future<Optional<Value>> PrivateKeySpace::get(
ReadYourWritesTransaction* ryw, Reference<ReadYourWritesTransaction> ryw,
const Key& key, const Key& key,
bool snapshot) bool snapshot)
{ {

View File

@ -6,8 +6,9 @@
#include "flow/Arena.h" #include "flow/Arena.h"
#include "fdbclient/FDBTypes.h" #include "fdbclient/FDBTypes.h"
#include "fdbclient/KeyRangeMap.h" #include "fdbclient/KeyRangeMap.h"
#include "fdbclient/ReadYourWrites.h"
class ReadYourWritesTransaction; // class ReadYourWritesTransaction;
class PrivateKeyRangeBaseImpl { class PrivateKeyRangeBaseImpl {
public: public:
@ -18,7 +19,7 @@ public:
// virtual Future<Standalone<RangeResultRef>> getRange(ReadYourWritesTransaction* ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false) const = 0; // virtual Future<Standalone<RangeResultRef>> 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 // Each derived class only needs to implement this simple version of getRange
virtual Future<Standalone<RangeResultRef>> getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const = 0; virtual Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw, KeyRangeRef kr) const = 0;
explicit PrivateKeyRangeBaseImpl(KeyRef start, KeyRef end) { explicit PrivateKeyRangeBaseImpl(KeyRef start, KeyRef end) {
range = KeyRangeRef(range.arena(), KeyRangeRef(start, end)); range = KeyRangeRef(range.arena(), KeyRangeRef(start, end));
@ -39,9 +40,9 @@ protected:
class PrivateKeySpace { class PrivateKeySpace {
public: public:
Future<Optional<Value>> get(ReadYourWritesTransaction* ryw, const Key& key, bool snapshot = false); Future<Optional<Value>> get(Reference<ReadYourWritesTransaction> ryw, const Key& key, bool snapshot = false);
Future<Standalone<RangeResultRef>> getRange(ReadYourWritesTransaction* ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false); Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false);
PrivateKeySpace(KeyRef spaceStartKey = Key(), KeyRef spaceEndKey = allKeys.end) { PrivateKeySpace(KeyRef spaceStartKey = Key(), KeyRef spaceEndKey = allKeys.end) {
// Default value is NULL, begin of KeyRangeMap is Key() // Default value is NULL, begin of KeyRangeMap is Key()

View File

@ -21,6 +21,7 @@
#include "fdbclient/ReadYourWrites.h" #include "fdbclient/ReadYourWrites.h"
#include "fdbclient/Atomic.h" #include "fdbclient/Atomic.h"
#include "fdbclient/DatabaseContext.h" #include "fdbclient/DatabaseContext.h"
#include "fdbclient/PrivateKeySpace.h"
#include "fdbclient/StatusClient.h" #include "fdbclient/StatusClient.h"
#include "fdbclient/MonitorLeader.h" #include "fdbclient/MonitorLeader.h"
#include "flow/Util.h" #include "flow/Util.h"
@ -1282,7 +1283,7 @@ Future< Standalone<RangeResultRef> > ReadYourWritesTransaction::getRange(
// start with simplest point, private key space are only allowed to query if both begin and end start with \xff\xff // 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; const KeyRef privateKeyPrefix = systemKeys.end;
if (begin.getKey().startsWith(privateKeyPrefix) && end.getKey().startsWith(privateKeyPrefix)) if (begin.getKey().startsWith(privateKeyPrefix) && end.getKey().startsWith(privateKeyPrefix))
return getDatabase()->privateKeySpace.getRange(this, begin, end, limits, snapshot, reverse); return getDatabase()->privateKeySpace->getRange(Reference<ReadYourWritesTransaction>(this), begin, end, limits, snapshot, reverse);
if(checkUsedDuringCommit()) { if(checkUsedDuringCommit()) {
return used_during_commit(); return used_during_commit();

View File

@ -1289,7 +1289,7 @@ public:
return Key( prefix + format("%010d", idx)).withPrefix(range.begin); return Key( prefix + format("%010d", idx)).withPrefix(range.begin);
} }
virtual Future<Standalone<RangeResultRef>> getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const override { virtual Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw, KeyRangeRef kr) const override {
int startIndex=0, endIndex= size; int startIndex=0, endIndex= size;
while (startIndex < size && kvs[startIndex].key < kr.begin) while (startIndex < size && kvs[startIndex].key < kr.begin)
++startIndex; ++startIndex;
@ -1314,13 +1314,14 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") {
pks.registerKeyRange(pkr1.getKeyRange(), &pkr1); pks.registerKeyRange(pkr1.getKeyRange(), &pkr1);
pks.registerKeyRange(pkr2.getKeyRange(), &pkr2); pks.registerKeyRange(pkr2.getKeyRange(), &pkr2);
pks.registerKeyRange(pkr3.getKeyRange(), &pkr3); pks.registerKeyRange(pkr3.getKeyRange(), &pkr3);
auto nullRef = Reference<ReadYourWritesTransaction>();
// get // get
{ {
auto resultFuture = pks.get(NULL, LiteralStringRef("\xff\xff/cat/small0000000009")); auto resultFuture = pks.get(nullRef, LiteralStringRef("\xff\xff/cat/small0000000009"));
ASSERT(resultFuture.isReady()); ASSERT(resultFuture.isReady());
auto result = resultFuture.getValue().get(); auto result = resultFuture.getValue().get();
ASSERT(result == pkr1.getKeyValueForIndex(9).value); 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()); ASSERT(emptyFuture.isReady());
auto emptyResult = emptyFuture.getValue(); auto emptyResult = emptyFuture.getValue();
ASSERT(!emptyResult.present()); ASSERT(!emptyResult.present());
@ -1329,7 +1330,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") {
{ {
KeySelector start = KeySelectorRef(LiteralStringRef("\xff\xff/elepant"), false, -9); KeySelector start = KeySelectorRef(LiteralStringRef("\xff\xff/elepant"), false, -9);
KeySelector end = KeySelectorRef(LiteralStringRef("\xff\xff/frog"), false, +11); 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()); ASSERT(resultFuture.isReady());
auto result = resultFuture.getValue(); auto result = resultFuture.getValue();
ASSERT(result.size() == 20); ASSERT(result.size() == 20);
@ -1340,7 +1341,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") {
{ {
KeySelector start = KeySelectorRef(pkr3.getKeyForIndex(999), true, -1110); KeySelector start = KeySelectorRef(pkr3.getKeyForIndex(999), true, -1110);
KeySelector end = KeySelectorRef(pkr1.getKeyForIndex(0), false, +1112); 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()); ASSERT(resultFuture.isReady());
auto result = resultFuture.getValue(); auto result = resultFuture.getValue();
ASSERT(result.size() == 1110); ASSERT(result.size() == 1110);
@ -1351,7 +1352,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") {
{ {
KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0); KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0);
KeySelector end = KeySelectorRef(pkr3.getKeyForIndex(0), false, 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()); ASSERT(resultFuture.isReady());
auto result = resultFuture.getValue(); auto result = resultFuture.getValue();
ASSERT(result.size() == 2); ASSERT(result.size() == 2);
@ -1362,7 +1363,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") {
{ {
KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0); KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0);
KeySelector end = KeySelectorRef(pkr3.getKeyForIndex(0), false, 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()); ASSERT(resultFuture.isReady());
auto result = resultFuture.getValue(); auto result = resultFuture.getValue();
int bytes = 0; int bytes = 0;
@ -1375,7 +1376,7 @@ TEST_CASE("/fdbclient/PrivateKeySpace/Aggregation") {
{ {
KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0); KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0);
KeySelector end = KeySelectorRef(pkr3.getKeyForIndex(0), false, 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()); ASSERT(resultFuture.isReady());
auto result = resultFuture.getValue(); auto result = resultFuture.getValue();
for (int i = 0; i < result.size(); ++i) for (int i = 0; i < result.size(); ++i)