private void verifyNotClosed(Exception suppressed) throws IllegalIndexShardStateException { IndexShardState state = this.state; // one time volatile read if (state == IndexShardState.CLOSED) { final IllegalIndexShardStateException exc = new IndexShardClosedException(shardId, "operation only allowed when not closed"); if (suppressed != null) { exc.addSuppressed(suppressed); } throw exc; } }
@Override public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { return new ResyncTask(id, type, action, getDescription(), parentTaskId, headers); }
/** * Returns {@code true} if this shard can ignore a recovery attempt made to it (since the already doing/done it) */ public boolean ignoreRecoveryAttempt() { IndexShardState state = state(); // one time volatile read return state == IndexShardState.POST_RECOVERY || state == IndexShardState.RECOVERING || state == IndexShardState.STARTED || state == IndexShardState.CLOSED; }
private void maybeSyncTranslog(final IndexShard indexShard) throws IOException { if (indexShard.getTranslogDurability() == Translog.Durability.REQUEST && indexShard.getLastSyncedGlobalCheckpoint() < indexShard.getGlobalCheckpoint()) { indexShard.sync(); } }
private void completeIndexAttributes(ProtobufSystemInfo.Section.Builder protobuf) { IndicesStatsResponse indicesStats = esClient.prepareStats().all().get(); for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) { String prefix = "Index " + indexStats.getKey() + " - "; setAttribute(protobuf, prefix + "Docs", indexStats.getValue().getPrimaries().getDocs().getCount()); setAttribute(protobuf, prefix + "Shards", indexStats.getValue().getShards().length); setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes())); } } }
@Override public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingStrategy splitSchedulingStrategy) { ElasticsearchTableLayoutHandle layoutHandle = (ElasticsearchTableLayoutHandle) layout; ElasticsearchTableHandle tableHandle = layoutHandle.getTable(); ElasticsearchTableDescription table = client.getTable(tableHandle.getSchemaName(), tableHandle.getTableName()); verify(table != null, "Table no longer exists: %s", tableHandle.toString()); List<String> indices = client.getIndices(table); ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder(); for (String index : indices) { ClusterSearchShardsResponse response = client.getSearchShards(index, table); DiscoveryNode[] nodes = response.getNodes(); for (ClusterSearchShardsGroup group : response.getGroups()) { int nodeIndex = group.getShardId().getId() % nodes.length; ElasticsearchSplit split = new ElasticsearchSplit( index, table.getType(), group.getShardId().getId(), nodes[nodeIndex].getHostName(), nodes[nodeIndex].getAddress().getPort(), layoutHandle.getTupleDomain()); splits.add(split); } } return new FixedSplitSource(splits.build()); } }
@Override public String toString() { return "local_shard_snapshot:[" + shard.shardId() + " indexCommit: " + indexCommit + "]"; } }
public Engine.IndexResult applyIndexOperationOnReplica(long seqNo, long version, VersionType versionType, long autoGeneratedTimeStamp, boolean isRetry, SourceToParse sourceToParse) throws IOException { return applyIndexOperation(getEngine(), seqNo, operationPrimaryTerm, version, versionType, UNASSIGNED_SEQ_NO, 0, autoGeneratedTimeStamp, isRetry, Engine.Operation.Origin.REPLICA, sourceToParse); }
/** * Creates a new request with resolved shard id */ public ReplicationRequest(ShardId shardId) { this.index = shardId.getIndexName(); this.shardId = shardId; }
public IllegalIndexShardStateException(ShardId shardId, IndexShardState currentState, String msg, Throwable ex, Object... args) { super("CurrentState[" + currentState + "] " + msg, ex, args); setShard(shardId); this.currentState = currentState; }
public ShardId(Index index, int shardId) { this.index = index; this.shardId = shardId; this.hashCode = computeHashCode(); }
protected final void verifyActive() throws IllegalIndexShardStateException { IndexShardState state = this.state; // one time volatile read if (state != IndexShardState.STARTED) { throw new IllegalIndexShardStateException(shardId, state, "operation only allowed when shard is active"); } }
@Override public void close() throws IOException { List<Tuple<Translog.Location, Consumer<Boolean>>> oldListeners; synchronized (this) { oldListeners = refreshListeners; refreshListeners = null; closed = true; } // Fire any listeners we might have had fireListeners(oldListeners); }
/** * Should be called for each no-op update operation to increment relevant statistics. * * @param type the doc type of the update */ public void noopUpdate(String type) { internalIndexingStats.noopUpdate(type); }
/** * @return a list of describing each permit that wasn't released yet. The description consist of the debugInfo supplied * when the permit was acquired plus a stack traces that was captured when the permit was request. */ public List<String> getActiveOperations() { return indexShardOperationPermits.getActiveOperations(); }
/** * Executes the logic for acquiring one or more operation permit on a primary shard. The default is to acquire a single permit but this * method can be overridden to acquire more. */ protected void acquirePrimaryOperationPermit(final IndexShard primary, final Request request, final ActionListener<Releasable> onAcquired) { primary.acquirePrimaryOperationPermit(onAcquired, executor, request); }
/** * Executes the logic for acquiring one or more operation permit on a replica shard. The default is to acquire a single permit but this * method can be overridden to acquire more. */ protected void acquireReplicaOperationPermit(final IndexShard replica, final ReplicaRequest request, final ActionListener<Releasable> onAcquired, final long primaryTerm, final long globalCheckpoint, final long maxSeqNoOfUpdatesOrDeletes) { replica.acquireReplicaOperationPermit(primaryTerm, globalCheckpoint, maxSeqNoOfUpdatesOrDeletes, onAcquired, executor, request); }
public ShardGetService(IndexSettings indexSettings, IndexShard indexShard, MapperService mapperService) { super(indexShard.shardId(), indexSettings); this.mapperService = mapperService; this.indexShard = indexShard; }
/** * The index the document was changed in. */ public String getIndex() { return this.shardId.getIndexName(); }