Skip to content

Use fewer connections in the multi-version client - #4667

Merged
sfc-gh-anoyes merged 11 commits into
apple:masterfrom
sfc-gh-abeamon:feature-mvc-monitor-protocol-version
Apr 28, 2021
Merged

sfc-gh-anoyes merged 11 commits into
apple:masterfrom
sfc-gh-abeamon:feature-mvc-monitor-protocol-version

Conversation

@sfc-gh-abeamon

@sfc-gh-abeamon sfc-gh-abeamon commented Apr 15, 2021 •

Copy link
Copy Markdown
Contributor

This updates the multi-version client to monitor the protocol version of the cluster and use only the appropriately-versioned client to connect. For clusters older than 7.0, it will also be necessary to monitor the cluster version from the primary client.

As a result, this should eliminate the impact of incompatible clients on the cluster.

The following real-world tests were performed to verify that the client functioned and that we had the expected number of connections:

  • 5.0 external, cluster at 5.0
  • 5.1 and 6.3 external, cluster at 5.1
  • 6.1, 6.2, and 6.3 external; cluster at 6.2
  • 6.2 and 6.3 external; cluster at 6.3
  • 6.2 and 6.3 external; cluster at 6.3 (local client disabled)
  • 6.2, 6.3, and 7.0 external; cluster at 7.0
  • 6.2, 6.3, and 7.0 external; cluster at 7.0 (local client disabled)
  • 5.0 and 5.1 external, cluster upgraded from 5.0 to 5.1
  • 5.1, 5.2, and 6.3 external; cluster upgraded from 5.1 to 5.2
  • 5.1 and 6.3 external; cluster upgraded from 5.1 to 6.3
  • 6.2 and 6.3 external; cluster upgraded from 6.2 to 6.3
  • 6.2 and 6.3 external; cluster upgraded from 6.2 to 7.0
  • 6.2 and 6.3 external, cluster upgraded from 6.3 to 7.0
  • 6.2, 6.3, and 7.0 external, cluster upgraded from 6.3 to 7.0 (local client disabled)
  • 6.3 external, cluster upgraded from 6.2 to 6.3 (no connection before upgrade)
  • 6.2 external, cluster upgraded from 6.2 to 6.3 (no connection after upgrade)
  • 6.2 external, cluster upgraded from 6.2 to 6.3 to 7.0 (no connection in the middle)
  • 6.2 and 7.0 external, cluster upgraded from 6.2 to 6.3 to 7.0 (local client disabled, no connection in the middle)
  • 5.0 and 6.2 external, cluster "downgraded" from 6.2 to 5.0
  • 5.1 and 6.2 external, cluster "downgraded" from 6.2 to 5.1
  • 5.0 external, cluster "downgraded" from 7.0 to 5.0
  • 5.1 external, cluster "downgraded" from 7.0 to 5.1
  • 6.3 external, cluster "downgraded" from 7.0 to 6.3

Note that the downgrade from 7.0 to 5.1 has spotty success (it sometimes works and sometimes doesn't), but best I can tell this is a behavior of the 5.1 client and not specifically a problem of the new implementation. Possibly aspects of the new client make the behavior in 5.1 more likely to trigger.

Code-Reviewer Section

The general guidelines can be found here.

Please check each of the following things and check all boxes before accepting a PR.

  • The PR has a description, explaining both the problem and the solution.
  • The description mentions which forms of testing were done and the testing seems reasonable.
  • Every function/class/actor that was touched is reasonably well documented.

…only activates the client library that can connect.
@foundationdb-ci

Copy link
Copy Markdown
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: foundationdb-pull-request-build
  • Commit ID: b2d6930
  • Result: FAILED
  • Build Logs (available for 7 days)

… where getting an error with a network option didn't properly terminate the database connection. Reduce option lock critical section.
@foundationdb-ci

Copy link
Copy Markdown
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: foundationdb-pull-request-build
  • Commit ID: 486260e
  • Result: FAILED
  • Build Logs (available for 7 days)

Comment thread fdbclient/NativeAPI.actor.cpp Resolved
@dongxinEric

Copy link
Copy Markdown
Contributor

Really appreciate the comments!!

@sfc-gh-abeamon
sfc-gh-abeamon marked this pull request as ready for review April 16, 2021 22:16
@sfc-gh-abeamon

Copy link
Copy Markdown
Contributor Author

Marking as draft until I resolve an issue I recently discovered.

…I versions < 610). Fix reference counting of DLDatabase objects to avoid leaking the underlying database handle. Update release notes to note that clients older than 6.2 still create extra connections.
@sfc-gh-abeamon
sfc-gh-abeamon marked this pull request as ready for review April 20, 2021 23:24
@sfc-gh-abeamon

Copy link
Copy Markdown
Contributor Author

I fixed an issue when using older API versions that could result in crashes. I've updated the tested scenarios to include some older FDB versions as well.

…ld versions. Update the C bindings implementation of get_server_protocol to convert the ProtocolVersion object into a uint64_t. Rename a misleading protocol version alias.
ThreadFuture<Void> protocolVersionMonitor;
std::list<LegacyVersionMonitor> legacyVersionMonitors;
Optional<ProtocolVersion> dbProtocolVersion;
std::map<ProtocolVersion, Reference<ClientInfo>> clients;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that this map is keyed by normalized protocol version

Comment thread fdbclient/MultiVersionTransaction.h Outdated
// A struct that enables monitoring whether the cluster is running an old version (<= 5.0) that doesn't support
// connect packet monitoring.
struct LegacyVersionMonitor {
LegacyVersionMonitor(Reference<ClientInfo> client) : client(client), monitorRunning(false) {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: pass by const reference

// Returns the protocol version reported by a quorum of coordinators
// 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
ThreadFuture<ProtocolVersion> MultiVersionDatabase::getServerProtocol(Optional<ProtocolVersion> expectedVersion) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this future become ready if the server is older than 6.2? Is that documented anywhere? I think we're technically exposing this through the c api so maybe the documentation could go there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but not if it's older than 5.1. I can add a note about that.


MultiVersionDatabase::DatabaseState::DatabaseState(std::string clusterFilePath, Reference<IDatabase> versionMonitorDb)
: clusterFilePath(clusterFilePath), versionMonitorDb(versionMonitorDb),
dbVar(new ThreadSafeAsyncVar<Reference<IDatabase>>(Reference<IDatabase>(NULL))) {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dbVar(new ThreadSafeAsyncVar<Reference<IDatabase>>(Reference<IDatabase>(NULL))) {}
dbVar(new ThreadSafeAsyncVar<Reference<IDatabase>>(Reference<IDatabase>(nullptr))) {}

Reference<ClientInfo> keptClient = itr->second;
Reference<ClientInfo> discardedClient = client;
if (client->canReplace(itr->second)) {
std::swap(keptClient, discardedClient);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this have an effect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My memory of writing this is a bit hazy, but it looks like what this is saying is that if you add a new client with the same protocol as one we've already added, then it will by default keep the one you've already added. However, if the new one is in some way preferable (as determined by canReplace), then it will use the new one instead.

Use nullptr instead of NULL
Use const& for a parameter
Add some comments

@sfc-gh-anoyes sfc-gh-anoyes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. As one final assurance I built this PR using TSAN, and a TSAN enabled 6.3 libfdb_c to use as an external client. TSAN didn't complain.

@sfc-gh-anoyes
sfc-gh-anoyes merged commit 904a39e into apple:master Apr 28, 2021
@sfc-gh-abeamon
sfc-gh-abeamon deleted the feature-mvc-monitor-protocol-version branch June 3, 2021 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants