diff --git a/src/Cassandra.IntegrationTests/Core/MetadataTests.cs b/src/Cassandra.IntegrationTests/Core/MetadataTests.cs index f611025c6..621d34d47 100644 --- a/src/Cassandra.IntegrationTests/Core/MetadataTests.cs +++ b/src/Cassandra.IntegrationTests/Core/MetadataTests.cs @@ -49,7 +49,7 @@ public void KeyspacesMetadataUpToDateViaCassandraEvents() Assert.Greater(initialLength, 0); //GetReplicas should yield the primary replica when the Keyspace is not found - Assert.AreEqual(1, cluster.GetReplicas("ks2", new byte[] { 0, 0, 0, 1 }).Count); + Assert.AreEqual(1, cluster.GetReplicas("ks2", null, new byte[] { 0, 0, 0, 1 }).Count); const string createKeyspaceQuery = "CREATE KEYSPACE {0} WITH replication = {{ 'class' : '{1}', {2} }}"; session.Execute(string.Format(createKeyspaceQuery, "ks1", "NetworkTopologyStrategy", "'replication_factor' : 1")); @@ -66,7 +66,7 @@ public void KeyspacesMetadataUpToDateViaCassandraEvents() Assert.NotNull(ks2); Assert.AreEqual(ks2.Replication["replication_factor"], 3); //GetReplicas should yield the 2 replicas (rf=3 but cluster=2) when the Keyspace is found - Assert.AreEqual(2, cluster.GetReplicas("ks2", new byte[] { 0, 0, 0, 1 }).Count); + Assert.AreEqual(2, cluster.GetReplicas("ks2", null, new byte[] { 0, 0, 0, 1 }).Count); var ks3 = cluster.Metadata.GetKeyspace("ks3"); Assert.NotNull(ks3); Assert.AreEqual(ks3.Replication["dc1"], 1); diff --git a/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeMetadataSyncTests.cs b/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeMetadataSyncTests.cs index cbe0f5602..22bf357a0 100644 --- a/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeMetadataSyncTests.cs +++ b/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeMetadataSyncTests.cs @@ -77,7 +77,7 @@ public void TokenMap_Should_NotUpdateExistingTokenMap_When_KeyspaceIsCreated() newSession.ChangeKeyspace(keyspaceName); Assert.IsNull(newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName)); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); Assert.IsTrue(object.ReferenceEquals(newCluster.Metadata.TokenToReplicasMap, oldTokenMap)); } } @@ -102,7 +102,7 @@ public void TokenMap_Should_NotUpdateExistingTokenMap_When_KeyspaceIsRemoved() TestUtils.WaitForSchemaAgreement(newCluster); var oldTokenMap = newCluster.Metadata.TokenToReplicasMap; Assert.IsNull(newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName)); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); Assert.IsTrue(object.ReferenceEquals(newCluster.Metadata.TokenToReplicasMap, oldTokenMap)); } } @@ -126,7 +126,7 @@ public void TokenMap_Should_NotUpdateExistingTokenMap_When_KeyspaceIsChanged() { var replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.IsNull(replicas); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); }); Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); @@ -139,7 +139,7 @@ public void TokenMap_Should_NotUpdateExistingTokenMap_When_KeyspaceIsChanged() { var replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.IsNull(replicas); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); }); Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); @@ -169,9 +169,9 @@ public async Task TokenMap_Should_RefreshTokenMapForSingleKeyspace_When_RefreshS var oldTokenMap = newCluster.Metadata.TokenToReplicasMap; var replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.IsNull(replicas); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); await newCluster.RefreshSchemaAsync(keyspaceName).ConfigureAwait(false); @@ -179,7 +179,7 @@ public async Task TokenMap_Should_RefreshTokenMapForSingleKeyspace_When_RefreshS replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.AreEqual(newCluster.Metadata.Hosts.Sum(h => h.Tokens.Count()), replicas.Count); - Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); Assert.IsTrue(object.ReferenceEquals(newCluster.Metadata.TokenToReplicasMap, oldTokenMap)); @@ -207,10 +207,10 @@ public async Task TokenMap_Should_RefreshTokenMapForAllKeyspaces_When_RefreshSch var newSession = newCluster.Connect(keyspaceName); var replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.IsNull(replicas); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); var oldTokenMap = newCluster.Metadata.TokenToReplicasMap; Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); - Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(1, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); await newCluster.RefreshSchemaAsync().ConfigureAwait(false); @@ -218,11 +218,11 @@ public async Task TokenMap_Should_RefreshTokenMapForAllKeyspaces_When_RefreshSch replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.AreEqual(newCluster.Metadata.Hosts.Sum(h => h.Tokens.Count()), replicas.Count); - Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName1); Assert.AreEqual(newCluster.Metadata.Hosts.Sum(h => h.Tokens.Count()), replicas.Count); - Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); Assert.IsFalse(object.ReferenceEquals(newCluster.Metadata.TokenToReplicasMap, oldTokenMap)); diff --git a/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeTests.cs b/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeTests.cs index 14f7018a4..fa12944bb 100644 --- a/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeTests.cs +++ b/src/Cassandra.IntegrationTests/MetadataTests/TokenMapSchemaChangeTests.cs @@ -96,7 +96,7 @@ public void TokenMap_Should_UpdateExistingTokenMap_When_KeyspaceIsChanged() { var replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.AreEqual(newCluster.Metadata.Hosts.Sum(h => h.Tokens.Count()), replicas.Count); - Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(3, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); }); Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); @@ -109,7 +109,7 @@ public void TokenMap_Should_UpdateExistingTokenMap_When_KeyspaceIsChanged() { var replicas = newCluster.Metadata.TokenToReplicasMap.GetByKeyspace(keyspaceName); Assert.AreEqual(newCluster.Metadata.Hosts.Sum(h => h.Tokens.Count()), replicas.Count); - Assert.AreEqual(2, newCluster.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")).Count); + Assert.AreEqual(2, newCluster.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")).Count); }); Assert.AreEqual(3, newCluster.Metadata.Hosts.Count(h => h.IsUp)); diff --git a/src/Cassandra.IntegrationTests/MetadataTests/TokenMapTopologyChangeTests.cs b/src/Cassandra.IntegrationTests/MetadataTests/TokenMapTopologyChangeTests.cs index 0b2fccb84..38fbf7393 100644 --- a/src/Cassandra.IntegrationTests/MetadataTests/TokenMapTopologyChangeTests.cs +++ b/src/Cassandra.IntegrationTests/MetadataTests/TokenMapTopologyChangeTests.cs @@ -78,8 +78,8 @@ public void TokenMap_Should_RebuildTokenMap_When_NodeIsDecommissioned() Assert.AreEqual(3, ClusterObjSync.Metadata.Hosts.Count); Assert.AreEqual(3, ClusterObjNotSync.Metadata.Hosts.Count); - replicasSync = ClusterObjSync.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")); - replicasNotSync = ClusterObjNotSync.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")); + replicasSync = ClusterObjSync.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")); + replicasNotSync = ClusterObjNotSync.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")); Assert.AreEqual(3, replicasSync.Count); Assert.AreEqual(1, replicasNotSync.Count); @@ -97,8 +97,8 @@ public void TokenMap_Should_RebuildTokenMap_When_NodeIsDecommissioned() Assert.AreEqual(2, ClusterObjSync.Metadata.Hosts.Count, "ClusterObjSync.Metadata.Hosts.Count"); Assert.AreEqual(2, ClusterObjNotSync.Metadata.Hosts.Count, "ClusterObjNotSync.Metadata.Hosts.Count"); - replicasSync = ClusterObjSync.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")); - replicasNotSync = ClusterObjNotSync.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")); + replicasSync = ClusterObjSync.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")); + replicasNotSync = ClusterObjNotSync.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")); Assert.AreEqual(2, replicasSync.Count, "replicasSync.Count"); Assert.AreEqual(1, replicasNotSync.Count, "replicasNotSync.Count"); @@ -116,8 +116,8 @@ public void TokenMap_Should_RebuildTokenMap_When_NodeIsDecommissioned() Assert.AreEqual(3, ClusterObjSync.Metadata.Hosts.Count); Assert.AreEqual(3, ClusterObjNotSync.Metadata.Hosts.Count); - replicasSync = ClusterObjSync.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")); - replicasNotSync = ClusterObjNotSync.Metadata.GetReplicas(keyspaceName, Encoding.UTF8.GetBytes("123")); + replicasSync = ClusterObjSync.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")); + replicasNotSync = ClusterObjNotSync.Metadata.GetReplicas(keyspaceName, null, Encoding.UTF8.GetBytes("123")); Assert.AreEqual(3, replicasSync.Count); Assert.AreEqual(1, replicasNotSync.Count); diff --git a/src/Cassandra.IntegrationTests/Policies/Tests/LoadBalancingPolicyShortTests.cs b/src/Cassandra.IntegrationTests/Policies/Tests/LoadBalancingPolicyShortTests.cs index 00f2f8943..143c55714 100644 --- a/src/Cassandra.IntegrationTests/Policies/Tests/LoadBalancingPolicyShortTests.cs +++ b/src/Cassandra.IntegrationTests/Policies/Tests/LoadBalancingPolicyShortTests.cs @@ -396,7 +396,7 @@ public void Token_Aware_Uses_Keyspace_From_Statement_To_Determine_Replication(bo // Manually calculate the routing key var routingKey = SerializerManager.Default.GetCurrentSerializer().Serialize(id); // Get the replicas - var replicas = cluster.GetReplicas(ks, routingKey); + var replicas = cluster.GetReplicas(ks, "tbl1", routingKey); Assert.AreEqual(metadataSync ? 2 : 1, replicas.Count); CollectionAssert.AreEquivalent(replicas.Select(h => h.Host.Address), coordinators); } diff --git a/src/Cassandra.IntegrationTests/ScyllaLwtTests.cs b/src/Cassandra.IntegrationTests/ScyllaLwtTests.cs index 807b12e39..f9470048c 100644 --- a/src/Cassandra.IntegrationTests/ScyllaLwtTests.cs +++ b/src/Cassandra.IntegrationTests/ScyllaLwtTests.cs @@ -71,7 +71,7 @@ private Host GetReplicaOwner() { var routingKey = new RoutingKey(); routingKey.RawRoutingKey = PkBytes; - var replicas = _cluster.GetReplicas("lwt_test", routingKey.RawRoutingKey); + var replicas = _cluster.GetReplicas("lwt_test", "foo", routingKey.RawRoutingKey); return replicas.First().Host; } diff --git a/src/Cassandra.Tests/PoliciesUnitTests.cs b/src/Cassandra.Tests/PoliciesUnitTests.cs index 378b164d9..4b1407cfc 100644 --- a/src/Cassandra.Tests/PoliciesUnitTests.cs +++ b/src/Cassandra.Tests/PoliciesUnitTests.cs @@ -489,8 +489,8 @@ public void TokenAwarePolicyReturnsLocalReplicasFirst() .Returns(hostList) .Verifiable(); clusterMock - .Setup(c => c.GetReplicas(It.IsAny(), It.IsAny())) - .Returns((keyspace, key) => + .Setup(c => c.GetReplicas(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns((keyspace, table, key) => { var i = key[0]; return hostList.Where(h => @@ -550,8 +550,8 @@ public void TokenAwarePolicyRoundRobinsOnLocalReplicas() .Returns(hostList) .Verifiable(); clusterMock - .Setup(c => c.GetReplicas(It.IsAny(), It.IsAny())) - .Returns((keyspace, key) => + .Setup(c => c.GetReplicas(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns((keyspace, table, key) => { var i = key[0]; return hostList.Where(h => diff --git a/src/Cassandra.Tests/StatementTests.cs b/src/Cassandra.Tests/StatementTests.cs index 5c1aa7639..f1a4aacff 100644 --- a/src/Cassandra.Tests/StatementTests.cs +++ b/src/Cassandra.Tests/StatementTests.cs @@ -332,7 +332,7 @@ public void BatchStatement_Should_UseRoutingKeyAndKeyspaceOfFirstStatement_When_ var rawRoutingKey = new byte[] { 1, 2, 3, 4 }; var lbp = new TokenAwarePolicy(new ClusterTests.FakeLoadBalancingPolicy()); var clusterMock = Mock.Of(); - Mock.Get(clusterMock).Setup(c => c.GetReplicas(It.IsAny(), It.IsAny())) + Mock.Get(clusterMock).Setup(c => c.GetReplicas(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List()); Mock.Get(clusterMock).Setup(c => c.AllHosts()) .Returns(new List()); @@ -345,7 +345,7 @@ public void BatchStatement_Should_UseRoutingKeyAndKeyspaceOfFirstStatement_When_ var _ = lbp.NewQueryPlan("ks2", batch).ToList(); - Mock.Get(clusterMock).Verify(c => c.GetReplicas("ks1", rawRoutingKey), Times.Once); + Mock.Get(clusterMock).Verify(c => c.GetReplicas("ks1", null, rawRoutingKey), Times.Once); } } } diff --git a/src/Cassandra/Cluster.cs b/src/Cassandra/Cluster.cs index 0b1517921..5f67c4692 100644 --- a/src/Cassandra/Cluster.cs +++ b/src/Cassandra/Cluster.cs @@ -490,15 +490,23 @@ public Host GetHost(IPEndPoint address) } /// + [Obsolete("Use GetReplicas(string keyspace, string table, byte[] partitionKey) for tablet-aware replica resolution.")] public ICollection GetReplicas(byte[] partitionKey) { - return Metadata.GetReplicas(partitionKey); + return Metadata.GetReplicas(null, null, partitionKey); } /// + [Obsolete("Use GetReplicas(string keyspace, string table, byte[] partitionKey) for tablet-aware replica resolution.")] public ICollection GetReplicas(string keyspace, byte[] partitionKey) { - return Metadata.GetReplicas(keyspace, partitionKey); + return Metadata.GetReplicas(keyspace, null, partitionKey); + } + + /// + public ICollection GetReplicas(string keyspace, string table, byte[] partitionKey) + { + return Metadata.GetReplicas(keyspace, table, partitionKey); } private void OnHostRemoved(Host h) diff --git a/src/Cassandra/ICluster.cs b/src/Cassandra/ICluster.cs index 872ffcb2a..80b0b1f84 100644 --- a/src/Cassandra/ICluster.cs +++ b/src/Cassandra/ICluster.cs @@ -31,9 +31,9 @@ namespace Cassandra /// Cassandra cluster would be: /// /// - /// Cluster cluster = Cluster.Builder().AddContactPoint("192.168.0.1").Build(); - /// Session session = cluster.Connect("db1"); - /// foreach (var row in session.Execute("SELECT * FROM table1")) + /// Cluster cluster = Cluster.Builder().AddContactPoint("192.168.0.1").Build(); + /// Session session = cluster.Connect("db1"); + /// foreach (var row in session.Execute("SELECT * FROM table1")) /// // do something ... /// /// @@ -46,7 +46,7 @@ namespace Cassandra public interface ICluster : IDisposable { /// - /// Gets read-only metadata on the connected cluster. + /// Gets read-only metadata on the connected cluster. /// This includes the /// know nodes (with their status as seen by the driver) as well as the schema /// definitions. @@ -108,20 +108,32 @@ public interface ICluster : IDisposable Host GetHost(IPEndPoint address); /// - /// Gets a collection of replicas for a given partitionKey. Backward-compatibility only, use GetReplicas(keyspace, partitionKey) instead. + /// Gets a collection of replicas for a given partitionKey. Backward-compatibility only. /// /// Byte array representing the partition key /// + [Obsolete("Use GetReplicas(string keyspace, string table, byte[] partitionKey) for tablet-aware replica resolution.")] ICollection GetReplicas(byte[] partitionKey); /// /// Gets a collection of replicas for a given partitionKey on a given keyspace /// - /// Byte array representing the partition key + /// The keyspace name /// Byte array representing the partition key /// + [Obsolete("Use GetReplicas(string keyspace, string table, byte[] partitionKey) for tablet-aware replica resolution.")] ICollection GetReplicas(string keyspace, byte[] partitionKey); + /// + /// Gets a collection of replicas for a given partition key on a given keyspace and table. + /// Tablet metadata is used when available, with token-map fallback otherwise. + /// + /// The keyspace name. + /// The table name. + /// Byte array representing the partition key. + /// A collection of replicas for the provided partition key. + ICollection GetReplicas(string keyspace, string table, byte[] partitionKey); + /// /// Shutdown this cluster instance. This closes all connections from all the /// sessions of this * Cluster instance and reclaim all resources diff --git a/src/Cassandra/Metadata.cs b/src/Cassandra/Metadata.cs index c0c3202d6..440825faa 100644 --- a/src/Cassandra/Metadata.cs +++ b/src/Cassandra/Metadata.cs @@ -274,21 +274,53 @@ internal async Task UpdateTokenMapForKeyspace(string name) } /// - /// Get the replicas for a given partition key and keyspace + /// Get the replicas for a given partition key, keyspace and table. /// - public ICollection GetReplicas(string keyspaceName, byte[] partitionKey) + /// The keyspace name. + /// The table name. + /// Byte array representing the partition key. + /// + /// A collection of replicas resolved using tablet metadata when available for the provided + /// keyspace and table, falling back to token-map resolution otherwise. + /// + public ICollection GetReplicas(string keyspaceName, string tableName, byte[] partitionKey) { if (_tokenMap == null) { Metadata.Logger.Warning("Metadata.GetReplicas was called but there was no token map."); return new HostShard[0]; } - return _tokenMap.GetReplicas(keyspaceName, _tokenMap.Factory.Hash(partitionKey)); + + var token = _tokenMap.Factory.Hash(partitionKey); + if (!string.IsNullOrEmpty(keyspaceName) && !string.IsNullOrEmpty(tableName)) + { + var tabletReplicas = TabletMap.GetReplicas(keyspaceName, tableName, token); + if (tabletReplicas != null && tabletReplicas.Count > 0) + { + if (tabletReplicas is ICollection collection) + { + return collection; + } + return tabletReplicas.ToList(); + } + } + + return _tokenMap.GetReplicas(keyspaceName, token); + } + + /// + /// Get the replicas for a given partition key and keyspace. + /// + [Obsolete("Use GetReplicas(string keyspaceName, string tableName, byte[] partitionKey) for tablet-aware replica resolution.")] + public ICollection GetReplicas(string keyspaceName, byte[] partitionKey) + { + return GetReplicas(keyspaceName, null, partitionKey); } + [Obsolete("Use GetReplicas(string keyspaceName, string tableName, byte[] partitionKey) for tablet-aware replica resolution.")] public ICollection GetReplicas(byte[] partitionKey) { - return GetReplicas(null, partitionKey); + return GetReplicas(null, null, partitionKey); } /// diff --git a/src/Cassandra/Policies/TokenAwarePolicy.cs b/src/Cassandra/Policies/TokenAwarePolicy.cs index 43c1dd848..8a4cda6d2 100644 --- a/src/Cassandra/Policies/TokenAwarePolicy.cs +++ b/src/Cassandra/Policies/TokenAwarePolicy.cs @@ -104,16 +104,7 @@ public IEnumerable NewQueryPlan(string loggedKeyspace, IStatement que var keyspace = query.Keyspace ?? loggedKeyspace; var table = query.TableName; - IEnumerable replicas = null; - if (table != null) - { - var token = _cluster.Metadata.GetTokenFactory().Hash(routingKey.RawRoutingKey); - replicas = _cluster.Metadata.TabletMap.GetReplicas(keyspace, table, token); - } - if (replicas == null || !replicas.Any()) - { - replicas = _cluster.GetReplicas(keyspace, routingKey.RawRoutingKey); - } + var replicas = _cluster.GetReplicas(keyspace, table, routingKey.RawRoutingKey) ?? new HostShard[0]; var localReplicaSet = new HashSet(); var localReplicaList = new List(replicas.Count());