remove snapshot argument in the interface

This commit is contained in:
chaoguang 2020-04-06 22:09:17 -07:00
parent 9408915ab9
commit e4d99b0197
4 changed files with 24 additions and 20 deletions

View File

@ -1229,6 +1229,14 @@ Future< Optional<Value> > ReadYourWritesTransaction::get( const Key& key, bool s
return Optional<Value>();
}
// special key space are only allowed to query if both begin and end start with \xff\xff
if (key.startsWith(specialKeys.begin)) {
Reference<ReadYourWritesTransaction> self = Reference<ReadYourWritesTransaction>(this);
auto result = getDatabase()->specialKeySpace->get(self, key);
self.extractPtr(); // avoid to destory the transaction object itself
return result;
}
if(checkUsedDuringCommit()) {
return used_during_commit();
}
@ -1280,20 +1288,13 @@ Future< Standalone<RangeResultRef> > ReadYourWritesTransaction::getRange(
}
}
// start with simplest point, special key space are only allowed to query if both begin and end start with \xff\xff
// special key space are only allowed to query if both begin and end start with \xff\xff
if (begin.getKey().startsWith(specialKeys.begin) && end.getKey().startsWith(specialKeys.begin)) {
Reference<ReadYourWritesTransaction> self = Reference<ReadYourWritesTransaction>(this);
auto result = getDatabase()->specialKeySpace->getRange(self, begin, end, limits, snapshot, reverse);
self.extractPtr();
auto result = getDatabase()->specialKeySpace->getRange(self, begin, end, limits, reverse);
self.extractPtr(); // avoid to destory the transaction object itself
return result;
}
// Use special key prefix "\xff\xff/transaction/conflicting_keys/<some_key>",
// to retrieve keys which caused latest not_committed(conflicting with another transaction) error.
// The returned key value pairs are interpretted as :
// prefix/<key1> : '1' - any keys equal or larger than this key are (probably) conflicting keys
// prefix/<key2> : '0' - any keys equal or larger than this key are (definitely) not conflicting keys
// Currently, the conflicting keyranges returned are original read_conflict_ranges or union of them.
if(checkUsedDuringCommit()) {
return used_during_commit();

View File

@ -206,7 +206,7 @@ ACTOR Future<Standalone<RangeResultRef>> SpecialKeySpace::getRangeAggregationAct
Future<Standalone<RangeResultRef>> SpecialKeySpace::getRange(Reference<ReadYourWritesTransaction> ryw,
KeySelector begin, KeySelector end, GetRangeLimits limits,
bool snapshot, bool reverse) {
bool reverse) {
// validate limits here
if (!limits.isValid()) return range_limits_invalid();
if (limits.isReached()) {
@ -216,7 +216,7 @@ Future<Standalone<RangeResultRef>> SpecialKeySpace::getRange(Reference<ReadYourW
// make sure orEqual == false
begin.removeOrEqual(begin.arena());
end.removeOrEqual(end.arena());
// ignore snapshot, which is not used
return getRangeAggregationActor(this, ryw, begin, end, limits, reverse);
}
@ -234,8 +234,7 @@ ACTOR Future<Optional<Value>> SpecialKeySpace::getActor(SpecialKeySpace* pks, Re
}
}
Future<Optional<Value>> SpecialKeySpace::get(Reference<ReadYourWritesTransaction> ryw, const Key& key, bool snapshot) {
// ignore snapshot, which is not used
Future<Optional<Value>> SpecialKeySpace::get(Reference<ReadYourWritesTransaction> ryw, const Key& key) {
return getActor(this, ryw, key);
}
@ -362,7 +361,7 @@ TEST_CASE("/fdbclient/SpecialKeySpace/Unittest") {
{
KeySelector start = KeySelectorRef(pkr2.getKeyForIndex(0), true, 0);
KeySelector end = KeySelectorRef(pkr3.getKeyForIndex(999), true, +1);
auto resultFuture = pks.getRange(nullRef, start, end, GetRangeLimits(1100), false, true);
auto resultFuture = pks.getRange(nullRef, start, end, GetRangeLimits(1100), true);
ASSERT(resultFuture.isReady());
auto result = resultFuture.getValue();
for (int i = 0; i < pkr3.getSize(); ++i) ASSERT(result[i] == pkr3.getKeyValueForIndex(pkr3.getSize() - 1 - i));

View File

@ -32,12 +32,10 @@ protected:
class SpecialKeySpace {
public:
// TODO : remove snapshot parameter
Future<Optional<Value>> get(Reference<ReadYourWritesTransaction> ryw, const Key& key, bool snapshot = false);
Future<Optional<Value>> get(Reference<ReadYourWritesTransaction> ryw, const Key& key);
Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw, KeySelector begin,
KeySelector end, GetRangeLimits limits, bool snapshot = false,
bool reverse = false);
KeySelector end, GetRangeLimits limits, bool reverse = false);
SpecialKeySpace(KeyRef spaceStartKey = Key(), KeyRef spaceEndKey = normalKeys.end) {
// Default value is nullptr, begin of KeyRangeMap is Key()
@ -62,6 +60,12 @@ private:
KeyRange range;
};
// Use special key prefix "\xff\xff/transaction/conflicting_keys/<some_key>",
// to retrieve keys which caused latest not_committed(conflicting with another transaction) error.
// The returned key value pairs are interpretted as :
// prefix/<key1> : '1' - any keys equal or larger than this key are (probably) conflicting keys
// prefix/<key2> : '0' - any keys equal or larger than this key are (definitely) not conflicting keys
// Currently, the conflicting keyranges returned are original read_conflict_ranges or union of them.
class ConflictingKeysImpl : public SpecialKeyRangeBaseImpl {
public:
explicit ConflictingKeysImpl(KeyRef start, KeyRef end);

View File

@ -89,7 +89,7 @@ struct SpecialKeySpaceCorrectnessWorkload : TestWorkload {
auto correctResultFuture = self->ryw->getRange(begin, end, limit, false, reverse);
ASSERT(correctResultFuture.isReady());
auto correctResult = correctResultFuture.getValue();
auto testResultFuture = cx->specialKeySpace->getRange(self->ryw, begin, end, limit, false, reverse);
auto testResultFuture = cx->specialKeySpace->getRange(self->ryw, begin, end, limit, reverse);
ASSERT(testResultFuture.isReady());
auto testResult = testResultFuture.getValue();