From 3dcd35d1c84b7b371955717f8c0c064886736402 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Mon, 23 Nov 2015 18:14:02 +0100 Subject: [PATCH] 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 --- .../org/elasticsearch/index/shard/ShardStateMetaData.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/shard/ShardStateMetaData.java b/core/src/main/java/org/elasticsearch/index/shard/ShardStateMetaData.java index fbe99d3aca2..3cee89f84be 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/ShardStateMetaData.java +++ b/core/src/main/java/org/elasticsearch/index/shard/ShardStateMetaData.java @@ -46,7 +46,7 @@ public final class ShardStateMetaData { public final String indexUUID; public final boolean primary; @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) { assert indexUUID != null; @@ -111,7 +111,9 @@ public final class ShardStateMetaData { builder.field(VERSION_KEY, shardStateMetaData.version); builder.field(PRIMARY_KEY, shardStateMetaData.primary); 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