org.elasticsearch.index.IndexService Java Examples

The following examples show how to use org.elasticsearch.index.IndexService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Elasticsearch   Author: baidu   File: TransportFieldStatsTransportAction.java    License: Apache License 2.0 7 votes vote down vote up
@Override
protected FieldStatsShardResponse shardOperation(FieldStatsShardRequest request) {
    ShardId shardId = request.shardId();
    Map<String, FieldStats> fieldStats = new HashMap<>();
    IndexService indexServices = indicesService.indexServiceSafe(shardId.getIndex());
    MapperService mapperService = indexServices.mapperService();
    IndexShard shard = indexServices.shardSafe(shardId.id());
    try (Engine.Searcher searcher = shard.acquireSearcher("fieldstats")) {
        for (String field : request.getFields()) {
            MappedFieldType fieldType = mapperService.fullName(field);
            if (fieldType != null) {
                IndexReader reader = searcher.reader();
                Terms terms = MultiFields.getTerms(reader, field);
                if (terms != null) {
                    fieldStats.put(field, fieldType.stats(terms, reader.maxDoc()));
                }
            } else {
                throw new IllegalArgumentException("field [" + field + "] doesn't exist");
            }
        }
    } catch (IOException e) {
        throw ExceptionsHelper.convertToElastic(e);
    }
    return new FieldStatsShardResponse(shardId, fieldStats);
}
 
Example #2
Source Project: deprecated-security-advanced-modules   Author: opendistro-for-elasticsearch   File: FieldReadCallback.java    License: Apache License 2.0 6 votes vote down vote up
public FieldReadCallback(final ThreadContext threadContext, final IndexService indexService,
        final ClusterService clusterService, final ComplianceConfig complianceConfig, final AuditLog auditLog,
        final Set<String> maskedFields, ShardId shardId) {
    super();
    //this.threadContext = Objects.requireNonNull(threadContext);
    //this.clusterService = Objects.requireNonNull(clusterService);
    this.index = Objects.requireNonNull(indexService).index();
    this.complianceConfig = complianceConfig;
    this.auditLog = auditLog;
    this.maskedFields = maskedFields;
    this.shardId = shardId;
    try {
        sfc = (SourceFieldsContext) HeaderHelper.deserializeSafeFromHeader(threadContext, "_opendistro_security_source_field_context");
        if(sfc != null && sfc.hasIncludesOrExcludes()) {
            if(log.isTraceEnabled()) {
                log.trace("_opendistro_security_source_field_context: "+sfc);
            }

            filterFunction = XContentMapValues.filter(sfc.getIncludes(), sfc.getExcludes());
        }
    } catch (Exception e) {
        if(log.isDebugEnabled()) {
            log.debug("Cannot deserialize _opendistro_security_source_field_context because of {}", e.toString());
        }
    }
}
 
Example #3
Source Project: crate   Author: crate   File: TransportShardDeleteActionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void prepare() throws Exception {
    indexUUID = UUIDs.randomBase64UUID();
    IndicesService indicesService = mock(IndicesService.class);
    IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(new Index(TABLE_IDENT.indexNameOrAlias(), indexUUID))).thenReturn(indexService);
    indexShard = mock(IndexShard.class);
    when(indexService.getShard(0)).thenReturn(indexShard);


    transportShardDeleteAction = new TransportShardDeleteAction(
        MockTransportService.createNewService(
            Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings()),
        mock(IndexNameExpressionResolver.class),
        mock(ClusterService.class),
        indicesService,
        mock(ThreadPool.class),
        mock(ShardStateAction.class),
        mock(SchemaUpdateClient.class)
    );
}
 
