Skip to content

Commit

Permalink
refactor: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BorysTheDev committed Feb 23, 2024
1 parent df4223b commit 7eb4b64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/server/cluster/cluster_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ TEST_F(ClusterConfigTest, ConfigSetMultipleInstances) {
.replicas = {{.id = "other-replica3", .ip = "192.168.0.105", .port = 7005}}}});
EXPECT_NE(config, nullptr);
SlotSet owned_slots = config->GetOwnedSlots();
EXPECT_EQ(owned_slots.ToSlotRanges().size(), 1);
EXPECT_EQ(owned_slots.Count(), 5'000);

{
Expand Down
16 changes: 6 additions & 10 deletions src/server/cluster/slot_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SlotSet {
return slots_->all();
}

// Get SlotSet that are absent in the slots
SlotSet GetRemovedSlots(SlotSet slots) {
slots.slots_->flip();
*slots.slots_ &= *slots_;
Expand All @@ -73,23 +74,18 @@ class SlotSet {

SlotRanges ToSlotRanges() const {
SlotRanges res;
bool current_val = false;

for (SlotId i = 0; i <= kMaxSlot; ++i) {
if (slots_->test(i) == current_val) {
for (SlotId i = 0; i < kSlotsNumber; ++i) {
if (!slots_->test(i)) {
continue;
} else {
if (!current_val) {
res.emplace_back(SlotRange{i, i});
} else {
res.back().end = i - 1;
auto& range = res.emplace_back(SlotRange{i, i});
for (++i; i < kSlotsNumber && slots_->test(i); ++i) {
range.end = i;
}
}
}

if (current_val) {
res.back().end = kMaxSlot;
}
return res;
}

Expand Down

0 comments on commit 7eb4b64

Please sign in to comment.