Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segment Replication stats throwing NPE when shards are unassigned or are in delayed allocation phase #14580

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add allowlist setting for ingest-common and search-pipeline-common processors ([#14439](https://github.com/opensearch-project/OpenSearch/issues/14439))
- Create SystemIndexRegistry with helper method matchesSystemIndex ([#14415](https://github.com/opensearch-project/OpenSearch/pull/14415))
- Print reason why parent task was cancelled ([#14604](https://github.com/opensearch-project/OpenSearch/issues/14604))
- Fix Segment Replication stats throwing NPE when shards are unassigned or are in delayed allocation phase ([#14580](https://github.com/opensearch-project/OpenSearch/pull/14580))

### Dependencies
- Bump `org.gradle.test-retry` from 1.5.8 to 1.5.9 ([#13442](https://github.com/opensearch-project/OpenSearch/pull/13442))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,9 @@ public ReplicationCheckpoint getLatestReplicationCheckpoint() {
}

private boolean isPrimaryRelocation(String allocationId) {
Optional<ShardRouting> shardRouting = routingTable.shards()
Optional<ShardRouting> shardRouting = routingTable.assignedShards()
rampreeth marked this conversation as resolved.
Show resolved Hide resolved
.stream()
.filter(routing -> Objects.nonNull(routing.allocationId()))
.filter(routing -> routing.allocationId().getId().equals(allocationId))
.findAny();
return shardRouting.isPresent() && shardRouting.get().primary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ static IndexShardRoutingTable routingTable(
assert activeIds.contains(primaryShard.allocationId());
final ShardId shardId = new ShardId("test", "_na_", 0);
final IndexShardRoutingTable.Builder builder = new IndexShardRoutingTable.Builder(shardId);

// Add a shard that is unassigned to simulate #11945
builder.addShard(
TestShardRouting.newShardRoutingWithNullAllocationId(
shardId,
null,
null,
false,
ShardRoutingState.UNASSIGNED
)
);

for (final AllocationId initializingId : initializingIds) {
builder.addShard(
TestShardRouting.newShardRouting(
Expand All @@ -146,6 +158,8 @@ static IndexShardRoutingTable routingTable(
)
);
}


for (final AllocationId activeId : activeIds) {
if (activeId.equals(primaryShard.allocationId())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,9 @@ public void testPeerRecoveryRetentionLeaseCreationAndRenewal() {
IndexShardRoutingTable.Builder routingTableBuilder = new IndexShardRoutingTable.Builder(routingTable);
for (ShardRouting replicaShard : routingTable.replicaShards()) {
routingTableBuilder.removeShard(replicaShard);
routingTableBuilder.addShard(replicaShard.moveToStarted());
if (replicaShard.assignedToNode()) {
mch2 marked this conversation as resolved.
Show resolved Hide resolved
routingTableBuilder.addShard(replicaShard.moveToStarted());
}
}
routingTable = routingTableBuilder.build();
activeAllocationIds.addAll(initializingAllocationIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ public static ShardRouting newShardRouting(
);
}

public static ShardRouting newShardRoutingWithNullAllocationId(
ShardId shardId,
String currentNodeId,
String relocatingNodeId,
boolean primary,
ShardRoutingState state
) {
return new ShardRouting(
shardId,
currentNodeId,
relocatingNodeId,
primary,
state,
buildRecoveryTarget(primary, state),
buildUnassignedInfo(state),
null,
-1
);
}

public static ShardRouting newShardRouting(
String index,
int shardId,
Expand Down
Loading