From 879eb98dec2aef65b528ea36d0ff5268e225e5be Mon Sep 17 00:00:00 2001 From: Chaoguang Lin Date: Thu, 21 Apr 2022 12:54:34 -0700 Subject: [PATCH] Rename registerSpecialKeySpaceModule to registerSpecialKeysImpl --- documentation/sphinx/source/special-keys.rst | 2 +- fdbclient/DatabaseContext.h | 2 +- fdbclient/NativeAPI.actor.cpp | 180 +++++++++---------- 3 files changed, 92 insertions(+), 92 deletions(-) diff --git a/documentation/sphinx/source/special-keys.rst b/documentation/sphinx/source/special-keys.rst index e5183501ef..55a6fcdd23 100644 --- a/documentation/sphinx/source/special-keys.rst +++ b/documentation/sphinx/source/special-keys.rst @@ -277,7 +277,7 @@ Versioning For how FDB clients deal with versioning, see :ref:`api-versions`. The special key space deals with versioning by using the ``API_VERSION`` passed to initialize the client. Any module added at a version larger than the API version set by the client will be inaccessible. For example, if a module is added in version 7.0 and the client sets its API version to 630, then the module will not available. When removing or updating existing modules, module developers need to continue to provide the old behavior for clients that specify old API versions. -To remove the functionality of a certain special key(s), specify the API version where the function is being deprecated in the ``registerSpecialKeySpaceModule`` function. When a client specifies an API version greater than or equal to the deprecation version, the functionality will not be available. Move and update the its documentation to :ref:`special-key-space-deprecation`. +To remove the functionality of a certain special key(s), specify the API version where the function is being deprecated in the ``registerSpecialKeysImpl`` function. When a client specifies an API version greater than or equal to the deprecation version, the functionality will not be available. Move and update the its documentation to :ref:`special-key-space-deprecation`. To update the implementation of any special keys, add the new implementation and use ``API_VERSION`` to switch between different implementations. diff --git a/fdbclient/DatabaseContext.h b/fdbclient/DatabaseContext.h index 037e56928f..27f3e450f3 100644 --- a/fdbclient/DatabaseContext.h +++ b/fdbclient/DatabaseContext.h @@ -594,7 +594,7 @@ public: AsyncTrigger updateCache; std::vector> specialKeySpaceModules; std::unique_ptr specialKeySpace; - void registerSpecialKeySpaceModule(SpecialKeySpace::MODULE module, + void registerSpecialKeysImpl(SpecialKeySpace::MODULE module, SpecialKeySpace::IMPLTYPE type, std::unique_ptr&& impl, int deprecatedVersion = -1); diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index 699ae8d71f..b67d7435cc 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -1228,10 +1228,11 @@ Future DatabaseContext::getHealthMetrics(bool detailed = false) { return getHealthMetricsActor(this, detailed); } -void DatabaseContext::registerSpecialKeySpaceModule(SpecialKeySpace::MODULE module, - SpecialKeySpace::IMPLTYPE type, - std::unique_ptr&& impl, - int deprecatedVersion) { +// register a special key(s) implementation under the specified module +void DatabaseContext::registerSpecialKeysImpl(SpecialKeySpace::MODULE module, + SpecialKeySpace::IMPLTYPE type, + std::unique_ptr&& impl, + int deprecatedVersion) { // if deprecated, add the implementation when the api version is less than the deprecated version if (deprecatedVersion == -1 || apiVersion < deprecatedVersion) { specialKeySpace->registerKeyRange(module, type, impl->getKeyRange(), impl.get()); @@ -1476,189 +1477,188 @@ DatabaseContext::DatabaseContext(ReferenceINIT_MID_SHARD_BYTES); if (apiVersionAtLeast(710)) { - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique(SpecialKeySpace::getManagementApiCommandRange("tenantmap"))); } if (apiVersionAtLeast(700)) { - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::ERRORMSG, - SpecialKeySpace::IMPLTYPE::READONLY, - std::make_unique( - SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::ERRORMSG).begin, - [](ReadYourWritesTransaction* ryw) -> Future> { - if (ryw->getSpecialKeySpaceErrorMsg().present()) - return Optional(ryw->getSpecialKeySpaceErrorMsg().get()); - else - return Optional(); - })); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl(SpecialKeySpace::MODULE::ERRORMSG, + SpecialKeySpace::IMPLTYPE::READONLY, + std::make_unique( + SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::ERRORMSG).begin, + [](ReadYourWritesTransaction* ryw) -> Future> { + if (ryw->getSpecialKeySpaceErrorMsg().present()) + return Optional(ryw->getSpecialKeySpaceErrorMsg().get()); + else + return Optional(); + })); + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( KeyRangeRef(LiteralStringRef("options/"), LiteralStringRef("options0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique(SpecialKeySpace::getManagementApiCommandRange("exclude"))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique(SpecialKeySpace::getManagementApiCommandRange("failed"))); - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::MANAGEMENT, - SpecialKeySpace::IMPLTYPE::READWRITE, - std::make_unique( - SpecialKeySpace::getManagementApiCommandRange("excludedlocality"))); - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::MANAGEMENT, - SpecialKeySpace::IMPLTYPE::READWRITE, - std::make_unique( - SpecialKeySpace::getManagementApiCommandRange("failedlocality"))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl(SpecialKeySpace::MODULE::MANAGEMENT, + SpecialKeySpace::IMPLTYPE::READWRITE, + std::make_unique( + SpecialKeySpace::getManagementApiCommandRange("excludedlocality"))); + registerSpecialKeysImpl(SpecialKeySpace::MODULE::MANAGEMENT, + SpecialKeySpace::IMPLTYPE::READWRITE, + std::make_unique( + SpecialKeySpace::getManagementApiCommandRange("failedlocality"))); + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READONLY, std::make_unique( KeyRangeRef(LiteralStringRef("in_progress_exclusion/"), LiteralStringRef("in_progress_exclusion0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::CONFIGURATION, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( KeyRangeRef(LiteralStringRef("process/class_type/"), LiteralStringRef("process/class_type0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::CONFIGURATION).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::CONFIGURATION, SpecialKeySpace::IMPLTYPE::READONLY, std::make_unique( KeyRangeRef(LiteralStringRef("process/class_source/"), LiteralStringRef("process/class_source0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::CONFIGURATION).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( singleKeyRange(LiteralStringRef("db_locked")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( singleKeyRange(LiteralStringRef("consistency_check_suspended")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::GLOBALCONFIG, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::GLOBALCONFIG))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::TRACING, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::TRACING))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::CONFIGURATION, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( KeyRangeRef(LiteralStringRef("coordinators/"), LiteralStringRef("coordinators0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::CONFIGURATION).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READONLY, std::make_unique( singleKeyRange(LiteralStringRef("auto_coordinators")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( singleKeyRange(LiteralStringRef("min_required_commit_version")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( singleKeyRange(LiteralStringRef("version_epoch")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( KeyRangeRef(LiteralStringRef("profiling/"), LiteralStringRef("profiling0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin)), /* deprecated */ 720); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( KeyRangeRef(LiteralStringRef("maintenance/"), LiteralStringRef("maintenance0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::MANAGEMENT, SpecialKeySpace::IMPLTYPE::READWRITE, std::make_unique( KeyRangeRef(LiteralStringRef("data_distribution/"), LiteralStringRef("data_distribution0")) .withPrefix(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::MANAGEMENT).begin))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::ACTORLINEAGE, SpecialKeySpace::IMPLTYPE::READONLY, std::make_unique(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::ACTORLINEAGE))); - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::ACTOR_PROFILER_CONF, - SpecialKeySpace::IMPLTYPE::READWRITE, - std::make_unique(SpecialKeySpace::getModuleRange( - SpecialKeySpace::MODULE::ACTOR_PROFILER_CONF))); + registerSpecialKeysImpl(SpecialKeySpace::MODULE::ACTOR_PROFILER_CONF, + SpecialKeySpace::IMPLTYPE::READWRITE, + std::make_unique( + SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::ACTOR_PROFILER_CONF))); } if (apiVersionAtLeast(630)) { - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::TRANSACTION, - SpecialKeySpace::IMPLTYPE::READONLY, - std::make_unique(conflictingKeysRange)); - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::TRANSACTION, - SpecialKeySpace::IMPLTYPE::READONLY, - std::make_unique(readConflictRangeKeysRange)); - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::TRANSACTION, - SpecialKeySpace::IMPLTYPE::READONLY, - std::make_unique(writeConflictRangeKeysRange)); - registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::METRICS, - SpecialKeySpace::IMPLTYPE::READONLY, - std::make_unique(ddStatsRange)); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl(SpecialKeySpace::MODULE::TRANSACTION, + SpecialKeySpace::IMPLTYPE::READONLY, + std::make_unique(conflictingKeysRange)); + registerSpecialKeysImpl(SpecialKeySpace::MODULE::TRANSACTION, + SpecialKeySpace::IMPLTYPE::READONLY, + std::make_unique(readConflictRangeKeysRange)); + registerSpecialKeysImpl(SpecialKeySpace::MODULE::TRANSACTION, + SpecialKeySpace::IMPLTYPE::READONLY, + std::make_unique(writeConflictRangeKeysRange)); + registerSpecialKeysImpl(SpecialKeySpace::MODULE::METRICS, + SpecialKeySpace::IMPLTYPE::READONLY, + std::make_unique(ddStatsRange)); + registerSpecialKeysImpl( SpecialKeySpace::MODULE::METRICS, SpecialKeySpace::IMPLTYPE::READONLY, std::make_unique(KeyRangeRef(LiteralStringRef("\xff\xff/metrics/health/"), LiteralStringRef("\xff\xff/metrics/health0")))); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::WORKERINTERFACE, SpecialKeySpace::IMPLTYPE::READONLY, std::make_unique(KeyRangeRef( LiteralStringRef("\xff\xff/worker_interfaces/"), LiteralStringRef("\xff\xff/worker_interfaces0")))); - registerSpecialKeySpaceModule( - SpecialKeySpace::MODULE::STATUSJSON, - SpecialKeySpace::IMPLTYPE::READONLY, - std::make_unique(LiteralStringRef("\xff\xff/status/json"), - [](ReadYourWritesTransaction* ryw) -> Future> { - if (ryw->getDatabase().getPtr() && - ryw->getDatabase()->getConnectionRecord()) { - ++ryw->getDatabase()->transactionStatusRequests; - return getJSON(ryw->getDatabase()); - } else { - return Optional(); - } - })); - registerSpecialKeySpaceModule( - SpecialKeySpace::MODULE::CLUSTERFILEPATH, - SpecialKeySpace::IMPLTYPE::READONLY, - std::make_unique( - LiteralStringRef("\xff\xff/cluster_file_path"), - [](ReadYourWritesTransaction* ryw) -> Future> { - try { - if (ryw->getDatabase().getPtr() && ryw->getDatabase()->getConnectionRecord()) { - Optional output = - StringRef(ryw->getDatabase()->getConnectionRecord()->getLocation()); - return output; - } - } catch (Error& e) { - return e; - } - return Optional(); - })); + registerSpecialKeysImpl(SpecialKeySpace::MODULE::STATUSJSON, + SpecialKeySpace::IMPLTYPE::READONLY, + std::make_unique( + LiteralStringRef("\xff\xff/status/json"), + [](ReadYourWritesTransaction* ryw) -> Future> { + if (ryw->getDatabase().getPtr() && ryw->getDatabase()->getConnectionRecord()) { + ++ryw->getDatabase()->transactionStatusRequests; + return getJSON(ryw->getDatabase()); + } else { + return Optional(); + } + })); + registerSpecialKeysImpl(SpecialKeySpace::MODULE::CLUSTERFILEPATH, + SpecialKeySpace::IMPLTYPE::READONLY, + std::make_unique( + LiteralStringRef("\xff\xff/cluster_file_path"), + [](ReadYourWritesTransaction* ryw) -> Future> { + try { + if (ryw->getDatabase().getPtr() && + ryw->getDatabase()->getConnectionRecord()) { + Optional output = + StringRef(ryw->getDatabase()->getConnectionRecord()->getLocation()); + return output; + } + } catch (Error& e) { + return e; + } + return Optional(); + })); - registerSpecialKeySpaceModule( + registerSpecialKeysImpl( SpecialKeySpace::MODULE::CONNECTIONSTRING, SpecialKeySpace::IMPLTYPE::READONLY, std::make_unique(