From 94c4fcf02ca79a436e3a39cfcb453254c30aff5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Mon, 1 Feb 2021 17:57:25 +0100 Subject: [PATCH] do not wait for shards, fix 'index' field value casting, more logging when pruning --- .../xbib/elx/common/AbstractAdminClient.java | 23 ++++++++++++++----- .../xbib/elx/common/AbstractBasicClient.java | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java index 03f9077..bb1aaa7 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java @@ -151,7 +151,6 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest().indices(index); client.execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet(); waitForCluster("YELLOW", 30L, TimeUnit.SECONDS); - waitForShards(30L, TimeUnit.SECONDS); return this; } @@ -168,7 +167,6 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements return this; } updateIndexSetting(index, "number_of_replicas", level, maxWaitTime, timeUnit); - waitForShards(maxWaitTime, timeUnit); return this; } @@ -367,7 +365,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements GetIndexRequestBuilder getIndexRequestBuilder = new GetIndexRequestBuilder(client, GetIndexAction.INSTANCE); GetIndexResponse getIndexResponse = getIndexRequestBuilder.execute().actionGet(); Pattern pattern = Pattern.compile("^(.*?)(\\d+)$"); - logger.info("found {} indices for pruning", getIndexResponse.getIndices().length); + logger.info("found {} indices in the cluster", getIndexResponse.getIndices().length); List candidateIndices = new ArrayList<>(); for (String s : getIndexResponse.getIndices()) { Matcher m = pattern.matcher(s); @@ -375,10 +373,13 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements candidateIndices.add(s); } } + logger.info("found {} as candidates for pruning", candidateIndices); if (candidateIndices.isEmpty()) { + logger.info("empty pruning"); return EMPTY_INDEX_PRUNE_RESULT; } if (mintokeep > 0 && candidateIndices.size() <= mintokeep) { + logger.info("nothing to prune, min to keep = " + mintokeep); return new NothingToDoPruneResult(candidateIndices, Collections.emptyList()); } List indicesToDelete = new ArrayList<>(); @@ -396,6 +397,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements } } } + logger.warn("removing {}", indicesToDelete); if (indicesToDelete.isEmpty()) { return new NothingToDoPruneResult(candidateIndices, indicesToDelete); } @@ -403,6 +405,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest() .indices(indicesToDelete.toArray(s)); AcknowledgedResponse response = client.execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet(); + logger.info("removed {}", indicesToDelete); return new SuccessPruneResult(candidateIndices, indicesToDelete, response); } @@ -628,9 +631,17 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements path = path + fieldName; } if (map.containsKey("index")) { - String mode = (String) map.get("index"); - if ("no".equals(mode)) { - return; + Object mode = map.get("index"); + if (mode instanceof String) { + if ("no".equals(mode)) { + return; + } + } + if (mode instanceof Boolean) { + Boolean b = (Boolean) mode; + if (!b) { + return; + } } } for (Map.Entry entry : map.entrySet()) { diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java index 72f445c..f8883f4 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java @@ -110,7 +110,7 @@ public abstract class AbstractBasicClient implements BasicClient { ClusterHealthResponse healthResponse = client.execute(ClusterHealthAction.INSTANCE, clusterHealthRequest).actionGet(); if (healthResponse.isTimedOut()) { - String message = "timeout waiting for cluster shards"; + String message = "timeout waiting for cluster shards: " + timeout; logger.error(message); throw new IllegalStateException(message); }