add flag to only shift an index if there are documents
This commit is contained in:
parent
0e0817ca84
commit
d967d84cfd
6 changed files with 31 additions and 1 deletions
|
@ -47,6 +47,8 @@ public interface BasicClient extends Closeable {
|
||||||
|
|
||||||
boolean isIndexExists(IndexDefinition indexDefinition);
|
boolean isIndexExists(IndexDefinition indexDefinition);
|
||||||
|
|
||||||
|
boolean isIndexEmpty(IndexDefinition indexDefinition);
|
||||||
|
|
||||||
String getIndexState(IndexDefinition indexDefinition);
|
String getIndexState(IndexDefinition indexDefinition);
|
||||||
|
|
||||||
boolean isIndexOpen(IndexDefinition indexDefinition);
|
boolean isIndexOpen(IndexDefinition indexDefinition);
|
||||||
|
|
|
@ -59,6 +59,10 @@ public interface IndexDefinition {
|
||||||
|
|
||||||
boolean isShiftEnabled();
|
boolean isShiftEnabled();
|
||||||
|
|
||||||
|
void setShiftNotEmpty(boolean shiftNotEmpty);
|
||||||
|
|
||||||
|
boolean isShiftNotEmpty();
|
||||||
|
|
||||||
void setPrune(boolean prune);
|
void setPrune(boolean prune);
|
||||||
|
|
||||||
boolean isPruneEnabled();
|
boolean isPruneEnabled();
|
||||||
|
|
|
@ -351,6 +351,12 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
||||||
return new EmptyIndexShiftResult();
|
return new EmptyIndexShiftResult();
|
||||||
}
|
}
|
||||||
if (indexDefinition.isShiftEnabled()) {
|
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()) {
|
if (indexDefinition.isCloseShifted()) {
|
||||||
getAlias(indexDefinition.getIndex()).stream()
|
getAlias(indexDefinition.getIndex()).stream()
|
||||||
.filter(s -> !s.equals(indexDefinition.getFullIndexName()))
|
.filter(s -> !s.equals(indexDefinition.getFullIndexName()))
|
||||||
|
|
|
@ -212,6 +212,11 @@ public abstract class AbstractBasicClient implements BasicClient {
|
||||||
return indicesExistsResponse.isExists();
|
return indicesExistsResponse.isExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndexEmpty(IndexDefinition indexDefinition) {
|
||||||
|
return getSearchableDocs(indexDefinition) == 0L;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIndexState(IndexDefinition indexDefinition) {
|
public String getIndexState(IndexDefinition indexDefinition) {
|
||||||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||||
|
|
|
@ -44,6 +44,8 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
||||||
|
|
||||||
private boolean shift;
|
private boolean shift;
|
||||||
|
|
||||||
|
private boolean shiftNotEmpty;
|
||||||
|
|
||||||
private boolean prune;
|
private boolean prune;
|
||||||
|
|
||||||
private boolean forcemerge;
|
private boolean forcemerge;
|
||||||
|
@ -74,6 +76,7 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
||||||
setFullIndexName(index + getDateTimeFormatter().format(LocalDateTime.now()));
|
setFullIndexName(index + getDateTimeFormatter().format(LocalDateTime.now()));
|
||||||
setShardCount(1);
|
setShardCount(1);
|
||||||
setShift(false);
|
setShift(false);
|
||||||
|
setShiftNotEmpty(false);
|
||||||
setPrune(false);
|
setPrune(false);
|
||||||
setForceMerge(false);
|
setForceMerge(false);
|
||||||
setCloseShifted(false);
|
setCloseShifted(false);
|
||||||
|
@ -265,6 +268,16 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
||||||
return shift;
|
return shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setShiftNotEmpty(boolean shiftNotEmpty) {
|
||||||
|
this.shiftNotEmpty = shiftNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isShiftNotEmpty() {
|
||||||
|
return shiftNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPrune(boolean prune) {
|
public void setPrune(boolean prune) {
|
||||||
this.prune = prune;
|
this.prune = prune;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = elx
|
name = elx
|
||||||
version = 7.10.2.45
|
version = 7.10.2.46
|
||||||
|
|
Loading…
Reference in a new issue