Java Code Examples for org.elasticsearch.index.IndexService#getShard()
The following examples show how to use
org.elasticsearch.index.IndexService#getShard() .
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 File: PeerRecoverySourceService.java From crate with Apache License 2.0 | 7 votes |
private void recover(StartRecoveryRequest request, ActionListener<RecoveryResponse> listener) throws IOException { final IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); final IndexShard shard = indexService.getShard(request.shardId().id()); final ShardRouting routingEntry = shard.routingEntry(); if (routingEntry.primary() == false || routingEntry.active() == false) { throw new DelayRecoveryException("source shard [" + routingEntry + "] is not an active primary"); } if (request.isPrimaryRelocation() && ( routingEntry.relocating() == false || routingEntry.relocatingNodeId().equals(request.targetNode().getId()) == false)) { LOGGER.debug( "delaying recovery of {} as source shard is not marked yet as relocating to {}", request.shardId(), request.targetNode()); throw new DelayRecoveryException("source shard is not marked yet as relocating to [" + request.targetNode() + "]"); } RecoverySourceHandler handler = ongoingRecoveries.addNewRecovery(request, shard); LOGGER.trace( "[{}][{}] starting recovery to {}", request.shardId().getIndex().getName(), request.shardId().id(), request.targetNode()); handler.recoverToTarget(ActionListener.runAfter(listener, () -> ongoingRecoveries.remove(shard, handler))); }
Example 2
Source File: SyncedFlushService.java From crate with Apache License 2.0 | 6 votes |
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 3
Source File: SyncedFlushService.java From crate with Apache License 2.0 | 5 votes |
private InFlightOpsResponse performInFlightOps(InFlightOpsRequest request) { IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); IndexShard indexShard = indexService.getShard(request.shardId().id()); if (indexShard.routingEntry().primary() == false) { throw new IllegalStateException("[" + request.shardId() + "] expected a primary shard"); } int opCount = indexShard.getActiveOperationsCount(); return new InFlightOpsResponse(opCount); }
Example 4
Source File: InternalCountOperation.java From crate with Apache License 2.0 | 5 votes |
@Override public long count(TransactionContext txnCtx, Index index, int shardId, Symbol filter) throws IOException, InterruptedException { IndexService indexService; try { indexService = indicesService.indexServiceSafe(index); } catch (IndexNotFoundException e) { if (IndexParts.isPartitioned(index.getName())) { return 0L; } throw e; } IndexShard indexShard = indexService.getShard(shardId); try (Engine.Searcher searcher = indexShard.acquireSearcher("count-operation")) { String indexName = indexShard.shardId().getIndexName(); var relationName = RelationName.fromIndexName(indexName); DocTableInfo table = schemas.getTableInfo(relationName, Operation.READ); LuceneQueryBuilder.Context queryCtx = queryBuilder.convert( filter, txnCtx, indexService.mapperService(), indexName, indexService.newQueryShardContext(), table, indexService.cache() ); if (Thread.interrupted()) { throw new InterruptedException("thread interrupted during count-operation"); } return searcher.searcher().count(queryCtx.query()); } }
Example 5
Source File: TransportIndicesStatsAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected ShardStats shardOperation(IndicesStatsRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()); 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()); } CommonStatsFlags flags = new CommonStatsFlags().clear(); if (request.docs()) { flags.set(CommonStatsFlags.Flag.Docs); } if (request.store()) { flags.set(CommonStatsFlags.Flag.Store); } if (request.completion()) { flags.set(CommonStatsFlags.Flag.Completion); flags.completionDataFields(request.completionFields()); } CommitStats commitStats; SeqNoStats seqNoStats; try { commitStats = indexShard.commitStats(); seqNoStats = indexShard.seqNoStats(); } catch (AlreadyClosedException e) { // shard is closed - no stats is fine commitStats = null; seqNoStats = null; } return new ShardStats( indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), commitStats, seqNoStats ); }
Example 6
Source File: TransportRecoveryAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected RecoveryState shardOperation(RecoveryRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()); IndexShard indexShard = indexService.getShard(shardRouting.shardId().id()); return indexShard.recoveryState(); }
Example 7
Source File: TransportReplicationAction.java From crate with Apache License 2.0 | 4 votes |
protected IndexShard getIndexShard(ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); return indexService.getShard(shardId.id()); }