use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.
the class RecoverySettingsDynamicUpdateTests method testRetryDelayNetwork.
public void testRetryDelayNetwork() {
long duration = between(1, 1000);
TimeUnit timeUnit = randomFrom(TimeUnit.MILLISECONDS, TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS);
clusterSettings.applySettings(Settings.builder().put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK_SETTING.getKey(), duration, timeUnit).build());
assertEquals(new TimeValue(duration, timeUnit), recoverySettings.retryDelayNetwork());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.
the class RestRecoveryActionTests method testRestRecoveryAction.
public void testRestRecoveryAction() {
final Settings settings = Settings.EMPTY;
final RestController restController = new RestController(settings, Collections.emptySet(), null, null, null);
final RestRecoveryAction action = new RestRecoveryAction(settings, restController);
final int totalShards = randomIntBetween(1, 32);
final int successfulShards = Math.max(0, totalShards - randomIntBetween(1, 2));
final int failedShards = totalShards - successfulShards;
final boolean detailed = randomBoolean();
final Map<String, List<RecoveryState>> shardRecoveryStates = new HashMap<>();
final List<RecoveryState> recoveryStates = new ArrayList<>();
for (int i = 0; i < successfulShards; i++) {
final RecoveryState state = mock(RecoveryState.class);
when(state.getShardId()).thenReturn(new ShardId(new Index("index", "_na_"), i));
final RecoveryState.Timer timer = mock(RecoveryState.Timer.class);
when(timer.time()).thenReturn((long) randomIntBetween(1000000, 10 * 1000000));
when(state.getTimer()).thenReturn(timer);
when(state.getRecoverySource()).thenReturn(TestShardRouting.randomRecoverySource());
when(state.getStage()).thenReturn(randomFrom(RecoveryState.Stage.values()));
final DiscoveryNode sourceNode = randomBoolean() ? mock(DiscoveryNode.class) : null;
if (sourceNode != null) {
when(sourceNode.getHostName()).thenReturn(randomAsciiOfLength(8));
}
when(state.getSourceNode()).thenReturn(sourceNode);
final DiscoveryNode targetNode = mock(DiscoveryNode.class);
when(targetNode.getHostName()).thenReturn(randomAsciiOfLength(8));
when(state.getTargetNode()).thenReturn(targetNode);
RecoveryState.Index index = mock(RecoveryState.Index.class);
final int totalRecoveredFiles = randomIntBetween(1, 64);
when(index.totalRecoverFiles()).thenReturn(totalRecoveredFiles);
final int recoveredFileCount = randomIntBetween(0, totalRecoveredFiles);
when(index.recoveredFileCount()).thenReturn(recoveredFileCount);
when(index.recoveredFilesPercent()).thenReturn((100f * recoveredFileCount) / totalRecoveredFiles);
when(index.totalFileCount()).thenReturn(randomIntBetween(totalRecoveredFiles, 2 * totalRecoveredFiles));
final int totalRecoveredBytes = randomIntBetween(1, 1 << 24);
when(index.totalRecoverBytes()).thenReturn((long) totalRecoveredBytes);
final int recoveredBytes = randomIntBetween(0, totalRecoveredBytes);
when(index.recoveredBytes()).thenReturn((long) recoveredBytes);
when(index.recoveredBytesPercent()).thenReturn((100f * recoveredBytes) / totalRecoveredBytes);
when(index.totalRecoverBytes()).thenReturn((long) randomIntBetween(totalRecoveredBytes, 2 * totalRecoveredBytes));
when(state.getIndex()).thenReturn(index);
final RecoveryState.Translog translog = mock(RecoveryState.Translog.class);
final int translogOps = randomIntBetween(0, 1 << 18);
when(translog.totalOperations()).thenReturn(translogOps);
final int translogOpsRecovered = randomIntBetween(0, translogOps);
when(translog.recoveredOperations()).thenReturn(translogOpsRecovered);
when(translog.recoveredPercent()).thenReturn(translogOps == 0 ? 100f : (100f * translogOpsRecovered / translogOps));
when(state.getTranslog()).thenReturn(translog);
recoveryStates.add(state);
}
final List<RecoveryState> shuffle = new ArrayList<>(recoveryStates);
Randomness.shuffle(shuffle);
shardRecoveryStates.put("index", shuffle);
final List<ShardOperationFailedException> shardFailures = new ArrayList<>();
final RecoveryResponse response = new RecoveryResponse(totalShards, successfulShards, failedShards, detailed, shardRecoveryStates, shardFailures);
final Table table = action.buildRecoveryTable(null, response);
assertNotNull(table);
List<Table.Cell> headers = table.getHeaders();
assertThat(headers.get(0).value, equalTo("index"));
assertThat(headers.get(1).value, equalTo("shard"));
assertThat(headers.get(2).value, equalTo("time"));
assertThat(headers.get(3).value, equalTo("type"));
assertThat(headers.get(4).value, equalTo("stage"));
assertThat(headers.get(5).value, equalTo("source_host"));
assertThat(headers.get(6).value, equalTo("source_node"));
assertThat(headers.get(7).value, equalTo("target_host"));
assertThat(headers.get(8).value, equalTo("target_node"));
assertThat(headers.get(9).value, equalTo("repository"));
assertThat(headers.get(10).value, equalTo("snapshot"));
assertThat(headers.get(11).value, equalTo("files"));
assertThat(headers.get(12).value, equalTo("files_recovered"));
assertThat(headers.get(13).value, equalTo("files_percent"));
assertThat(headers.get(14).value, equalTo("files_total"));
assertThat(headers.get(15).value, equalTo("bytes"));
assertThat(headers.get(16).value, equalTo("bytes_recovered"));
assertThat(headers.get(17).value, equalTo("bytes_percent"));
assertThat(headers.get(18).value, equalTo("bytes_total"));
assertThat(headers.get(19).value, equalTo("translog_ops"));
assertThat(headers.get(20).value, equalTo("translog_ops_recovered"));
assertThat(headers.get(21).value, equalTo("translog_ops_percent"));
assertThat(table.getRows().size(), equalTo(successfulShards));
for (int i = 0; i < successfulShards; i++) {
final RecoveryState state = recoveryStates.get(i);
List<Table.Cell> cells = table.getRows().get(i);
assertThat(cells.get(0).value, equalTo("index"));
assertThat(cells.get(1).value, equalTo(i));
assertThat(cells.get(2).value, equalTo(new TimeValue(state.getTimer().time())));
assertThat(cells.get(3).value, equalTo(state.getRecoverySource().getType().name().toLowerCase(Locale.ROOT)));
assertThat(cells.get(4).value, equalTo(state.getStage().name().toLowerCase(Locale.ROOT)));
assertThat(cells.get(5).value, equalTo(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getHostName()));
assertThat(cells.get(6).value, equalTo(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getName()));
assertThat(cells.get(7).value, equalTo(state.getTargetNode().getHostName()));
assertThat(cells.get(8).value, equalTo(state.getTargetNode().getName()));
assertThat(cells.get(9).value, equalTo(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getRepository()));
assertThat(cells.get(10).value, equalTo(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getSnapshotId().getName()));
assertThat(cells.get(11).value, equalTo(state.getIndex().totalRecoverFiles()));
assertThat(cells.get(12).value, equalTo(state.getIndex().recoveredFileCount()));
assertThat(cells.get(13).value, equalTo(percent(state.getIndex().recoveredFilesPercent())));
assertThat(cells.get(14).value, equalTo(state.getIndex().totalFileCount()));
assertThat(cells.get(15).value, equalTo(state.getIndex().totalRecoverBytes()));
assertThat(cells.get(16).value, equalTo(state.getIndex().recoveredBytes()));
assertThat(cells.get(17).value, equalTo(percent(state.getIndex().recoveredBytesPercent())));
assertThat(cells.get(18).value, equalTo(state.getIndex().totalBytes()));
assertThat(cells.get(19).value, equalTo(state.getTranslog().totalOperations()));
assertThat(cells.get(20).value, equalTo(state.getTranslog().recoveredOperations()));
assertThat(cells.get(21).value, equalTo(percent(state.getTranslog().recoveredPercent())));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.
the class TransportClusterHealthAction method executeHealth.
private void executeHealth(final ClusterHealthRequest request, final ActionListener<ClusterHealthResponse> listener) {
int waitFor = 5;
if (request.waitForStatus() == null) {
waitFor--;
}
if (request.waitForNoRelocatingShards() == false) {
waitFor--;
}
if (request.waitForActiveShards().equals(ActiveShardCount.NONE)) {
waitFor--;
}
if (request.waitForNodes().isEmpty()) {
waitFor--;
}
if (request.indices() == null || request.indices().length == 0) {
// check that they actually exists in the meta data
waitFor--;
}
assert waitFor >= 0;
final ClusterState state = clusterService.state();
final ClusterStateObserver observer = new ClusterStateObserver(state, clusterService, null, logger, threadPool.getThreadContext());
if (request.timeout().millis() == 0) {
listener.onResponse(getResponse(request, state, waitFor, request.timeout().millis() == 0));
return;
}
final int concreteWaitFor = waitFor;
final Predicate<ClusterState> validationPredicate = newState -> validateRequest(request, newState, concreteWaitFor);
final ClusterStateObserver.Listener stateListener = new ClusterStateObserver.Listener() {
@Override
public void onNewClusterState(ClusterState clusterState) {
listener.onResponse(getResponse(request, clusterState, concreteWaitFor, false));
}
@Override
public void onClusterServiceClose() {
listener.onFailure(new IllegalStateException("ClusterService was close during health call"));
}
@Override
public void onTimeout(TimeValue timeout) {
final ClusterHealthResponse response = getResponse(request, observer.setAndGetObservedState(), concreteWaitFor, true);
listener.onResponse(response);
}
};
if (validationPredicate.test(state)) {
stateListener.onNewClusterState(state);
} else {
observer.waitForNextChange(stateListener, validationPredicate, request.timeout());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.
the class ClusterService method runTasks.
void runTasks(TaskInputs taskInputs) {
if (!lifecycle.started()) {
logger.debug("processing [{}]: ignoring, cluster service not started", taskInputs.summary);
return;
}
logger.debug("processing [{}]: execute", taskInputs.summary);
ClusterState previousClusterState = state();
if (!previousClusterState.nodes().isLocalNodeElectedMaster() && taskInputs.runOnlyOnMaster()) {
logger.debug("failing [{}]: local node is no longer master", taskInputs.summary);
taskInputs.onNoLongerMaster();
return;
}
long startTimeNS = currentTimeInNanos();
TaskOutputs taskOutputs = calculateTaskOutputs(taskInputs, previousClusterState, startTimeNS);
taskOutputs.notifyFailedTasks();
if (taskOutputs.clusterStateUnchanged()) {
taskOutputs.notifySuccessfulTasksOnUnchangedClusterState();
TimeValue executionTime = TimeValue.timeValueMillis(Math.max(0, TimeValue.nsecToMSec(currentTimeInNanos() - startTimeNS)));
logger.debug("processing [{}]: took [{}] no change in cluster_state", taskInputs.summary, executionTime);
warnAboutSlowTaskIfNeeded(executionTime, taskInputs.summary);
} else {
ClusterState newClusterState = taskOutputs.newClusterState;
if (logger.isTraceEnabled()) {
logger.trace("cluster state updated, source [{}]\n{}", taskInputs.summary, newClusterState);
} else if (logger.isDebugEnabled()) {
logger.debug("cluster state updated, version [{}], source [{}]", newClusterState.version(), taskInputs.summary);
}
try {
publishAndApplyChanges(taskInputs, taskOutputs);
TimeValue executionTime = TimeValue.timeValueMillis(Math.max(0, TimeValue.nsecToMSec(currentTimeInNanos() - startTimeNS)));
logger.debug("processing [{}]: took [{}] done applying updated cluster_state (version: {}, uuid: {})", taskInputs.summary, executionTime, newClusterState.version(), newClusterState.stateUUID());
warnAboutSlowTaskIfNeeded(executionTime, taskInputs.summary);
} catch (Exception e) {
TimeValue executionTime = TimeValue.timeValueMillis(Math.max(0, TimeValue.nsecToMSec(currentTimeInNanos() - startTimeNS)));
final long version = newClusterState.version();
final String stateUUID = newClusterState.stateUUID();
final String fullState = newClusterState.toString();
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to apply updated cluster state in [{}]:\nversion [{}], uuid [{}], source [{}]\n{}", executionTime, version, stateUUID, taskInputs.summary, fullState), e);
// TODO: do we want to call updateTask.onFailure here?
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.
the class RestRecoveryAction method buildRecoveryTable.
/**
* buildRecoveryTable will build a table of recovery information suitable
* for displaying at the command line.
*
* @param request A Rest request
* @param response A recovery status response
* @return A table containing index, shardId, node, target size, recovered size and percentage for each recovering replica
*/
public Table buildRecoveryTable(RestRequest request, RecoveryResponse response) {
Table t = getTableWithHeader(request);
for (String index : response.shardRecoveryStates().keySet()) {
List<RecoveryState> shardRecoveryStates = response.shardRecoveryStates().get(index);
if (shardRecoveryStates.size() == 0) {
continue;
}
// Sort ascending by shard id for readability
CollectionUtil.introSort(shardRecoveryStates, new Comparator<RecoveryState>() {
@Override
public int compare(RecoveryState o1, RecoveryState o2) {
int id1 = o1.getShardId().id();
int id2 = o2.getShardId().id();
if (id1 < id2) {
return -1;
} else if (id1 > id2) {
return 1;
} else {
return 0;
}
}
});
for (RecoveryState state : shardRecoveryStates) {
t.startRow();
t.addCell(index);
t.addCell(state.getShardId().id());
t.addCell(new TimeValue(state.getTimer().time()));
t.addCell(state.getRecoverySource().getType().toString().toLowerCase(Locale.ROOT));
t.addCell(state.getStage().toString().toLowerCase(Locale.ROOT));
t.addCell(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getHostName());
t.addCell(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getName());
t.addCell(state.getTargetNode().getHostName());
t.addCell(state.getTargetNode().getName());
t.addCell(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getRepository());
t.addCell(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getSnapshotId().getName());
t.addCell(state.getIndex().totalRecoverFiles());
t.addCell(state.getIndex().recoveredFileCount());
t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getIndex().recoveredFilesPercent()));
t.addCell(state.getIndex().totalFileCount());
t.addCell(state.getIndex().totalRecoverBytes());
t.addCell(state.getIndex().recoveredBytes());
t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getIndex().recoveredBytesPercent()));
t.addCell(state.getIndex().totalBytes());
t.addCell(state.getTranslog().totalOperations());
t.addCell(state.getTranslog().recoveredOperations());
t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getTranslog().recoveredPercent()));
t.endRow();
}
}
return t;
}
Aggregations