Repository navigation
Use fewer connections in the multi-version client - #4667
sfc-gh-anoyes merged 11 commits into
Conversation
…only activates the client library that can connect.
AWS CodeBuild CI Report
|
… where getting an error with a network option didn't properly terminate the database connection. Reduce option lock critical section.
AWS CodeBuild CI Report
|
|
Really appreciate the comments!! |
|
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.
|
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. |
… the version async var
…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; |
There was a problem hiding this comment.
Mention that this map is keyed by normalized protocol version
| // 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) {} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))) {} |
There was a problem hiding this comment.
| 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); |
There was a problem hiding this comment.
does this have an effect?
There was a problem hiding this comment.
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
… around quickly closing the database.
sfc-gh-anoyes
left a comment
There was a problem hiding this comment.
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.
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:
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.