Skip to content

Commit

Permalink
chore: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dranikpg committed Jul 16, 2024
1 parent ec6755c commit fb63e93
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/server/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,28 +190,24 @@ void Transaction::InitGlobal() {
}

void Transaction::BuildShardIndex(const KeyIndex& key_index, std::vector<PerShardCache>* out) {
auto& shard_index = *out;

auto add = [&shard_index](uint32_t sid, uint32_t b, uint32_t e) {
auto& slices = shard_index[sid].slices;
if (!slices.empty() && slices.back().second == b) {
slices.back().second = e;
} else {
slices.emplace_back(b, e);
}
};

// Because of the way we iterate in InitShardData
DCHECK(!key_index.bonus || key_index.step == 1);

auto& shard_index = *out;
for (unsigned i : key_index.Range()) {
string_view key = ArgS(full_args_, i);
unique_slot_checker_.Add(key);
ShardId sid = Shard(key, shard_data_.size());

unsigned step = i == key_index.bonus ? 1 : key_index.step;

shard_index[sid].key_step = step;
add(sid, i, step);
auto& slices = shard_index[sid].slices;
if (!slices.empty() && slices.back().second == i) {
slices.back().second = i + step;
} else {
slices.emplace_back(i, i + step);
}
}
}

Expand Down Expand Up @@ -242,7 +238,7 @@ void Transaction::InitShardData(absl::Span<const PerShardCache> shard_index, siz
unique_shard_cnt_++;
unique_shard_id_ = i;

for (const auto [start, end] : src.slices) {
for (const auto& [start, end] : src.slices) {
args_slices_.emplace_back(start, end);
for (string_view key : KeyIndex(start, end, src.key_step).Range(full_args_)) {
kv_fp_.push_back(LockTag(key).Fingerprint());
Expand Down

0 comments on commit fb63e93

Please sign in to comment.