rename fooSafe into getFoo and getFooOrNull
This commit is contained in:
parent
e94f242456
commit
674a9851cf
|
@ -83,7 +83,7 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastByNodeAc
|
|||
protected EmptyResult shardOperation(ClearIndicesCacheRequest request, ShardRouting shardRouting) {
|
||||
IndexService service = indicesService.indexService(shardRouting.getIndex());
|
||||
if (service != null) {
|
||||
IndexShard shard = service.shard(shardRouting.id());
|
||||
IndexShard shard = service.getShardOrNull(shardRouting.id());
|
||||
boolean clearedAtLeastOne = false;
|
||||
if (request.queryCache()) {
|
||||
clearedAtLeastOne = true;
|
||||
|
|
|
@ -62,7 +62,7 @@ public class TransportShardFlushAction extends TransportReplicationAction<ShardF
|
|||
|
||||
@Override
|
||||
protected Tuple<ActionWriteResponse, ShardFlushRequest> shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) throws Throwable {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId.getIndex()).shardSafe(shardRequest.shardId.id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId.getIndex()).getShard(shardRequest.shardId.id());
|
||||
indexShard.flush(shardRequest.request.getRequest());
|
||||
logger.trace("{} flush request executed on primary", indexShard.shardId());
|
||||
return new Tuple<>(new ActionWriteResponse(), shardRequest.request);
|
||||
|
@ -70,7 +70,7 @@ public class TransportShardFlushAction extends TransportReplicationAction<ShardF
|
|||
|
||||
@Override
|
||||
protected void shardOperationOnReplica(ShardId shardId, ShardFlushRequest request) {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).getShard(request.shardId().id());
|
||||
indexShard.flush(request.getRequest());
|
||||
logger.trace("{} flush request executed on replica", indexShard.shardId());
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class TransportOptimizeAction extends TransportBroadcastByNodeAction<Opti
|
|||
|
||||
@Override
|
||||
protected EmptyResult shardOperation(OptimizeRequest request, ShardRouting shardRouting) throws IOException {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).shardSafe(shardRouting.shardId().id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(shardRouting.shardId().id());
|
||||
indexShard.optimize(request);
|
||||
return EmptyResult.INSTANCE;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ public class TransportRecoveryAction extends TransportBroadcastByNodeAction<Reco
|
|||
@Override
|
||||
protected RecoveryState shardOperation(RecoveryRequest request, ShardRouting shardRouting) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
|
||||
return indexShard.recoveryState();
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ public class TransportShardRefreshAction extends TransportReplicationAction<Repl
|
|||
|
||||
@Override
|
||||
protected Tuple<ActionWriteResponse, ReplicationRequest> shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) throws Throwable {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId.getIndex()).shardSafe(shardRequest.shardId.id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId.getIndex()).getShard(shardRequest.shardId.id());
|
||||
indexShard.refresh("api");
|
||||
logger.trace("{} refresh request executed on primary", indexShard.shardId());
|
||||
return new Tuple<>(new ActionWriteResponse(), shardRequest.request);
|
||||
|
@ -71,7 +71,7 @@ public class TransportShardRefreshAction extends TransportReplicationAction<Repl
|
|||
|
||||
@Override
|
||||
protected void shardOperationOnReplica(ShardId shardId, ReplicationRequest request) {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).shardSafe(shardId.id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).getShard(shardId.id());
|
||||
indexShard.refresh("api");
|
||||
logger.trace("{} refresh request executed on replica", indexShard.shardId());
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class TransportIndicesSegmentsAction extends TransportBroadcastByNodeActi
|
|||
@Override
|
||||
protected ShardSegments shardOperation(IndicesSegmentsRequest request, ShardRouting shardRouting) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardRouting.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardRouting.id());
|
||||
IndexShard indexShard = indexService.getShard(shardRouting.id());
|
||||
return new ShardSegments(indexShard.routingEntry(), indexShard.segments(request.verbose()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class TransportIndicesStatsAction extends TransportBroadcastByNodeAction<
|
|||
@Override
|
||||
protected ShardStats shardOperation(IndicesStatsRequest request, ShardRouting shardRouting) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
|
||||
// if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet
|
||||
if (indexShard.routingEntry() == null) {
|
||||
throw new ShardNotFoundException(indexShard.shardId());
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TransportUpgradeStatusAction extends TransportBroadcastByNodeAction
|
|||
@Override
|
||||
protected ShardUpgradeStatus shardOperation(UpgradeStatusRequest request, ShardRouting shardRouting) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
|
||||
List<Segment> segments = indexShard.segments(false);
|
||||
long total_bytes = 0;
|
||||
long to_upgrade_bytes = 0;
|
||||
|
|
|
@ -119,7 +119,7 @@ public class TransportUpgradeAction extends TransportBroadcastByNodeAction<Upgra
|
|||
|
||||
@Override
|
||||
protected ShardUpgradeResult shardOperation(UpgradeRequest request, ShardRouting shardRouting) throws IOException {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).shardSafe(shardRouting.shardId().id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(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);
|
||||
|
|
|
@ -163,7 +163,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
|
|||
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexQueryParserService queryParserService = indexService.queryParserService();
|
||||
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
||||
|
||||
boolean valid;
|
||||
String explanation = null;
|
||||
|
|
|
@ -116,7 +116,7 @@ public class TransportShardBulkAction extends TransportReplicationAction<BulkSha
|
|||
protected Tuple<BulkShardResponse, BulkShardRequest> shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) {
|
||||
final BulkShardRequest request = shardRequest.request;
|
||||
final IndexService indexService = indicesService.indexServiceSafe(request.index());
|
||||
final IndexShard indexShard = indexService.shardSafe(shardRequest.shardId.id());
|
||||
final IndexShard indexShard = indexService.getShard(shardRequest.shardId.id());
|
||||
|
||||
long[] preVersions = new long[request.items().length];
|
||||
VersionType[] preVersionTypes = new VersionType[request.items().length];
|
||||
|
@ -447,7 +447,7 @@ public class TransportShardBulkAction extends TransportReplicationAction<BulkSha
|
|||
@Override
|
||||
protected void shardOperationOnReplica(ShardId shardId, BulkShardRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
Translog.Location location = null;
|
||||
for (int i = 0; i < request.items().length; i++) {
|
||||
BulkItemRequest item = request.items()[i];
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.elasticsearch.index.VersionType;
|
|||
import org.elasticsearch.index.engine.Engine;
|
||||
import org.elasticsearch.index.shard.IndexShard;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.translog.Translog;
|
||||
import org.elasticsearch.indices.IndexAlreadyExistsException;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -130,7 +129,7 @@ public class TransportDeleteAction extends TransportReplicationAction<DeleteRequ
|
|||
@Override
|
||||
protected Tuple<DeleteResponse, DeleteRequest> shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) {
|
||||
DeleteRequest request = shardRequest.request;
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId.getIndex()).shardSafe(shardRequest.shardId.id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.shardId.getIndex()).getShard(shardRequest.shardId.id());
|
||||
Engine.Delete delete = indexShard.prepareDelete(request.type(), request.id(), request.version(), request.versionType(), Engine.Operation.Origin.PRIMARY);
|
||||
indexShard.delete(delete);
|
||||
// update the request with teh version so it will go to the replicas
|
||||
|
@ -146,7 +145,7 @@ public class TransportDeleteAction extends TransportReplicationAction<DeleteRequ
|
|||
|
||||
@Override
|
||||
protected void shardOperationOnReplica(ShardId shardId, DeleteRequest request) {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).shardSafe(shardId.id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).getShard(shardId.id());
|
||||
Engine.Delete delete = indexShard.prepareDelete(request.type(), request.id(), request.version(), request.versionType(), Engine.Operation.Origin.REPLICA);
|
||||
|
||||
indexShard.delete(delete);
|
||||
|
|
|
@ -148,7 +148,7 @@ public class TransportExistsAction extends TransportBroadcastAction<ExistsReques
|
|||
@Override
|
||||
protected ShardExistsResponse shardOperation(ShardExistsRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
||||
|
||||
SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.shardId().getIndex(), request.shardId().id());
|
||||
SearchContext context = new DefaultSearchContext(0,
|
||||
|
|
|
@ -104,7 +104,7 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
|
|||
@Override
|
||||
protected ExplainResponse shardOperation(ExplainRequest request, ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id()));
|
||||
Engine.GetResult result = indexShard.get(new Engine.Get(false, uidTerm));
|
||||
if (!result.exists()) {
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TransportFieldStatsTransportAction extends TransportBroadcastAction
|
|||
Map<String, FieldStats> fieldStats = new HashMap<>();
|
||||
IndexService indexServices = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
MapperService mapperService = indexServices.mapperService();
|
||||
IndexShard shard = indexServices.shardSafe(shardId.id());
|
||||
IndexShard shard = indexServices.getShard(shardId.id());
|
||||
try (Engine.Searcher searcher = shard.acquireSearcher("fieldstats")) {
|
||||
for (String field : request.getFields()) {
|
||||
MappedFieldType fieldType = mapperService.fullName(field);
|
||||
|
|
|
@ -92,7 +92,7 @@ public class TransportGetAction extends TransportSingleShardAction<GetRequest, G
|
|||
@Override
|
||||
protected GetResponse shardOperation(GetRequest request, ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
|
||||
if (request.refresh() && !request.realtime()) {
|
||||
indexShard.refresh("refresh_flag_get");
|
||||
|
|
|
@ -87,7 +87,7 @@ public class TransportShardMultiGetAction extends TransportSingleShardAction<Mul
|
|||
@Override
|
||||
protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
|
||||
if (request.refresh() && !request.realtime()) {
|
||||
indexShard.refresh("refresh_flag_mget");
|
||||
|
|
|
@ -164,7 +164,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
|
|||
}
|
||||
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardRequest.shardId.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardRequest.shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardRequest.shardId.id());
|
||||
|
||||
final WriteResult<IndexResponse> result = executeIndexRequestOnPrimary(null, request, indexShard);
|
||||
final IndexResponse response = result.response;
|
||||
|
@ -176,7 +176,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
|
|||
@Override
|
||||
protected void shardOperationOnReplica(ShardId shardId, IndexRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.REPLICA, request.source()).index(shardId.getIndex()).type(request.type()).id(request.id())
|
||||
.routing(request.routing()).parent(request.parent()).timestamp(request.timestamp()).ttl(request.ttl());
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ public class TransportSuggestAction extends TransportBroadcastAction<SuggestRequ
|
|||
@Override
|
||||
protected ShardSuggestResponse shardOperation(ShardSuggestRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
||||
ShardSuggestMetric suggestMetric = indexShard.getSuggestMetric();
|
||||
suggestMetric.preSuggest();
|
||||
long startTime = System.nanoTime();
|
||||
|
|
|
@ -666,7 +666,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
|
||||
protected Releasable getIndexShardOperationsCounter(ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.index().getName());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
return new IndexShardReference(indexShard);
|
||||
}
|
||||
|
||||
|
@ -678,7 +678,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
logger.debug("ignoring failed replica [{}][{}] because index was already removed.", index, shardId);
|
||||
return;
|
||||
}
|
||||
IndexShard indexShard = indexService.shard(shardId);
|
||||
IndexShard indexShard = indexService.getShardOrNull(shardId);
|
||||
if (indexShard == null) {
|
||||
logger.debug("ignoring failed replica [{}][{}] because index was already removed.", index, shardId);
|
||||
return;
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TransportShardMultiTermsVectorAction extends TransportSingleShardAc
|
|||
TermVectorsRequest termVectorsRequest = request.requests.get(i);
|
||||
try {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.index());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
TermVectorsResponse termVectorsResponse = indexShard.getTermVectors(termVectorsRequest);
|
||||
termVectorsResponse.updateTookInMillis(termVectorsRequest.startTime());
|
||||
response.add(request.locations.get(i), termVectorsResponse);
|
||||
|
|
|
@ -82,7 +82,7 @@ public class TransportTermVectorsAction extends TransportSingleShardAction<TermV
|
|||
@Override
|
||||
protected TermVectorsResponse shardOperation(TermVectorsRequest request, ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
TermVectorsResponse response = indexShard.getTermVectors(request);
|
||||
response.updateTookInMillis(request.startTime());
|
||||
return response;
|
||||
|
|
|
@ -166,7 +166,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
|||
|
||||
protected void shardOperation(final UpdateRequest request, final ActionListener<UpdateResponse> listener, final int retryCount) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.concreteIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(request.shardId());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId());
|
||||
final UpdateHelper.Result result = updateHelper.prepare(request, indexShard);
|
||||
switch (result.operation()) {
|
||||
case UPSERT:
|
||||
|
@ -266,7 +266,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
|||
UpdateResponse update = result.action();
|
||||
IndexService indexServiceOrNull = indicesService.indexService(request.concreteIndex());
|
||||
if (indexServiceOrNull != null) {
|
||||
IndexShard shard = indexService.shard(request.shardId());
|
||||
IndexShard shard = indexService.getShardOrNull(request.shardId());
|
||||
if (shard != null) {
|
||||
shard.indexingService().noopUpdate(request.type());
|
||||
}
|
||||
|
|
|
@ -67,21 +67,15 @@ import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
|
|||
public class IndexService extends AbstractIndexComponent implements IndexComponent, Iterable<IndexShard> {
|
||||
|
||||
private final Settings indexSettings;
|
||||
|
||||
private final InternalIndicesLifecycle indicesLifecycle;
|
||||
|
||||
private final AnalysisService analysisService;
|
||||
|
||||
private final IndexFieldDataService indexFieldData;
|
||||
|
||||
private final BitsetFilterCache bitsetFilterCache;
|
||||
|
||||
private final IndexSettingsService settingsService;
|
||||
private final NodeEnvironment nodeEnv;
|
||||
private final IndicesService indicesServices;
|
||||
private final IndexServicesProvider indexServicesProvider;
|
||||
private final IndexStore indexStore;
|
||||
|
||||
private volatile ImmutableMap<Integer, IndexShard> shards = ImmutableMap.of();
|
||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
private final AtomicBoolean deleted = new AtomicBoolean(false);
|
||||
|
@ -131,15 +125,15 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
|||
* Return the shard with the provided id, or null if there is no such shard.
|
||||
*/
|
||||
@Nullable
|
||||
public IndexShard shard(int shardId) {
|
||||
public IndexShard getShardOrNull(int shardId) {
|
||||
return shards.get(shardId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shard with the provided id, or throw an exception if it doesn't exist.
|
||||
*/
|
||||
public IndexShard shardSafe(int shardId) {
|
||||
IndexShard indexShard = shard(shardId);
|
||||
public IndexShard getShard(int shardId) {
|
||||
IndexShard indexShard = getShardOrNull(shardId);
|
||||
if (indexShard == null) {
|
||||
throw new ShardNotFoundException(new ShardId(index, shardId));
|
||||
}
|
||||
|
@ -420,7 +414,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
|||
@Override
|
||||
public void onCache(ShardId shardId, Accountable accountable) {
|
||||
if (shardId != null) {
|
||||
final IndexShard shard = indexService.shard(shardId.id());
|
||||
final IndexShard shard = indexService.getShardOrNull(shardId.id());
|
||||
if (shard != null) {
|
||||
long ramBytesUsed = accountable != null ? accountable.ramBytesUsed() : 0l;
|
||||
shard.shardBitsetFilterCache().onCached(ramBytesUsed);
|
||||
|
@ -431,7 +425,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
|||
@Override
|
||||
public void onRemoval(ShardId shardId, Accountable accountable) {
|
||||
if (shardId != null) {
|
||||
final IndexShard shard = indexService.shard(shardId.id());
|
||||
final IndexShard shard = indexService.getShardOrNull(shardId.id());
|
||||
if (shard != null) {
|
||||
long ramBytesUsed = accountable != null ? accountable.ramBytesUsed() : 0l;
|
||||
shard.shardBitsetFilterCache().onRemoval(ramBytesUsed);
|
||||
|
@ -450,7 +444,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
|||
@Override
|
||||
public void onCache(ShardId shardId, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, Accountable ramUsage) {
|
||||
if (shardId != null) {
|
||||
final IndexShard shard = indexService.shard(shardId.id());
|
||||
final IndexShard shard = indexService.getShardOrNull(shardId.id());
|
||||
if (shard != null) {
|
||||
shard.fieldData().onCache(shardId, fieldNames, fieldDataType, ramUsage);
|
||||
}
|
||||
|
@ -460,7 +454,7 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
|
|||
@Override
|
||||
public void onRemoval(ShardId shardId, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, boolean wasEvicted, long sizeInBytes) {
|
||||
if (shardId != null) {
|
||||
final IndexShard shard = indexService.shard(shardId.id());
|
||||
final IndexShard shard = indexService.getShardOrNull(shardId.id());
|
||||
if (shard != null) {
|
||||
shard.fieldData().onRemoval(shardId, fieldNames, fieldDataType, wasEvicted, sizeInBytes);
|
||||
}
|
||||
|
|
|
@ -338,7 +338,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
if (newRouting.state() == ShardRoutingState.STARTED || newRouting.state() == ShardRoutingState.RELOCATING) {
|
||||
// we want to refresh *before* we move to internal STARTED state
|
||||
try {
|
||||
engine().refresh("cluster_state_started");
|
||||
getEngine().refresh("cluster_state_started");
|
||||
} catch (Throwable t) {
|
||||
logger.debug("failed to refresh due to move to cluster wide started", t);
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("index [{}][{}]{}", create.type(), create.id(), create.docs());
|
||||
}
|
||||
engine().create(create);
|
||||
getEngine().create(create);
|
||||
create.endTime(System.nanoTime());
|
||||
} catch (Throwable ex) {
|
||||
indexingService.postCreate(create, ex);
|
||||
|
@ -486,7 +486,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("index [{}][{}]{}", index.type(), index.id(), index.docs());
|
||||
}
|
||||
created = engine().index(index);
|
||||
created = getEngine().index(index);
|
||||
index.endTime(System.nanoTime());
|
||||
} catch (Throwable ex) {
|
||||
indexingService.postIndex(index, ex);
|
||||
|
@ -509,7 +509,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("delete [{}]", delete.uid().text());
|
||||
}
|
||||
engine().delete(delete);
|
||||
getEngine().delete(delete);
|
||||
delete.endTime(System.nanoTime());
|
||||
} catch (Throwable ex) {
|
||||
indexingService.postDelete(delete, ex);
|
||||
|
@ -520,7 +520,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
|
||||
public Engine.GetResult get(Engine.Get get) {
|
||||
readAllowed();
|
||||
return engine().get(get);
|
||||
return getEngine().get(get);
|
||||
}
|
||||
|
||||
public void refresh(String source) {
|
||||
|
@ -529,7 +529,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
logger.trace("refresh with source: {}", source);
|
||||
}
|
||||
long time = System.nanoTime();
|
||||
engine().refresh(source);
|
||||
getEngine().refresh(source);
|
||||
refreshMetric.inc(System.nanoTime() - time);
|
||||
}
|
||||
|
||||
|
@ -555,7 +555,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
*/
|
||||
@Nullable
|
||||
public CommitStats commitStats() {
|
||||
Engine engine = engineUnsafe();
|
||||
Engine engine = getEngineOrNull();
|
||||
return engine == null ? null : engine.commitStats();
|
||||
}
|
||||
|
||||
|
@ -582,7 +582,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
}
|
||||
|
||||
public MergeStats mergeStats() {
|
||||
final Engine engine = engineUnsafe();
|
||||
final Engine engine = getEngineOrNull();
|
||||
if (engine == null) {
|
||||
return new MergeStats();
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
}
|
||||
|
||||
public SegmentsStats segmentStats() {
|
||||
SegmentsStats segmentsStats = engine().segmentsStats();
|
||||
SegmentsStats segmentsStats = getEngine().segmentsStats();
|
||||
segmentsStats.addBitsetMemoryInBytes(shardBitsetFilterCache.getMemorySizeInBytes());
|
||||
return segmentsStats;
|
||||
}
|
||||
|
@ -616,7 +616,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
}
|
||||
|
||||
public TranslogStats translogStats() {
|
||||
return engine().getTranslog().stats();
|
||||
return getEngine().getTranslog().stats();
|
||||
}
|
||||
|
||||
public SuggestStats suggestStats() {
|
||||
|
@ -641,7 +641,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
public Engine.SyncedFlushResult syncFlush(String syncId, Engine.CommitId expectedCommitId) {
|
||||
verifyStartedOrRecovering();
|
||||
logger.trace("trying to sync flush. sync id [{}]. expected commit id [{}]]", syncId, expectedCommitId);
|
||||
return engine().syncFlush(syncId, expectedCommitId);
|
||||
return getEngine().syncFlush(syncId, expectedCommitId);
|
||||
}
|
||||
|
||||
public Engine.CommitId flush(FlushRequest request) throws ElasticsearchException {
|
||||
|
@ -656,7 +656,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
verifyStartedOrRecovering();
|
||||
|
||||
long time = System.nanoTime();
|
||||
Engine.CommitId commitId = engine().flush(force, waitIfOngoing);
|
||||
Engine.CommitId commitId = getEngine().flush(force, waitIfOngoing);
|
||||
flushMetric.inc(System.nanoTime() - time);
|
||||
return commitId;
|
||||
|
||||
|
@ -667,7 +667,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("optimize with {}", optimize);
|
||||
}
|
||||
engine().forceMerge(optimize.flush(), optimize.maxNumSegments(), optimize.onlyExpungeDeletes(), false, false);
|
||||
getEngine().forceMerge(optimize.flush(), optimize.maxNumSegments(), optimize.onlyExpungeDeletes(), false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -680,7 +680,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
}
|
||||
org.apache.lucene.util.Version previousVersion = minimumCompatibleVersion();
|
||||
// we just want to upgrade the segments, not actually optimize to a single segment
|
||||
engine().forceMerge(true, // we need to flush at the end to make sure the upgrade is durable
|
||||
getEngine().forceMerge(true, // we need to flush at the end to make sure the upgrade is durable
|
||||
Integer.MAX_VALUE, // we just want to upgrade the segments, not actually optimize to a single segment
|
||||
false, true, upgrade.upgradeOnlyAncientSegments());
|
||||
org.apache.lucene.util.Version version = minimumCompatibleVersion();
|
||||
|
@ -693,7 +693,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
|
||||
public org.apache.lucene.util.Version minimumCompatibleVersion() {
|
||||
org.apache.lucene.util.Version luceneVersion = null;
|
||||
for (Segment segment : engine().segments(false)) {
|
||||
for (Segment segment : getEngine().segments(false)) {
|
||||
if (luceneVersion == null || luceneVersion.onOrAfter(segment.getVersion())) {
|
||||
luceneVersion = segment.getVersion();
|
||||
}
|
||||
|
@ -711,7 +711,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
IndexShardState state = this.state; // one time volatile read
|
||||
// we allow snapshot on closed index shard, since we want to do one after we close the shard and before we close the engine
|
||||
if (state == IndexShardState.STARTED || state == IndexShardState.RELOCATED || state == IndexShardState.CLOSED) {
|
||||
return engine().snapshotIndex(flushFirst);
|
||||
return getEngine().snapshotIndex(flushFirst);
|
||||
} else {
|
||||
throw new IllegalIndexShardStateException(shardId, state, "snapshot is not allowed");
|
||||
}
|
||||
|
@ -732,12 +732,12 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
*/
|
||||
public void failShard(String reason, @Nullable Throwable e) {
|
||||
// fail the engine. This will cause this shard to also be removed from the node's index service.
|
||||
engine().failEngine(reason, e);
|
||||
getEngine().failEngine(reason, e);
|
||||
}
|
||||
|
||||
public Engine.Searcher acquireSearcher(String source) {
|
||||
readAllowed();
|
||||
Engine engine = engine();
|
||||
Engine engine = getEngine();
|
||||
return searcherWrapper == null ? engine.acquireSearcher(source) : searcherWrapper.wrap(engineConfig, engine.acquireSearcher(source));
|
||||
}
|
||||
|
||||
|
@ -769,7 +769,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
public IndexShard postRecovery(String reason) throws IndexShardStartedException, IndexShardRelocatedException, IndexShardClosedException {
|
||||
if (mapperService.hasMapping(PercolatorService.TYPE_NAME)) {
|
||||
refresh("percolator_load_queries");
|
||||
try (Engine.Searcher searcher = engine().acquireSearcher("percolator_load_queries")) {
|
||||
try (Engine.Searcher searcher = getEngine().acquireSearcher("percolator_load_queries")) {
|
||||
this.percolatorQueriesRegistry.loadQueries(searcher.reader());
|
||||
}
|
||||
}
|
||||
|
@ -809,7 +809,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
if (state != IndexShardState.RECOVERING) {
|
||||
throw new IndexShardNotRecoveringException(shardId, state);
|
||||
}
|
||||
return engineConfig.getTranslogRecoveryPerformer().performBatchRecovery(engine(), operations);
|
||||
return engineConfig.getTranslogRecoveryPerformer().performBatchRecovery(getEngine(), operations);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -848,7 +848,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
* a remote peer.
|
||||
*/
|
||||
public void skipTranslogRecovery() throws IOException {
|
||||
assert engineUnsafe() == null : "engine was already created";
|
||||
assert getEngineOrNull() == null : "engine was already created";
|
||||
internalPerformTranslogRecovery(true, true);
|
||||
assert recoveryState.getTranslog().recoveredOperations() == 0;
|
||||
}
|
||||
|
@ -888,7 +888,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
*/
|
||||
public void finalizeRecovery() {
|
||||
recoveryState().setStage(RecoveryState.Stage.FINALIZE);
|
||||
engine().refresh("recovery_finalization");
|
||||
getEngine().refresh("recovery_finalization");
|
||||
startScheduledTasksIfNeeded();
|
||||
engineConfig.setEnableGcDeletes(true);
|
||||
}
|
||||
|
@ -978,7 +978,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
|
||||
config.setIndexingBufferSize(shardIndexingBufferSize);
|
||||
|
||||
Engine engine = engineUnsafe();
|
||||
Engine engine = getEngineOrNull();
|
||||
if (engine == null) {
|
||||
logger.debug("updateBufferSize: engine is closed; skipping");
|
||||
return;
|
||||
|
@ -1053,7 +1053,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
*/
|
||||
boolean shouldFlush() {
|
||||
if (disableFlush == false) {
|
||||
Engine engine = engineUnsafe();
|
||||
Engine engine = getEngineOrNull();
|
||||
if (engine != null) {
|
||||
try {
|
||||
Translog translog = engine.getTranslog();
|
||||
|
@ -1167,26 +1167,26 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
searchService.onRefreshSettings(settings);
|
||||
indexingService.onRefreshSettings(settings);
|
||||
if (change) {
|
||||
engine().onSettingsChanged();
|
||||
getEngine().onSettingsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Translog.View acquireTranslogView() {
|
||||
Engine engine = engine();
|
||||
Engine engine = getEngine();
|
||||
assert engine.getTranslog() != null : "translog must not be null";
|
||||
return engine.getTranslog().newView();
|
||||
}
|
||||
|
||||
public List<Segment> segments(boolean verbose) {
|
||||
return engine().segments(verbose);
|
||||
return getEngine().segments(verbose);
|
||||
}
|
||||
|
||||
public void flushAndCloseEngine() throws IOException {
|
||||
engine().flushAndClose();
|
||||
getEngine().flushAndClose();
|
||||
}
|
||||
|
||||
public Translog getTranslog() {
|
||||
return engine().getTranslog();
|
||||
return getEngine().getTranslog();
|
||||
}
|
||||
|
||||
public PercolateStats percolateStats() {
|
||||
|
@ -1197,7 +1197,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
@Override
|
||||
public void run() {
|
||||
// we check before if a refresh is needed, if not, we reschedule, otherwise, we fork, refresh, and then reschedule
|
||||
if (!engine().refreshNeeded()) {
|
||||
if (!getEngine().refreshNeeded()) {
|
||||
reschedule();
|
||||
return;
|
||||
}
|
||||
|
@ -1205,7 +1205,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (engine().refreshNeeded()) {
|
||||
if (getEngine().refreshNeeded()) {
|
||||
refresh("schedule");
|
||||
}
|
||||
} catch (EngineClosedException e) {
|
||||
|
@ -1318,8 +1318,8 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
recoveryState.getVerifyIndex().checkIndexTime(Math.max(0, TimeValue.nsecToMSec(System.nanoTime() - timeNS)));
|
||||
}
|
||||
|
||||
Engine engine() {
|
||||
Engine engine = engineUnsafe();
|
||||
Engine getEngine() {
|
||||
Engine engine = getEngineOrNull();
|
||||
if (engine == null) {
|
||||
throw new EngineClosedException(shardId);
|
||||
}
|
||||
|
@ -1328,7 +1328,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
|
||||
/** NOTE: returns null if engine is not yet started (e.g. recovery phase 1, copying over index files, is still running), or if engine is
|
||||
* closed. */
|
||||
protected Engine engineUnsafe() {
|
||||
protected Engine getEngineOrNull() {
|
||||
return this.currentEngineReference.get();
|
||||
}
|
||||
|
||||
|
@ -1462,7 +1462,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndexSett
|
|||
*/
|
||||
public void sync(Translog.Location location) {
|
||||
try {
|
||||
final Engine engine = engine();
|
||||
final Engine engine = getEngine();
|
||||
engine.getTranslog().ensureSynced(location);
|
||||
} catch (EngineClosedException ex) {
|
||||
// that's fine since we already synced everything on engine close - this also is conform with the methods documentation
|
||||
|
|
|
@ -490,7 +490,7 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements
|
|||
public SnapshotContext(SnapshotId snapshotId, ShardId shardId, IndexShardSnapshotStatus snapshotStatus) {
|
||||
super(snapshotId, Version.CURRENT, shardId);
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
store = indexService.shard(shardId.id()).store();
|
||||
store = indexService.getShardOrNull(shardId.id()).store();
|
||||
this.snapshotStatus = snapshotStatus;
|
||||
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements
|
|||
*/
|
||||
public RestoreContext(SnapshotId snapshotId, Version version, ShardId shardId, ShardId snapshotShardId, RecoveryState recoveryState) {
|
||||
super(snapshotId, version, shardId, snapshotShardId);
|
||||
store = indicesService.indexServiceSafe(shardId.getIndex()).shard(shardId.id()).store();
|
||||
store = indicesService.indexServiceSafe(shardId.getIndex()).getShardOrNull(shardId.id()).store();
|
||||
this.recoveryState = recoveryState;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public final class IndicesWarmer extends AbstractComponent {
|
|||
if (indexService == null) {
|
||||
return;
|
||||
}
|
||||
final IndexShard indexShard = indexService.shard(context.shardId().id());
|
||||
final IndexShard indexShard = indexService.getShardOrNull(context.shardId().id());
|
||||
if (indexShard == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -505,7 +505,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
|||
continue;
|
||||
}
|
||||
|
||||
IndexShard indexShard = indexService.shard(shardId);
|
||||
IndexShard indexShard = indexService.getShardOrNull(shardId);
|
||||
if (indexShard != null) {
|
||||
ShardRouting currentRoutingEntry = indexShard.routingEntry();
|
||||
// if the current and global routing are initializing, but are still not the same, its a different "shard" being allocated
|
||||
|
@ -591,7 +591,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
|||
final int shardId = shardRouting.id();
|
||||
|
||||
if (indexService.hasShard(shardId)) {
|
||||
IndexShard indexShard = indexService.shardSafe(shardId);
|
||||
IndexShard indexShard = indexService.getShard(shardId);
|
||||
if (indexShard.state() == IndexShardState.STARTED || indexShard.state() == IndexShardState.POST_RECOVERY) {
|
||||
// the master thinks we are initializing, but we are already started or on POST_RECOVERY and waiting
|
||||
// for master to confirm a shard started message (either master failover, or a cluster event before
|
||||
|
@ -647,7 +647,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
|||
return;
|
||||
}
|
||||
}
|
||||
final IndexShard indexShard = indexService.shardSafe(shardId);
|
||||
final IndexShard indexShard = indexService.getShard(shardId);
|
||||
|
||||
if (indexShard.ignoreRecoveryAttempt()) {
|
||||
// we are already recovering (we can get to this state since the cluster event can happen several
|
||||
|
@ -835,7 +835,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
|||
ShardRouting shardRouting = null;
|
||||
final IndexService indexService = indicesService.indexService(shardId.index().name());
|
||||
if (indexService != null) {
|
||||
IndexShard indexShard = indexService.shard(shardId.id());
|
||||
IndexShard indexShard = indexService.getShardOrNull(shardId.id());
|
||||
if (indexShard != null) {
|
||||
shardRouting = indexShard.routingEntry();
|
||||
}
|
||||
|
|
|
@ -398,7 +398,7 @@ public class SyncedFlushService extends AbstractComponent {
|
|||
}
|
||||
|
||||
private PreSyncedFlushResponse performPreSyncedFlush(PreSyncedFlushRequest request) {
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).getShard(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);
|
||||
|
@ -408,7 +408,7 @@ public class SyncedFlushService extends AbstractComponent {
|
|||
|
||||
private SyncedFlushResponse performSyncedFlush(SyncedFlushRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(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);
|
||||
|
@ -426,7 +426,7 @@ public class SyncedFlushService extends AbstractComponent {
|
|||
|
||||
private InFlightOpsResponse performInFlightOps(InFlightOpsRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
||||
if (indexShard.routingEntry().primary() == false) {
|
||||
throw new IllegalStateException("[" + request.shardId() +"] expected a primary shard");
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ public class IndexingMemoryController extends AbstractLifecycleComponent<Indexin
|
|||
protected IndexShard getShard(ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexService(shardId.index().name());
|
||||
if (indexService != null) {
|
||||
IndexShard indexShard = indexService.shard(shardId.id());
|
||||
IndexShard indexShard = indexService.getShardOrNull(shardId.id());
|
||||
return indexShard;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -89,7 +89,7 @@ public class RecoverySource extends AbstractComponent {
|
|||
|
||||
private RecoveryResponse recover(final StartRecoveryRequest request) {
|
||||
final IndexService indexService = indicesService.indexServiceSafe(request.shardId().index().name());
|
||||
final IndexShard shard = indexService.shardSafe(request.shardId().id());
|
||||
final IndexShard shard = indexService.getShard(request.shardId().id());
|
||||
|
||||
// starting recovery from that our (the source) shard state is marking the shard to be in recovery mode as well, otherwise
|
||||
// the index operations will not be routed to it properly
|
||||
|
|
|
@ -395,7 +395,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe
|
|||
ShardId shardId = request.shardId;
|
||||
IndexService indexService = indicesService.indexService(shardId.index().getName());
|
||||
if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) {
|
||||
return indexService.shard(shardId.id());
|
||||
return indexService.getShardOrNull(shardId.id());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction<T
|
|||
try {
|
||||
IndexService indexService = indicesService.indexService(shardId.index().name());
|
||||
if (indexService != null) {
|
||||
IndexShard indexShard = indexService.shard(shardId.id());
|
||||
IndexShard indexShard = indexService.getShardOrNull(shardId.id());
|
||||
if (indexShard != null) {
|
||||
final Store store = indexShard.store();
|
||||
store.incRef();
|
||||
|
|
|
@ -176,7 +176,7 @@ public class PercolatorService extends AbstractComponent {
|
|||
|
||||
public PercolateShardResponse percolate(PercolateShardRequest request) {
|
||||
IndexService percolateIndexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexShard indexShard = percolateIndexService.shardSafe(request.shardId().id());
|
||||
IndexShard indexShard = percolateIndexService.getShard(request.shardId().id());
|
||||
indexShard.readAllowed(); // check if we can read the shard...
|
||||
PercolatorQueriesRegistry percolateQueryRegistry = indexShard.percolateRegistry();
|
||||
percolateQueryRegistry.prePercolate();
|
||||
|
|
|
@ -559,7 +559,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
|||
|
||||
final SearchContext createContext(ShardSearchRequest request, @Nullable Engine.Searcher searcher) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.index());
|
||||
IndexShard indexShard = indexService.shardSafe(request.shardId());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId());
|
||||
|
||||
SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.index(), request.shardId());
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent<SnapshotSh
|
|||
for (final Map.Entry<ShardId, IndexShardSnapshotStatus> shardEntry : entry.getValue().entrySet()) {
|
||||
final ShardId shardId = shardEntry.getKey();
|
||||
try {
|
||||
final IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).shard(shardId.id());
|
||||
final IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).getShardOrNull(shardId.id());
|
||||
executor.execute(new AbstractRunnable() {
|
||||
@Override
|
||||
public void doRun() {
|
||||
|
|
|
@ -158,7 +158,7 @@ public class IndicesShardStoreRequestIT extends ESIntegTestCase {
|
|||
IndicesService indexServices = internalCluster().getInstance(IndicesService.class, node);
|
||||
IndexService indexShards = indexServices.indexServiceSafe(index);
|
||||
for (Integer shardId : indexShards.shardIds()) {
|
||||
IndexShard shard = indexShards.shardSafe(shardId);
|
||||
IndexShard shard = indexShards.getShard(shardId);
|
||||
if (randomBoolean()) {
|
||||
shard.failShard("test", new CorruptIndexException("test corrupted", ""));
|
||||
Set<String> nodes = corruptedShardIDMap.get(shardId);
|
||||
|
|
|
@ -65,7 +65,7 @@ public class UpgradeReallyOldIndexIT extends StaticIndexBackwardCompatibilityIT
|
|||
for (IndicesService services : internalCluster().getInstances(IndicesService.class)) {
|
||||
IndexService indexService = services.indexService(index);
|
||||
if (indexService != null) {
|
||||
assertEquals(version, indexService.shard(0).minimumCompatibleVersion());
|
||||
assertEquals(version, indexService.getShardOrNull(0).minimumCompatibleVersion());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ public class ClusterInfoServiceIT extends ESIntegTestCase {
|
|||
DiscoveryNode discoveryNode = state.getNodes().get(nodeId);
|
||||
IndicesService indicesService = internalTestCluster.getInstance(IndicesService.class, discoveryNode.getName());
|
||||
IndexService indexService = indicesService.indexService(shard.index());
|
||||
IndexShard indexShard = indexService.shard(shard.id());
|
||||
IndexShard indexShard = indexService.getShardOrNull(shard.id());
|
||||
assertEquals(indexShard.shardPath().getRootDataPath().toString(), dataPath);
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
|
|||
|
||||
for (IndicesService service : internalCluster().getDataNodeInstances(IndicesService.class)) {
|
||||
if (service.hasIndex("foo-copy")) {
|
||||
IndexShard shard = service.indexServiceSafe("foo-copy").shard(0);
|
||||
IndexShard shard = service.indexServiceSafe("foo-copy").getShardOrNull(0);
|
||||
if (shard.routingEntry().primary()) {
|
||||
assertFalse(shard instanceof ShadowIndexShard);
|
||||
} else {
|
||||
|
|
|
@ -34,7 +34,7 @@ public class InternalEngineSettingsTests extends ESSingleNodeTestCase {
|
|||
public void testSettingsUpdate() {
|
||||
final IndexService service = createIndex("foo");
|
||||
// INDEX_COMPOUND_ON_FLUSH
|
||||
InternalEngine engine = ((InternalEngine) EngineAccess.engine(service.shard(0)));
|
||||
InternalEngine engine = ((InternalEngine) EngineAccess.engine(service.getShardOrNull(0)));
|
||||
assertThat(engine.getCurrentIndexWriterConfig().getUseCompoundFile(), is(true));
|
||||
client().admin().indices().prepareUpdateSettings("foo").setSettings(Settings.builder().put(EngineConfig.INDEX_COMPOUND_ON_FLUSH, false).build()).get();
|
||||
assertThat(engine.getCurrentIndexWriterConfig().getUseCompoundFile(), is(false));
|
||||
|
|
|
@ -433,7 +433,7 @@ public class SimpleAllMapperTests extends ESSingleNodeTestCase {
|
|||
client().prepareIndex(index, "type").setSource("foo", "bar").get();
|
||||
client().admin().indices().prepareRefresh(index).get();
|
||||
Query query = indexService.mapperService().documentMapper("type").allFieldMapper().fieldType().termQuery("bar", null);
|
||||
try (Searcher searcher = indexService.shard(0).acquireSearcher("tests")) {
|
||||
try (Searcher searcher = indexService.getShardOrNull(0).acquireSearcher("tests")) {
|
||||
query = searcher.searcher().rewrite(query);
|
||||
final Class<?> expected = boost ? AllTermQuery.class : TermQuery.class;
|
||||
assertThat(query, Matchers.instanceOf(expected));
|
||||
|
|
|
@ -71,7 +71,7 @@ public class MultiMatchQueryTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext queryShardContext = new QueryShardContext(new Index("test"), queryParser);
|
||||
queryShardContext.setAllowUnmappedFields(true);
|
||||
Query parsedQuery = multiMatchQuery("banon").field("name.first", 2).field("name.last", 3).field("foobar").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).toQuery(queryShardContext);
|
||||
try (Engine.Searcher searcher = indexService.shardSafe(0).acquireSearcher("test")) {
|
||||
try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
|
||||
Query rewrittenQuery = searcher.searcher().rewrite(parsedQuery);
|
||||
|
||||
BooleanQuery.Builder expected = new BooleanQuery.Builder();
|
||||
|
|
|
@ -26,6 +26,6 @@ import org.elasticsearch.index.engine.Engine;
|
|||
public final class EngineAccess {
|
||||
|
||||
public static Engine engine(IndexShard shard) {
|
||||
return shard.engine();
|
||||
return shard.getEngine();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
assertEquals(initValue, shard.isFlushOnClose());
|
||||
final boolean newValue = !initValue;
|
||||
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_FLUSH_ON_CLOSE, newValue).build()));
|
||||
|
@ -183,7 +183,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
ShardStateMetaData shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
|
||||
assertEquals(getShardStateMetadata(shard), shardStateMetaData);
|
||||
ShardRouting routing = new ShardRouting(shard.shardRouting, shard.shardRouting.version() + 1);
|
||||
|
@ -232,7 +232,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
try {
|
||||
shard.deleteShardState();
|
||||
fail("shard is active metadata delete must fail");
|
||||
|
@ -259,7 +259,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
// fail shard
|
||||
shard.failShard("test shard fail", new CorruptIndexException("", ""));
|
||||
// check state file still exists
|
||||
|
@ -304,7 +304,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen("test");
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService indexService = indicesService.indexServiceSafe("test");
|
||||
IndexShard indexShard = indexService.shard(0);
|
||||
IndexShard indexShard = indexService.getShardOrNull(0);
|
||||
client().admin().indices().prepareDelete("test").get();
|
||||
assertThat(indexShard.getOperationsCount(), equalTo(0));
|
||||
try {
|
||||
|
@ -321,7 +321,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen("test");
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService indexService = indicesService.indexServiceSafe("test");
|
||||
IndexShard indexShard = indexService.shard(0);
|
||||
IndexShard indexShard = indexService.getShardOrNull(0);
|
||||
assertEquals(0, indexShard.getOperationsCount());
|
||||
indexShard.incrementOperationCounter();
|
||||
assertEquals(1, indexShard.getOperationsCount());
|
||||
|
@ -339,7 +339,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
client().prepareIndex("test", "test").setSource("{}").get();
|
||||
ensureGreen("test");
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
indicesService.indexService("test").shard(0).markAsInactive();
|
||||
indicesService.indexService("test").getShardOrNull(0).markAsInactive();
|
||||
assertBusy(new Runnable() { // should be very very quick
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -366,31 +366,31 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
client().prepareIndex("test", "bar", "1").setSource("{}").get();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
setDurability(shard, Translog.Durabilty.REQUEST);
|
||||
assertFalse(shard.engine().getTranslog().syncNeeded());
|
||||
assertFalse(shard.getEngine().getTranslog().syncNeeded());
|
||||
setDurability(shard, Translog.Durabilty.ASYNC);
|
||||
client().prepareIndex("test", "bar", "2").setSource("{}").get();
|
||||
assertTrue(shard.engine().getTranslog().syncNeeded());
|
||||
assertTrue(shard.getEngine().getTranslog().syncNeeded());
|
||||
setDurability(shard, Translog.Durabilty.REQUEST);
|
||||
client().prepareDelete("test", "bar", "1").get();
|
||||
assertFalse(shard.engine().getTranslog().syncNeeded());
|
||||
assertFalse(shard.getEngine().getTranslog().syncNeeded());
|
||||
|
||||
setDurability(shard, Translog.Durabilty.ASYNC);
|
||||
client().prepareDelete("test", "bar", "2").get();
|
||||
assertTrue(shard.engine().getTranslog().syncNeeded());
|
||||
assertTrue(shard.getEngine().getTranslog().syncNeeded());
|
||||
setDurability(shard, Translog.Durabilty.REQUEST);
|
||||
assertNoFailures(client().prepareBulk()
|
||||
.add(client().prepareIndex("test", "bar", "3").setSource("{}"))
|
||||
.add(client().prepareDelete("test", "bar", "1")).get());
|
||||
assertFalse(shard.engine().getTranslog().syncNeeded());
|
||||
assertFalse(shard.getEngine().getTranslog().syncNeeded());
|
||||
|
||||
setDurability(shard, Translog.Durabilty.ASYNC);
|
||||
assertNoFailures(client().prepareBulk()
|
||||
.add(client().prepareIndex("test", "bar", "4").setSource("{}"))
|
||||
.add(client().prepareDelete("test", "bar", "3")).get());
|
||||
setDurability(shard, Translog.Durabilty.REQUEST);
|
||||
assertTrue(shard.engine().getTranslog().syncNeeded());
|
||||
assertTrue(shard.getEngine().getTranslog().syncNeeded());
|
||||
}
|
||||
|
||||
private void setDurability(IndexShard shard, Translog.Durabilty durabilty) {
|
||||
|
@ -407,12 +407,12 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
int numDocs = 1;
|
||||
shard.state = IndexShardState.RECOVERING;
|
||||
try {
|
||||
shard.recoveryState().getTranslog().totalOperations(1);
|
||||
shard.engine().config().getTranslogRecoveryPerformer().performRecoveryOperation(shard.engine(), new Translog.DeleteByQuery(new Engine.DeleteByQuery(null, new BytesArray("{\"term\" : { \"user\" : \"kimchy\" }}"), null, null, null, Engine.Operation.Origin.RECOVERY, 0, "person")), false);
|
||||
shard.getEngine().config().getTranslogRecoveryPerformer().performRecoveryOperation(shard.getEngine(), new Translog.DeleteByQuery(new Engine.DeleteByQuery(null, new BytesArray("{\"term\" : { \"user\" : \"kimchy\" }}"), null, null, null, Engine.Operation.Origin.RECOVERY, 0, "person")), false);
|
||||
assertTrue(version.onOrBefore(Version.V_1_0_0_Beta2));
|
||||
numDocs = 0;
|
||||
} catch (ParsingException ex) {
|
||||
|
@ -420,9 +420,9 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
} finally {
|
||||
shard.state = IndexShardState.STARTED;
|
||||
}
|
||||
shard.engine().refresh("foo");
|
||||
shard.getEngine().refresh("foo");
|
||||
|
||||
try (Engine.Searcher searcher = shard.engine().acquireSearcher("foo")) {
|
||||
try (Engine.Searcher searcher = shard.getEngine().acquireSearcher("foo")) {
|
||||
assertEquals(numDocs, searcher.reader().numDocs());
|
||||
}
|
||||
}
|
||||
|
@ -434,11 +434,11 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
client().prepareIndex("test", "test").setSource("{}").get();
|
||||
ensureGreen("test");
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexShard test = indicesService.indexService("test").shard(0);
|
||||
IndexShard test = indicesService.indexService("test").getShardOrNull(0);
|
||||
assertEquals(versionCreated.luceneVersion, test.minimumCompatibleVersion());
|
||||
client().prepareIndex("test", "test").setSource("{}").get();
|
||||
assertEquals(versionCreated.luceneVersion, test.minimumCompatibleVersion());
|
||||
test.engine().flush();
|
||||
test.getEngine().flush();
|
||||
assertEquals(Version.CURRENT.luceneVersion, test.minimumCompatibleVersion());
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
assertHitCount(response, 1l);
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
ShardPath shardPath = shard.shardPath();
|
||||
Path dataPath = shardPath.getDataPath();
|
||||
client().admin().indices().prepareClose("test").get();
|
||||
|
@ -580,7 +580,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
ShardStats stats = new ShardStats(shard.routingEntry(), shard.shardPath(), new CommonStats(shard, new CommonStatsFlags()), shard.commitStats());
|
||||
assertEquals(shard.shardPath().getRootDataPath().toString(), stats.getDataPath());
|
||||
assertEquals(shard.shardPath().getRootStatePath().toString(), stats.getStatePath());
|
||||
|
@ -619,7 +619,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("testpreindex");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
ShardIndexingService shardIndexingService = shard.indexingService();
|
||||
final AtomicBoolean preIndexCalled = new AtomicBoolean(false);
|
||||
|
||||
|
@ -642,7 +642,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("testpostindex");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
ShardIndexingService shardIndexingService = shard.indexingService();
|
||||
final AtomicBoolean postIndexCalled = new AtomicBoolean(false);
|
||||
|
||||
|
@ -665,7 +665,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("testpostindexwithexception");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
ShardIndexingService shardIndexingService = shard.indexingService();
|
||||
|
||||
shard.close("Unexpected close", true);
|
||||
|
@ -700,7 +700,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
assertFalse(shard.shouldFlush());
|
||||
client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, 1).build()).get();
|
||||
client().prepareIndex("test", "test", "0").setSource("{}").setRefresh(randomBoolean()).get();
|
||||
|
@ -709,25 +709,25 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
|
||||
shard.index(index);
|
||||
assertTrue(shard.shouldFlush());
|
||||
assertEquals(2, shard.engine().getTranslog().totalOperations());
|
||||
assertEquals(2, shard.getEngine().getTranslog().totalOperations());
|
||||
client().prepareIndex("test", "test", "2").setSource("{}").setRefresh(randomBoolean()).get();
|
||||
assertBusy(() -> { // this is async
|
||||
assertFalse(shard.shouldFlush());
|
||||
});
|
||||
assertEquals(0, shard.engine().getTranslog().totalOperations());
|
||||
shard.engine().getTranslog().sync();
|
||||
long size = shard.engine().getTranslog().sizeInBytes();
|
||||
logger.info("--> current translog size: [{}] num_ops [{}] generation [{}]", shard.engine().getTranslog().sizeInBytes(), shard.engine().getTranslog().totalOperations(), shard.engine().getTranslog().getGeneration());
|
||||
assertEquals(0, shard.getEngine().getTranslog().totalOperations());
|
||||
shard.getEngine().getTranslog().sync();
|
||||
long size = shard.getEngine().getTranslog().sizeInBytes();
|
||||
logger.info("--> current translog size: [{}] num_ops [{}] generation [{}]", shard.getEngine().getTranslog().sizeInBytes(), shard.getEngine().getTranslog().totalOperations(), shard.getEngine().getTranslog().getGeneration());
|
||||
client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, 1000)
|
||||
.put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(size, ByteSizeUnit.BYTES))
|
||||
.build()).get();
|
||||
client().prepareDelete("test", "test", "2").get();
|
||||
logger.info("--> translog size after delete: [{}] num_ops [{}] generation [{}]", shard.engine().getTranslog().sizeInBytes(), shard.engine().getTranslog().totalOperations(), shard.engine().getTranslog().getGeneration());
|
||||
logger.info("--> translog size after delete: [{}] num_ops [{}] generation [{}]", shard.getEngine().getTranslog().sizeInBytes(), shard.getEngine().getTranslog().totalOperations(), shard.getEngine().getTranslog().getGeneration());
|
||||
assertBusy(() -> { // this is async
|
||||
logger.info("--> translog size on iter : [{}] num_ops [{}] generation [{}]", shard.engine().getTranslog().sizeInBytes(), shard.engine().getTranslog().totalOperations(), shard.engine().getTranslog().getGeneration());
|
||||
logger.info("--> translog size on iter : [{}] num_ops [{}] generation [{}]", shard.getEngine().getTranslog().sizeInBytes(), shard.getEngine().getTranslog().totalOperations(), shard.getEngine().getTranslog().getGeneration());
|
||||
assertFalse(shard.shouldFlush());
|
||||
});
|
||||
assertEquals(0, shard.engine().getTranslog().totalOperations());
|
||||
assertEquals(0, shard.getEngine().getTranslog().totalOperations());
|
||||
}
|
||||
|
||||
public void testStressMaybeFlush() throws Exception {
|
||||
|
@ -735,7 +735,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
final IndexShard shard = test.shard(0);
|
||||
final IndexShard shard = test.getShardOrNull(0);
|
||||
assertFalse(shard.shouldFlush());
|
||||
client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, 1).build()).get();
|
||||
client().prepareIndex("test", "test", "0").setSource("{}").setRefresh(randomBoolean()).get();
|
||||
|
@ -778,7 +778,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
final IndexShard shard = test.shard(0);
|
||||
final IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
client().prepareIndex("test", "test", "0").setSource("{}").setRefresh(randomBoolean()).get();
|
||||
if (randomBoolean()) {
|
||||
|
@ -804,7 +804,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
DiscoveryNode localNode = new DiscoveryNode("foo", DummyTransportAddress.INSTANCE, Version.CURRENT);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
final IndexShard shard = test.shard(0);
|
||||
final IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
client().prepareIndex("test", "test", "0").setSource("{}").setRefresh(randomBoolean()).get();
|
||||
if (randomBoolean()) {
|
||||
|
@ -852,14 +852,14 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService test = indicesService.indexService("test");
|
||||
IndexService test_target = indicesService.indexService("test_target");
|
||||
final IndexShard test_shard = test.shard(0);
|
||||
final IndexShard test_shard = test.getShardOrNull(0);
|
||||
|
||||
client().prepareIndex("test", "test", "0").setSource("{}").setRefresh(randomBoolean()).get();
|
||||
client().prepareIndex("test_target", "test", "1").setSource("{}").setRefresh(true).get();
|
||||
assertHitCount(client().prepareSearch("test_target").get(), 1);
|
||||
assertSearchHits(client().prepareSearch("test_target").get(), "1");
|
||||
client().admin().indices().prepareFlush("test").get(); // only flush test
|
||||
final ShardRouting origRouting = test_target.shard(0).routingEntry();
|
||||
final ShardRouting origRouting = test_target.getShardOrNull(0).routingEntry();
|
||||
ShardRouting routing = new ShardRouting(origRouting);
|
||||
ShardRoutingHelper.reinit(routing);
|
||||
routing = ShardRoutingHelper.newWithRestoreSource(routing, new RestoreSource(new SnapshotId("foo", "bar"), Version.CURRENT, "test"));
|
||||
|
@ -912,7 +912,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
|||
ensureGreen();
|
||||
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
|
||||
IndexService indexService = indicesService.indexService("test");
|
||||
IndexShard shard = indexService.shard(0);
|
||||
IndexShard shard = indexService.getShardOrNull(0);
|
||||
IndexSettingsService settingsService = indexService.settingsService();
|
||||
assertTrue(settingsService.isRegistered(shard));
|
||||
indexService.removeShard(0, "simon says so");
|
||||
|
|
|
@ -137,8 +137,8 @@ public class IndicesServiceTests extends ESSingleNodeTestCase {
|
|||
IndexService test = createIndex("test");
|
||||
|
||||
assertTrue(test.hasShard(0));
|
||||
ShardPath path = test.shard(0).shardPath();
|
||||
assertTrue(test.shard(0).routingEntry().started());
|
||||
ShardPath path = test.getShardOrNull(0).shardPath();
|
||||
assertTrue(test.getShardOrNull(0).routingEntry().started());
|
||||
ShardPath shardPath = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings());
|
||||
assertEquals(shardPath, path);
|
||||
try {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
|
|||
createIndex("test");
|
||||
client().prepareIndex("test", "test", "1").setSource("{}").get();
|
||||
IndexService test = getInstanceFromNode(IndicesService.class).indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class);
|
||||
final ShardId shardId = shard.shardId();
|
||||
|
@ -86,7 +86,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
|
|||
createIndex("test");
|
||||
client().prepareIndex("test", "test", "1").setSource("{}").get();
|
||||
IndexService test = getInstanceFromNode(IndicesService.class).indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class);
|
||||
final ShardId shardId = shard.shardId();
|
||||
|
@ -106,7 +106,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
|
|||
createIndex("test");
|
||||
client().prepareIndex("test", "test", "1").setSource("{}").get();
|
||||
IndexService test = getInstanceFromNode(IndicesService.class).indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class);
|
||||
final ShardId shardId = shard.shardId();
|
||||
|
@ -129,7 +129,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
|
|||
public void testSyncFailsOnIndexClosedOrMissing() throws InterruptedException {
|
||||
createIndex("test");
|
||||
IndexService test = getInstanceFromNode(IndicesService.class).indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class);
|
||||
SyncedFlushUtil.LatchedListener listener = new SyncedFlushUtil.LatchedListener();
|
||||
|
@ -162,7 +162,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
|
|||
createIndex("test");
|
||||
client().prepareIndex("test", "test", "1").setSource("{}").get();
|
||||
IndexService test = getInstanceFromNode(IndicesService.class).indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class);
|
||||
final ShardId shardId = shard.shardId();
|
||||
|
@ -195,7 +195,7 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
|
|||
createIndex("test");
|
||||
client().prepareIndex("test", "test", "1").setSource("{}").get();
|
||||
IndexService test = getInstanceFromNode(IndicesService.class).indexService("test");
|
||||
IndexShard shard = test.shard(0);
|
||||
IndexShard shard = test.getShardOrNull(0);
|
||||
|
||||
SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class);
|
||||
final ShardId shardId = shard.shardId();
|
||||
|
|
|
@ -270,10 +270,10 @@ public class IndexRecoveryIT extends ESIntegTestCase {
|
|||
@Override
|
||||
public void run() {
|
||||
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeA);
|
||||
assertThat(indicesService.indexServiceSafe(INDEX_NAME).shardSafe(0).recoveryStats().currentAsSource(),
|
||||
assertThat(indicesService.indexServiceSafe(INDEX_NAME).getShard(0).recoveryStats().currentAsSource(),
|
||||
equalTo(1));
|
||||
indicesService = internalCluster().getInstance(IndicesService.class, nodeB);
|
||||
assertThat(indicesService.indexServiceSafe(INDEX_NAME).shardSafe(0).recoveryStats().currentAsTarget(),
|
||||
assertThat(indicesService.indexServiceSafe(INDEX_NAME).getShard(0).recoveryStats().currentAsTarget(),
|
||||
equalTo(1));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -39,7 +39,7 @@ public class RecoveryStatusTests extends ESSingleNodeTestCase {
|
|||
public void testRenameTempFiles() throws IOException {
|
||||
IndexService service = createIndex("foo");
|
||||
|
||||
IndexShard indexShard = service.shard(0);
|
||||
IndexShard indexShard = service.getShardOrNull(0);
|
||||
DiscoveryNode node = new DiscoveryNode("foo", new LocalTransportAddress("bar"), Version.CURRENT);
|
||||
RecoveryStatus status = new RecoveryStatus(indexShard, node, new RecoveryTarget.RecoveryListener() {
|
||||
@Override
|
||||
|
|
|
@ -171,7 +171,7 @@ public class RecoveriesCollectionTests extends ESSingleNodeTestCase {
|
|||
|
||||
long startRecovery(RecoveriesCollection collection, RecoveryTarget.RecoveryListener listener, TimeValue timeValue) {
|
||||
IndicesService indexServices = getInstanceFromNode(IndicesService.class);
|
||||
IndexShard indexShard = indexServices.indexServiceSafe("test").shard(0);
|
||||
IndexShard indexShard = indexServices.indexServiceSafe("test").getShardOrNull(0);
|
||||
final DiscoveryNode sourceNode = new DiscoveryNode("id", DummyTransportAddress.INSTANCE, Version.CURRENT);
|
||||
return collection.startRecovery(indexShard, sourceNode, listener, timeValue);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public class TestSearchContext extends SearchContext {
|
|||
this.indexFieldDataService = indexService.fieldData();
|
||||
this.fixedBitSetFilterCache = indexService.bitsetFilterCache();
|
||||
this.threadPool = threadPool;
|
||||
this.indexShard = indexService.shard(0);
|
||||
this.indexShard = indexService.getShardOrNull(0);
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue