/** * The shard id. */ public int id() { return shardId.id(); }
/** * Resolves the given shards directory against this NodePath * ${data.paths}/nodes/{node.id}/indices/{index.uuid}/{shard.id} */ public Path resolve(ShardId shardId) { return resolve(shardId.getIndex()).resolve(Integer.toString(shardId.id())); }
@Override public int hashCode() { // customized to account for discrepancies in shardId/Index toXContent/fromXContent related to uuid return Objects.hash(shardId.id(), shardId.getIndexName(), reason, nodeId, status.getStatus()); } }
/** * Just like {@link #getLogger(Class, ShardId, String...)} but String loggerName instead of * Class and no extra prefixes. */ public static Logger getLogger(String loggerName, ShardId shardId) { String prefix = formatPrefix(shardId.getIndexName(), Integer.toString(shardId.id())); return new PrefixLogger(LogManager.getLogger(loggerName), prefix); }
private static String buildMessage(ShardId shardId, String message) { if (shardId == null) { return message; } return buildMessage(shardId.getIndexName(), shardId.id(), message); }
@Override public void doRun() { final IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).getShardOrNull(shardId.id()); assert indexId != null; snapshot(indexShard, snapshot, indexId, shardEntry.getValue()); }
public void setShard(ShardId shardId) { if (shardId != null) { setIndex(shardId.getIndex()); addMetadata(SHARD_METADATA_KEY, Integer.toString(shardId.id())); } }
public static void writeToThin(IndexShardRoutingTable indexShard, StreamOutput out) throws IOException { out.writeVInt(indexShard.shardId.id()); out.writeVInt(indexShard.shards.size()); for (ShardRouting entry : indexShard) { entry.writeToThin(out); } }
/** * Returns shard for the specified id if it exists otherwise returns <code>null</code>. */ default T getShardOrNull(ShardId shardId) { U indexRef = indexService(shardId.getIndex()); if (indexRef != null) { return indexRef.getShardOrNull(shardId.id()); } return null; }
@Override public void onCache(ShardId shardId, String fieldName, Accountable ramUsage) { if (shardId != null) { final IndexShard shard = indexService.getShardOrNull(shardId.id()); if (shard != null) { shard.fieldData().onCache(shardId, fieldName, ramUsage); } } }
@Override public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, long sizeInBytes) { if (shardId != null) { final IndexShard shard = indexService.getShardOrNull(shardId.id()); if (shard != null) { shard.fieldData().onRemoval(shardId, fieldName, wasEvicted, sizeInBytes); } } } }
@Override public void onCache(ShardId shardId, Accountable accountable) { if (shardId != null) { final IndexShard shard = indexService.getShardOrNull(shardId.id()); if (shard != null) { long ramBytesUsed = accountable != null ? accountable.ramBytesUsed() : 0L; shard.shardBitsetFilterCache().onCached(ramBytesUsed); } } }
@Override protected TermVectorsResponse shardOperation(TermVectorsRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(shardId.id()); return TermVectorsService.getTermVectors(indexShard, request); }
@Override public void onRemoval(ShardId shardId, Accountable accountable) { if (shardId != null) { final IndexShard shard = indexService.getShardOrNull(shardId.id()); if (shard != null) { long ramBytesUsed = accountable != null ? accountable.ramBytesUsed() : 0L; shard.shardBitsetFilterCache().onRemoval(ramBytesUsed); } } } }
public RecoverySourceHandler(final IndexShard shard, RecoveryTargetHandler recoveryTarget, final StartRecoveryRequest request, final int fileChunkSizeInBytes) { this.shard = shard; this.recoveryTarget = recoveryTarget; this.request = request; this.shardId = this.request.shardId().id(); this.logger = Loggers.getLogger(getClass(), request.shardId(), "recover to " + request.targetNode().getName()); this.chunkSizeInBytes = fileChunkSizeInBytes; this.response = new RecoveryResponse(); }
@Override protected MergeThread getMergeThread(IndexWriter writer, MergePolicy.OneMerge merge) throws IOException { MergeThread thread = super.getMergeThread(writer, merge); thread.setName(EsExecutors.threadName(indexSettings, "[" + shardId.getIndexName() + "][" + shardId.id() + "]: " + thread.getName())); return thread; }
@Override protected EmptyResult shardOperation(ForceMergeRequest request, ShardRouting shardRouting) throws IOException { IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(shardRouting.shardId().id()); indexShard.forceMerge(request); return EmptyResult.INSTANCE; }
@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(); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("index", shardId.getIndexName()); builder.field("index_uuid", shardId.getIndexName()); builder.field("shard_id", shardId.id()); builder.field("reason", reason); if (nodeId != null) { builder.field("node_id", nodeId); } builder.field("status", status.name()); return builder; }
private PreSyncedFlushResponse performPreSyncedFlush(PreShardSyncedFlushRequest request) { 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()); indexShard.flush(flushRequest); final CommitStats commitStats = indexShard.commitStats(); final Engine.CommitId commitId = commitStats.getRawCommitId(); logger.trace("{} pre sync flush done. commit id {}, num docs {}", request.shardId(), commitId, commitStats.getNumDocs()); return new PreSyncedFlushResponse(commitId, commitStats.getNumDocs(), commitStats.syncId()); }