add flag to only shift an index if there are documents

This commit is contained in:
Jörg Prante 2024-07-05 17:06:13 +02:00
parent 0e0817ca84
commit d967d84cfd
6 changed files with 31 additions and 1 deletions

View file

@ -47,6 +47,8 @@ public interface BasicClient extends Closeable {
boolean isIndexExists(IndexDefinition indexDefinition);
boolean isIndexEmpty(IndexDefinition indexDefinition);
String getIndexState(IndexDefinition indexDefinition);
boolean isIndexOpen(IndexDefinition indexDefinition);

View file

@ -59,6 +59,10 @@ public interface IndexDefinition {
boolean isShiftEnabled();
void setShiftNotEmpty(boolean shiftNotEmpty);
boolean isShiftNotEmpty();
void setPrune(boolean prune);
boolean isPruneEnabled();

View file

@ -351,6 +351,12 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
return new EmptyIndexShiftResult();
}
if (indexDefinition.isShiftEnabled()) {
if (indexDefinition.isShiftNotEmpty() && isIndexEmpty(indexDefinition)) {
logger.log(Level.WARNING, "index is empty, deleting index and rejecting to continue shifting: " +
indexDefinition);
deleteIndex(indexDefinition);
return new EmptyIndexShiftResult();
}
if (indexDefinition.isCloseShifted()) {
getAlias(indexDefinition.getIndex()).stream()
.filter(s -> !s.equals(indexDefinition.getFullIndexName()))

View file

@ -212,6 +212,11 @@ public abstract class AbstractBasicClient implements BasicClient {
return indicesExistsResponse.isExists();
}
@Override
public boolean isIndexEmpty(IndexDefinition indexDefinition) {
return getSearchableDocs(indexDefinition) == 0L;
}
@Override
public String getIndexState(IndexDefinition indexDefinition) {
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();

View file

@ -44,6 +44,8 @@ public class DefaultIndexDefinition implements IndexDefinition {
private boolean shift;
private boolean shiftNotEmpty;
private boolean prune;
private boolean forcemerge;
@ -74,6 +76,7 @@ public class DefaultIndexDefinition implements IndexDefinition {
setFullIndexName(index + getDateTimeFormatter().format(LocalDateTime.now()));
setShardCount(1);
setShift(false);
setShiftNotEmpty(false);
setPrune(false);
setForceMerge(false);
setCloseShifted(false);
@ -265,6 +268,16 @@ public class DefaultIndexDefinition implements IndexDefinition {
return shift;
}
@Override
public void setShiftNotEmpty(boolean shiftNotEmpty) {
this.shiftNotEmpty = shiftNotEmpty;
}
@Override
public boolean isShiftNotEmpty() {
return shiftNotEmpty;
}
@Override
public void setPrune(boolean prune) {
this.prune = prune;

View file

@ -1,3 +1,3 @@
group = org.xbib
name = elx
version = 7.10.2.45
version = 7.10.2.46