Skip to content

Commit

Permalink
"scheme" -> "schema" cleanup; fix some log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKostousov committed Apr 14, 2020
1 parent 5d063bc commit c1a272a
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 66 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v2.3.x - 2020.04.14
- Separate `ICassandraSchemaActualizer` API from `ICassandraCluster` (PR [#10](https://github.com/skbkontur/cassandra-thrift-client/pull/10)).

Note that `ICassandraCluster.ActualizeKeyspaces()` method was removed. Use `CassandraSchemaActualizer` directly to modify thrift db schema.

## v2.2.19 - 2020.04.10
- Add ability to pass custom timeout to `SchemeActualizer` (PR [#9](https://github.com/skbkontur/cassandra-thrift-client/pull/9)).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using SkbKontur.Cassandra.ThriftClient.Connections;
using SkbKontur.Cassandra.ThriftClient.Exceptions;
using SkbKontur.Cassandra.ThriftClient.Helpers;
using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace Cassandra.ThriftClient.Tests.FunctionalTests.Tests
{
Expand All @@ -31,7 +31,7 @@ public virtual void SetUp()
cassandraSchemaActualizer = new CassandraSchemaActualizer(cassandraCluster, null, Logger.Instance);
cassandraSchemaActualizer.ActualizeKeyspaces(new[]
{
new KeyspaceScheme
new KeyspaceSchema
{
Name = KeyspaceName,
Configuration = new KeyspaceConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using SkbKontur.Cassandra.ThriftClient.Abstractions;
using SkbKontur.Cassandra.ThriftClient.Clusters;
using SkbKontur.Cassandra.ThriftClient.Clusters.ActualizationEventListener;
using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace Cassandra.ThriftClient.Tests.FunctionalTests.Tests.SchemaTests
{
Expand All @@ -32,7 +32,7 @@ public void TearDown()
[Test]
public void TestDoubleActualizeWithoutChangingSchema()
{
var scheme = new KeyspaceScheme
var scheme = new KeyspaceSchema
{
Name = TestSchemaUtils.GetRandomKeyspaceName(),
Configuration = new KeyspaceConfiguration
Expand All @@ -56,7 +56,7 @@ public void TestDoubleActualizeWithoutChangingSchema()
[Test]
public void TestUpdateColumnFamilyProperty()
{
var scheme = new KeyspaceScheme
var scheme = new KeyspaceSchema
{
Name = TestSchemaUtils.GetRandomKeyspaceName(),
Configuration = new KeyspaceConfiguration
Expand All @@ -79,7 +79,7 @@ public void TestUpdateColumnFamilyProperty()
[Test]
public void TestAddNewColumnFamily()
{
var scheme = new KeyspaceScheme
var scheme = new KeyspaceSchema
{
Name = TestSchemaUtils.GetRandomKeyspaceName(),
Configuration = new KeyspaceConfiguration
Expand All @@ -106,9 +106,9 @@ public void TestAddNewColumnFamily()
Assert.That(cassandraActualizerEventListener.ColumnFamilyAddedInvokeCount, Is.EqualTo(1));
}

private void ActualizeKeyspaces(KeyspaceScheme scheme)
private void ActualizeKeyspaces(KeyspaceSchema schema)
{
cassandraSchemaActualizer.ActualizeKeyspaces(new[] {scheme}, changeExistingKeyspaceMetadata : true);
cassandraSchemaActualizer.ActualizeKeyspaces(new[] {schema}, changeExistingKeyspaceMetadata : true);
}

private CassandraCluster cluster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using SkbKontur.Cassandra.ThriftClient.Abstractions;
using SkbKontur.Cassandra.ThriftClient.Clusters;
using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace Cassandra.ThriftClient.Tests.FunctionalTests.Tests.SchemaTests
{
Expand All @@ -26,16 +26,16 @@ public void TearDown()
cluster.Dispose();
}

private void ActualizeKeyspaces(KeyspaceScheme scheme)
private void ActualizeKeyspaces(KeyspaceSchema schema)
{
cassandraSchemaActualizer.ActualizeKeyspaces(new[] {scheme}, changeExistingKeyspaceMetadata : true);
cassandraSchemaActualizer.ActualizeKeyspaces(new[] {schema}, changeExistingKeyspaceMetadata : true);
}

[Test]
public void TestActualizeWithNullProperties()
{
var keyspaceName = TestSchemaUtils.GetRandomKeyspaceName();
var scheme = new KeyspaceScheme
var scheme = new KeyspaceSchema
{
Name = keyspaceName,
Configuration = new KeyspaceConfiguration
Expand Down Expand Up @@ -67,7 +67,7 @@ public void TestActualizeWithNullProperties()
[Test]
public void TestChangeCompactionProperties()
{
var scheme = new KeyspaceScheme
var scheme = new KeyspaceSchema
{
Name = TestSchemaUtils.GetRandomKeyspaceName(),
Configuration = new KeyspaceConfiguration
Expand Down Expand Up @@ -115,7 +115,7 @@ public void TestChangeCompactionProperties()
[Test]
public void TestChangeCompressionProperty()
{
var scheme = new KeyspaceScheme
var scheme = new KeyspaceSchema
{
Name = TestSchemaUtils.GetRandomKeyspaceName(),
Configuration = new KeyspaceConfiguration
Expand All @@ -139,7 +139,7 @@ public void TestChangeCompressionProperty()
[Test]
public void TestDoubleActualizeWithoutChangingSchema()
{
var scheme = new KeyspaceScheme
var scheme = new KeyspaceSchema
{
Name = TestSchemaUtils.GetRandomKeyspaceName(),
Configuration = new KeyspaceConfiguration
Expand Down Expand Up @@ -174,7 +174,7 @@ public void TestUpdateColumnFamilyCaching()
var keyspaceName = TestSchemaUtils.GetRandomKeyspaceName();
var keyspaceSchemes = new[]
{
new KeyspaceScheme
new KeyspaceSchema
{
Name = keyspaceName,
Configuration = new KeyspaceConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using SkbKontur.Cassandra.ThriftClient.Abstractions;
using SkbKontur.Cassandra.ThriftClient.Connections;
using SkbKontur.Cassandra.ThriftClient.Exceptions;
using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;
using SkbKontur.Cassandra.TimeBasedUuid;

namespace Cassandra.ThriftClient.Tests.FunctionalTests.Tests
Expand All @@ -20,7 +20,7 @@ public override void SetUp()
var cfName = Guid.NewGuid().ToString("N").Substring(10);
cassandraSchemaActualizer.ActualizeKeyspaces(new[]
{
new KeyspaceScheme
new KeyspaceSchema
{
Name = KeyspaceName,
Configuration = new KeyspaceConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

using SkbKontur.Cassandra.ThriftClient.Abstractions;
using SkbKontur.Cassandra.ThriftClient.Connections;
using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;
using SkbKontur.Cassandra.TimeBasedUuid;

namespace Cassandra.ThriftClient.Tests.FunctionalTests.Tests
Expand All @@ -23,7 +23,7 @@ public override void SetUp()
var cfName = Guid.NewGuid().ToString("N").Substring(10);
cassandraSchemaActualizer.ActualizeKeyspaces(new[]
{
new KeyspaceScheme
new KeyspaceSchema
{
Name = KeyspaceName,
Configuration = new KeyspaceConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using NUnit.Framework;

using SkbKontur.Cassandra.ThriftClient.Abstractions;
using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace Cassandra.ThriftClient.Tests.FunctionalTests.Tests
{
Expand All @@ -20,7 +20,7 @@ public void TestUpdateKeyspace(bool durableWrites)
var keyspaceName = Guid.NewGuid().ToString("N");
cassandraSchemaActualizer.ActualizeKeyspaces(new[]
{
new KeyspaceScheme
new KeyspaceSchema
{
Name = keyspaceName,
Configuration = new KeyspaceConfiguration
Expand Down Expand Up @@ -104,7 +104,7 @@ public void TestActualizeColumnFamily()
{
var keyspaceName = Guid.NewGuid().ToString("N");
const string columnFamilyName = "1";
var keyspaceScheme = new KeyspaceScheme
var keyspaceScheme = new KeyspaceSchema
{
Name = keyspaceName,
Configuration = new KeyspaceConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NUnit.Framework;

using SkbKontur.Cassandra.ThriftClient.Abstractions;
using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace Cassandra.ThriftClient.Tests.UnitTests.CoreTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Globalization;
using System.Linq;

using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace SkbKontur.Cassandra.ThriftClient.Abstractions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Apache.Cassandra;

using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace SkbKontur.Cassandra.ThriftClient.Abstractions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Globalization;

using SkbKontur.Cassandra.ThriftClient.Scheme;
using SkbKontur.Cassandra.ThriftClient.Schema;

namespace SkbKontur.Cassandra.ThriftClient.Abstractions
{
Expand Down
8 changes: 4 additions & 4 deletions Cassandra.ThriftClient/Connections/ClusterConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void AddKeyspace(Keyspace keyspace)
logger.Info("Keyspace adding result: {0}", addKeyspaceCommand.Output);
}

public void WaitUntilSchemeAgreementIsReached(TimeSpan timeout)
public void WaitUntilSchemaAgreementIsReached(TimeSpan timeout)
{
var sw = Stopwatch.StartNew();
do
Expand All @@ -64,15 +64,15 @@ public void WaitUntilSchemeAgreementIsReached(TimeSpan timeout)
return;
LogVersions(schemaAgreementCommand.Output);
} while (sw.Elapsed < timeout);
throw new InvalidOperationException($"WaitUntilSchemeAgreementIsReached didn't complete in {timeout}");
throw new InvalidOperationException($"WaitUntilSchemaAgreementIsReached didn't complete in {timeout}");
}

private void LogVersions(IDictionary<string, List<string>> versions)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Cassandra scheme is not synchronized:");
stringBuilder.AppendLine("Cassandra schema is not synchronized:");
foreach (var kvp in versions)
stringBuilder.AppendLine($"\tVerson: {kvp.Key}, Nodes: {string.Join(",", kvp.Value)}");
stringBuilder.AppendLine($"\tVersion: {kvp.Key}, Nodes: {string.Join(",", kvp.Value)}");
logger.Info(stringBuilder.ToString());
}

Expand Down
2 changes: 1 addition & 1 deletion Cassandra.ThriftClient/Connections/IClusterConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface IClusterConnection
void UpdateKeyspace(Keyspace keyspace);
void RemoveKeyspace(string keyspace);
string DescribeVersion();
void WaitUntilSchemeAgreementIsReached(TimeSpan timeout);
void WaitUntilSchemaAgreementIsReached(TimeSpan timeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using Vostok.Logging.Abstractions;

namespace SkbKontur.Cassandra.ThriftClient.Scheme
namespace SkbKontur.Cassandra.ThriftClient.Schema
{
public class CassandraSchemaActualizer : ICassandraSchemaActualizer
{
Expand All @@ -17,55 +17,54 @@ public CassandraSchemaActualizer(ICassandraCluster cassandraCluster, ICassandraA
this.cassandraCluster = cassandraCluster;
this.logger = logger;
this.eventListener = eventListener ?? EmptyCassandraActualizerEventListener.Instance;
columnFamilyComparer = new ColumnFamilyEqualityByPropertiesComparer();
}

public void ActualizeKeyspaces(KeyspaceScheme[] keyspaceShemas, bool changeExistingKeyspaceMetadata)
public void ActualizeKeyspaces(KeyspaceSchema[] keyspaceShemas, bool changeExistingKeyspaceMetadata)
{
if (keyspaceShemas == null || keyspaceShemas.Length == 0)
{
logger.Info("Found 0 keyspaces in scheme, skip applying scheme");
logger.Info("Nothing to actualize since keyspaceShemas is empty");
return;
}
logger.Info("Start apply scheme...");

logger.Info("Start schema actualization...");
eventListener.ActualizationStarted();
var clusterConnection = cassandraCluster.RetrieveClusterConnection();
clusterConnection.WaitUntilSchemeAgreementIsReached(TimeSpan.FromMinutes(1));
logger.Info("Found {0} keyspaces in scheme", keyspaceShemas.Length);
clusterConnection.WaitUntilSchemaAgreementIsReached(schemaAgreementWaitTimeout);
logger.Info("Found {0} keyspaces in schema", keyspaceShemas.Length);
var keyspaces = clusterConnection.RetrieveKeyspaces().ToDictionary(keyspace => keyspace.Name, StringComparer.OrdinalIgnoreCase);
eventListener.SchemaRetrieved(keyspaces.Values.ToArray());
logger.Info("Found {0} keyspaces in database", keyspaces.Count);
foreach (var keyspaceScheme in keyspaceShemas)
foreach (var keyspaceSchema in keyspaceShemas)
{
logger.Info("Start actualize scheme for keyspace {0}", keyspaceScheme.Name);
eventListener.KeyspaceActualizationStarted(keyspaceScheme.Name);
logger.Info("Start schema actualization for keyspace: {0}", keyspaceSchema.Name);
eventListener.KeyspaceActualizationStarted(keyspaceSchema.Name);
var keyspace = new Keyspace
{
Name = keyspaceScheme.Name,
DurableWrites = keyspaceScheme.Configuration.DurableWrites,
ReplicationStrategy = keyspaceScheme.Configuration.ReplicationStrategy,
Name = keyspaceSchema.Name,
DurableWrites = keyspaceSchema.Configuration.DurableWrites,
ReplicationStrategy = keyspaceSchema.Configuration.ReplicationStrategy,
};
if (keyspaces.ContainsKey(keyspaceScheme.Name))
if (keyspaces.ContainsKey(keyspaceSchema.Name))
{
if (changeExistingKeyspaceMetadata)
{
logger.Info("Keyspace {0} already exists in the database, so run update keyspace command", keyspaceScheme.Name);
logger.Info("Keyspace {0} already exists in the database, so run update keyspace command", keyspaceSchema.Name);
clusterConnection.UpdateKeyspace(keyspace);
}
else
logger.Info("Keyspace {0} already exists in the database, changeExistingKeyspaceMetadata is set to False, so do not run update keyspace command", keyspaceScheme.Name);
ActualizeColumnFamilies(keyspaceScheme.Name, keyspaceScheme.Configuration.ColumnFamilies);
logger.Info("Keyspace {0} already exists in the database, changeExistingKeyspaceMetadata is set to False, so do not run update keyspace command", keyspaceSchema.Name);
ActualizeColumnFamilies(keyspaceSchema.Name, keyspaceSchema.Configuration.ColumnFamilies);
}
else
{
logger.Info("Keyspace {0} is new, so run add keyspace command", keyspaceScheme.Name);
keyspace.ColumnFamilies = keyspaceScheme.Configuration.ColumnFamilies.ToDictionary(family => family.Name);
logger.Info("Keyspace {0} is new, so run add keyspace command", keyspaceSchema.Name);
keyspace.ColumnFamilies = keyspaceSchema.Configuration.ColumnFamilies.ToDictionary(family => family.Name);
clusterConnection.AddKeyspace(keyspace);
eventListener.KeyspaceAdded(keyspace);
}
}
clusterConnection.WaitUntilSchemeAgreementIsReached(TimeSpan.FromMinutes(1));
clusterConnection.WaitUntilSchemaAgreementIsReached(schemaAgreementWaitTimeout);
eventListener.ActualizationCompleted();
}

Expand Down Expand Up @@ -100,7 +99,8 @@ private void ActualizeColumnFamilies(string keyspaceName, ColumnFamily[] columnF

private readonly ICassandraCluster cassandraCluster;
private readonly ILog logger;
private readonly ColumnFamilyEqualityByPropertiesComparer columnFamilyComparer;
private readonly ICassandraActualizerEventListener eventListener;
private readonly ColumnFamilyEqualityByPropertiesComparer columnFamilyComparer = new ColumnFamilyEqualityByPropertiesComparer();
private readonly TimeSpan schemaAgreementWaitTimeout = TimeSpan.FromMinutes(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using SkbKontur.Cassandra.ThriftClient.Abstractions;

namespace SkbKontur.Cassandra.ThriftClient.Scheme
namespace SkbKontur.Cassandra.ThriftClient.Schema
{
internal class ColumnFamilyEqualityByPropertiesComparer
{
Expand Down
7 changes: 7 additions & 0 deletions Cassandra.ThriftClient/Schema/ICassandraSchemaActualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SkbKontur.Cassandra.ThriftClient.Schema
{
public interface ICassandraSchemaActualizer
{
void ActualizeKeyspaces(KeyspaceSchema[] keyspaceShemas, bool changeExistingKeyspaceMetadata);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SkbKontur.Cassandra.ThriftClient.Abstractions;

namespace SkbKontur.Cassandra.ThriftClient.Scheme
namespace SkbKontur.Cassandra.ThriftClient.Schema
{
public class KeyspaceConfiguration
{
Expand Down
Loading

0 comments on commit c1a272a

Please sign in to comment.