Start with simplest interface

This commit is contained in:
chaoguang 2020-02-20 13:52:48 -08:00
parent f97261f75f
commit 22e0a8e9b3
5 changed files with 114 additions and 0 deletions

View File

@ -44,6 +44,8 @@ set(FDBCLIENT_SRCS
NativeAPI.actor.cpp
NativeAPI.actor.h
Notified.h
PrivateKeySpace.actor.cpp
PrivateKeySpace.h
ReadYourWrites.actor.cpp
ReadYourWrites.h
RestoreWorkerInterface.actor.h

View File

@ -25,6 +25,7 @@
#include "fdbclient/NativeAPI.actor.h"
#include "fdbclient/KeyRangeMap.h"
#include "fdbclient/MasterProxyInterface.h"
#include "fdbclient/PrivateKeySpace.h"
#include "fdbrpc/QueueModel.h"
#include "fdbrpc/MultiInterface.h"
#include "flow/TDMetric.actor.h"
@ -202,6 +203,7 @@ public:
double detailedHealthMetricsLastUpdated;
UniqueOrderedOptionList<FDBTransactionOptions> transactionDefaults;
PrivateKeySpace privateKeySpace;
};
#endif

View File

@ -0,0 +1,52 @@
#include "fdbclient/PrivateKeySpace.h"
#include "flow/actorcompiler.h" // This must be the last #include.
ACTOR Future<Optional<Value>> getActor(
PrivateKeySpace* pks,
ReadYourWritesTransaction* ryw,
KeyRef key,
bool snapshot )
{
// use getRange to workaround this
Standalone<RangeResultRef> result = wait(pks->getRange(ryw, KeySelector( firstGreaterOrEqual(key) ),
KeySelector( firstGreaterOrEqual(keyAfter(key)) ), GetRangeLimits(1), snapshot));
if (result.size()) {
return Optional<Value>(result[0].value);
} else {
return Optional<Value>();
}
}
Future<Standalone<RangeResultRef>> PrivateKeyRangeSimpleImpl::getRange(
ReadYourWritesTransaction* ryw,
KeySelector begin,
KeySelector end,
GetRangeLimits limits,
bool snapshot,
bool reverse ) const
{
// do the easiest stuff here, suppose we have no snapshot and reverse
KeyRef startkey = begin.getKey();
KeyRef endkey = end.getKey();
KeyRange kr = KeyRangeRef(startkey, endkey);
return getRange(ryw, kr);
}
Future<Standalone<RangeResultRef>> PrivateKeySpace::getRange(
ReadYourWritesTransaction* ryw,
KeySelector begin,
KeySelector end,
GetRangeLimits limits,
bool snapshot,
bool reverse ) const
{
// do stuff here
return Standalone<RangeResultRef>();
}
Future<Optional<Value>> PrivateKeySpace::get(
ReadYourWritesTransaction* ryw,
const Key& key,
bool snapshot)
{
return getActor(this, ryw, key, snapshot);
}

View File

@ -0,0 +1,53 @@
#ifndef FDBCLIENT_PRIVATEKEYSPACE_H
#define FDBCLIENT_PRIVATEKEYSPACE_H
#pragma once
#include "flow/flow.h"
#include "fdbclient/FDBTypes.h"
#include "fdbclient/KeyRangeMap.h"
class ReadYourWritesTransaction;
class PrivateKeyRangeBaseImpl {
public:
virtual Future<Standalone<RangeResultRef>> getRange(ReadYourWritesTransaction* ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false) const = 0;
};
// This class
class PrivateKeyRangeSimpleImpl : public PrivateKeyRangeBaseImpl {
public:
virtual Future<Standalone<RangeResultRef>> getRange(ReadYourWritesTransaction* ryw, const KeyRange& keys) const = 0;
virtual Future<Standalone<RangeResultRef>> getRange(ReadYourWritesTransaction* ryw, KeySelector begin, KeySelector end, GetRangeLimits limits, bool snapshot = false, bool reverse = false) const;
};
// class PrivateKeyRangeGetAllImpl : public PrivateKeyRangeSimpleGetRangeImpl {
// public:
// virtual Future<Standalone<RangeResultRef>> getRange(const KeyRange& keys, ReadYourWritesTransaction* ryw) const;
// virtual Future<Standalone<RangeResultRef>> get(ReadYourWritesTransaction* ryw) const = 0;
// };
class PrivateKeySpace {
public:
Future<Optional<Value>> get(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) const;
void registerKeyRange(const KeyRange& kr, PrivateKeyRangeBaseImpl* impl) {
impls.insert(kr, impl);
}
private:
// ACTOR Future<Optional<Value>> getActor(ReadYourWritesTransaction* ryw, const Key& key, bool snapshot) {
// // use getRange to workaround this
// Standalone<RangeResultRef> result = wait(getRange(ryw, KeySelector( firstGreaterOrEqual(key), key.arena() ),
// KeySelector( firstGreaterOrEqual(keyAfter(key)), key.arena() ), GetRangeLimits(1), snapshot));
// if (result.size()) {
// return Optional<Value>(result[0].value);
// } else {
// return Optional<Value>();
// }
// };
KeyRangeMap<PrivateKeyRangeBaseImpl*> impls;
};
#endif

View File

@ -1278,6 +1278,11 @@ Future< Standalone<RangeResultRef> > ReadYourWritesTransaction::getRange(
return Standalone<RangeResultRef>();
}
}
// 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);
if(checkUsedDuringCommit()) {
return used_during_commit();