2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* MonitorLeader.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
#include "fdbclient/ClusterConnectionMemoryRecord.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/MonitorLeader.h"
|
|
|
|
#include "fdbclient/CoordinationInterface.h"
|
2021-10-11 11:44:56 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/ActorCollection.h"
|
|
|
|
#include "flow/UnitTest.h"
|
|
|
|
#include "fdbrpc/genericactors.actor.h"
|
2020-02-29 06:56:10 +08:00
|
|
|
#include "flow/Platform.h"
|
2019-02-18 06:55:47 +08:00
|
|
|
#include "flow/actorcompiler.h" // has to be last include
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-07-14 05:28:46 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::string trim(std::string const& connectionString) {
|
|
|
|
// Strip out whitespace
|
|
|
|
// Strip out characters between a # and a newline
|
|
|
|
std::string trimmed;
|
|
|
|
auto end = connectionString.end();
|
|
|
|
for (auto c = connectionString.begin(); c != end; ++c) {
|
|
|
|
if (*c == '#') {
|
|
|
|
++c;
|
|
|
|
while (c != end && *c != '\n' && *c != '\r')
|
|
|
|
++c;
|
|
|
|
if (c == end)
|
|
|
|
break;
|
|
|
|
} else if (*c != ' ' && *c != '\n' && *c != '\r' && *c != '\t')
|
|
|
|
trimmed += *c;
|
|
|
|
}
|
|
|
|
return trimmed;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-10-12 05:39:05 +08:00
|
|
|
FDB_DEFINE_BOOLEAN_PARAM(ConnectionStringNeedsPersisted);
|
|
|
|
|
2021-10-28 03:13:19 +08:00
|
|
|
// Returns the connection string currently held in this object. This may not match the stored record if it hasn't
|
|
|
|
// been persisted or if the persistent storage for the record has been modified externally.
|
2022-01-28 09:43:56 +08:00
|
|
|
ClusterConnectionString& IClusterConnectionRecord::getConnectionString() {
|
2021-10-28 03:13:19 +08:00
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
Future<bool> IClusterConnectionRecord::upToDate() {
|
2017-05-26 04:48:44 +08:00
|
|
|
ClusterConnectionString temp;
|
2021-10-11 11:44:56 +08:00
|
|
|
return upToDate(temp);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
void IClusterConnectionRecord::notifyConnected() {
|
|
|
|
if (connectionStringNeedsPersisted) {
|
|
|
|
this->persist();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
bool IClusterConnectionRecord::needsToBePersisted() const {
|
|
|
|
return connectionStringNeedsPersisted;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
void IClusterConnectionRecord::setPersisted() {
|
|
|
|
connectionStringNeedsPersisted = false;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-02-19 06:30:53 +08:00
|
|
|
ClusterConnectionString::ConnectionStringStatus IClusterConnectionRecord::connectionStringStatus() const {
|
|
|
|
return cs.status;
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> IClusterConnectionRecord::resolveHostnames() {
|
|
|
|
return cs.resolveHostnames();
|
|
|
|
}
|
|
|
|
|
2022-01-28 09:43:56 +08:00
|
|
|
void IClusterConnectionRecord::resolveHostnamesBlocking() {
|
|
|
|
cs.resolveHostnamesBlocking();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
std::string ClusterConnectionString::getErrorString(std::string const& source, Error const& e) {
|
|
|
|
if (e.code() == error_code_connection_string_invalid) {
|
2017-05-26 04:48:44 +08:00
|
|
|
return format("Invalid connection string `%s: %d %s", source.c_str(), e.code(), e.what());
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2017-05-26 04:48:44 +08:00
|
|
|
return format("Unexpected error parsing connection string `%s: %d %s", source.c_str(), e.code(), e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 07:43:43 +08:00
|
|
|
ACTOR Future<Void> resolveHostnamesImpl(ClusterConnectionString* self) {
|
2022-02-19 06:30:53 +08:00
|
|
|
loop {
|
|
|
|
if (self->status == ClusterConnectionString::UNRESOLVED) {
|
|
|
|
self->status = ClusterConnectionString::RESOLVING;
|
|
|
|
std::vector<Future<Void>> fs;
|
|
|
|
for (auto const& hostname : self->hostnames) {
|
|
|
|
fs.push_back(map(INetworkConnections::net()->resolveTCPEndpoint(hostname.host, hostname.service),
|
|
|
|
[=](std::vector<NetworkAddress> const& addresses) -> Void {
|
|
|
|
NetworkAddress address =
|
|
|
|
addresses[deterministicRandom()->randomInt(0, addresses.size())];
|
|
|
|
address.flags = 0; // Reset the parsed address to public
|
|
|
|
address.fromHostname = NetworkAddressFromHostname::True;
|
|
|
|
if (hostname.isTLS) {
|
|
|
|
address.flags |= NetworkAddress::FLAG_TLS;
|
|
|
|
}
|
|
|
|
self->addResolved(hostname, address);
|
|
|
|
return Void();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
wait(waitForAll(fs));
|
|
|
|
std::sort(self->coords.begin(), self->coords.end());
|
|
|
|
if (std::unique(self->coords.begin(), self->coords.end()) != self->coords.end()) {
|
|
|
|
self->status = ClusterConnectionString::UNRESOLVED;
|
|
|
|
self->resolveFinish.trigger();
|
|
|
|
throw connection_string_invalid();
|
|
|
|
}
|
|
|
|
self->status = ClusterConnectionString::RESOLVED;
|
|
|
|
self->resolveFinish.trigger();
|
|
|
|
break;
|
|
|
|
} else if (self->status == ClusterConnectionString::RESOLVING) {
|
|
|
|
wait(self->resolveFinish.onTrigger());
|
|
|
|
if (self->status == ClusterConnectionString::RESOLVED) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Otherwise, this means other threads failed on resolve, so here we go back to the loop and try to resolve
|
|
|
|
// again.
|
|
|
|
} else {
|
|
|
|
// status is RESOLVED, nothing to do.
|
|
|
|
break;
|
|
|
|
}
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> ClusterConnectionString::resolveHostnames() {
|
2022-02-19 06:30:53 +08:00
|
|
|
return resolveHostnamesImpl(this);
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
|
2022-01-28 09:43:56 +08:00
|
|
|
void ClusterConnectionString::resolveHostnamesBlocking() {
|
2022-02-19 06:30:53 +08:00
|
|
|
if (status != RESOLVED) {
|
|
|
|
status = RESOLVING;
|
2022-01-28 09:43:56 +08:00
|
|
|
for (auto const& hostname : hostnames) {
|
|
|
|
std::vector<NetworkAddress> addresses =
|
|
|
|
INetworkConnections::net()->resolveTCPEndpointBlocking(hostname.host, hostname.service);
|
|
|
|
NetworkAddress address = addresses[deterministicRandom()->randomInt(0, addresses.size())];
|
|
|
|
address.flags = 0; // Reset the parsed address to public
|
|
|
|
address.fromHostname = NetworkAddressFromHostname::True;
|
|
|
|
if (hostname.isTLS) {
|
|
|
|
address.flags |= NetworkAddress::FLAG_TLS;
|
|
|
|
}
|
2022-02-19 06:30:53 +08:00
|
|
|
addResolved(hostname, address);
|
2022-01-28 09:43:56 +08:00
|
|
|
}
|
|
|
|
std::sort(coords.begin(), coords.end());
|
|
|
|
if (std::unique(coords.begin(), coords.end()) != coords.end()) {
|
2022-02-19 06:30:53 +08:00
|
|
|
status = UNRESOLVED;
|
2022-01-28 09:43:56 +08:00
|
|
|
throw connection_string_invalid();
|
|
|
|
}
|
2022-02-19 06:30:53 +08:00
|
|
|
status = RESOLVED;
|
2022-01-28 09:43:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 04:19:58 +08:00
|
|
|
void ClusterConnectionString::resetToUnresolved() {
|
2022-01-21 07:43:43 +08:00
|
|
|
if (hostnames.size() > 0) {
|
|
|
|
coords.clear();
|
|
|
|
hostnames.clear();
|
|
|
|
networkAddressToHostname.clear();
|
2022-02-19 06:30:53 +08:00
|
|
|
status = UNRESOLVED;
|
2022-01-21 04:19:58 +08:00
|
|
|
parseConnString();
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-01-21 04:19:58 +08:00
|
|
|
void ClusterConnectionString::parseConnString() {
|
2017-05-26 04:48:44 +08:00
|
|
|
// Split on '@' into key@addrs
|
2022-01-21 04:19:58 +08:00
|
|
|
int pAt = connectionString.find_first_of('@');
|
|
|
|
if (pAt == connectionString.npos) {
|
2017-05-26 04:48:44 +08:00
|
|
|
throw connection_string_invalid();
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
std::string key = connectionString.substr(0, pAt);
|
|
|
|
std::string addrs = connectionString.substr(pAt + 1);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
parseKey(key);
|
2022-01-21 04:19:58 +08:00
|
|
|
std::string curAddr;
|
|
|
|
for (int p = 0; p <= addrs.size();) {
|
|
|
|
int pComma = addrs.find_first_of(',', p);
|
|
|
|
if (pComma == addrs.npos)
|
|
|
|
pComma = addrs.size();
|
|
|
|
curAddr = addrs.substr(p, pComma - p);
|
|
|
|
if (Hostname::isHostname(curAddr)) {
|
2022-01-21 07:43:43 +08:00
|
|
|
hostnames.push_back(Hostname::parse(curAddr));
|
2022-01-21 04:19:58 +08:00
|
|
|
} else {
|
2022-01-21 07:43:43 +08:00
|
|
|
coords.push_back(NetworkAddress::parse(curAddr));
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
p = pComma + 1;
|
|
|
|
}
|
2022-02-19 06:30:53 +08:00
|
|
|
if (hostnames.size() > 0) {
|
|
|
|
status = UNRESOLVED;
|
|
|
|
}
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT((coords.size() + hostnames.size()) > 0);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-01-21 07:43:43 +08:00
|
|
|
std::sort(coords.begin(), coords.end());
|
2017-05-26 04:48:44 +08:00
|
|
|
// Check that there are no duplicate addresses
|
2022-01-21 07:43:43 +08:00
|
|
|
if (std::unique(coords.begin(), coords.end()) != coords.end()) {
|
2017-05-26 04:48:44 +08:00
|
|
|
throw connection_string_invalid();
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 10:09:01 +08:00
|
|
|
ClusterConnectionString::ClusterConnectionString(const std::string& connStr) {
|
2022-01-21 04:19:58 +08:00
|
|
|
connectionString = trim(connStr);
|
|
|
|
parseConnString();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-01-21 04:19:58 +08:00
|
|
|
TEST_CASE("/fdbclient/MonitorLeader/parseConnectionString/addresses") {
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string input;
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "asdf:2345@1.1.1.1:345";
|
|
|
|
ClusterConnectionString cs(input);
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(input == cs.toString());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "0xxdeadbeef:100100100@1.1.1.1:34534,5.1.5.3:23443";
|
|
|
|
ClusterConnectionString cs(input);
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(input == cs.toString());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "0xxdeadbeef:100100100@1.1.1.1:34534,5.1.5.3:23443";
|
|
|
|
std::string commented("#start of comment\n");
|
|
|
|
commented += input;
|
|
|
|
commented += "\n";
|
|
|
|
commented += "# asdfasdf ##";
|
|
|
|
|
|
|
|
ClusterConnectionString cs(commented);
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(input == cs.toString());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2019-02-27 10:04:03 +08:00
|
|
|
{
|
|
|
|
input = "0xxdeadbeef:100100100@[::1]:1234,[::1]:1235";
|
|
|
|
std::string commented("#start of comment\n");
|
|
|
|
commented += input;
|
|
|
|
commented += "\n";
|
|
|
|
commented += "# asdfasdf ##";
|
|
|
|
|
|
|
|
ClusterConnectionString cs(commented);
|
|
|
|
ASSERT(input == cs.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "0xxdeadbeef:100100100@[abcd:dcba::1]:1234,[abcd:dcba::abcd:1]:1234";
|
|
|
|
std::string commented("#start of comment\n");
|
|
|
|
commented += input;
|
|
|
|
commented += "\n";
|
|
|
|
commented += "# asdfasdf ##";
|
|
|
|
|
|
|
|
ClusterConnectionString cs(commented);
|
|
|
|
ASSERT(input == cs.toString());
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2022-01-21 04:19:58 +08:00
|
|
|
TEST_CASE("/fdbclient/MonitorLeader/parseConnectionString/hostnames") {
|
|
|
|
std::string input;
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "asdf:2345@localhost:1234";
|
|
|
|
ClusterConnectionString cs(input);
|
2022-02-19 06:30:53 +08:00
|
|
|
ASSERT(cs.status == ClusterConnectionString::UNRESOLVED);
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT(cs.hostnames.size() == 1);
|
2022-01-21 04:19:58 +08:00
|
|
|
ASSERT(input == cs.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "0xxdeadbeef:100100100@localhost:34534,host-name:23443";
|
|
|
|
ClusterConnectionString cs(input);
|
2022-02-19 06:30:53 +08:00
|
|
|
ASSERT(cs.status == ClusterConnectionString::UNRESOLVED);
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT(cs.hostnames.size() == 2);
|
2022-01-21 04:19:58 +08:00
|
|
|
ASSERT(input == cs.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "0xxdeadbeef:100100100@localhost:34534,host-name:23443";
|
|
|
|
std::string commented("#start of comment\n");
|
|
|
|
commented += input;
|
|
|
|
commented += "\n";
|
|
|
|
commented += "# asdfasdf ##";
|
|
|
|
|
|
|
|
ClusterConnectionString cs(commented);
|
2022-02-19 06:30:53 +08:00
|
|
|
ASSERT(cs.status == ClusterConnectionString::UNRESOLVED);
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT(cs.hostnames.size() == 2);
|
2022-01-21 04:19:58 +08:00
|
|
|
ASSERT(input == cs.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
input = "0xxdeadbeef:100100100@localhost:34534,host-name_part1.host-name_part2:1234:tls";
|
|
|
|
std::string commented("#start of comment\n");
|
|
|
|
commented += input;
|
|
|
|
commented += "\n";
|
|
|
|
commented += "# asdfasdf ##";
|
|
|
|
|
|
|
|
ClusterConnectionString cs(commented);
|
2022-02-19 06:30:53 +08:00
|
|
|
ASSERT(cs.status == ClusterConnectionString::UNRESOLVED);
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT(cs.hostnames.size() == 2);
|
2022-01-21 04:19:58 +08:00
|
|
|
ASSERT(input == cs.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("/fdbclient/MonitorLeader/ConnectionString") {
|
|
|
|
state std::string connectionString = "TestCluster:0@localhost:1234,host-name:5678";
|
|
|
|
std::string hn1 = "localhost", port1 = "1234";
|
|
|
|
state std::string hn2 = "host-name";
|
|
|
|
state std::string port2 = "5678";
|
|
|
|
state std::vector<Hostname> hostnames;
|
|
|
|
hostnames.push_back(Hostname::parse(hn1 + ":" + port1));
|
|
|
|
hostnames.push_back(Hostname::parse(hn2 + ":" + port2));
|
|
|
|
|
|
|
|
NetworkAddress address1 = NetworkAddress::parse("127.0.0.0:1234");
|
|
|
|
NetworkAddress address2 = NetworkAddress::parse("127.0.0.1:5678");
|
|
|
|
|
|
|
|
INetworkConnections::net()->addMockTCPEndpoint(hn1, port1, { address1 });
|
|
|
|
INetworkConnections::net()->addMockTCPEndpoint(hn2, port2, { address2 });
|
|
|
|
|
|
|
|
state ClusterConnectionString cs(hostnames, LiteralStringRef("TestCluster:0"));
|
2022-02-19 06:30:53 +08:00
|
|
|
ASSERT(cs.status == ClusterConnectionString::UNRESOLVED);
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT(cs.hostnames.size() == 2);
|
2022-01-21 04:19:58 +08:00
|
|
|
ASSERT(cs.coordinators().size() == 0);
|
|
|
|
wait(cs.resolveHostnames());
|
2022-02-19 06:30:53 +08:00
|
|
|
ASSERT(cs.status == ClusterConnectionString::RESOLVED);
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT(cs.hostnames.size() == 2);
|
2022-01-21 04:19:58 +08:00
|
|
|
ASSERT(cs.coordinators().size() == 2);
|
|
|
|
ASSERT(cs.toString() == connectionString);
|
|
|
|
cs.resetToUnresolved();
|
2022-02-19 06:30:53 +08:00
|
|
|
ASSERT(cs.status == ClusterConnectionString::UNRESOLVED);
|
2022-01-21 07:43:43 +08:00
|
|
|
ASSERT(cs.hostnames.size() == 2);
|
2022-01-21 04:19:58 +08:00
|
|
|
ASSERT(cs.coordinators().size() == 0);
|
|
|
|
ASSERT(cs.toString() == connectionString);
|
|
|
|
|
|
|
|
INetworkConnections::net()->removeMockTCPEndpoint(hn2, port2);
|
|
|
|
NetworkAddress address3 = NetworkAddress::parse("127.0.0.0:5678");
|
|
|
|
INetworkConnections::net()->addMockTCPEndpoint(hn2, port2, { address3 });
|
|
|
|
|
|
|
|
try {
|
|
|
|
wait(cs.resolveHostnames());
|
|
|
|
} catch (Error& e) {
|
|
|
|
ASSERT(e.code() == error_code_connection_string_invalid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2019-02-01 04:23:12 +08:00
|
|
|
TEST_CASE("/flow/FlatBuffers/LeaderInfo") {
|
2019-02-01 06:45:42 +08:00
|
|
|
{
|
|
|
|
LeaderInfo in;
|
|
|
|
LeaderInfo out;
|
2019-05-24 00:23:27 +08:00
|
|
|
in.forward = deterministicRandom()->coinflip();
|
|
|
|
in.changeID = deterministicRandom()->randomUniqueID();
|
2019-02-01 06:45:42 +08:00
|
|
|
{
|
2019-05-24 00:23:27 +08:00
|
|
|
std::string rndString(deterministicRandom()->randomInt(10, 400), 'x');
|
2019-02-01 06:45:42 +08:00
|
|
|
for (auto& c : rndString) {
|
2019-05-24 00:23:27 +08:00
|
|
|
c = deterministicRandom()->randomAlphaNumeric();
|
2019-02-01 06:45:42 +08:00
|
|
|
}
|
|
|
|
in.serializedInfo = rndString;
|
|
|
|
}
|
2019-07-17 04:28:29 +08:00
|
|
|
ObjectWriter writer(IncludeVersion());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(in);
|
|
|
|
Standalone<StringRef> copy = writer.toStringRef();
|
2019-07-17 04:28:29 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, IncludeVersion());
|
2019-02-01 06:45:42 +08:00
|
|
|
reader.deserialize(out);
|
|
|
|
ASSERT(in.forward == out.forward);
|
|
|
|
ASSERT(in.changeID == out.changeID);
|
|
|
|
ASSERT(in.serializedInfo == out.serializedInfo);
|
|
|
|
}
|
2019-02-01 04:23:12 +08:00
|
|
|
LeaderInfo leaderInfo;
|
2019-05-24 00:23:27 +08:00
|
|
|
leaderInfo.forward = deterministicRandom()->coinflip();
|
|
|
|
leaderInfo.changeID = deterministicRandom()->randomUniqueID();
|
2019-02-01 04:23:12 +08:00
|
|
|
{
|
2019-05-24 00:23:27 +08:00
|
|
|
std::string rndString(deterministicRandom()->randomInt(10, 400), 'x');
|
2019-02-01 04:23:12 +08:00
|
|
|
for (auto& c : rndString) {
|
2019-05-24 00:23:27 +08:00
|
|
|
c = deterministicRandom()->randomAlphaNumeric();
|
2019-02-01 04:23:12 +08:00
|
|
|
}
|
|
|
|
leaderInfo.serializedInfo = rndString;
|
|
|
|
}
|
2019-02-01 07:07:27 +08:00
|
|
|
ErrorOr<EnsureTable<Optional<LeaderInfo>>> objIn(leaderInfo);
|
|
|
|
ErrorOr<EnsureTable<Optional<LeaderInfo>>> objOut;
|
2019-02-01 04:23:12 +08:00
|
|
|
Standalone<StringRef> copy;
|
2019-07-17 04:28:29 +08:00
|
|
|
ObjectWriter writer(IncludeVersion());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(objIn);
|
|
|
|
copy = writer.toStringRef();
|
2019-07-17 04:28:29 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, IncludeVersion());
|
2019-02-01 04:23:12 +08:00
|
|
|
reader.deserialize(objOut);
|
|
|
|
|
|
|
|
ASSERT(!objOut.isError());
|
2019-02-01 07:07:27 +08:00
|
|
|
ASSERT(objOut.get().asUnderlyingType().present());
|
|
|
|
LeaderInfo outLeader = objOut.get().asUnderlyingType().get();
|
2019-02-01 04:23:12 +08:00
|
|
|
ASSERT(outLeader.changeID == leaderInfo.changeID);
|
|
|
|
ASSERT(outLeader.forward == leaderInfo.forward);
|
|
|
|
ASSERT(outLeader.serializedInfo == leaderInfo.serializedInfo);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2018-10-06 13:09:58 +08:00
|
|
|
TEST_CASE("/fdbclient/MonitorLeader/parseConnectionString/fuzz") {
|
2017-05-26 04:48:44 +08:00
|
|
|
// For a static connection string, add in fuzzed comments and whitespace
|
|
|
|
// SOMEDAY: create a series of random connection strings, rather than the one we started with
|
|
|
|
std::string connectionString = "0xxdeadbeef:100100100@1.1.1.1:34534,5.1.5.3:23443";
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < 10000; i++) {
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string output("");
|
2021-03-11 02:06:03 +08:00
|
|
|
auto c = connectionString.begin();
|
|
|
|
while (c != connectionString.end()) {
|
|
|
|
if (deterministicRandom()->random01() < 0.1) // Add whitespace character
|
2019-05-11 05:01:52 +08:00
|
|
|
output += deterministicRandom()->randomChoice(LiteralStringRef(" \t\n\r"));
|
2021-03-11 02:06:03 +08:00
|
|
|
if (deterministicRandom()->random01() < 0.5) { // Add one of the input characters
|
2017-05-26 04:48:44 +08:00
|
|
|
output += *c;
|
|
|
|
++c;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
if (deterministicRandom()->random01() < 0.1) { // Add a comment block
|
2017-05-26 04:48:44 +08:00
|
|
|
output += "#";
|
2019-05-11 05:01:52 +08:00
|
|
|
int charCount = deterministicRandom()->randomInt(0, 20);
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < charCount; i++) {
|
2019-05-11 05:01:52 +08:00
|
|
|
output += deterministicRandom()->randomChoice(LiteralStringRef("asdfzxcv123345:!@#$#$&()<\"\' \t"));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2019-05-11 05:01:52 +08:00
|
|
|
output += deterministicRandom()->randomChoice(LiteralStringRef("\n\r"));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClusterConnectionString cs(output);
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(connectionString == cs.toString());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2022-01-21 10:09:01 +08:00
|
|
|
ClusterConnectionString::ClusterConnectionString(const std::vector<NetworkAddress>& servers, Key key)
|
2022-02-19 06:30:53 +08:00
|
|
|
: status(RESOLVED), coords(servers) {
|
2022-01-21 07:43:43 +08:00
|
|
|
std::string keyString = key.toString();
|
|
|
|
parseKey(keyString);
|
|
|
|
connectionString = keyString + "@";
|
|
|
|
for (int i = 0; i < coords.size(); i++) {
|
|
|
|
if (i) {
|
|
|
|
connectionString += ',';
|
|
|
|
}
|
|
|
|
connectionString += coords[i].toString();
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-01-21 10:09:01 +08:00
|
|
|
ClusterConnectionString::ClusterConnectionString(const std::vector<Hostname>& hosts, Key key)
|
2022-02-19 06:30:53 +08:00
|
|
|
: status(UNRESOLVED), hostnames(hosts) {
|
2022-01-21 04:19:58 +08:00
|
|
|
std::string keyString = key.toString();
|
|
|
|
parseKey(keyString);
|
|
|
|
connectionString = keyString + "@";
|
|
|
|
for (int i = 0; i < hostnames.size(); i++) {
|
|
|
|
if (i) {
|
|
|
|
connectionString += ',';
|
|
|
|
}
|
|
|
|
connectionString += hostnames[i].toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 10:09:01 +08:00
|
|
|
void ClusterConnectionString::parseKey(const std::string& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
// Check the structure of the given key, and fill in this->key and this->keyDesc
|
|
|
|
|
|
|
|
// The key must contain one (and only one) : character
|
|
|
|
int colon = key.find_first_of(':');
|
2022-01-21 04:19:58 +08:00
|
|
|
if (colon == key.npos) {
|
2017-05-26 04:48:44 +08:00
|
|
|
throw connection_string_invalid();
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string desc = key.substr(0, colon);
|
2021-03-11 02:06:03 +08:00
|
|
|
std::string id = key.substr(colon + 1);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Check that description contains only allowed characters (a-z, A-Z, 0-9, _)
|
2022-01-21 04:19:58 +08:00
|
|
|
for (auto c = desc.begin(); c != desc.end(); ++c) {
|
|
|
|
if (!(isalnum(*c) || *c == '_')) {
|
2017-05-26 04:48:44 +08:00
|
|
|
throw connection_string_invalid();
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Check that ID contains only allowed characters (a-z, A-Z, 0-9)
|
2022-01-21 04:19:58 +08:00
|
|
|
for (auto c = id.begin(); c != id.end(); ++c) {
|
|
|
|
if (!isalnum(*c)) {
|
2017-05-26 04:48:44 +08:00
|
|
|
throw connection_string_invalid();
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
this->key = StringRef(key);
|
|
|
|
this->keyDesc = StringRef(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ClusterConnectionString::toString() const {
|
|
|
|
std::string s = key.toString();
|
|
|
|
s += '@';
|
2022-01-21 07:43:43 +08:00
|
|
|
for (int i = 0; i < coords.size(); i++) {
|
|
|
|
if (networkAddressToHostname.find(coords[i]) == networkAddressToHostname.end()) {
|
|
|
|
if (s.find('@') != s.length() - 1) {
|
2022-01-21 04:19:58 +08:00
|
|
|
s += ',';
|
|
|
|
}
|
2022-01-21 07:43:43 +08:00
|
|
|
s += coords[i].toString();
|
2022-01-21 04:19:58 +08:00
|
|
|
}
|
|
|
|
}
|
2022-01-21 07:43:43 +08:00
|
|
|
for (auto const& host : hostnames) {
|
2022-01-21 04:19:58 +08:00
|
|
|
if (s.find('@') != s.length() - 1) {
|
2021-03-11 02:06:03 +08:00
|
|
|
s += ',';
|
2021-11-03 13:59:28 +08:00
|
|
|
}
|
2022-01-21 04:19:58 +08:00
|
|
|
s += host.toString();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
ClientCoordinators::ClientCoordinators(Reference<IClusterConnectionRecord> ccr) : ccr(ccr) {
|
|
|
|
ClusterConnectionString cs = ccr->getConnectionString();
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto s = cs.coordinators().begin(); s != cs.coordinators().end(); ++s)
|
|
|
|
clientLeaderServers.push_back(ClientLeaderRegInterface(*s));
|
2017-05-26 04:48:44 +08:00
|
|
|
clusterKey = cs.clusterKey();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ClientCoordinators::ClientCoordinators(Key clusterKey, std::vector<NetworkAddress> coordinators)
|
|
|
|
: clusterKey(clusterKey) {
|
2020-05-02 05:40:21 +08:00
|
|
|
for (const auto& coord : coordinators) {
|
2021-03-11 02:06:03 +08:00
|
|
|
clientLeaderServers.push_back(ClientLeaderRegInterface(coord));
|
2020-05-02 05:40:21 +08:00
|
|
|
}
|
2021-10-11 11:44:56 +08:00
|
|
|
ccr = makeReference<ClusterConnectionMemoryRecord>(ClusterConnectionString(coordinators, clusterKey));
|
2020-05-02 05:40:21 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ClientLeaderRegInterface::ClientLeaderRegInterface(NetworkAddress remote)
|
2021-09-21 00:46:34 +08:00
|
|
|
: getLeader(Endpoint::wellKnown({ remote }, WLTOKEN_CLIENTLEADERREG_GETLEADER)),
|
|
|
|
openDatabase(Endpoint::wellKnown({ remote }, WLTOKEN_CLIENTLEADERREG_OPENDATABASE)),
|
|
|
|
checkDescriptorMutable(Endpoint::wellKnown({ remote }, WLTOKEN_CLIENTLEADERREG_DESCRIPTOR_MUTABLE)) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ClientLeaderRegInterface::ClientLeaderRegInterface(INetwork* local) {
|
|
|
|
getLeader.makeWellKnownEndpoint(WLTOKEN_CLIENTLEADERREG_GETLEADER, TaskPriority::Coordination);
|
|
|
|
openDatabase.makeWellKnownEndpoint(WLTOKEN_CLIENTLEADERREG_OPENDATABASE, TaskPriority::Coordination);
|
2021-05-06 23:51:33 +08:00
|
|
|
checkDescriptorMutable.makeWellKnownEndpoint(WLTOKEN_CLIENTLEADERREG_DESCRIPTOR_MUTABLE,
|
|
|
|
TaskPriority::Coordination);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-09-17 05:22:44 +08:00
|
|
|
// Nominee is the worker among all workers that are considered as leader by one coordinator
|
|
|
|
// This function contacts a coordinator coord to ask who is its nominee.
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> monitorNominee(Key key,
|
|
|
|
ClientLeaderRegInterface coord,
|
|
|
|
AsyncTrigger* nomineeChange,
|
|
|
|
Optional<LeaderInfo>* info) {
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
2021-03-11 02:06:03 +08:00
|
|
|
state Optional<LeaderInfo> li =
|
|
|
|
wait(retryBrokenPromise(coord.getLeader,
|
|
|
|
GetLeaderRequest(key, info->present() ? info->get().changeID : UID()),
|
|
|
|
TaskPriority::CoordinationReply));
|
|
|
|
wait(Future<Void>(Void())); // Make sure we weren't cancelled
|
|
|
|
|
|
|
|
TraceEvent("GetLeaderReply")
|
|
|
|
.suppressFor(1.0)
|
|
|
|
.detail("Coordinator", coord.getLeader.getEndpoint().getPrimaryAddress())
|
|
|
|
.detail("Nominee", li.present() ? li.get().changeID : UID())
|
|
|
|
.detail("ClusterKey", key.printable());
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-09-21 08:42:12 +08:00
|
|
|
if (li != *info) {
|
|
|
|
*info = li;
|
|
|
|
nomineeChange->trigger();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (li.present() && li.get().forward)
|
|
|
|
wait(Future<Void>(Never()));
|
|
|
|
wait(Future<Void>(Void()));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also used in fdbserver/LeaderElection.actor.cpp!
|
2018-05-31 07:48:04 +08:00
|
|
|
// bool represents if the LeaderInfo is a majority answer or not.
|
2018-06-02 09:23:24 +08:00
|
|
|
// This function also masks the first 7 bits of changeId of the nominees and returns the Leader with masked changeId
|
2021-09-17 08:42:34 +08:00
|
|
|
Optional<std::pair<LeaderInfo, bool>> getLeader(const std::vector<Optional<LeaderInfo>>& nominees) {
|
2020-05-11 05:20:50 +08:00
|
|
|
// If any coordinator says that the quorum is forwarded, then it is
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < nominees.size(); i++)
|
2020-05-11 05:20:50 +08:00
|
|
|
if (nominees[i].present() && nominees[i].get().forward)
|
|
|
|
return std::pair<LeaderInfo, bool>(nominees[i].get(), true);
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<std::pair<UID, int>> maskedNominees;
|
2018-06-02 09:23:24 +08:00
|
|
|
maskedNominees.reserve(nominees.size());
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < nominees.size(); i++) {
|
2020-05-11 05:20:50 +08:00
|
|
|
if (nominees[i].present()) {
|
2021-05-11 07:32:02 +08:00
|
|
|
maskedNominees.emplace_back(
|
2021-04-15 01:30:21 +08:00
|
|
|
UID(nominees[i].get().changeID.first() & LeaderInfo::changeIDMask, nominees[i].get().changeID.second()),
|
2021-05-11 07:32:02 +08:00
|
|
|
i);
|
2018-06-02 09:23:24 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!maskedNominees.size())
|
2018-05-31 07:48:04 +08:00
|
|
|
return Optional<std::pair<LeaderInfo, bool>>();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
std::sort(maskedNominees.begin(),
|
|
|
|
maskedNominees.end(),
|
|
|
|
[](const std::pair<UID, int>& l, const std::pair<UID, int>& r) { return l.first < r.first; });
|
2018-05-31 07:48:04 +08:00
|
|
|
|
2017-11-28 07:08:03 +08:00
|
|
|
int bestCount = 0;
|
2020-05-11 05:20:50 +08:00
|
|
|
int bestIdx = 0;
|
|
|
|
int currentIdx = 0;
|
|
|
|
int curCount = 1;
|
|
|
|
for (int i = 1; i < maskedNominees.size(); i++) {
|
|
|
|
if (maskedNominees[currentIdx].first == maskedNominees[i].first) {
|
2018-06-02 09:23:24 +08:00
|
|
|
curCount++;
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2018-05-31 07:48:04 +08:00
|
|
|
if (curCount > bestCount) {
|
2020-05-11 05:20:50 +08:00
|
|
|
bestIdx = currentIdx;
|
2018-05-31 07:48:04 +08:00
|
|
|
bestCount = curCount;
|
2017-11-28 07:08:03 +08:00
|
|
|
}
|
2020-05-11 05:20:50 +08:00
|
|
|
currentIdx = i;
|
2018-06-02 09:23:24 +08:00
|
|
|
curCount = 1;
|
2017-11-28 07:08:03 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-02 09:23:24 +08:00
|
|
|
if (curCount > bestCount) {
|
2020-05-11 05:20:50 +08:00
|
|
|
bestIdx = currentIdx;
|
2018-06-02 09:23:24 +08:00
|
|
|
bestCount = curCount;
|
|
|
|
}
|
2017-11-28 07:08:03 +08:00
|
|
|
|
2018-06-02 09:33:29 +08:00
|
|
|
bool majority = bestCount >= nominees.size() / 2 + 1;
|
2020-05-11 05:20:50 +08:00
|
|
|
return std::pair<LeaderInfo, bool>(nominees[maskedNominees[bestIdx].second].get(), majority);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 13:00:19 +08:00
|
|
|
// Leader is the process that will be elected by coordinators as the cluster controller
|
2021-10-11 11:44:56 +08:00
|
|
|
ACTOR Future<MonitorLeaderInfo> monitorLeaderOneGeneration(Reference<IClusterConnectionRecord> connRecord,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<AsyncVar<Value>> outSerializedLeaderInfo,
|
|
|
|
MonitorLeaderInfo info) {
|
2021-10-11 11:44:56 +08:00
|
|
|
state ClientCoordinators coordinators(info.intermediateConnRecord);
|
2017-09-23 06:06:11 +08:00
|
|
|
state AsyncTrigger nomineeChange;
|
|
|
|
state std::vector<Optional<LeaderInfo>> nominees;
|
|
|
|
state Future<Void> allActors;
|
|
|
|
|
|
|
|
nominees.resize(coordinators.clientLeaderServers.size());
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-09-23 06:06:11 +08:00
|
|
|
std::vector<Future<Void>> actors;
|
2019-03-06 13:00:19 +08:00
|
|
|
// Ask all coordinators if the worker is considered as a leader (leader nominee) by the coordinator.
|
2021-03-04 11:36:21 +08:00
|
|
|
actors.reserve(coordinators.clientLeaderServers.size());
|
|
|
|
for (int i = 0; i < coordinators.clientLeaderServers.size(); i++)
|
2021-03-11 02:06:03 +08:00
|
|
|
actors.push_back(
|
|
|
|
monitorNominee(coordinators.clusterKey, coordinators.clientLeaderServers[i], &nomineeChange, &nominees[i]));
|
2017-09-23 06:06:11 +08:00
|
|
|
allActors = waitForAll(actors);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-09-23 06:06:11 +08:00
|
|
|
loop {
|
2018-05-31 07:48:04 +08:00
|
|
|
Optional<std::pair<LeaderInfo, bool>> leader = getLeader(nominees);
|
2021-03-11 02:06:03 +08:00
|
|
|
TraceEvent("MonitorLeaderChange")
|
|
|
|
.detail("NewLeader", leader.present() ? leader.get().first.changeID : UID(1, 1));
|
2017-09-23 06:06:11 +08:00
|
|
|
if (leader.present()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (leader.get().first.forward) {
|
|
|
|
TraceEvent("MonitorLeaderForwarding")
|
|
|
|
.detail("NewConnStr", leader.get().first.serializedInfo.toString())
|
2021-10-11 11:44:56 +08:00
|
|
|
.detail("OldConnStr", info.intermediateConnRecord->getConnectionString().toString())
|
2021-05-06 23:51:33 +08:00
|
|
|
.trackLatest("MonitorLeaderForwarding");
|
2021-10-11 11:44:56 +08:00
|
|
|
info.intermediateConnRecord = connRecord->makeIntermediateRecord(
|
|
|
|
ClusterConnectionString(leader.get().first.serializedInfo.toString()));
|
2017-09-23 06:06:11 +08:00
|
|
|
return info;
|
|
|
|
}
|
2021-10-11 11:44:56 +08:00
|
|
|
if (connRecord != info.intermediateConnRecord) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!info.hasConnected) {
|
|
|
|
TraceEvent(SevWarnAlways, "IncorrectClusterFileContentsAtConnection")
|
2021-10-11 11:44:56 +08:00
|
|
|
.detail("ClusterFile", connRecord->toString())
|
|
|
|
.detail("StoredConnectionString", connRecord->getConnectionString().toString())
|
|
|
|
.detail("CurrentConnectionString",
|
|
|
|
info.intermediateConnRecord->getConnectionString().toString());
|
2017-09-23 06:06:11 +08:00
|
|
|
}
|
2022-01-28 09:43:56 +08:00
|
|
|
connRecord->setAndPersistConnectionString(info.intermediateConnRecord->getConnectionString());
|
2021-10-11 11:44:56 +08:00
|
|
|
info.intermediateConnRecord = connRecord;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2017-09-23 06:06:11 +08:00
|
|
|
info.hasConnected = true;
|
2021-10-11 11:44:56 +08:00
|
|
|
connRecord->notifyConnected();
|
2017-09-23 06:06:11 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
outSerializedLeaderInfo->set(leader.get().first.serializedInfo);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(nomineeChange.onTrigger() || allActors);
|
2017-09-23 06:06:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
ACTOR Future<Void> monitorLeaderInternal(Reference<IClusterConnectionRecord> connRecord,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<AsyncVar<Value>> outSerializedLeaderInfo) {
|
2021-10-11 11:44:56 +08:00
|
|
|
state MonitorLeaderInfo info(connRecord);
|
2017-09-23 06:06:11 +08:00
|
|
|
loop {
|
2021-10-11 11:44:56 +08:00
|
|
|
MonitorLeaderInfo _info = wait(monitorLeaderOneGeneration(connRecord, outSerializedLeaderInfo, info));
|
2017-09-23 06:06:11 +08:00
|
|
|
info = _info;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
2019-01-30 03:51:37 +08:00
|
|
|
|
|
|
|
ACTOR Future<Void> asyncDeserializeClusterInterface(Reference<AsyncVar<Value>> serializedInfo,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<AsyncVar<Optional<ClusterInterface>>> outKnownLeader) {
|
2019-01-30 03:51:37 +08:00
|
|
|
state Reference<AsyncVar<Optional<ClusterControllerClientInterface>>> knownLeader(
|
2021-03-11 02:06:03 +08:00
|
|
|
new AsyncVar<Optional<ClusterControllerClientInterface>>{});
|
2020-02-13 02:41:52 +08:00
|
|
|
state Future<Void> deserializer = asyncDeserialize(serializedInfo, knownLeader);
|
2019-01-30 03:51:37 +08:00
|
|
|
loop {
|
|
|
|
choose {
|
|
|
|
when(wait(deserializer)) { UNSTOPPABLE_ASSERT(false); }
|
|
|
|
when(wait(knownLeader->onChange())) {
|
|
|
|
if (knownLeader->get().present()) {
|
|
|
|
outKnownLeader->set(knownLeader->get().get().clientInterface);
|
|
|
|
} else {
|
|
|
|
outKnownLeader->set(Optional<ClusterInterface>{});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2019-07-26 08:15:31 +08:00
|
|
|
struct ClientStatusStats {
|
|
|
|
int count;
|
2021-03-11 02:06:03 +08:00
|
|
|
std::vector<std::pair<NetworkAddress, Key>> examples;
|
2019-07-26 08:15:31 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ClientStatusStats() : count(0) { examples.reserve(CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT); }
|
2019-07-26 08:15:31 +08:00
|
|
|
};
|
|
|
|
|
2019-07-24 10:22:44 +08:00
|
|
|
OpenDatabaseRequest ClientData::getRequest() {
|
|
|
|
OpenDatabaseRequest req;
|
2019-07-26 08:15:31 +08:00
|
|
|
|
|
|
|
std::map<StringRef, ClientStatusStats> issueMap;
|
|
|
|
std::map<ClientVersionRef, ClientStatusStats> versionMap;
|
|
|
|
std::map<StringRef, ClientStatusStats> maxProtocolMap;
|
2019-08-14 06:54:40 +08:00
|
|
|
int clientCount = 0;
|
2019-07-26 08:15:31 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// SOMEDAY: add a yield in this loop
|
|
|
|
for (auto& ci : clientStatusInfoMap) {
|
|
|
|
for (auto& it : ci.second.issues) {
|
2019-07-26 08:15:31 +08:00
|
|
|
auto& entry = issueMap[it];
|
|
|
|
entry.count++;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (entry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
|
2021-05-11 07:32:02 +08:00
|
|
|
entry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
|
2019-07-26 08:15:31 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
if (ci.second.versions.size()) {
|
2019-08-14 06:54:40 +08:00
|
|
|
clientCount++;
|
|
|
|
StringRef maxProtocol;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& it : ci.second.versions) {
|
2019-08-14 06:54:40 +08:00
|
|
|
maxProtocol = std::max(maxProtocol, it.protocolVersion);
|
|
|
|
auto& entry = versionMap[it];
|
|
|
|
entry.count++;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (entry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
|
2021-05-11 07:32:02 +08:00
|
|
|
entry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
|
2019-08-14 06:54:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
auto& maxEntry = maxProtocolMap[maxProtocol];
|
|
|
|
maxEntry.count++;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (maxEntry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
|
2021-05-11 07:32:02 +08:00
|
|
|
maxEntry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
|
2019-08-14 06:54:40 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto& entry = versionMap[ClientVersionRef()];
|
2019-07-26 08:15:31 +08:00
|
|
|
entry.count++;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (entry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
|
2021-05-11 07:32:02 +08:00
|
|
|
entry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
|
2019-07-26 08:15:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
req.issues.reserve(issueMap.size());
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& it : issueMap) {
|
2019-07-26 08:15:31 +08:00
|
|
|
req.issues.push_back(ItemWithExamples<Key>(it.first, it.second.count, it.second.examples));
|
|
|
|
}
|
|
|
|
req.supportedVersions.reserve(versionMap.size());
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& it : versionMap) {
|
|
|
|
req.supportedVersions.push_back(
|
|
|
|
ItemWithExamples<Standalone<ClientVersionRef>>(it.first, it.second.count, it.second.examples));
|
2019-07-26 08:15:31 +08:00
|
|
|
}
|
|
|
|
req.maxProtocolSupported.reserve(maxProtocolMap.size());
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& it : maxProtocolMap) {
|
2019-07-26 08:15:31 +08:00
|
|
|
req.maxProtocolSupported.push_back(ItemWithExamples<Key>(it.first, it.second.count, it.second.examples));
|
|
|
|
}
|
2019-08-14 06:54:40 +08:00
|
|
|
req.clientCount = clientCount;
|
2019-07-26 08:15:31 +08:00
|
|
|
|
2019-07-24 10:22:44 +08:00
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> getClientInfoFromLeader(Reference<AsyncVar<Optional<ClusterControllerClientInterface>>> knownLeader,
|
|
|
|
ClientData* clientData) {
|
|
|
|
while (!knownLeader->get().present()) {
|
|
|
|
wait(knownLeader->onChange());
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2019-07-26 08:15:31 +08:00
|
|
|
state double lastRequestTime = now();
|
|
|
|
state OpenDatabaseRequest req = clientData->getRequest();
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2019-07-24 10:22:44 +08:00
|
|
|
loop {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (now() - lastRequestTime > CLIENT_KNOBS->MAX_CLIENT_STATUS_AGE) {
|
2019-07-27 04:23:56 +08:00
|
|
|
lastRequestTime = now();
|
2019-07-26 08:15:31 +08:00
|
|
|
req = clientData->getRequest();
|
|
|
|
} else {
|
|
|
|
resetReply(req);
|
|
|
|
}
|
2019-09-12 06:19:42 +08:00
|
|
|
req.knownClientInfoID = clientData->clientInfo->get().read().id;
|
2019-07-24 10:22:44 +08:00
|
|
|
choose {
|
2021-03-11 02:06:03 +08:00
|
|
|
when(ClientDBInfo ni =
|
|
|
|
wait(brokenPromiseToNever(knownLeader->get().get().clientInterface.openDatabase.getReply(req)))) {
|
2021-09-17 05:22:44 +08:00
|
|
|
TraceEvent("GetClientInfoFromLeaderGotClientInfo", knownLeader->get().get().clientInterface.id())
|
2020-09-11 08:44:15 +08:00
|
|
|
.detail("CommitProxy0", ni.commitProxies.size() ? ni.commitProxies[0].id() : UID())
|
|
|
|
.detail("GrvProxy0", ni.grvProxies.size() ? ni.grvProxies[0].id() : UID())
|
2020-07-15 15:37:41 +08:00
|
|
|
.detail("ClientID", ni.id);
|
2019-09-12 06:19:42 +08:00
|
|
|
clientData->clientInfo->set(CachedSerialization<ClientDBInfo>(ni));
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
when(wait(knownLeader->onChange())) {}
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 05:22:44 +08:00
|
|
|
ACTOR Future<Void> monitorLeaderAndGetClientInfo(Key clusterKey,
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<NetworkAddress> coordinators,
|
2021-09-17 05:22:44 +08:00
|
|
|
ClientData* clientData,
|
|
|
|
Reference<AsyncVar<Optional<LeaderInfo>>> leaderInfo) {
|
2021-09-17 08:42:34 +08:00
|
|
|
state std::vector<ClientLeaderRegInterface> clientLeaderServers;
|
2019-07-24 10:22:44 +08:00
|
|
|
state AsyncTrigger nomineeChange;
|
|
|
|
state std::vector<Optional<LeaderInfo>> nominees;
|
|
|
|
state Future<Void> allActors;
|
2021-03-11 02:06:03 +08:00
|
|
|
state Reference<AsyncVar<Optional<ClusterControllerClientInterface>>> knownLeader(
|
|
|
|
new AsyncVar<Optional<ClusterControllerClientInterface>>{});
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto s = coordinators.begin(); s != coordinators.end(); ++s) {
|
|
|
|
clientLeaderServers.push_back(ClientLeaderRegInterface(*s));
|
2019-07-25 06:07:41 +08:00
|
|
|
}
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2019-07-25 06:07:41 +08:00
|
|
|
nominees.resize(clientLeaderServers.size());
|
|
|
|
|
|
|
|
std::vector<Future<Void>> actors;
|
|
|
|
// Ask all coordinators if the worker is considered as a leader (leader nominee) by the coordinator.
|
2021-03-04 11:36:21 +08:00
|
|
|
actors.reserve(clientLeaderServers.size());
|
|
|
|
for (int i = 0; i < clientLeaderServers.size(); i++) {
|
2021-03-11 02:06:03 +08:00
|
|
|
actors.push_back(monitorNominee(clusterKey, clientLeaderServers[i], &nomineeChange, &nominees[i]));
|
2019-07-25 06:07:41 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
actors.push_back(getClientInfoFromLeader(knownLeader, clientData));
|
2019-07-25 06:07:41 +08:00
|
|
|
allActors = waitForAll(actors);
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2019-07-25 06:07:41 +08:00
|
|
|
loop {
|
|
|
|
Optional<std::pair<LeaderInfo, bool>> leader = getLeader(nominees);
|
2021-09-17 05:22:44 +08:00
|
|
|
TraceEvent("MonitorLeaderAndGetClientInfoLeaderChange")
|
2021-03-11 02:06:03 +08:00
|
|
|
.detail("NewLeader", leader.present() ? leader.get().first.changeID : UID(1, 1))
|
|
|
|
.detail("Key", clusterKey.printable());
|
2019-07-25 06:07:41 +08:00
|
|
|
if (leader.present()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (leader.get().first.forward) {
|
2019-07-25 06:07:41 +08:00
|
|
|
ClientDBInfo outInfo;
|
|
|
|
outInfo.id = deterministicRandom()->randomUniqueID();
|
|
|
|
outInfo.forward = leader.get().first.serializedInfo;
|
2019-09-12 06:19:42 +08:00
|
|
|
clientData->clientInfo->set(CachedSerialization<ClientDBInfo>(outInfo));
|
2020-05-11 05:20:50 +08:00
|
|
|
leaderInfo->set(leader.get().first);
|
2021-09-17 05:22:44 +08:00
|
|
|
TraceEvent("MonitorLeaderAndGetClientInfoForwarding")
|
2021-03-11 02:06:03 +08:00
|
|
|
.detail("NewConnStr", leader.get().first.serializedInfo.toString());
|
2019-07-25 06:07:41 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leader.get().first.serializedInfo.size()) {
|
2020-02-13 02:41:52 +08:00
|
|
|
ObjectReader reader(leader.get().first.serializedInfo.begin(), IncludeVersion());
|
|
|
|
ClusterControllerClientInterface res;
|
|
|
|
reader.deserialize(res);
|
|
|
|
knownLeader->set(res);
|
2020-05-11 05:20:50 +08:00
|
|
|
leaderInfo->set(leader.get().first);
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(nomineeChange.onTrigger() || allActors);
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void shrinkProxyList(ClientDBInfo& ni,
|
|
|
|
std::vector<UID>& lastCommitProxyUIDs,
|
|
|
|
std::vector<CommitProxyInterface>& lastCommitProxies,
|
|
|
|
std::vector<UID>& lastGrvProxyUIDs,
|
2020-09-11 08:44:15 +08:00
|
|
|
std::vector<GrvProxyInterface>& lastGrvProxies) {
|
|
|
|
if (ni.commitProxies.size() > CLIENT_KNOBS->MAX_COMMIT_PROXY_CONNECTIONS) {
|
|
|
|
std::vector<UID> commitProxyUIDs;
|
|
|
|
for (auto& commitProxy : ni.commitProxies) {
|
|
|
|
commitProxyUIDs.push_back(commitProxy.id());
|
2020-01-11 04:20:30 +08:00
|
|
|
}
|
2020-09-11 08:44:15 +08:00
|
|
|
if (commitProxyUIDs != lastCommitProxyUIDs) {
|
|
|
|
lastCommitProxyUIDs.swap(commitProxyUIDs);
|
|
|
|
lastCommitProxies = ni.commitProxies;
|
|
|
|
deterministicRandom()->randomShuffle(lastCommitProxies);
|
|
|
|
lastCommitProxies.resize(CLIENT_KNOBS->MAX_COMMIT_PROXY_CONNECTIONS);
|
|
|
|
for (int i = 0; i < lastCommitProxies.size(); i++) {
|
|
|
|
TraceEvent("ConnectedCommitProxy").detail("CommitProxy", lastCommitProxies[i].id());
|
2020-01-11 04:20:30 +08:00
|
|
|
}
|
|
|
|
}
|
2020-09-11 08:44:15 +08:00
|
|
|
ni.firstCommitProxy = ni.commitProxies[0];
|
|
|
|
ni.commitProxies = lastCommitProxies;
|
2020-01-11 04:20:30 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
if (ni.grvProxies.size() > CLIENT_KNOBS->MAX_GRV_PROXY_CONNECTIONS) {
|
2020-07-15 15:37:41 +08:00
|
|
|
std::vector<UID> grvProxyUIDs;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& grvProxy : ni.grvProxies) {
|
2020-07-15 15:37:41 +08:00
|
|
|
grvProxyUIDs.push_back(grvProxy.id());
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
if (grvProxyUIDs != lastGrvProxyUIDs) {
|
2020-07-31 05:45:03 +08:00
|
|
|
lastGrvProxyUIDs.swap(grvProxyUIDs);
|
2020-07-15 15:37:41 +08:00
|
|
|
lastGrvProxies = ni.grvProxies;
|
|
|
|
deterministicRandom()->randomShuffle(lastGrvProxies);
|
|
|
|
lastGrvProxies.resize(CLIENT_KNOBS->MAX_GRV_PROXY_CONNECTIONS);
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < lastGrvProxies.size(); i++) {
|
2020-07-15 15:37:41 +08:00
|
|
|
TraceEvent("ConnectedGrvProxy").detail("GrvProxy", lastGrvProxies[i].id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ni.grvProxies = lastGrvProxies;
|
|
|
|
}
|
2020-01-11 04:20:30 +08:00
|
|
|
}
|
|
|
|
|
2020-09-11 08:44:15 +08:00
|
|
|
ACTOR Future<MonitorLeaderInfo> monitorProxiesOneGeneration(
|
2021-10-11 11:44:56 +08:00
|
|
|
Reference<IClusterConnectionRecord> connRecord,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<AsyncVar<ClientDBInfo>> clientInfo,
|
2021-04-16 02:45:14 +08:00
|
|
|
Reference<AsyncVar<Optional<ClientLeaderRegInterface>>> coordinator,
|
2021-03-11 02:06:03 +08:00
|
|
|
MonitorLeaderInfo info,
|
|
|
|
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions,
|
|
|
|
Key traceLogGroup) {
|
2021-10-11 11:44:56 +08:00
|
|
|
state ClusterConnectionString cs = info.intermediateConnRecord->getConnectionString();
|
2021-09-17 08:42:34 +08:00
|
|
|
state std::vector<NetworkAddress> addrs = cs.coordinators();
|
2022-01-21 04:19:58 +08:00
|
|
|
state int index = 0;
|
2021-09-17 05:22:44 +08:00
|
|
|
state int successIndex = 0;
|
2019-07-26 08:15:31 +08:00
|
|
|
state Optional<double> incorrectTime;
|
2020-09-11 08:44:15 +08:00
|
|
|
state std::vector<UID> lastCommitProxyUIDs;
|
|
|
|
state std::vector<CommitProxyInterface> lastCommitProxies;
|
2020-07-15 15:37:41 +08:00
|
|
|
state std::vector<UID> lastGrvProxyUIDs;
|
|
|
|
state std::vector<GrvProxyInterface> lastGrvProxies;
|
2019-07-31 08:15:24 +08:00
|
|
|
|
2019-07-24 10:22:44 +08:00
|
|
|
deterministicRandom()->randomShuffle(addrs);
|
2019-07-25 06:07:41 +08:00
|
|
|
loop {
|
2022-01-21 04:19:58 +08:00
|
|
|
state ClientLeaderRegInterface clientLeaderServer(addrs[index]);
|
2019-07-25 06:07:41 +08:00
|
|
|
state OpenDatabaseCoordRequest req;
|
2021-04-16 02:45:14 +08:00
|
|
|
|
|
|
|
coordinator->set(clientLeaderServer);
|
|
|
|
|
2019-07-27 04:23:56 +08:00
|
|
|
req.clusterKey = cs.clusterKey();
|
2019-07-26 08:15:31 +08:00
|
|
|
req.coordinators = cs.coordinators();
|
2019-07-25 06:07:41 +08:00
|
|
|
req.knownClientInfoID = clientInfo->get().id;
|
2020-02-29 01:35:21 +08:00
|
|
|
req.supportedVersions = supportedVersions->get();
|
2019-07-26 08:15:31 +08:00
|
|
|
req.traceLogGroup = traceLogGroup;
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
state ClusterConnectionString storedConnectionString;
|
|
|
|
if (connRecord) {
|
|
|
|
bool upToDate = wait(connRecord->upToDate(storedConnectionString));
|
|
|
|
if (!upToDate) {
|
|
|
|
req.issues.push_back_deep(req.issues.arena(), LiteralStringRef("incorrect_cluster_file_contents"));
|
|
|
|
std::string connectionString = connRecord->getConnectionString().toString();
|
|
|
|
if (!incorrectTime.present()) {
|
|
|
|
incorrectTime = now();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't log a SevWarnAlways initially to account for transient issues (e.g. someone else changing
|
|
|
|
// the file right before us)
|
2019-07-26 08:15:31 +08:00
|
|
|
TraceEvent(now() - incorrectTime.get() > 300 ? SevWarnAlways : SevWarn, "IncorrectClusterFileContents")
|
2021-10-11 11:44:56 +08:00
|
|
|
.detail("ClusterFile", connRecord->toString())
|
|
|
|
.detail("StoredConnectionString", storedConnectionString.toString())
|
2021-03-11 02:06:03 +08:00
|
|
|
.detail("CurrentConnectionString", connectionString);
|
2021-10-11 11:44:56 +08:00
|
|
|
} else {
|
|
|
|
incorrectTime = Optional<double>();
|
2019-07-26 08:15:31 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2019-07-26 08:15:31 +08:00
|
|
|
incorrectTime = Optional<double>();
|
|
|
|
}
|
2019-07-25 06:07:41 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
state ErrorOr<CachedSerialization<ClientDBInfo>> rep =
|
|
|
|
wait(clientLeaderServer.openDatabase.tryGetReply(req, TaskPriority::CoordinationReply));
|
2019-07-25 06:07:41 +08:00
|
|
|
if (rep.present()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (rep.get().read().forward.present()) {
|
|
|
|
TraceEvent("MonitorProxiesForwarding")
|
|
|
|
.detail("NewConnStr", rep.get().read().forward.get().toString())
|
2021-10-11 11:44:56 +08:00
|
|
|
.detail("OldConnStr", info.intermediateConnRecord->getConnectionString().toString());
|
|
|
|
info.intermediateConnRecord = connRecord->makeIntermediateRecord(
|
|
|
|
ClusterConnectionString(rep.get().read().forward.get().toString()));
|
2019-07-25 06:07:41 +08:00
|
|
|
return info;
|
|
|
|
}
|
2021-10-11 11:44:56 +08:00
|
|
|
if (connRecord != info.intermediateConnRecord) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!info.hasConnected) {
|
|
|
|
TraceEvent(SevWarnAlways, "IncorrectClusterFileContentsAtConnection")
|
2021-10-11 11:44:56 +08:00
|
|
|
.detail("ClusterFile", connRecord->toString())
|
|
|
|
.detail("StoredConnectionString", connRecord->getConnectionString().toString())
|
|
|
|
.detail("CurrentConnectionString",
|
|
|
|
info.intermediateConnRecord->getConnectionString().toString());
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
2022-01-28 09:43:56 +08:00
|
|
|
connRecord->setAndPersistConnectionString(info.intermediateConnRecord->getConnectionString());
|
2021-10-11 11:44:56 +08:00
|
|
|
info.intermediateConnRecord = connRecord;
|
2019-07-25 06:07:41 +08:00
|
|
|
}
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2019-07-25 06:07:41 +08:00
|
|
|
info.hasConnected = true;
|
2021-10-11 11:44:56 +08:00
|
|
|
connRecord->notifyConnected();
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2019-09-12 06:19:42 +08:00
|
|
|
auto& ni = rep.get().mutate();
|
2020-09-11 08:44:15 +08:00
|
|
|
shrinkProxyList(ni, lastCommitProxyUIDs, lastCommitProxies, lastGrvProxyUIDs, lastGrvProxies);
|
2021-03-11 02:06:03 +08:00
|
|
|
clientInfo->set(ni);
|
2022-01-21 04:19:58 +08:00
|
|
|
successIndex = index;
|
2020-05-11 05:20:50 +08:00
|
|
|
} else {
|
2021-08-28 08:17:19 +08:00
|
|
|
TEST(rep.getError().code() == error_code_failed_to_progress); // Coordinator cant talk to cluster controller
|
2022-01-21 04:19:58 +08:00
|
|
|
index = (index + 1) % addrs.size();
|
|
|
|
if (index == successIndex) {
|
2020-05-11 05:20:50 +08:00
|
|
|
wait(delay(CLIENT_KNOBS->COORDINATOR_RECONNECTION_DELAY));
|
|
|
|
}
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> monitorProxies(
|
2021-10-11 11:44:56 +08:00
|
|
|
Reference<AsyncVar<Reference<IClusterConnectionRecord>>> connRecord,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<AsyncVar<ClientDBInfo>> clientInfo,
|
2021-04-16 02:45:14 +08:00
|
|
|
Reference<AsyncVar<Optional<ClientLeaderRegInterface>>> coordinator,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions,
|
|
|
|
Key traceLogGroup) {
|
2021-10-11 11:44:56 +08:00
|
|
|
state MonitorLeaderInfo info(connRecord->get());
|
2019-07-24 10:22:44 +08:00
|
|
|
loop {
|
2019-07-27 06:05:02 +08:00
|
|
|
choose {
|
2021-03-11 02:06:03 +08:00
|
|
|
when(MonitorLeaderInfo _info = wait(monitorProxiesOneGeneration(
|
2021-10-11 11:44:56 +08:00
|
|
|
connRecord->get(), clientInfo, coordinator, info, supportedVersions, traceLogGroup))) {
|
2019-07-27 06:05:02 +08:00
|
|
|
info = _info;
|
|
|
|
}
|
2021-10-11 11:44:56 +08:00
|
|
|
when(wait(connRecord->onChange())) {
|
2019-07-27 06:05:02 +08:00
|
|
|
info.hasConnected = false;
|
2021-10-11 11:44:56 +08:00
|
|
|
info.intermediateConnRecord = connRecord->get();
|
2019-07-27 06:05:02 +08:00
|
|
|
}
|
|
|
|
}
|
2019-07-24 10:22:44 +08:00
|
|
|
}
|
|
|
|
}
|