@Override public String toString() { return "local_shard_snapshot:[" + shard.shardId() + " indexCommit: " + indexCommit + "]"; } }
public ShardGetService(IndexSettings indexSettings, IndexShard indexShard, MapperService mapperService) { super(indexShard.shardId(), indexSettings); this.mapperService = mapperService; this.indexShard = indexShard; }
@Override public void onFailure(Exception e) { logger.warn(() -> new ParameterizedMessage("failed to write indexing buffer for shard [{}]; ignoring", shard.shardId()), e); } });
@Override public void onFailure(Exception e) { logger.debug(() -> new ParameterizedMessage("{} sync flush on inactive shard failed", indexShard.shardId()), e); } });
/** * ask this shard to check now whether it is inactive, and reduces its indexing buffer if so. */ protected void checkIdle(IndexShard shard, long inactiveTimeNS) { try { shard.checkIdle(inactiveTimeNS); } catch (AlreadyClosedException e) { logger.trace(() -> new ParameterizedMessage("ignore exception while checking if shard {} is inactive", shard.shardId()), e); } } }
@Override protected ReplicaResult shardOperationOnReplica(BasicReplicationRequest request, IndexShard replica) { replica.refresh("api"); logger.trace("{} refresh request executed on replica", replica.shardId()); return new ReplicaResult(); } }
@Override public void onShardInactive(IndexShard indexShard) { for (IndexEventListener listener : listeners) { try { listener.onShardInactive(indexShard); } catch (Exception e) { logger.warn(() -> new ParameterizedMessage("[{}] failed to invoke on shard inactive callback", indexShard.shardId().getId()), e); throw e; } } }
@Override public void afterIndexShardStarted(IndexShard indexShard) { for (IndexEventListener listener : listeners) { try { listener.afterIndexShardStarted(indexShard); } catch (Exception e) { logger.warn(() -> new ParameterizedMessage("[{}] failed to invoke after shard started callback", indexShard.shardId().getId()), e); throw e; } } }
@Override protected ReplicaResult shardOperationOnReplica(ShardFlushRequest request, IndexShard replica) { replica.flush(request.getRequest()); logger.trace("{} flush request executed on replica", replica.shardId()); return new ReplicaResult(); } }
@Override public void afterIndexShardCreated(IndexShard indexShard) { for (IndexEventListener listener : listeners) { try { listener.afterIndexShardCreated(indexShard); } catch (Exception e) { logger.warn(() -> new ParameterizedMessage("[{}] failed to invoke after shard created callback", indexShard.shardId().getId()), e); throw e; } } }
@Override public void restoreShard(IndexShard shard, SnapshotId snapshotId, Version version, IndexId indexId, ShardId snapshotShardId, RecoveryState recoveryState) { final RestoreContext snapshotContext = new RestoreContext(shard, snapshotId, indexId, snapshotShardId, recoveryState); try { snapshotContext.restore(); } catch (Exception e) { throw new IndexShardRestoreFailedException(shard.shardId(), "failed to restore snapshot [" + snapshotId + "]", e); } }
@Override public void shardRoutingChanged(IndexShard indexShard, @Nullable ShardRouting oldRouting, ShardRouting newRouting) { for (IndexEventListener listener : listeners) { try { listener.shardRoutingChanged(indexShard, oldRouting, newRouting); } catch (Exception e) { logger.warn(() -> new ParameterizedMessage("[{}] failed to invoke shard touring changed callback", indexShard.shardId().getId()), e); } } }
@Override protected PrimaryResult shardOperationOnPrimary(BasicReplicationRequest shardRequest, IndexShard primary) { primary.refresh("api"); logger.trace("{} refresh request executed on primary", primary.shardId()); return new PrimaryResult(shardRequest, new ReplicationResponse()); }
public Engine.SyncedFlushResult syncFlush(String syncId, Engine.CommitId expectedCommitId) { verifyNotClosed(); logger.trace("trying to sync flush. sync id [{}]. expected commit id [{}]]", syncId, expectedCommitId); Engine engine = getEngine(); if (engine.isRecovering()) { throw new IllegalIndexShardStateException(shardId(), state, "syncFlush is only allowed if the engine is not recovery" + " from translog"); } return engine.syncFlush(syncId, expectedCommitId); }
@Override protected PrimaryResult shardOperationOnPrimary(ShardFlushRequest shardRequest, IndexShard primary) { primary.flush(shardRequest.getRequest()); logger.trace("{} flush request executed on primary", primary.shardId()); return new PrimaryResult(shardRequest, new ReplicationResponse()); }
@Override public void indexShardStateChanged(IndexShard indexShard, @Nullable IndexShardState previousState, IndexShardState currentState, @Nullable String reason) { for (IndexEventListener listener : listeners) { try { listener.indexShardStateChanged(indexShard, previousState, indexShard.state(), reason); } catch (Exception e) { logger.warn(() -> new ParameterizedMessage("[{}] failed to invoke index shard state changed callback", indexShard.shardId().getId()), e); throw e; } } }
@Override protected void onCancel(String reason, @Nullable Exception suppressedException) { RuntimeException e; if (shard.state() == IndexShardState.CLOSED) { // check if the shard got closed on us e = new IndexShardClosedException(shard.shardId(), "shard is closed and recovery was canceled reason [" + reason + "]"); } else { e = new ExecutionCancelledException("recovery was canceled reason [" + reason + "]"); } if (suppressedException != null) { e.addSuppressed(suppressedException); } throw e; } };
private void freeAllContextForIndex(Index index) { assert index != null; for (SearchContext ctx : activeContexts.values()) { if (index.equals(ctx.indexShard().shardId().getIndex())) { freeContext(ctx.id()); } } }
/** * Prepares an update request by converting it into an index or delete request or an update response (no action). */ public Result prepare(UpdateRequest request, IndexShard indexShard, LongSupplier nowInMillis) { final GetResult getResult = indexShard.getService().getForUpdate(request.type(), request.id(), request.version(), request.versionType()); return prepare(indexShard.shardId(), request, getResult, nowInMillis); }
private static void executeDeleteRequestOnPrimary(BulkPrimaryExecutionContext context, MappingUpdatePerformer mappingUpdater) throws Exception { final DeleteRequest request = context.getRequestToExecute(); final IndexShard primary = context.getPrimary(); executeOnPrimaryWhileHandlingMappingUpdates(context, () -> primary.applyDeleteOperationOnPrimary(request.version(), request.type(), request.id(), request.versionType(), request.ifSeqNo(), request.ifPrimaryTerm()), e -> primary.getFailedDeleteResult(e, request.version()), context::markOperationAsExecuted, mapping -> mappingUpdater.updateMappings(mapping, primary.shardId(), request.type())); }