Example #4
Source Project: deprecated-security-advanced-modules   Author: opendistro-for-elasticsearch   File: OpenDistroSecurityFlsDlsIndexSearcherWrapper.java    License: Apache License 2.0 6 votes vote down vote up
public OpenDistroSecurityFlsDlsIndexSearcherWrapper(final IndexService indexService, final Settings settings,
        final AdminDNs adminDNs, final ClusterService clusterService, final AuditLog auditlog,
        final ComplianceIndexingOperationListener ciol, final ComplianceConfig complianceConfig, final PrivilegesEvaluator evaluator) {
    super(indexService, settings, adminDNs, evaluator);
    ciol.setIs(indexService);
    this.clusterService = clusterService;
    this.indexService = indexService;
    this.complianceConfig = complianceConfig;
    this.auditlog = auditlog;
    final boolean allowNowinDlsQueries = settings.getAsBoolean(ConfigConstants.OPENDISTRO_SECURITY_UNSUPPORTED_ALLOW_NOW_IN_DLS, false);
    if (allowNowinDlsQueries) {
        nowInMillis = () -> System.currentTimeMillis();
    } else {
        nowInMillis = () -> {throw new IllegalArgumentException("'now' is not allowed in DLS queries");};
    }
}
 
Example #5
Source Project: Elasticsearch   Author: baidu   File: InternalCountOperation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public long count(String index, int shardId, WhereClause whereClause) throws IOException, InterruptedException {
    IndexService indexService;
    try {
        indexService = indicesService.indexServiceSafe(index);
    } catch (IndexNotFoundException e) {
        if (PartitionName.isPartition(index)) {
            return 0L;
        }
        throw e;
    }

    IndexShard indexShard = indexService.shardSafe(shardId);
    try (Engine.Searcher searcher = indexShard.acquireSearcher("count-operation")) {
        LuceneQueryBuilder.Context queryCtx = queryBuilder.convert(
                whereClause, indexService.mapperService(), indexService.fieldData(), indexService.cache());
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        return searcher.searcher().count(queryCtx.query());
    }
}
 
Example #6
Source Project: Elasticsearch   Author: baidu   File: CrateSearchContext.java    License: Apache License 2.0 6 votes vote down vote up
public CrateSearchContext(long id,
                          final long nowInMillis,
                          SearchShardTarget shardTarget,
                          Engine.Searcher engineSearcher,
                          IndexService indexService,
                          final IndexShard indexShard,
                          ScriptService scriptService,
                          PageCacheRecycler pageCacheRecycler,
                          BigArrays bigArrays,
                          Counter timeEstimateCounter,
                          Optional<Scroll> scroll) {
    super(id, new CrateSearchShardRequest(nowInMillis, scroll, indexShard),
            shardTarget, engineSearcher, indexService,
            indexShard, scriptService, pageCacheRecycler,
            bigArrays, timeEstimateCounter, ParseFieldMatcher.STRICT, SearchService.NO_TIMEOUT);
    this.engineSearcher = engineSearcher;
}
 
Example #7
Source Project: Elasticsearch   Author: baidu   File: TransportShardDeleteAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void processRequestItemsOnReplica(ShardId shardId, ShardDeleteRequest request) {
    IndexService indexService = indicesService.indexServiceSafe(request.index());
    IndexShard indexShard = indexService.shardSafe(shardId.id());
    for (int i = 0; i < request.itemIndices().size(); i++) {
        int location = request.itemIndices().get(i);
        if (request.skipFromLocation() == location) {
            // skipping this and all next items, the primary did not processed them (mostly due to a kill request)
            break;
        }

        ShardDeleteRequest.Item item = request.items().get(i);
        try {
            Engine.Delete delete = indexShard.prepareDeleteOnReplica(request.type(), item.id(), item.version(), item.versionType());
            indexShard.delete(delete);
            logger.trace("{} REPLICA: successfully deleted [{}]/[{}]", request.shardId(), request.type(), item.id());
        } catch (Throwable e) {
            // if its not an ignore replica failure, we need to make sure to bubble up the failure
            // so we will fail the shard
            if (!ignoreReplicaException(e)) {
                throw e;
            }
        }
    }

}
 
