2020-04-09 05:50:55 +08:00
|
|
|
/*
|
|
|
|
* SpecialKeySpace.actor.h
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2020 Apple Inc. and the FoundationDB project authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-03-04 10:35:24 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if defined(NO_INTELLISENSE) && !defined(FDBCLIENT_SPECIALKEYSPACE_ACTOR_G_H)
|
|
|
|
#define FDBCLIENT_SPECIALKEYSPACE_ACTOR_G_H
|
|
|
|
#include "fdbclient/SpecialKeySpace.actor.g.h"
|
|
|
|
#elif !defined(FDBCLIENT_SPECIALKEYSPACE_ACTOR_H)
|
|
|
|
#define FDBCLIENT_SPECIALKEYSPACE_ACTOR_H
|
|
|
|
|
|
|
|
#include "flow/flow.h"
|
|
|
|
#include "flow/Arena.h"
|
|
|
|
#include "fdbclient/FDBTypes.h"
|
|
|
|
#include "fdbclient/KeyRangeMap.h"
|
|
|
|
#include "fdbclient/ReadYourWrites.h"
|
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
|
|
|
class SpecialKeyRangeBaseImpl {
|
|
|
|
public:
|
|
|
|
// Each derived class only needs to implement this simple version of getRange
|
|
|
|
virtual Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw,
|
|
|
|
KeyRangeRef kr) const = 0;
|
|
|
|
|
2020-04-15 00:10:40 +08:00
|
|
|
explicit SpecialKeyRangeBaseImpl(KeyRangeRef kr) : range(kr) {}
|
2020-03-04 10:35:24 +08:00
|
|
|
KeyRangeRef getKeyRange() const { return range; }
|
|
|
|
|
2020-05-06 06:04:20 +08:00
|
|
|
virtual ~SpecialKeyRangeBaseImpl() {}
|
|
|
|
|
2020-03-04 10:35:24 +08:00
|
|
|
protected:
|
|
|
|
KeyRange range; // underlying key range for this function
|
|
|
|
};
|
|
|
|
|
|
|
|
class SpecialKeySpace {
|
|
|
|
public:
|
2020-05-13 05:52:37 +08:00
|
|
|
enum class MODULE {
|
2020-05-19 01:38:23 +08:00
|
|
|
CLUSTERFILEPATH,
|
|
|
|
CONNECTIONSTRING,
|
|
|
|
METRICS, // data-distribution metrics
|
2020-05-15 15:38:06 +08:00
|
|
|
TESTONLY, // only used by correctness tests
|
2020-05-19 01:38:23 +08:00
|
|
|
TRANSACTION, // transaction related info, conflicting keys, read/write conflict range
|
2020-05-13 05:52:37 +08:00
|
|
|
STATUSJSON,
|
2020-05-19 01:38:23 +08:00
|
|
|
UNKNOWN, // default value for all unregistered range
|
|
|
|
WORKERINTERFACE,
|
2020-05-13 05:52:37 +08:00
|
|
|
};
|
2020-05-12 18:29:17 +08:00
|
|
|
|
2020-04-09 04:38:12 +08:00
|
|
|
Future<Optional<Value>> get(Reference<ReadYourWritesTransaction> ryw, const Key& key);
|
2020-03-04 10:35:24 +08:00
|
|
|
|
|
|
|
Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw, KeySelector begin,
|
2020-04-09 04:38:12 +08:00
|
|
|
KeySelector end, GetRangeLimits limits, bool reverse = false);
|
2020-03-04 10:35:24 +08:00
|
|
|
|
2020-05-15 14:49:57 +08:00
|
|
|
SpecialKeySpace(KeyRef spaceStartKey = Key(), KeyRef spaceEndKey = normalKeys.end, bool testOnly = true) {
|
2020-03-04 10:35:24 +08:00
|
|
|
// Default value is nullptr, begin of KeyRangeMap is Key()
|
|
|
|
impls = KeyRangeMap<SpecialKeyRangeBaseImpl*>(nullptr, spaceEndKey);
|
|
|
|
range = KeyRangeRef(spaceStartKey, spaceEndKey);
|
2020-05-15 15:38:06 +08:00
|
|
|
modules = KeyRangeMap<SpecialKeySpace::MODULE>(
|
|
|
|
testOnly ? SpecialKeySpace::MODULE::TESTONLY : SpecialKeySpace::MODULE::UNKNOWN, spaceEndKey);
|
|
|
|
if (!testOnly) modulesBoundaryInit(); // testOnly is used in the correctness workload
|
2020-05-15 08:30:48 +08:00
|
|
|
}
|
2020-05-15 14:49:57 +08:00
|
|
|
// Initialize module boundaries, used to handle cross_module_read
|
2020-05-15 08:30:48 +08:00
|
|
|
void modulesBoundaryInit() {
|
|
|
|
for (const auto& pair : moduleToBoundary) {
|
|
|
|
ASSERT(range.contains(pair.second));
|
|
|
|
// Make sure the module is not overlapping with any registered modules
|
2020-05-15 14:49:57 +08:00
|
|
|
// Note: same like ranges, one module's end cannot be another module's start, relax the condition if needed
|
2020-05-15 08:30:48 +08:00
|
|
|
ASSERT(modules.rangeContaining(pair.second.begin) == modules.rangeContaining(pair.second.end) &&
|
|
|
|
modules[pair.second.begin] == SpecialKeySpace::MODULE::UNKNOWN);
|
|
|
|
modules.insert(pair.second, pair.first);
|
2020-05-15 14:49:57 +08:00
|
|
|
impls.insert(pair.second, nullptr); // Note: Due to underlying implementation, the insertion here is
|
|
|
|
// important to make cross_module_read being handled correctly
|
2020-05-15 08:30:48 +08:00
|
|
|
}
|
2020-03-04 10:35:24 +08:00
|
|
|
}
|
2020-05-12 18:29:17 +08:00
|
|
|
void registerKeyRange(SpecialKeySpace::MODULE module, const KeyRangeRef& kr, SpecialKeyRangeBaseImpl* impl) {
|
2020-05-15 15:38:06 +08:00
|
|
|
// module boundary check
|
|
|
|
if (module == SpecialKeySpace::MODULE::TESTONLY)
|
|
|
|
ASSERT(normalKeys.contains(kr))
|
|
|
|
else
|
|
|
|
ASSERT(moduleToBoundary.at(module).contains(kr));
|
2020-04-09 05:27:05 +08:00
|
|
|
// make sure the registered range is not overlapping with existing ones
|
|
|
|
// Note: kr.end should not be the same as another range's begin, although it should work even they are the same
|
2020-05-15 08:30:48 +08:00
|
|
|
for (auto iter = impls.rangeContaining(kr.begin); true; ++iter) {
|
|
|
|
ASSERT(iter->value() == nullptr);
|
2020-05-15 14:49:57 +08:00
|
|
|
if (iter == impls.rangeContaining(kr.end))
|
|
|
|
break; // relax the condition that the end can be another range's start, if needed
|
2020-05-15 08:30:48 +08:00
|
|
|
}
|
2020-03-04 10:35:24 +08:00
|
|
|
impls.insert(kr, impl);
|
|
|
|
}
|
2020-05-15 08:30:48 +08:00
|
|
|
|
2020-05-12 15:42:43 +08:00
|
|
|
KeyRangeMap<SpecialKeyRangeBaseImpl*>& getImpls() { return impls; }
|
2020-05-15 08:30:48 +08:00
|
|
|
KeyRangeMap<SpecialKeySpace::MODULE>& getModules() { return modules; }
|
2020-05-12 15:42:43 +08:00
|
|
|
KeyRangeRef getKeyRange() const { return range; }
|
2020-03-04 10:35:24 +08:00
|
|
|
|
|
|
|
private:
|
2020-05-12 15:42:43 +08:00
|
|
|
ACTOR static Future<Optional<Value>> getActor(SpecialKeySpace* sks, Reference<ReadYourWritesTransaction> ryw,
|
|
|
|
KeyRef key);
|
2020-03-04 10:35:24 +08:00
|
|
|
|
2020-05-12 10:47:00 +08:00
|
|
|
ACTOR static Future<Standalone<RangeResultRef>> checkModuleFound(SpecialKeySpace* sks,
|
2020-05-12 15:42:43 +08:00
|
|
|
Reference<ReadYourWritesTransaction> ryw,
|
|
|
|
KeySelector begin, KeySelector end,
|
|
|
|
GetRangeLimits limits, bool reverse);
|
2020-05-12 18:29:17 +08:00
|
|
|
ACTOR static Future<std::pair<Standalone<RangeResultRef>, Optional<SpecialKeySpace::MODULE>>>
|
2020-05-12 15:42:43 +08:00
|
|
|
getRangeAggregationActor(SpecialKeySpace* sks, Reference<ReadYourWritesTransaction> ryw, KeySelector begin,
|
|
|
|
KeySelector end, GetRangeLimits limits, bool reverse);
|
2020-03-04 10:35:24 +08:00
|
|
|
|
|
|
|
KeyRangeMap<SpecialKeyRangeBaseImpl*> impls;
|
2020-05-15 08:30:48 +08:00
|
|
|
KeyRangeMap<SpecialKeySpace::MODULE> modules;
|
2020-03-04 10:35:24 +08:00
|
|
|
KeyRange range;
|
2020-05-13 17:28:04 +08:00
|
|
|
|
|
|
|
static std::unordered_map<SpecialKeySpace::MODULE, KeyRange> moduleToBoundary;
|
2020-03-04 10:35:24 +08:00
|
|
|
};
|
|
|
|
|
2020-04-07 13:09:17 +08:00
|
|
|
// 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.
|
2020-04-04 07:11:20 +08:00
|
|
|
class ConflictingKeysImpl : public SpecialKeyRangeBaseImpl {
|
|
|
|
public:
|
2020-04-15 00:10:40 +08:00
|
|
|
explicit ConflictingKeysImpl(KeyRangeRef kr);
|
2020-04-09 04:38:12 +08:00
|
|
|
Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw,
|
|
|
|
KeyRangeRef kr) const override;
|
2020-04-04 07:11:20 +08:00
|
|
|
};
|
|
|
|
|
2020-04-29 00:00:06 +08:00
|
|
|
class ReadConflictRangeImpl : public SpecialKeyRangeBaseImpl {
|
|
|
|
public:
|
|
|
|
explicit ReadConflictRangeImpl(KeyRangeRef kr);
|
|
|
|
Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw,
|
|
|
|
KeyRangeRef kr) const override;
|
|
|
|
};
|
|
|
|
|
2020-04-29 01:34:10 +08:00
|
|
|
class WriteConflictRangeImpl : public SpecialKeyRangeBaseImpl {
|
|
|
|
public:
|
|
|
|
explicit WriteConflictRangeImpl(KeyRangeRef kr);
|
|
|
|
Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw,
|
|
|
|
KeyRangeRef kr) const override;
|
|
|
|
};
|
|
|
|
|
2020-05-19 01:38:23 +08:00
|
|
|
class DDStatsRangeImpl : public SpecialKeyRangeBaseImpl {
|
|
|
|
public:
|
|
|
|
explicit DDStatsRangeImpl(KeyRangeRef kr);
|
|
|
|
Future<Standalone<RangeResultRef>> getRange(Reference<ReadYourWritesTransaction> ryw,
|
|
|
|
KeyRangeRef kr) const override;
|
|
|
|
};
|
|
|
|
|
2020-03-04 10:35:24 +08:00
|
|
|
#include "flow/unactorcompiler.h"
|
|
|
|
#endif
|