/// <summary> /// Waits until that the schema version in all nodes is the same or the waiting time passed. /// This method blocks the calling thread. /// </summary> internal bool WaitForSchemaAgreement(IConnection connection) { if (Hosts.Count == 1) { //If there is just one node, the schema is up to date in all nodes :) return(true); } var start = DateTime.Now; var waitSeconds = Configuration.ProtocolOptions.MaxSchemaAgreementWaitSeconds; Metadata.Logger.Info("Waiting for schema agreement"); try { var totalVersions = 0; while (DateTime.Now.Subtract(start).TotalSeconds < waitSeconds) { var serializer = ControlConnection.Serializer.GetCurrentSerializer(); var schemaVersionLocalQuery = new QueryRequest( serializer, Metadata.SelectSchemaVersionLocal, QueryProtocolOptions.Default, false, null); var schemaVersionPeersQuery = new QueryRequest( serializer, Metadata.SelectSchemaVersionPeers, QueryProtocolOptions.Default, false, null); var queries = new[] { connection.Send(schemaVersionLocalQuery), connection.Send(schemaVersionPeersQuery) }; // ReSharper disable once CoVariantArrayConversion Task.WaitAll(queries, Configuration.DefaultRequestOptions.QueryAbortTimeout); if (Metadata.CheckSchemaVersionResults( Configuration.MetadataRequestHandler.GetRowSet(queries[0].Result), Configuration.MetadataRequestHandler.GetRowSet(queries[1].Result))) { return(true); } Thread.Sleep(500); } Metadata.Logger.Info($"Waited for schema agreement, still {totalVersions} schema versions in the cluster."); } catch (Exception ex) { //Exceptions are not fatal Metadata.Logger.Error("There was an exception while trying to retrieve schema versions", ex); } return(false); }