Skip to content

Commit

Permalink
fixed a IndexAlreadyExistsException error on startup (race condition)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Dec 14, 2015
1 parent 578cc4e commit 6ef4a85
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -225,7 +225,13 @@ public static void createIndex(JestClient client, String indexName, String setti
request.source(source);
JestResult response = client.execute(new CreateIndex.Builder(indexName).settings(source).build());
if (!response.isSucceeded()) {
throw new Exception("Failed to create index: '" + indexName + "' Reason: " + response.getErrorMessage()); //$NON-NLS-1$ //$NON-NLS-2$
// When running in e.g. Wildfly, the Gateway exists as two separate WARs - the API and the
// runtime Gateway itself. They both create a registry and thus they both try to initialize
// the ES index if it doesn't exist. A race condition could result in both WARs trying to
// create the index. So a result of "IndexAlreadyExistsException" should be ignored.
if (!"IndexAlreadyExistsException".equals(response.getErrorMessage())) { //$NON-NLS-1$
throw new Exception("Failed to create index: '" + indexName + "' Reason: " + response.getErrorMessage()); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}

Expand Down

0 comments on commit 6ef4a85

Please sign in to comment.