Example #8
Source Project: crate   Author: crate   File: InternalTestCluster.java    License: Apache License 2.0 6 votes vote down vote up
synchronized String routingKeyForShard(Index index, int shard, Random random) {
    assertThat(shard, greaterThanOrEqualTo(0));
    assertThat(shard, greaterThanOrEqualTo(0));
    for (NodeAndClient n : nodes.values()) {
        Node node = n.node;
        IndicesService indicesService = getInstanceFromNode(IndicesService.class, node);
        ClusterService clusterService = getInstanceFromNode(ClusterService.class, node);
        IndexService indexService = indicesService.indexService(index);
        if (indexService != null) {
            assertThat(indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1),
                    greaterThan(shard));
            OperationRouting operationRouting = clusterService.operationRouting();
            while (true) {
                String routing = RandomStrings.randomAsciiOfLength(random, 10);
                final int targetShard = operationRouting
                        .indexShards(clusterService.state(), index.getName(), null, routing)
                        .shardId().getId();
                if (shard == targetShard) {
                    return routing;
                }
            }
        }
    }
    fail("Could not find a node that holds " + index);
    return null;
}
 
Example #9
Source Project: Elasticsearch   Author: baidu   File: IndicesClusterStateService.java    License: Apache License 2.0 6 votes vote down vote up
private void applyAliases(ClusterChangedEvent event) {
    // check if aliases changed
    if (aliasesChanged(event)) {
        // go over and update aliases
        for (IndexMetaData indexMetaData : event.state().metaData()) {
            String index = indexMetaData.getIndex();
            IndexService indexService = indicesService.indexService(index);
            if (indexService == null) {
                // we only create / update here
                continue;
            }
            IndexAliasesService indexAliasesService = indexService.aliasesService();
            indexAliasesService.setAliases(indexMetaData.getAliases());
        }
    }
}
 
Example #10
Source Project: Elasticsearch   Author: baidu   File: IndicesClusterStateService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onFailedEngine(final ShardId shardId, final String reason, final @Nullable Throwable failure) {
    ShardRouting shardRouting = null;
    final IndexService indexService = indicesService.indexService(shardId.index().name());
    if (indexService != null) {
        IndexShard indexShard = indexService.shard(shardId.id());
        if (indexShard != null) {
            shardRouting = indexShard.routingEntry();
        }
    }
    if (shardRouting == null) {
        logger.warn("[{}][{}] engine failed, but can't find index shard. failure reason: [{}]", failure,
                shardId.index().name(), shardId.id(), reason);
        return;
    }
    final ShardRouting fShardRouting = shardRouting;
    threadPool.generic().execute(new Runnable() {
        @Override
        public void run() {
            synchronized (mutex) {
                failAndRemoveShard(fShardRouting, indexService, true, "engine failure, reason [" + reason + "]", failure);
            }
        }
    });
}
 
Example #11
Source Project: crate   Author: crate   File: InternalTestCluster.java    License: Apache License 2.0 6 votes vote down vote up
private void assertOpenTranslogReferences() throws Exception {
    assertBusy(() -> {
        for (NodeAndClient nodeAndClient : nodes.values()) {
            IndicesService indexServices = getInstance(IndicesService.class, nodeAndClient.name);
            for (IndexService indexService : indexServices) {
                for (IndexShard indexShard : indexService) {
                    try {
                        if (IndexShardTestCase.getEngine(indexShard) instanceof InternalEngine) {
                            IndexShardTestCase.getTranslog(indexShard).getDeletionPolicy().assertNoOpenTranslogRefs();
                        }
                    } catch (AlreadyClosedException ok) {
                        // all good
                    }
                }
            }
        }
    });
}
 
Example #12
Source Project: Elasticsearch   Author: baidu   File: TransportNodesListShardStoreMetaData.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected NodeStoreFilesMetaData nodeOperation(NodeRequest request) {
    if (request.unallocated) {
        IndexService indexService = indicesService.indexService(request.shardId.index().name());
        if (indexService == null) {
            return new NodeStoreFilesMetaData(clusterService.localNode(), null);
        }
        if (!indexService.hasShard(request.shardId.id())) {
            return new NodeStoreFilesMetaData(clusterService.localNode(), null);
        }
    }
    IndexMetaData metaData = clusterService.state().metaData().index(request.shardId.index().name());
    if (metaData == null) {
        return new NodeStoreFilesMetaData(clusterService.localNode(), null);
    }
    try {
        return new NodeStoreFilesMetaData(clusterService.localNode(), listStoreMetaData(request.shardId));
    } catch (IOException e) {
        throw new ElasticsearchException("Failed to list store metadata for shard [" + request.shardId + "]", e);
    }
}
 
