diff --git a/fdbclient/CMakeLists.txt b/fdbclient/CMakeLists.txt index 1349a66810..ca78b6986c 100644 --- a/fdbclient/CMakeLists.txt +++ b/fdbclient/CMakeLists.txt @@ -21,6 +21,7 @@ set(FDBCLIENT_SRCS CommitTransaction.h ConfigKnobs.cpp ConfigKnobs.h + ConfigTransactionInterface.cpp ConfigTransactionInterface.h CoordinationInterface.h DatabaseBackupAgent.actor.cpp diff --git a/fdbclient/ConfigTransactionInterface.cpp b/fdbclient/ConfigTransactionInterface.cpp new file mode 100644 index 0000000000..a837a7b26d --- /dev/null +++ b/fdbclient/ConfigTransactionInterface.cpp @@ -0,0 +1,45 @@ +/* + * ConfigTransactionInterface.cpp + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2013-2018 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. + */ + +#include "fdbclient/ConfigTransactionInterface.h" +#include "fdbclient/CoordinationInterface.h" +#include "flow/IRandom.h" + +ConfigTransactionInterface::ConfigTransactionInterface() : _id(deterministicRandom()->randomUniqueID()) {} + +void ConfigTransactionInterface::setupWellKnownEndpoints() { + getVersion.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETVERSION, TaskPriority::Coordination); + get.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GET, TaskPriority::Coordination); + getRange.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETRANGE, TaskPriority::Coordination); + commit.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_COMMIT, TaskPriority::Coordination); +} + +ConfigTransactionInterface::ConfigTransactionInterface(NetworkAddress const& remote) + : getVersion(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETVERSION)), get(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GET)), + getRange(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETRANGE)), commit(Endpoint({ remote }, WLTOKEN_CONFIGTXN_COMMIT)) { +} + +bool ConfigTransactionInterface::operator==(ConfigTransactionInterface const& rhs) const { + return _id == rhs._id; +} + +bool ConfigTransactionInterface::operator!=(ConfigTransactionInterface const& rhs) const { + return !(*this == rhs); +} diff --git a/fdbclient/ConfigTransactionInterface.h b/fdbclient/ConfigTransactionInterface.h index a9cd4c66dc..233e85d030 100644 --- a/fdbclient/ConfigTransactionInterface.h +++ b/fdbclient/ConfigTransactionInterface.h @@ -128,25 +128,22 @@ struct ConfigTransactionGetRangeRequest { }; struct ConfigTransactionInterface { + UID _id; + +public: static constexpr FileIdentifier file_identifier = 982485; struct RequestStream getVersion; struct RequestStream get; struct RequestStream getRange; struct RequestStream commit; - ConfigTransactionInterface() = default; + ConfigTransactionInterface(); + void setupWellKnownEndpoints(); + ConfigTransactionInterface(NetworkAddress const& remote); - void setupWellKnownEndpoints() { - getVersion.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETVERSION, TaskPriority::Coordination); - get.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GET, TaskPriority::Coordination); - getRange.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETRANGE, TaskPriority::Coordination); - commit.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_COMMIT, TaskPriority::Coordination); - } - - ConfigTransactionInterface(NetworkAddress const& remote) - : getVersion(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETVERSION)), - get(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GET)), getRange(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETRANGE)), - commit(Endpoint({ remote }, WLTOKEN_CONFIGTXN_COMMIT)) {} + bool operator==(ConfigTransactionInterface const& rhs) const; + bool operator!=(ConfigTransactionInterface const& rhs) const; + UID id() const { return _id; } template void serialize(Ar& ar) { diff --git a/fdbserver/ConfigDatabaseUnitTests.actor.cpp b/fdbserver/ConfigDatabaseUnitTests.actor.cpp index a9e11bbd48..c2d14e0c92 100644 --- a/fdbserver/ConfigDatabaseUnitTests.actor.cpp +++ b/fdbserver/ConfigDatabaseUnitTests.actor.cpp @@ -152,12 +152,18 @@ Future addTestGlobalSetMutation(ConfigStore& configStore, Version& lastWri class LocalConfigEnvironment { LocalConfiguration localConfiguration; + UID id; public: LocalConfigEnvironment(std::string const& configPath, std::map const& manualKnobOverrides) - : localConfiguration(configPath, manualKnobOverrides) {} + : localConfiguration(configPath, manualKnobOverrides), id(deterministicRandom()->randomUniqueID()) {} - Future setup() { return localConfiguration.initialize("./", deterministicRandom()->randomUniqueID()); } + Future setup() { return localConfiguration.initialize("./", id); } + + Future restart(std::string const& newConfigPath) { + localConfiguration = LocalConfiguration(newConfigPath, {}); + return setup(); + } template Future run(Args&&... args) { diff --git a/fdbserver/LocalConfiguration.actor.cpp b/fdbserver/LocalConfiguration.actor.cpp index 550f4d7c94..e6c0600031 100644 --- a/fdbserver/LocalConfiguration.actor.cpp +++ b/fdbserver/LocalConfiguration.actor.cpp @@ -360,6 +360,10 @@ LocalConfiguration::LocalConfiguration(std::string const& configPath, std::map const& manualKnobOverrides) : impl(std::make_unique(configPath, manualKnobOverrides)) {} +LocalConfiguration::LocalConfiguration(LocalConfiguration&&) = default; + +LocalConfiguration& LocalConfiguration::operator=(LocalConfiguration&&) = default; + LocalConfiguration::~LocalConfiguration() = default; Future LocalConfiguration::initialize(std::string const& dataFolder, UID id) { diff --git a/fdbserver/LocalConfiguration.h b/fdbserver/LocalConfiguration.h index 369f0e8b3b..d513550fe7 100644 --- a/fdbserver/LocalConfiguration.h +++ b/fdbserver/LocalConfiguration.h @@ -46,6 +46,8 @@ class LocalConfiguration { public: LocalConfiguration(std::string const& configPath, std::map const& manualKnobOverrides); LocalConfiguration(std::string const& configPath, std::map&& manualKnobOverrides); + LocalConfiguration(LocalConfiguration&&); + LocalConfiguration& operator=(LocalConfiguration&&); ~LocalConfiguration(); Future initialize(std::string const& dataFolder, UID id); FlowKnobs const& getFlowKnobs() const;