瀏覽代碼

Add shard ID to failed global checkpoint messages

When a global checkpoint sync fails we should log the shard ID for the
shard the sync failed for. This commit causes this to be the case.
Jason Tedor 8 年之前
父節點
當前提交
57aee93693

+ 7 - 2
core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java

@@ -379,12 +379,17 @@ public abstract class TransportReplicationAction<
                 @Override
                 public void onResponse(Response response) {
                     if (syncGlobalCheckpointAfterOperation) {
+                        final IndexShard shard = primaryShardReference.indexShard;
                         try {
-                            primaryShardReference.indexShard.maybeSyncGlobalCheckpoint("post-operation");
+                            shard.maybeSyncGlobalCheckpoint("post-operation");
                         } catch (final Exception e) {
                             // only log non-closed exceptions
                             if (ExceptionsHelper.unwrap(e, AlreadyClosedException.class, IndexShardClosedException.class) == null) {
-                                logger.info("post-operation global checkpoint sync failed", e);
+                                logger.info(
+                                        new ParameterizedMessage(
+                                                "{} failed to execute background global checkpoint sync",
+                                                shard.shardId()),
+                                        e);
                                 // intentionally swallow, a missed global checkpoint sync should not fail this operation
                             }
                         }

+ 5 - 1
core/src/main/java/org/elasticsearch/index/IndexService.java

@@ -747,7 +747,11 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
                                             },
                                             e -> {
                                                 if (!(e instanceof AlreadyClosedException || e instanceof IndexShardClosedException)) {
-                                                    logger.info("failed to execute background global checkpoint sync", e);
+                                                    logger.info(
+                                                            new ParameterizedMessage(
+                                                                    "{} failed to execute background global checkpoint sync",
+                                                                    shard.shardId()),
+                                                            e);
                                                 }
                                             }),
                                     ThreadPool.Names.SAME);

+ 2 - 3
core/src/main/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncAction.java

@@ -19,10 +19,10 @@
 
 package org.elasticsearch.index.seqno;
 
+import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.lucene.store.AlreadyClosedException;
 import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.Version;
-import org.elasticsearch.action.ActionFuture;
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.action.support.ActionFilters;
 import org.elasticsearch.action.support.replication.ReplicationOperation;
@@ -35,7 +35,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.inject.Inject;
 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;
@@ -85,7 +84,7 @@ public class GlobalCheckpointSyncAction extends TransportReplicationAction<
                 new Request(shardId),
                 ActionListener.wrap(r -> {}, e -> {
                     if (ExceptionsHelper.unwrap(e, AlreadyClosedException.class, IndexShardClosedException.class) == null) {
-                        logger.info(shardId + " global checkpoint sync failed", e);
+                        logger.info(new ParameterizedMessage("{} global checkpoint sync failed", shardId), e);
                     }
                 }));
     }