diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java
index 69ba50cd60291..ff8baaabb443c 100644
--- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java
+++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java
@@ -51,7 +51,6 @@
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.gateway.MetaDataStateFormat;
-import org.elasticsearch.gateway.WriteStateException;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
@@ -391,11 +390,7 @@ private static NodeMetaData loadOrCreateNodeMetaData(Settings settings, Logger l
metaData = new NodeMetaData(generateNodeId(settings));
}
// we write again to make sure all paths have the latest state file
- try {
- NodeMetaData.FORMAT.write(metaData, paths);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ NodeMetaData.FORMAT.write(metaData, paths);
return metaData;
}
diff --git a/server/src/main/java/org/elasticsearch/gateway/WriteStateException.java b/server/src/main/java/org/elasticsearch/gateway/WriteStateException.java
index f318949863f73..832cdcebfb457 100644
--- a/server/src/main/java/org/elasticsearch/gateway/WriteStateException.java
+++ b/server/src/main/java/org/elasticsearch/gateway/WriteStateException.java
@@ -18,12 +18,14 @@
*/
package org.elasticsearch.gateway;
+import java.io.IOException;
+
/**
* This exception is thrown when there is a problem of writing state to disk.
* If {@link #isDirty()} returns false, state is guaranteed to be not written to disk.
* If {@link #isDirty()} returns true, we don't know if state is written to disk.
*/
-public class WriteStateException extends Exception {
+public class WriteStateException extends IOException {
private boolean dirty;
public WriteStateException(boolean dirty, String message, Exception cause) {
diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
index 99b3741321378..17756630517d2 100644
--- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
+++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
@@ -64,7 +64,6 @@
import org.elasticsearch.common.util.concurrent.AsyncIOProcessor;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.internal.io.IOUtils;
-import org.elasticsearch.gateway.WriteStateException;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexNotFoundException;
@@ -2244,11 +2243,7 @@ private static void persistMetadata(
logger.trace("{} writing shard state, reason [{}]", shardId, writeReason);
final ShardStateMetaData newShardStateMetadata =
new ShardStateMetaData(newRouting.primary(), indexSettings.getUUID(), newRouting.allocationId());
- try {
- ShardStateMetaData.FORMAT.write(newShardStateMetadata, shardPath.getShardStatePath());
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ ShardStateMetaData.FORMAT.write(newShardStateMetadata, shardPath.getShardStatePath());
} else {
logger.trace("{} skip writing shard state, has been written before", shardId);
}
diff --git a/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java b/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java
index 432cc35dbdaa0..54c1dd7c1db69 100644
--- a/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java
+++ b/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java
@@ -53,7 +53,6 @@
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.NodeMetaData;
import org.elasticsearch.gateway.MetaDataStateFormat;
-import org.elasticsearch.gateway.WriteStateException;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.engine.Engine;
@@ -461,11 +460,8 @@ protected void newAllocationId(Environment environment, ShardPath shardPath, Ter
final ShardStateMetaData newShardStateMetaData =
new ShardStateMetaData(shardStateMetaData.primary, shardStateMetaData.indexUUID, newAllocationId);
- try {
- ShardStateMetaData.FORMAT.write(newShardStateMetaData, shardStatePath);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ ShardStateMetaData.FORMAT.write(newShardStateMetaData, shardStatePath);
+
terminal.println("");
terminal.println("You should run the following command to allocate this shard:");
diff --git a/server/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java b/server/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java
index d07adb3193aa6..d91e139121cc5 100644
--- a/server/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java
+++ b/server/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java
@@ -95,7 +95,7 @@ public MetaData fromXContent(XContentParser parser) throws IOException {
// indices are empty since they are serialized separately
}
- public void testReadWriteState() throws IOException, WriteStateException {
+ public void testReadWriteState() throws IOException {
Path[] dirs = new Path[randomIntBetween(1, 5)];
for (int i = 0; i < dirs.length; i++) {
dirs[i] = createTempDir();
@@ -136,7 +136,7 @@ public void testReadWriteState() throws IOException, WriteStateException {
}
}
- public void testVersionMismatch() throws IOException, WriteStateException {
+ public void testVersionMismatch() throws IOException {
Path[] dirs = new Path[randomIntBetween(1, 5)];
for (int i = 0; i < dirs.length; i++) {
dirs[i] = createTempDir();
@@ -161,7 +161,7 @@ public void testVersionMismatch() throws IOException, WriteStateException {
}
}
- public void testCorruption() throws IOException, WriteStateException {
+ public void testCorruption() throws IOException {
Path[] dirs = new Path[randomIntBetween(1, 5)];
for (int i = 0; i < dirs.length; i++) {
dirs[i] = createTempDir();
@@ -233,7 +233,7 @@ public static void corruptFile(Path file, Logger logger) throws IOException {
}
}
- public void testLoadState() throws IOException, WriteStateException {
+ public void testLoadState() throws IOException {
final Path[] dirs = new Path[randomIntBetween(1, 5)];
int numStates = randomIntBetween(1, 5);
List meta = new ArrayList<>();
@@ -291,7 +291,7 @@ public void testLoadState() throws IOException, WriteStateException {
}
}
- private DummyState writeAndReadStateSuccessfully(Format format, Path... paths) throws IOException, WriteStateException {
+ private DummyState writeAndReadStateSuccessfully(Format format, Path... paths) throws IOException {
format.noFailures();
DummyState state = new DummyState(randomRealisticUnicodeOfCodepointLengthBetween(1, 100), randomInt(), randomLong(),
randomDouble(), randomBoolean());
@@ -309,7 +309,7 @@ private static void ensureOnlyOneStateFile(Path[] paths) throws IOException {
}
}
- public void testFailWriteAndReadPreviousState() throws IOException, WriteStateException {
+ public void testFailWriteAndReadPreviousState() throws IOException {
Path path = createTempDir();
Format format = new Format("foo-");
@@ -330,7 +330,7 @@ public void testFailWriteAndReadPreviousState() throws IOException, WriteStateEx
writeAndReadStateSuccessfully(format, path);
}
- public void testFailWriteAndReadAnyState() throws IOException, WriteStateException {
+ public void testFailWriteAndReadAnyState() throws IOException {
Path path = createTempDir();
Format format = new Format("foo-");
Set possibleStates = new HashSet<>();
@@ -377,7 +377,7 @@ public void testFailCopyTmpFileToExtraLocation() throws IOException, WriteStateE
}
- public void testFailRandomlyAndReadAnyState() throws IOException, WriteStateException {
+ public void testFailRandomlyAndReadAnyState() throws IOException {
Path paths[] = new Path[randomIntBetween(1, 5)];
for (int i = 0; i < paths.length; i++) {
paths[i] = createTempDir();
diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
index aef8326e0d0a0..487ac7e0694ef 100644
--- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
+++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
@@ -76,7 +76,6 @@
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.env.NodeEnvironment;
-import org.elasticsearch.gateway.WriteStateException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.engine.CommitStats;
import org.elasticsearch.index.engine.Engine;
@@ -195,11 +194,7 @@ public static ShardStateMetaData load(Logger logger, Path... shardPaths) throws
public static void write(ShardStateMetaData shardStateMetaData,
Path... shardPaths) throws IOException {
- try {
- ShardStateMetaData.FORMAT.write(shardStateMetaData, shardPaths);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ ShardStateMetaData.FORMAT.write(shardStateMetaData, shardPaths);
}
public static Engine getEngineFromShard(IndexShard shard) {
diff --git a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java
index 980b2f92ead7c..6e34bb03860c5 100644
--- a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java
+++ b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java
@@ -36,7 +36,6 @@
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.TestEnvironment;
-import org.elasticsearch.gateway.WriteStateException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.MergePolicyConfig;
import org.elasticsearch.index.engine.EngineException;
@@ -402,11 +401,7 @@ private void writeIndexState() throws IOException {
// create _state of IndexMetaData
try(NodeEnvironment nodeEnvironment = new NodeEnvironment(environment.settings(), environment)) {
final Path[] paths = nodeEnvironment.indexPaths(indexMetaData.getIndex());
- try {
- IndexMetaData.FORMAT.write(indexMetaData, paths);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ IndexMetaData.FORMAT.write(indexMetaData, paths);
logger.info("--> index metadata persisted to {} ", Arrays.toString(paths));
}
}
diff --git a/server/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java b/server/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java
index fc63a90178445..fda2f8ef7d039 100644
--- a/server/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java
+++ b/server/src/test/java/org/elasticsearch/index/shard/ShardPathTests.java
@@ -24,7 +24,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
-import org.elasticsearch.gateway.WriteStateException;
import org.elasticsearch.index.Index;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule;
@@ -44,11 +43,7 @@ public void testLoadShardPath() throws IOException {
ShardId shardId = new ShardId("foo", "0xDEADBEEF", 0);
Path[] paths = env.availableShardPaths(shardId);
Path path = randomFrom(paths);
- try {
- ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, "0xDEADBEEF", AllocationId.newInitializing()), path);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, "0xDEADBEEF", AllocationId.newInitializing()), path);
ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings));
assertEquals(path, shardPath.getDataPath());
assertEquals("0xDEADBEEF", shardPath.getShardId().getIndex().getUUID());
@@ -67,11 +62,7 @@ public void testFailLoadShardPathOnMultiState() throws IOException {
ShardId shardId = new ShardId("foo", indexUUID, 0);
Path[] paths = env.availableShardPaths(shardId);
assumeTrue("This test tests multi data.path but we only got one", paths.length > 1);
- try {
- ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, indexUUID, AllocationId.newInitializing()), paths);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, indexUUID, AllocationId.newInitializing()), paths);
Exception e = expectThrows(IllegalStateException.class, () ->
ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings)));
assertThat(e.getMessage(), containsString("more than one shard state found"));
@@ -86,11 +77,7 @@ public void testFailLoadShardPathIndexUUIDMissmatch() throws IOException {
ShardId shardId = new ShardId("foo", "foobar", 0);
Path[] paths = env.availableShardPaths(shardId);
Path path = randomFrom(paths);
- try {
- ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, "0xDEADBEEF", AllocationId.newInitializing()), path);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, "0xDEADBEEF", AllocationId.newInitializing()), path);
Exception e = expectThrows(IllegalStateException.class, () ->
ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings)));
assertThat(e.getMessage(), containsString("expected: foobar on shard path"));
@@ -137,11 +124,7 @@ public void testGetRootPaths() throws IOException {
ShardId shardId = new ShardId("foo", indexUUID, 0);
Path[] paths = env.availableShardPaths(shardId);
Path path = randomFrom(paths);
- try {
- ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, indexUUID, AllocationId.newInitializing()), path);
- } catch (WriteStateException e) {
- throw new IOException(e);
- }
+ ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, indexUUID, AllocationId.newInitializing()), path);
ShardPath shardPath = ShardPath.loadShardPath(logger, env, shardId,
IndexSettingsModule.newIndexSettings(shardId.getIndex(), indexSettings, nodeSettings));
boolean found = false;