Skip to content

Commit

Permalink
Fix logger Strings.format calls (#104573)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Jan 26, 2024
1 parent 0381954 commit 504e7c8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/104573.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 104573
summary: Fix logger Strings.format calls
area: Distributed
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static <T> void addAllSynchronized(List<T> allResults, Collection<T> res

@Override
protected void onItemFailure(String nodeId, Exception e) {
logger.debug(() -> Strings.format("failed to execute on node [{}]", nodeId), e);
logger.debug(() -> Strings.format("failed to execute on node [%s]", nodeId), e);
synchronized (failedNodeExceptions) {
failedNodeExceptions.add(new FailedNodeException(nodeId, "Failed node [" + nodeId + "]", e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Setting;
Expand Down Expand Up @@ -163,7 +162,7 @@ void updateLeader(@Nullable final DiscoveryNode leader) {
*/
void setCurrentNodes(DiscoveryNodes discoveryNodes) {
// Sorting the nodes for deterministic logging until https://github.com/elastic/elasticsearch/issues/94946 is fixed
logger.trace(() -> Strings.format("setCurrentNodes: {}", discoveryNodes.mastersFirstStream().toList()));
logger.trace(() -> format("setCurrentNodes: %s", discoveryNodes.mastersFirstStream().toList()));
this.discoveryNodes = discoveryNodes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.elasticsearch.cluster.service.ClusterApplierService;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Setting;
Expand Down Expand Up @@ -651,7 +650,7 @@ private void createShardWhenLockAvailable(
listener.onResponse(true);
} catch (ShardLockObtainFailedException e) {
if (e.getCause() instanceof InterruptedException || Thread.currentThread().isInterrupted()) {
logger.warn(Strings.format("interrupted while creating shard [{}]", shardRouting), e);
logger.warn(format("interrupted while creating shard [%s]", shardRouting), e);
listener.onFailure(e);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -524,12 +523,12 @@ static void refreshRepositoryUuids(boolean enabled, RepositoriesService reposito
ActionListener.releaseAfter(new ActionListener<>() {
@Override
public void onResponse(RepositoryData repositoryData) {
logger.debug(() -> format("repository UUID [{}] refresh completed", repositoryName));
logger.debug(() -> format("repository UUID [%s] refresh completed", repositoryName));
}

@Override
public void onFailure(Exception e) {
logger.debug(() -> format("repository UUID [{}] refresh failed", repositoryName), e);
logger.debug(() -> format("repository UUID [%s] refresh failed", repositoryName), e);
}
}, refs.acquire())
);
Expand Down Expand Up @@ -1121,8 +1120,7 @@ private static IndexMetadata updateIndexSettings(
if (Objects.equals(previous, changed) == false) {
throw new SnapshotRestoreException(
snapshot,
String.format(
Locale.ROOT,
format(
"cannot change value of [%s] when restoring searchable snapshot [%s:%s] as index %s",
SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION,
snapshot.getRepository(),
Expand Down Expand Up @@ -1761,8 +1759,7 @@ private static void ensureSearchableSnapshotsRestorable(
throw new SnapshotRestoreException(
repositoryName,
snapshotInfo.snapshotId().getName(),
String.format(
Locale.ROOT,
format(
"cannot mount snapshot [%s/%s:%s] as index [%s] with the deletion of snapshot on index removal enabled "
+ "[index.store.snapshot.delete_searchable_snapshot: true]; snapshot contains [%d] indices instead of 1.",
repositoryName,
Expand Down Expand Up @@ -1796,8 +1793,7 @@ private static void ensureSearchableSnapshotsRestorable(
throw new SnapshotRestoreException(
repositoryName,
snapshotInfo.snapshotId().getName(),
String.format(
Locale.ROOT,
format(
"cannot mount snapshot [%s/%s:%s] as index [%s] with [index.store.snapshot.delete_searchable_snapshot: %b]; "
+ "another index %s is mounted with [index.store.snapshot.delete_searchable_snapshot: %b].",
repositoryName,
Expand Down

0 comments on commit 504e7c8

Please sign in to comment.