Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fewer connections in the multi-version client (release-6.3) #4677

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
bbaefbc
The multi-version client monitors the cluster's protocol version and …
sfc-gh-abeamon Apr 16, 2021
9241202
Fix case where getting an error with a network option didn't properly…
sfc-gh-abeamon Apr 16, 2021
8f7a47f
Update release notes
sfc-gh-abeamon Apr 16, 2021
680cad2
Silence compiler warning
sfc-gh-abeamon Apr 16, 2021
add1557
Don't use DLDatabase objects before they are ready (applicable for AP…
sfc-gh-abeamon Apr 20, 2021
1713c23
For old incompatible connections, set the correct protocol version on…
sfc-gh-abeamon Apr 21, 2021
003b308
Fix comment typo
sfc-gh-abeamon Apr 21, 2021
c1b8789
Support 5.0 (and earlier) client versions by adding GRV probing for o…
sfc-gh-abeamon Apr 23, 2021
47c5b0c
Address review comments:
sfc-gh-abeamon Apr 26, 2021
a698c8b
Fix bug that could cause the server to crash when an old client conne…
sfc-gh-abeamon Apr 27, 2021
c9ccddc
Keep connections older than 6.2 open indefinitely to avoid weird bugs…
sfc-gh-abeamon Apr 27, 2021
000102d
Fix cherry-pick merge issues
sfc-gh-abeamon Apr 28, 2021
e32803f
Explicitly cancel thread futures for the protocol version monitors in…
sfc-gh-abeamon Apr 30, 2021
54d6176
Mark coordinator endpoints as not failed on the client if we can't de…
sfc-gh-abeamon Apr 30, 2021
beea466
Add cancellation of the protocol monitor when the database is destroy…
sfc-gh-abeamon Apr 30, 2021
4c6cae6
Be more defensive with cancellation by not capturing the this pointer…
sfc-gh-abeamon Apr 30, 2021
6c8a680
Fix: simulation doesn't have a protocol version monitor and can't can…
sfc-gh-abeamon Apr 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions bindings/c/fdb_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define FDB_INCLUDE_LEGACY_TYPES

#include "fdbclient/MultiVersionTransaction.h"
#include "fdbclient/MultiVersionAssignmentVars.h"
#include "foundationdb/fdb_c.h"

int g_api_version = 0;
Expand Down Expand Up @@ -322,6 +323,22 @@ extern "C" DLLEXPORT fdb_error_t fdb_database_create_transaction(FDBDatabase* d,
*out_transaction = (FDBTransaction*)tr.extractPtr(););
}

// Returns the protocol version reported by the coordinator this client is connected to
// If an expected version is non-zero, the future won't return until the protocol version is different than expected
// Note: this will never return if the server is running a protocol from FDB 5.0 or older
extern "C" DLLEXPORT FDBFuture* fdb_database_get_server_protocol(FDBDatabase* db, uint64_t expected_version) {
Optional<ProtocolVersion> expected;
if (expected_version > 0) {
expected = ProtocolVersion(expected_version);
}

return (
FDBFuture*)(mapThreadFuture<ProtocolVersion,
uint64_t>(DB(db)->getServerProtocol(expected), [](ErrorOr<ProtocolVersion> result) {
return result.map<uint64_t>([](ProtocolVersion pv) { return pv.versionWithFlags(); });
}).extractPtr());
}

