protected Releasable getIndexShardOperationsCounter(ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.index().getName()); IndexShard indexShard = indexService.shardSafe(shardId.id()); return new IndexShardReference(indexShard); }
@Override protected RecoveryState shardOperation(RecoveryRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id()); return indexShard.recoveryState(); }
@Override protected EmptyResult shardOperation(ForceMergeRequest request, ShardRouting shardRouting) throws IOException { IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).shardSafe(shardRouting.shardId().id()); indexShard.forceMerge(request); return EmptyResult.INSTANCE; }
@Override protected ShardSegments shardOperation(IndicesSegmentsRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.getIndex()); IndexShard indexShard = indexService.shardSafe(shardRouting.id()); return new ShardSegments(indexShard.routingEntry(), indexShard.engine().segments(request.verbose())); } }
@Override protected void shardOperationOnReplica(ReplicationRequest request) { IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id()); indexShard.refresh("api"); logger.trace("{} refresh request executed on replica", indexShard.shardId()); }
@Override protected void shardOperationOnReplica(IndexRequest request) { final ShardId shardId = request.shardId(); IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.shardSafe(shardId.id()); final Engine.IndexingOperation operation = executeIndexRequestOnReplica(request, indexShard); processAfterWrite(request.refresh(), indexShard, operation.getTranslogLocation()); }
@Override protected TermVectorsResponse shardOperation(TermVectorsRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.shardSafe(shardId.id()); TermVectorsResponse response = indexShard.termVectorsService().getTermVectors(request, shardId.getIndex()); response.updateTookInMillis(request.startTime()); return response; }
private InFlightOpsResponse performInFlightOps(InFlightOpsRequest request) { IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(request.shardId().id()); if (indexShard.routingEntry().primary() == false) { throw new IllegalStateException("[" + request.shardId() +"] expected a primary shard"); } int opCount = indexShard.getOperationsCount(); logger.trace("{} in flight operations sampled at [{}]", request.shardId(), opCount); return new InFlightOpsResponse(opCount); }
@Override protected Tuple<DeleteResponse, DeleteRequest> shardOperationOnPrimary(MetaData metaData, DeleteRequest request) { IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id()); final WriteResult<DeleteResponse> result = executeDeleteRequestOnPrimary(request, indexShard); processAfterWrite(request.refresh(), indexShard, result.location); return new Tuple<>(result.response, request); }
@Override protected void shardOperationOnReplica(DeleteRequest request) { IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id()); Engine.Delete delete = executeDeleteRequestOnReplica(request, indexShard); processAfterWrite(request.refresh(), indexShard, delete.getTranslogLocation()); } }
@Override protected void shardOperationOnReplica(ShardFlushRequest request) { IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id()); indexShard.flush(request.getRequest()); logger.trace("{} flush request executed on replica", indexShard.shardId()); }
@Override protected ShardUpgradeResult shardOperation(UpgradeRequest request, ShardRouting shardRouting) throws IOException { IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).shardSafe(shardRouting.shardId().id()); org.apache.lucene.util.Version oldestLuceneSegment = indexShard.upgrade(request); // We are using the current version of Elasticsearch as upgrade version since we update mapping to match the current version return new ShardUpgradeResult(shardRouting.shardId(), indexShard.routingEntry().primary(), Version.CURRENT, oldestLuceneSegment); }
@Override protected ShardIndexVersion shardOperation(GetIndicesVersionRequest request, ShardRouting shardRouting) throws IOException { IndexService indexService = indicesService.indexServiceSafe(shardRouting.getIndex()); IndexShard indexShard = indexService.shardSafe(shardRouting.id()); // Get the IndexVersionShardService associated to this shard Injector injector = indexService.shardInjectorSafe(shardRouting.id()); IndexVersionShardService indexVersionService = injector.getBinding(IndexVersionShardService.class).getProvider().get(); long version = indexVersionService.getVersion(); return new ShardIndexVersion(indexShard.routingEntry(), version); }
@Override protected Tuple<ActionWriteResponse, ReplicationRequest> shardOperationOnPrimary(MetaData metaData, ReplicationRequest shardRequest) throws Throwable { IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId().getIndex()).shardSafe(shardRequest.shardId().id()); indexShard.refresh("api"); logger.trace("{} refresh request executed on primary", indexShard.shardId()); return new Tuple<>(new ActionWriteResponse(), shardRequest); }
@Override protected Tuple<ActionWriteResponse, ShardFlushRequest> shardOperationOnPrimary(MetaData metaData, ShardFlushRequest shardRequest) throws Throwable { IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId().getIndex()).shardSafe(shardRequest.shardId().id()); indexShard.flush(shardRequest.getRequest()); logger.trace("{} flush request executed on primary", indexShard.shardId()); return new Tuple<>(new ActionWriteResponse(), shardRequest); }
@Override protected ShardUpgradeStatus shardOperation(UpgradeStatusRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id()); List<Segment> segments = indexShard.engine().segments(false); long total_bytes = 0; long to_upgrade_bytes = 0; long to_upgrade_bytes_ancient = 0; for (Segment seg : segments) { total_bytes += seg.sizeInBytes; if (seg.version.major != Version.CURRENT.luceneVersion.major) { to_upgrade_bytes_ancient += seg.sizeInBytes; to_upgrade_bytes += seg.sizeInBytes; } else if (seg.version.minor != Version.CURRENT.luceneVersion.minor) { // TODO: this comparison is bogus! it would cause us to upgrade even with the same format // instead, we should check if the codec has changed to_upgrade_bytes += seg.sizeInBytes; } } return new ShardUpgradeStatus(indexShard.routingEntry(), total_bytes, to_upgrade_bytes, to_upgrade_bytes_ancient); } }
private PreSyncedFlushResponse performPreSyncedFlush(PreShardSyncedFlushRequest request) { IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id()); FlushRequest flushRequest = new FlushRequest().force(false).waitIfOngoing(true); logger.trace("{} performing pre sync flush", request.shardId()); Engine.CommitId commitId = indexShard.flush(flushRequest); logger.trace("{} pre sync flush done. commit id {}", request.shardId(), commitId); return new PreSyncedFlushResponse(commitId); }
@Override protected GetResponse shardOperation(GetRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.shardSafe(shardId.id()); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_get"); } GetResult result = indexShard.getService().get(request.type(), request.id(), request.fields(), request.realtime(), request.version(), request.versionType(), request.fetchSourceContext(), request.ignoreErrorsOnGeneratedFields()); return new GetResponse(result); }
private ShardSyncedFlushResponse performSyncedFlush(ShardSyncedFlushRequest request) { IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(request.shardId().id()); logger.trace("{} performing sync flush. sync id [{}], expected commit id {}", request.shardId(), request.syncId(), request.expectedCommitId()); Engine.SyncedFlushResult result = indexShard.syncFlush(request.syncId(), request.expectedCommitId()); logger.trace("{} sync flush done. sync id [{}], result [{}]", request.shardId(), request.syncId(), result); switch (result) { case SUCCESS: return new ShardSyncedFlushResponse(); case COMMIT_MISMATCH: return new ShardSyncedFlushResponse("commit has changed"); case PENDING_OPERATIONS: return new ShardSyncedFlushResponse("pending operations"); default: throw new ElasticsearchException("unknown synced flush result [" + result + "]"); } }
@Override protected Tuple<IndexResponse, IndexRequest> shardOperationOnPrimary(MetaData metaData, IndexRequest request) throws Throwable { // validate, if routing is required, that we got routing IndexMetaData indexMetaData = metaData.index(request.shardId().getIndex()); MappingMetaData mappingMd = indexMetaData.mappingOrDefault(request.type()); if (mappingMd != null && mappingMd.routing().required()) { if (request.routing() == null) { throw new RoutingMissingException(request.shardId().getIndex(), request.type(), request.id()); } } IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(request.shardId().id()); final WriteResult<IndexResponse> result = executeIndexRequestOnPrimary(null, request, indexShard, mappingUpdatedAction); final IndexResponse response = result.response; final Translog.Location location = result.location; processAfterWrite(request.refresh(), indexShard, location); return new Tuple<>(response, request); }