Example #13
Source Project: Elasticsearch   Author: baidu   File: PercolateContext.java    License: Apache License 2.0 6 votes vote down vote up
public PercolateContext(PercolateShardRequest request, SearchShardTarget searchShardTarget, IndexShard indexShard,
                        IndexService indexService, PageCacheRecycler pageCacheRecycler,
                        BigArrays bigArrays, ScriptService scriptService, Query aliasFilter, ParseFieldMatcher parseFieldMatcher) {
    super(parseFieldMatcher, request);
    this.indexShard = indexShard;
    this.indexService = indexService;
    this.fieldDataService = indexService.fieldData();
    this.searchShardTarget = searchShardTarget;
    this.percolateQueries = indexShard.percolateRegistry().percolateQueries();
    this.types = new String[]{request.documentType()};
    this.pageCacheRecycler = pageCacheRecycler;
    this.bigArrays = bigArrays.withCircuitBreaking();
    this.querySearchResult = new QuerySearchResult(0, searchShardTarget);
    this.engineSearcher = indexShard.acquireSearcher("percolate");
    this.searcher = new ContextIndexSearcher(engineSearcher, indexService.cache().query(), indexShard.getQueryCachingPolicy());
    this.scriptService = scriptService;
    this.numberOfShards = request.getNumberOfShards();
    this.aliasFilter = aliasFilter;
    this.startTime = request.getStartTime();
}
 
Example #14
Source Project: Elasticsearch   Author: baidu   File: ShadowIndexShard.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public ShadowIndexShard(ShardId shardId, IndexSettingsService indexSettingsService,
                        IndicesLifecycle indicesLifecycle, Store store, StoreRecoveryService storeRecoveryService,
                        ThreadPool threadPool, MapperService mapperService,
                        IndexQueryParserService queryParserService, IndexCache indexCache,
                        IndexAliasesService indexAliasesService, IndicesQueryCache indicesQueryCache,
                        ShardPercolateService shardPercolateService, CodecService codecService,
                        ShardTermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService,
                        IndexService indexService, @Nullable IndicesWarmer warmer,
                        SnapshotDeletionPolicy deletionPolicy, SimilarityService similarityService,
                        EngineFactory factory, ClusterService clusterService,
                        ShardPath path, BigArrays bigArrays, IndexSearcherWrappingService wrappingService,
                        IndexingMemoryController indexingMemoryController, SearchService shardSearchService) throws IOException {
    super(shardId, indexSettingsService, indicesLifecycle, store, storeRecoveryService,
          threadPool, mapperService, queryParserService, indexCache, indexAliasesService,
          indicesQueryCache, shardPercolateService, codecService,
          termVectorsService, indexFieldDataService, indexService,
          warmer, deletionPolicy, similarityService,
          factory, clusterService, path, bigArrays, wrappingService, indexingMemoryController, shardSearchService);
}
 
Example #15
Source Project: Elasticsearch   Author: baidu   File: TransportUpgradeStatusAction.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #16
Source Project: Elasticsearch   Author: baidu   File: TransportClusterStatsAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(false, true, false, true, false, true, false, true);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, SHARD_STATS_FLAGS), indexShard.commitStats()));
            }
        }
    }

    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().localNodeMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }

    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));

}
 
