This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Should_ReturnEqualsTrueAndSameHashCode_When_BothStrategiesHaveSameReplicationSettings() | |
{ | |
var target1 = new NetworkTopologyStrategy( | |
new Dictionary<string, int> | |
{ | |
{ "dc1", 2 }, | |
{ "dc2", 3 }, | |
{ "dc3", 1 } | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Build_Should_OnlyCallOncePerReplicationConfiguration_When_MultipleKeyspacesWithSameReplicationOptions() | |
{ | |
var hosts = new List<Host> | |
{ | |
{ TestHelper.CreateHost("192.168.0.0", "dc1", "rack", new HashSet<string>{"0"})}, | |
{ TestHelper.CreateHost("192.168.0.1", "dc1", "rack", new HashSet<string>{"10"})}, | |
{ TestHelper.CreateHost("192.168.0.2", "dc1", "rack", new HashSet<string>{"20"})}, | |
{ TestHelper.CreateHost("192.168.0.3", "dc2", "rack", new HashSet<string>{"30"})}, | |
{ TestHelper.CreateHost("192.168.0.4", "dc2", "rack", new HashSet<string>{"40"})} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class DatacenterReplicationFactorComparer : IComparer<DatacenterReplicationFactor> | |
{ | |
private DatacenterReplicationFactorComparer() { } | |
public static DatacenterReplicationFactorComparer Instance { get; } = new DatacenterReplicationFactorComparer(); | |
public int Compare(DatacenterReplicationFactor x, DatacenterReplicationFactor y) | |
{ | |
return string.Compare(x.Datacenter, y.Datacenter, StringComparison.Ordinal); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool SetEquals(IEnumerable<T> other) | |
{ | |
SortedSet<T> asSorted = other as SortedSet<T>; | |
if (asSorted != null && AreComparersEqual(this, asSorted)) | |
{ | |
IEnumerator<T> mine = this.GetEnumerator(); | |
IEnumerator<T> theirs = asSorted.GetEnumerator(); | |
bool mineEnded = !mine.MoveNext(); | |
bool theirsEnded = !theirs.MoveNext(); | |
while (!mineEnded && !theirsEnded) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class NetworkTopologyStrategy : IReplicationStrategy, IEquatable<NetworkTopologyStrategy> | |
{ | |
private readonly SortedSet<DatacenterReplicationFactor> _replicationFactorsSet; | |
private readonly IReadOnlyDictionary<string, int> _replicationFactorsMap; | |
private readonly int _hashCode; | |
public NetworkTopologyStrategy(IReadOnlyDictionary<string, int> replicationFactors) | |
{ | |
_replicationFactorsSet = new SortedSet<DatacenterReplicationFactor>( | |
replicationFactors.Select(rf => new DatacenterReplicationFactor(rf.Key, rf.Value)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Insert(TKey key, TValue value, bool add) | |
{ | |
// these 3 variables are fields of the Dictionary | |
// int[] buckets; | |
// Entry[] entries; | |
// IEqualityComparer<TKey> comparer; | |
int hashCode = comparer.GetHashCode(key) & 0x7FFFFFFF; | |
int targetBucket = hashCode % buckets.Length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool TryAddInternal(TKey key, TValue value, bool updateIfExists, bool acquireLock, out TValue resultingValue) | |
{ | |
IEqualityComparer<TKey> comparer = m_tables.m_comparer; | |
var hashcode = comparer.GetHashCode(key); | |
var bucketCount = m_tables.m_buckets.Length; | |
var bucketNo = (hashcode & 0x7fffffff) % bucketCount; | |
// removed locking logic for simplicity | |
for (Node node = tables.m_buckets[bucketNo]; node != null; node = node.m_next) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void InitializeFromCollection(IEnumerable<KeyValuePair<TKey, TValue>> collection) | |
{ | |
TValue dummy; | |
foreach (KeyValuePair<TKey, TValue> pair in collection) | |
{ | |
if (pair.Key == null) throw new ArgumentNullException("key"); | |
if (!TryAddInternal(pair.Key, pair.Value, false, false, out dummy)) | |
{ | |
throw new ArgumentException(GetResource("ConcurrentDictionary_SourceContainsDuplicateKeys")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal async Task RebuildTokenMapAsync() | |
{ | |
keyspacesList = await _schemaParser.GetKeyspacesAsync().ConfigureAwait(false); | |
_tokenMap = TokenMap.Build(keyspacesList); | |
} | |
public static TokenMap Build(ICollection<KeyspaceMetadata> keyspaces) | |
{ | |
var primaryReplicas = new Dictionary<IToken, Host>(); | |
var sortedTokens = new SortedSet<IToken>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ISession session; | |
try | |
{ | |
session = cluster.Connect(); | |
} | |
catch (NoHostAvailableException ex) | |
{ | |
var innerExceptions = ex.Errors.Select( | |
kvp => $"Host: {kvp.Key}; Message: {kvp.Value.Message}; StackTrace: {kvp.Value.StackTrace}"); | |
log.Error($"{ex.Message};{innerExceptions}"); |
NewerOlder