Skip to content

Commit 763c860

Browse files
committed
Fixes after review
1 parent 0faded9 commit 763c860

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Storages/IStorageCluster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void ReadFromCluster::createExtension(const ActionsDAG::Node * predicate)
7171
std::vector<std::string> ids_of_hosts;
7272
for (const auto & shard : cluster->getShardsInfo())
7373
{
74-
if (shard.per_replica_pools.size() < 1)
74+
if (shard.per_replica_pools.empty())
7575
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cluster {} with empty shard {}", cluster->getName(), shard.shard_num);
7676
if (!shard.per_replica_pools[0])
7777
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cluster {}, shard {} with empty node", cluster->getName(), shard.shard_num);

src/Storages/ObjectStorage/StorageObjectStorageStableTaskDistributor.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ std::optional<String> StorageObjectStorageStableTaskDistributor::getNextTask(siz
3939
size_t StorageObjectStorageStableTaskDistributor::getReplicaForFile(const String & file_path)
4040
{
4141
if (!ids_of_nodes.has_value())
42-
return 0;
42+
throw Exception(ErrorCodes::LOGICAL_ERROR, "No list of nodes inside Task Distributer.");
43+
44+
const auto & ids_of_nodes_value = ids_of_nodes.value();
45+
size_t nodes_count = ids_of_nodes_value.size();
4346

4447
/// Trivial case
45-
if (ids_of_nodes.value().size() < 2)
48+
if (nodes_count < 2)
4649
return 0;
4750

4851
/// Rendezvous hashing
4952
size_t best_id = 0;
50-
UInt64 best_weight = sipHash64(ids_of_nodes.value()[0] + file_path);
51-
for (size_t id = ids_of_nodes.value().size() - 1; id > 0; --id)
53+
UInt64 best_weight = sipHash64(ids_of_nodes_value[0] + file_path);
54+
for (size_t id = 1; id < nodes_count; ++id)
5255
{
53-
UInt64 weight = sipHash64(ids_of_nodes.value()[id] + file_path);
56+
UInt64 weight = sipHash64(ids_of_nodes_value[id] + file_path);
5457
if (weight > best_weight)
5558
{
5659
best_weight = weight;

0 commit comments

Comments
 (0)