Example #17
Source Project: Elasticsearch   Author: baidu   File: TransportShardMultiTermsVectorAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected MultiTermVectorsShardResponse shardOperation(MultiTermVectorsShardRequest request, ShardId shardId) {
    MultiTermVectorsShardResponse response = new MultiTermVectorsShardResponse();
    for (int i = 0; i < request.locations.size(); i++) {
        TermVectorsRequest termVectorsRequest = request.requests.get(i);
        try {
            IndexService indexService = indicesService.indexServiceSafe(request.index());
            IndexShard indexShard = indexService.shardSafe(shardId.id());
            TermVectorsResponse termVectorsResponse = indexShard.termVectorsService().getTermVectors(termVectorsRequest, shardId.getIndex());
            termVectorsResponse.updateTookInMillis(termVectorsRequest.startTime());
            response.add(request.locations.get(i), termVectorsResponse);
        } catch (Throwable t) {
            if (TransportActions.isShardNotAvailableException(t)) {
                throw (ElasticsearchException) t;
            } else {
                logger.debug("{} failed to execute multi term vectors for [{}]/[{}]", t, shardId, termVectorsRequest.type(), termVectorsRequest.id());
                response.add(request.locations.get(i),
                        new MultiTermVectorsResponse.Failure(request.index(), termVectorsRequest.type(), termVectorsRequest.id(), t));
            }
        }
    }

    return response;
}
 
Example #18
Source Project: crate   Author: crate   File: SyncedFlushService.java    License: Apache License 2.0 6 votes vote down vote up
private ShardSyncedFlushResponse performSyncedFlush(ShardSyncedFlushRequest request) {
    IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
    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);
    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 + "]");
    }
}
 
Example #19
Source Project: deprecated-security-advanced-modules   Author: opendistro-for-elasticsearch   File: DlsFlsFilterLeafReader.java    License: Apache License 2.0 5 votes vote down vote up
public DlsFlsDirectoryReader(final DirectoryReader in, final Set<String> includes, final Query dlsQuery,
                             final IndexService indexService, final ThreadContext threadContext,
                             final ClusterService clusterService, final ComplianceConfig complianceConfig,
                             final AuditLog auditlog, final Set<String> maskedFields, ShardId shardId) throws IOException {
    super(in, new DlsFlsSubReaderWrapper(includes, dlsQuery, indexService, threadContext, clusterService, complianceConfig, auditlog, maskedFields, shardId));
    this.includes = includes;
    this.dlsQuery = dlsQuery;
    this.indexService = indexService;
    this.threadContext = threadContext;
    this.clusterService = clusterService;
    this.complianceConfig = complianceConfig;
    this.auditlog = auditlog;
    this.maskedFields = maskedFields;
    this.shardId = shardId;
}
 
Example #20
Source Project: crate   Author: crate   File: BlobIndicesService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void afterIndexCreated(IndexService indexService) {
    String indexName = indexService.index().getName();
    if (isBlobIndex(indexName)) {
        BlobIndex oldBlobIndex = indices.put(indexName, new BlobIndex(LOGGER, globalBlobPath));
        assert oldBlobIndex == null : "There must not be an index present if a new index is created";
    }
}
 
Example #21
Source Project: crate   Author: crate   File: InternalTestCluster.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that the document history in Lucene index is consistent with Translog's on every index shard of the cluster.
 * This assertion might be expensive, thus we prefer not to execute on every test but only interesting tests.
 */
public void assertConsistentHistoryBetweenTranslogAndLuceneIndex() throws IOException {
    for (NodeAndClient nodeAndClient : nodes.values()) {
        IndicesService indexServices = getInstance(IndicesService.class, nodeAndClient.name);
        for (IndexService indexService : indexServices) {
            for (IndexShard indexShard : indexService) {
                try {
                    IndexShardTestCase.assertConsistentHistoryBetweenTranslogAndLucene(indexShard);
                } catch (AlreadyClosedException ignored) {
                    // shard is closed
                }
            }
        }
    }
}
 
Example #22
private List<IndexShard> getIndexShards(IndicesService indicesService) {
    List<IndexShard> indexShards = Lists.newArrayList();
    Iterator<IndexService> indexServiceIterator = indicesService.iterator();
    while (indexServiceIterator.hasNext()) {
        IndexService indexService = indexServiceIterator.next();
        for (int shardId : indexService.shardIds()) {
            indexShards.add(indexService.shard(shardId));
        }
    }
    return indexShards;
}
 
