Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import org.elasticsearch.action.support.single.shard.TransportSingleShardAction;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.PlainShardIterator;
import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.Writeable;
Expand All @@ -30,7 +27,6 @@
import org.elasticsearch.transport.TransportService;

import java.io.IOException;
import java.util.stream.Collectors;

/**
* Performs the get operation.
Expand Down Expand Up @@ -79,19 +75,7 @@ protected ShardIterator shards(ClusterState state, InternalRequest request) {
request.request().routing(),
request.request().preference()
);
if (iterator == null) {
return null;
}
// If it is stateless, only route isPromotableToPrimary shards. This is a temporary workaround until a more cohesive solution can be
// implemented for search shards.
if (DiscoveryNode.isStateless(clusterService.getSettings())) {
return new PlainShardIterator(
iterator.shardId(),
iterator.getShardRoutings().stream().filter(ShardRouting::isPromotableToPrimary).collect(Collectors.toList())
);
} else {
return iterator;
}
return clusterService.operationRouting().useOnlyPromotableShardsForStateless(iterator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnhatn are these changes to Get and MGet necessary for correctly routing term vector requests? Or is it just to make use of useOnlyPromotableShardsForStateless? I need to change this to route gets to search shards, and I am wondering whether this is needed/shared with term vectors or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pxsalehi The term vectors API just uses useOnlyPromotableShardsForStateless shards. Feel free to make changes to the get and mget APIs.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import org.elasticsearch.action.support.single.shard.TransportSingleShardAction;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.PlainShardIterator;
import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.Writeable;
Expand All @@ -32,7 +29,6 @@
import org.elasticsearch.transport.TransportService;

import java.io.IOException;
import java.util.stream.Collectors;

import static org.elasticsearch.core.Strings.format;

Expand Down Expand Up @@ -87,19 +83,7 @@ protected boolean resolveIndex(MultiGetShardRequest request) {
protected ShardIterator shards(ClusterState state, InternalRequest request) {
ShardIterator iterator = clusterService.operationRouting()
.getShards(state, request.request().index(), request.request().shardId(), request.request().preference());
if (iterator == null) {
return null;
}
// If it is stateless, only route promotable shards. This is a temporary workaround until a more cohesive solution can be
// implemented for search shards.
if (DiscoveryNode.isStateless(clusterService.getSettings())) {
return new PlainShardIterator(
iterator.shardId(),
iterator.getShardRoutings().stream().filter(ShardRouting::isPromotableToPrimary).collect(Collectors.toList())
);
} else {
return iterator;
}
return clusterService.operationRouting().useOnlyPromotableShardsForStateless(iterator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ protected boolean resolveIndex(MultiTermVectorsShardRequest request) {

@Override
protected ShardIterator shards(ClusterState state, InternalRequest request) {
return clusterService.operationRouting()
ShardIterator shards = clusterService.operationRouting()
.getShards(state, request.concreteIndex(), request.request().shardId(), request.request().preference());
return clusterService.operationRouting().useOnlyPromotableShardsForStateless(shards);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ protected ShardIterator shards(ClusterState state, InternalRequest request) {
return groupShardsIter.iterator().next();
}

return clusterService.operationRouting()
ShardIterator shards = clusterService.operationRouting()
.getShards(state, request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference());
return clusterService.operationRouting().useOnlyPromotableShardsForStateless(shards);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.ClusterSettings;
Expand Down Expand Up @@ -39,8 +40,10 @@ public class OperationRouting {
);

private boolean useAdaptiveReplicaSelection;
private final boolean isStateless;

public OperationRouting(Settings settings, ClusterSettings clusterSettings) {
this.isStateless = DiscoveryNode.isStateless(settings);
this.useAdaptiveReplicaSelection = USE_ADAPTIVE_REPLICA_SELECTION_SETTING.get(settings);
clusterSettings.addSettingsUpdateConsumer(USE_ADAPTIVE_REPLICA_SELECTION_SETTING, this::setUseAdaptiveReplicaSelection);
}
Expand Down Expand Up @@ -76,6 +79,19 @@ public ShardIterator getShards(ClusterState clusterState, String index, int shar
);
}

public ShardIterator useOnlyPromotableShardsForStateless(ShardIterator shards) {
// If it is stateless, only route promotable shards. This is a temporary workaround until a more cohesive solution can be
// implemented for search shards.
if (isStateless && shards != null) {
return new PlainShardIterator(
shards.shardId(),
shards.getShardRoutings().stream().filter(ShardRouting::isPromotableToPrimary).collect(Collectors.toList())
);
} else {
return shards;
}
}

public GroupShardsIterator<ShardIterator> searchShards(
ClusterState clusterState,
String[] concreteIndices,
Expand Down