Watch the cluster protocol version for changes and update the database state when it does. Must be called from the main thread
| 1891 | // Watch the cluster protocol version for changes and update the database state when it does. |
| 1892 | // Must be called from the main thread |
| 1893 | ThreadFuture<Void> MultiVersionDatabase::DatabaseState::monitorProtocolVersion() { |
| 1894 | startLegacyVersionMonitors(); |
| 1895 | |
| 1896 | Optional<ProtocolVersion> expected = dbProtocolVersion; |
| 1897 | ThreadFuture<ProtocolVersion> f = versionMonitorDb->getServerProtocol(dbProtocolVersion); |
| 1898 | |
| 1899 | Reference<DatabaseState> self = Reference<DatabaseState>::addRef(this); |
| 1900 | return mapThreadFuture<ProtocolVersion, Void>(f, [self, expected](ErrorOr<ProtocolVersion> cv) { |
| 1901 | if (cv.isError()) { |
| 1902 | if (cv.getError().code() == error_code_operation_cancelled) { |
| 1903 | return ErrorOr<Void>(cv.getError()); |
| 1904 | } |
| 1905 | |
| 1906 | TraceEvent("ErrorGettingClusterProtocolVersion") |
| 1907 | .error(cv.getError()) |
| 1908 | .detail("ExpectedProtocolVersion", expected); |
| 1909 | } |
| 1910 | |
| 1911 | ProtocolVersion clusterVersion = |
| 1912 | !cv.isError() ? cv.get() : self->dbProtocolVersion.orDefault(currentProtocolVersion()); |
| 1913 | onMainThreadVoid([self, clusterVersion]() { self->protocolVersionChanged(clusterVersion); }); |
| 1914 | return ErrorOr<Void>(Void()); |
| 1915 | }); |
| 1916 | } |
| 1917 | |
| 1918 | // Called when a change to the protocol version of the cluster has been detected. |
| 1919 | // Must be called from the main thread |
no test coverage detected