Skip to content

Commit 77618b6

Browse files
author
michael stack
committed
Fix uninitialized targetServer when first DC has empty server list
The targetServer was only set when dcid == 0, but dcid gets incremented even for empty DC server lists (via continue). So if the first DC had an empty server list, dcid would be 1 when we encounter the first non-empty DC, and targetServer would never be set, causing a crash when accessed. Fixed by using a targetServerSet flag instead of checking dcid == 0. Now targetServer is set on the FIRST non-empty DC, regardless of index. This was the root cause of -2 crashes in general test runs.
1 parent 6f8be78 commit 77618b6

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

fdbserver/DataDistribution.actor.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4465,18 +4465,20 @@ ACTOR Future<Void> scheduleAuditOnRange(Reference<DataDistributor> self,
44654465
taskRangeBegin = taskRange.end;
44664466
continue; // Continue to check if there are more states in this range
44674467
}
4468-
int dcid = 0;
4469-
for (const auto& [_, dcServers] : rangeLocations[rangeLocationIndex].servers) {
4470-
if (dcServers.empty()) {
4471-
// Skip empty server lists for this DC
4472-
dcid++;
4473-
continue;
4474-
}
4475-
if (dcid == 0) {
4476-
// in primary DC randomly select a server to do the audit task
4477-
const int idx = deterministicRandom()->randomInt(0, dcServers.size());
4478-
targetServer = dcServers[idx];
4479-
}
4468+
int dcid = 0;
4469+
bool targetServerSet = false;
4470+
for (const auto& [_, dcServers] : rangeLocations[rangeLocationIndex].servers) {
4471+
if (dcServers.empty()) {
4472+
// Skip empty server lists for this DC
4473+
dcid++;
4474+
continue;
4475+
}
4476+
if (!targetServerSet) {
4477+
// On first non-empty DC, randomly select a server to do the audit task
4478+
const int idx = deterministicRandom()->randomInt(0, dcServers.size());
4479+
targetServer = dcServers[idx];
4480+
targetServerSet = true;
4481+
}
44804482
for (int i = 0; i < dcServers.size(); i++) {
44814483
if (dcServers[i].id() == targetServer.id()) {
44824484
ASSERT_WE_THINK(dcid == 0);

0 commit comments

Comments
 (0)