Skip to content

Commit

Permalink
Recovery: change check for finished to a ref count check
Browse files Browse the repository at this point in the history
we current check that the recovery is not finished when people access the status local variables. This is wrong and we should check for the refcount being > 0 as it is OK to use the status after it has marked as finished but there are still on going, in-flight reference to it.

Relates to #8092

Closes #8271
  • Loading branch information
bleskes committed Oct 29, 2014
1 parent dd04a7d commit f57e981
Showing 1 changed file with 9 additions and 9 deletions.
Expand Up @@ -102,7 +102,7 @@ public ShardId shardId() {
}

public InternalIndexShard indexShard() {
ensureNotFinished();
ensureRefCount();
return indexShard;
}

Expand All @@ -115,7 +115,7 @@ public RecoveryState state() {
}

public Store store() {
ensureNotFinished();
ensureRefCount();
return store;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public Store.LegacyChecksums legacyChecksums() {

/** renames all temporary files to their true name, potentially overriding existing files */
public void renameAllTempFiles() throws IOException {
ensureNotFinished();
ensureRefCount();
Iterator<String> tempFileIterator = tempFileNames.iterator();
final Directory directory = store.directory();
while (tempFileIterator.hasNext()) {
Expand Down Expand Up @@ -222,7 +222,7 @@ private boolean isTempFile(String filename) {
}

public IndexOutput getOpenIndexOutput(String key) {
ensureNotFinished();
ensureRefCount();
return openIndexOutputs.get(key);
}

Expand All @@ -236,7 +236,7 @@ private String originalNameForTempFile(String tempFile) {

/** remove and {@link org.apache.lucene.store.IndexOutput} for a given file. It is the caller's responsibility to close it */
public IndexOutput removeOpenIndexOutputs(String name) {
ensureNotFinished();
ensureRefCount();
return openIndexOutputs.remove(name);
}

Expand All @@ -248,7 +248,7 @@ public IndexOutput removeOpenIndexOutputs(String name) {
* at a later stage
*/
public IndexOutput openAndPutIndexOutput(String fileName, StoreFileMetaData metaData, Store store) throws IOException {
ensureNotFinished();
ensureRefCount();
String tempFileName = getTempNameForFile(fileName);
// add first, before it's created
tempFileNames.add(tempFileName);
Expand Down Expand Up @@ -284,9 +284,9 @@ public String toString() {
return shardId + " [" + recoveryId + "]";
}

private void ensureNotFinished() {
if (finished.get()) {
throw new ElasticsearchException("RecoveryStatus is used after it was finished. Probably a mismatch between incRef/decRef calls");
private void ensureRefCount() {
if (refCount() <= 0) {
throw new ElasticsearchException("RecoveryStatus is used but it's refcount is 0. Probably a mismatch between incRef/decRef calls");
}
}

Expand Down

0 comments on commit f57e981

Please sign in to comment.