Skip to content

Commit

Permalink
handle closed
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Sep 21, 2017
1 parent 507806b commit 530addd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package org.elasticsearch.action.support.replication;

import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.store.AlreadyClosedException;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionListenerResponseHandler;
Expand Down Expand Up @@ -55,6 +57,7 @@
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.IndexShardClosedException;
import org.elasticsearch.index.shard.IndexShardState;
import org.elasticsearch.index.shard.ReplicationGroup;
import org.elasticsearch.index.shard.ShardId;
Expand Down Expand Up @@ -379,8 +382,11 @@ public void onResponse(Response response) {
try {
primaryShardReference.indexShard.maybeSyncGlobalCheckpoint("post-operation");
} catch (final Exception e) {
logger.info("post-operation global checkpoint sync failed", e);
// intentionally swallow, a missed global checkpoint sync should not fail this operation
// only log non-closed exceptions
if (ExceptionsHelper.unwrap(e, AlreadyClosedException.class, IndexShardClosedException.class) == null) {
logger.info("post-operation global checkpoint sync failed", e);
// intentionally swallow, a missed global checkpoint sync should not fail this operation
}
}
}
primaryShardReference.close(); // release shard operation lock before responding to caller
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/org/elasticsearch/index/IndexService.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,11 @@ private void syncGlobalCheckpoints() {
shard.maybeSyncGlobalCheckpoint("background");
}
},
e -> logger.info("failed to execute background global checkpoint sync", e)),
e -> {
if (!(e instanceof AlreadyClosedException || e instanceof IndexShardClosedException)) {
logger.info("failed to execute background global checkpoint sync", e);
}
}),
ThreadPool.Names.SAME);
} catch (final AlreadyClosedException | IndexShardClosedException e) {
// the shard was closed concurrently, continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.index.seqno;

import org.apache.lucene.store.AlreadyClosedException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionListener;
Expand All @@ -35,6 +37,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.shard.IndexEventListener;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.IndexShardClosedException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -78,7 +81,13 @@ public GlobalCheckpointSyncAction(
}

public void updateGlobalCheckpointForShard(final ShardId shardId) {
execute(new Request(shardId), ActionListener.wrap(r -> {}, e -> logger.info(shardId + " global checkpoint sync failed", e)));
execute(
new Request(shardId),
ActionListener.wrap(r -> {}, e -> {
if (ExceptionsHelper.unwrap(e, AlreadyClosedException.class, IndexShardClosedException.class) == null) {
logger.info(shardId + " global checkpoint sync failed", e);
}
}));
}

@Override
Expand Down

0 comments on commit 530addd

Please sign in to comment.