Fix issue where shard state metadata is written while containing no allocation id

Such a write can happen when upgrading shard state metadata using the MultiDataPathUpgrader

Relates to #14831
This commit is contained in:
Yannick Welsch 2015-11-23 18:14:02 +01:00
parent b804a0c4a6
commit 3dcd35d1c8
1 changed files with 4 additions and 2 deletions

View File

@ -46,7 +46,7 @@ public final class ShardStateMetaData {
public final String indexUUID; public final String indexUUID;
public final boolean primary; public final boolean primary;
@Nullable @Nullable
public final AllocationId allocationId; // can be null if we read from legacy format (see fromXContent) public final AllocationId allocationId; // can be null if we read from legacy format (see fromXContent and MultiDataPathUpgrader)
public ShardStateMetaData(long version, boolean primary, String indexUUID, AllocationId allocationId) { public ShardStateMetaData(long version, boolean primary, String indexUUID, AllocationId allocationId) {
assert indexUUID != null; assert indexUUID != null;
@ -111,7 +111,9 @@ public final class ShardStateMetaData {
builder.field(VERSION_KEY, shardStateMetaData.version); builder.field(VERSION_KEY, shardStateMetaData.version);
builder.field(PRIMARY_KEY, shardStateMetaData.primary); builder.field(PRIMARY_KEY, shardStateMetaData.primary);
builder.field(INDEX_UUID_KEY, shardStateMetaData.indexUUID); builder.field(INDEX_UUID_KEY, shardStateMetaData.indexUUID);
builder.field(ALLOCATION_ID_KEY, shardStateMetaData.allocationId); if (shardStateMetaData.allocationId != null) {
builder.field(ALLOCATION_ID_KEY, shardStateMetaData.allocationId);
}
} }
@Override @Override