Example #23
Source Project: Elasticsearch   Author: baidu   File: NodeFetchOperation.java    License: Apache License 2.0 5 votes vote down vote up
public FetchCollector createCollector(int readerId) {
    IndexService indexService = fetchContext.indexService(readerId);
    LuceneReferenceResolver resolver = new LuceneReferenceResolver(indexService.mapperService());
    ArrayList<LuceneCollectorExpression<?>> exprs = new ArrayList<>(refs.size());
    for (Reference reference : refs) {
        exprs.add(resolver.getImplementation(reference.info()));
    }
    return new FetchCollector(exprs,
            indexService.mapperService(),
            fetchContext.searcher(readerId),
            indexService.fieldData(),
            readerId
    );
}
 
Example #24
Source Project: crate   Author: crate   File: BlobIndicesServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBlobComponentsAreNotCreatedForNonBlobIndex() throws Exception {
    IndexService indexService = mock(IndexService.class);
    Index index = new Index("dummy", UUIDs.randomBase64UUID());
    when(indexService.index()).thenReturn(index);
    blobIndicesService.afterIndexCreated(indexService);

    IndexShard indexShard = mock(IndexShard.class);
    when(indexShard.shardId()).thenReturn(new ShardId(index, 0));
    blobIndicesService.afterIndexShardCreated(indexShard);

    assertThat(blobIndicesService.indices.keySet(), Matchers.empty());
}
 
Example #25
Source Project: Elasticsearch   Author: baidu   File: BlobIndices.java    License: Apache License 2.0 5 votes vote down vote up
public BlobShard blobShard(String index, int shardId) {
    IndexService indexService = indicesService.indexService(index);
    if (indexService != null) {
        try {
            Injector injector = indexService.shardInjectorSafe(shardId);
            return injector.getInstance(BlobShard.class);
        } catch (ShardNotFoundException e) {
            return null;
        }
    }
    return null;
}
 
Example #26
Source Project: Elasticsearch   Author: baidu   File: TransportShardUpsertAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void processRequestItemsOnReplica(ShardId shardId, ShardUpsertRequest request) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.shardSafe(shardId.id());
    for (ShardUpsertRequest.Item item : request.items()) {
        if (item.source() == null) {
            if (logger.isTraceEnabled()) {
                logger.trace("[{} (R)] Document with id {}, has no source, primary operation must have failed",
                        indexShard.shardId(), item.id());
            }
            continue;
        }
        shardIndexOperationOnReplica(request, item, indexShard);
    }
}
 
Example #27
Source Project: Elasticsearch   Author: baidu   File: InternalIndicesLifecycle.java    License: Apache License 2.0 5 votes vote down vote up
public void afterIndexCreated(IndexService indexService) {
    for (Listener listener : listeners) {
        try {
            listener.afterIndexCreated(indexService);
        } catch (Throwable t) {
            logger.warn("[{}] failed to invoke after index created callback", t, indexService.index().name());
            throw t;
        }
    }
}
 
Example #28
Source Project: Elasticsearch   Author: baidu   File: InternalIndicesLifecycle.java    License: Apache License 2.0 5 votes vote down vote up
public void beforeIndexClosed(IndexService indexService) {
    for (Listener listener : listeners) {
        try {
            listener.beforeIndexClosed(indexService);
        } catch (Throwable t) {
            logger.warn("[{}] failed to invoke before index closed callback", t, indexService.index().name());
            throw t;
        }
    }
}
 
Example #29
Source Project: Elasticsearch   Author: baidu   File: SyncedFlushService.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #30
Source Project: crate   Author: crate   File: FetchTask.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public IndexService indexService(int readerId) {
    SharedShardContext sharedShardContext = shardContexts.get(readerId);
    if (sharedShardContext == null) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Reader with id %d not found", readerId));
    }
    return sharedShardContext.indexService();
}