From 1792bd6b160993aae2d925ad4b7c0663d14a9e82 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 10 Oct 2013 16:15:33 +0200 Subject: [PATCH] Fixed serialization error. POST_RECOVERY is now also serialized --- .../index/shard/IndexShardState.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/shard/IndexShardState.java b/src/main/java/org/elasticsearch/index/shard/IndexShardState.java index 89a6f306373..17ae6212a7a 100644 --- a/src/main/java/org/elasticsearch/index/shard/IndexShardState.java +++ b/src/main/java/org/elasticsearch/index/shard/IndexShardState.java @@ -32,6 +32,14 @@ public enum IndexShardState { RELOCATED((byte) 4), CLOSED((byte) 5); + private static final IndexShardState[] ORDS = new IndexShardState[IndexShardState.values().length]; + + static { + for (IndexShardState state : IndexShardState.values()) { + ORDS[state.id()] = state; + } + } + private final byte id; IndexShardState(byte id) { @@ -43,17 +51,9 @@ public enum IndexShardState { } public static IndexShardState fromId(byte id) throws ElasticSearchIllegalArgumentException { - if (id == 0) { - return CREATED; - } else if (id == 1) { - return RECOVERING; - } else if (id == 2) { - return STARTED; - } else if (id == 3) { - return RELOCATED; - } else if (id == 4) { - return CLOSED; + if (id < ORDS[0].id && id > ORDS[ORDS.length - 1].id) { + throw new ElasticSearchIllegalArgumentException("No mapping for id [" + id + "]"); } - throw new ElasticSearchIllegalArgumentException("No mapping for id [" + id + "]"); + return ORDS[id]; } }