extern "C" DLLEXPORT void fdb_transaction_destroy(FDBTransaction* tr) {
try {
TXN(tr)->delref();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
Release Notes
#############

6.3.13
======
* The multi-version client now requires at most two client connections with version 6.2 or larger, regardless of how many external clients are configured. Clients older than 6.2 will continue to create an additional connection each. `(PR #4667) <https://github.com/apple/foundationdb/pull/4667>`_

6.3.12
======
* Change the default for --knob_tls_server_handshake_threads to 64. The previous was 1000. This avoids starting 1000 threads by default, but may adversely affect recovery time for large clusters using tls. Users with large tls clusters should consider explicitly setting this knob in their foundationdb.conf file. `(PR #4421) <https://github.com/apple/foundationdb/pull/4421>`_
Expand Down
5 changes: 5 additions & 0 deletions fdbclient/CoordinationInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@

const int MAX_CLUSTER_FILE_BYTES = 60000;

// The coordinator interface as exposed to clients
struct ClientLeaderRegInterface {
RequestStream<struct GetLeaderRequest> getLeader;
RequestStream<struct OpenDatabaseCoordRequest> openDatabase;

ClientLeaderRegInterface() {}
ClientLeaderRegInterface(NetworkAddress remote);
ClientLeaderRegInterface(INetwork* local);

bool operator==(const ClientLeaderRegInterface& rhs) const {
return getLeader == rhs.getLeader && openDatabase == rhs.openDatabase;
}
};

class ClusterConnectionString {
Expand Down
12 changes: 12 additions & 0 deletions fdbclient/DatabaseContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAll
return (DatabaseContext*)DatabaseContext::operator new(sizeof(DatabaseContext));
}

// Static constructor used by server processes to create a DatabaseContext
// For internal (fdbserver) use only
static Database create(Reference<AsyncVar<ClientDBInfo>> clientInfo,
Future<Void> clientInfoMonitor,
Expand All @@ -129,9 +130,11 @@ class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAll

~DatabaseContext();

// Constructs a new copy of this DatabaseContext from the parameters of this DatabaseContext
Database clone() const {
return Database(new DatabaseContext(connectionFile,
clientInfo,
coordinator,
clientInfoMonitor,
taskID,
clientLocality,
Expand All @@ -158,6 +161,11 @@ class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAll
Future<Void> onMasterProxiesChanged();
Future<HealthMetrics> getHealthMetrics(bool detailed);

// Returns the protocol version reported by the coordinator this client is connected to
// If an expected version is given, the future won't return until the protocol version is different than expected
// Note: this will never return if the server is running a protocol from FDB 5.0 or older
Future<ProtocolVersion> getClusterProtocol(Optional<ProtocolVersion> expectedVersion = Optional<ProtocolVersion>());

// Update the watch counter for the database
void addWatch();
void removeWatch();
Expand Down Expand Up @@ -195,6 +203,7 @@ class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAll
// private:
explicit DatabaseContext(Reference<AsyncVar<Reference<ClusterConnectionFile>>> connectionFile,
Reference<AsyncVar<ClientDBInfo>> clientDBInfo,
Reference<AsyncVar<Optional<ClientLeaderRegInterface>>> coordinator,
Future<Void> clientInfoMonitor,
TaskPriority taskID,
LocalityData const& clientLocality,
Expand Down Expand Up @@ -324,6 +333,9 @@ class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAll
Future<Void> clientInfoMonitor;
Future<Void> connected;

// An AsyncVar that reports the coordinator this DatabaseContext is interacting with
Reference<AsyncVar<Optional<ClientLeaderRegInterface>>> coordinator;

Reference<AsyncVar<Optional<ClusterInterface>>> statusClusterInterface;
Future<Void> statusLeaderMon;
double lastStatusFetch;
Expand Down
6 changes: 6 additions & 0 deletions fdbclient/IClientApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class IDatabase {
virtual Reference<ITransaction> createTransaction() = 0;
virtual void setOption(FDBDatabaseOptions::Option option, Optional<StringRef> value = Optional<StringRef>()) = 0;

// Returns the protocol version reported by the coordinator this client is connected to
// If an expected version is given, the future won't return until the protocol version is different than expected
// Note: this will never return if the server is running a protocol from FDB 5.0 or older
virtual ThreadFuture<ProtocolVersion> getServerProtocol(
Optional<ProtocolVersion> expectedVersion = Optional<ProtocolVersion>()) = 0;

virtual void addref() = 0;
virtual void delref() = 0;
};
Expand Down
7 changes: 6 additions & 1 deletion fdbclient/MonitorLeader.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ void shrinkProxyList(ClientDBInfo& ni,
ACTOR Future<MonitorLeaderInfo> monitorProxiesOneGeneration(
Reference<ClusterConnectionFile> connFile,
Reference<AsyncVar<ClientDBInfo>> clientInfo,
Reference<AsyncVar<Optional<ClientLeaderRegInterface>>> coordinator,
MonitorLeaderInfo info,
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions,
Key traceLogGroup) {
Expand All @@ -755,6 +756,9 @@ ACTOR Future<MonitorLeaderInfo> monitorProxiesOneGeneration(
loop {
state ClientLeaderRegInterface clientLeaderServer(addrs[idx]);
state OpenDatabaseCoordRequest req;

coordinator->set(clientLeaderServer);

req.clusterKey = cs.clusterKey();
req.coordinators = cs.coordinators();
req.knownClientInfoID = clientInfo->get().id;
Expand Down Expand Up @@ -821,13 +825,14 @@ ACTOR Future<MonitorLeaderInfo> monitorProxiesOneGeneration(
ACTOR Future<Void> monitorProxies(
Reference<AsyncVar<Reference<ClusterConnectionFile>>> connFile,
Reference<AsyncVar<ClientDBInfo>> clientInfo,
Reference<AsyncVar<Optional<ClientLeaderRegInterface>>> coordinator,
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions,
Key traceLogGroup) {
state MonitorLeaderInfo info(connFile->get());
loop {
choose {
when(MonitorLeaderInfo _info = wait(monitorProxiesOneGeneration(
connFile->get(), clientInfo, info, supportedVersions, traceLogGroup))) {
connFile->get(), clientInfo, coordinator, info, supportedVersions, traceLogGroup))) {
info = _info;
}
when(wait(connFile->onChange())) {
Expand Down
1 change: 1 addition & 0 deletions fdbclient/MonitorLeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Future<Void> monitorLeaderForProxies(Value const& key,
Future<Void> monitorProxies(
Reference<AsyncVar<Reference<ClusterConnectionFile>>> const& connFile,
Reference<AsyncVar<ClientDBInfo>> const& clientInfo,
Reference<AsyncVar<Optional<ClientLeaderRegInterface>>> const& coordinator,
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> const& supportedVersions,
Key const& traceLogGroup);

Expand Down
Loading