Skip to content

Commit 82434e3

Browse files
committed
TMP
1 parent ab4e1ed commit 82434e3

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/termvectors/30_realtime.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
settings:
88
index:
99
refresh_interval: -1
10-
number_of_replicas: 0
1110

1211
- do:
1312
cluster.health:

server/src/main/java/org/elasticsearch/action/termvectors/TransportEnsureDocsSearchableAction.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
import org.elasticsearch.action.ActionResponse;
1818
import org.elasticsearch.action.ActionType;
1919
import org.elasticsearch.action.NoShardAvailableActionException;
20+
import org.elasticsearch.action.admin.indices.refresh.TransportShardRefreshAction;
2021
import org.elasticsearch.action.support.ActionFilters;
22+
import org.elasticsearch.action.support.ActiveShardCount;
23+
import org.elasticsearch.action.support.replication.BasicReplicationRequest;
2124
import org.elasticsearch.action.support.single.shard.TransportSingleShardAction;
25+
import org.elasticsearch.client.internal.node.NodeClient;
2226
import org.elasticsearch.cluster.ProjectState;
2327
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
2428
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -48,6 +52,7 @@
4852
public class TransportEnsureDocsSearchableAction extends TransportSingleShardAction<MultiTermVectorsShardRequest, ActionResponse.Empty> {
4953

5054
private static final Logger logger = LogManager.getLogger(TransportEnsureDocsSearchableAction.class);
55+
private final NodeClient client;
5156
private final IndicesService indicesService;
5257

5358
private static final String ACTION_NAME = MultiTermVectorsAction.NAME + "/eds";
@@ -56,6 +61,7 @@ public class TransportEnsureDocsSearchableAction extends TransportSingleShardAct
5661
@Inject
5762
public TransportEnsureDocsSearchableAction(
5863
ClusterService clusterService,
64+
NodeClient client,
5965
TransportService transportService,
6066
IndicesService indicesService,
6167
ThreadPool threadPool,
@@ -74,6 +80,7 @@ public TransportEnsureDocsSearchableAction(
7480
MultiTermVectorsShardRequest::new,
7581
threadPool.executor(ThreadPool.Names.GET)
7682
);
83+
this.client = client;
7784
this.indicesService = indicesService;
7885
}
7986

@@ -112,7 +119,7 @@ protected void asyncShardOperation(MultiTermVectorsShardRequest request, ShardId
112119
assert DiscoveryNode.isStateless(clusterService.getSettings()) : ACTION_NAME + " should only be used in stateless";
113120
assert DiscoveryNode.hasRole(clusterService.getSettings(), DiscoveryNodeRole.INDEX_ROLE)
114121
: ACTION_NAME + " should only be executed on a stateless indexing node";
115-
logger.debug("received locally {} with {} sub requests", request, request.locations.size());
122+
logger.error("received locally {} with {} sub requests", request, request.locations.size());
116123
getExecutor(shardId).execute(() -> ActionListener.run(listener, l -> {
117124
final IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
118125
final IndexShard indexShard = indexService.getShard(shardId.id());
@@ -129,24 +136,45 @@ protected void asyncShardOperation(MultiTermVectorsShardRequest request, ShardId
129136
// We prefer simplicity to complexity (trying to avoid the unnecessary stateless refresh) for these limited cases.
130137
boolean docInLiveVersionMap = indexShard.withEngine(engine -> engine.isDocumentInLiveVersionMap(docUid));
131138
if (docInLiveVersionMap) {
132-
logger.debug("doc id [{}] (uid [{}]) found in live version map of index shard [{}]", docId, docUid, shardId);
139+
logger.error("doc id [{}] (uid [{}]) found in live version map of index shard [{}]", docId, docUid, shardId);
133140
docsFoundInLiveVersionMap = true;
134141
break;
135142
}
136143
}
137144
}
138145
if (docsFoundInLiveVersionMap) {
139-
logger.debug("refreshing index shard [{}] due to mtv_eds", shardId);
140-
indexShard.externalRefresh("refresh_mtv_eds", l.map(r -> {
141-
logger.debug("refreshed index shard [{}] due to mtv_eds", shardId);
142-
return ActionResponse.Empty.INSTANCE;
146+
logger.error("refreshing index shard [{}] due to mtv_eds", shardId);
147+
BasicReplicationRequest refreshRequest = new BasicReplicationRequest(shardId);
148+
refreshRequest.waitForActiveShards(ActiveShardCount.NONE);
149+
client.executeLocally(TransportShardRefreshAction.TYPE, refreshRequest, l.delegateFailureAndWrap((ll, r) -> {
150+
if (r.getShardInfo().getFailed() > 0) {
151+
throw r.getShardInfo().getFailures()[0];
152+
}
153+
// super.asyncShardOperation(request, shardId, ll);
154+
logger.error("refreshed index shard [{}] due to mtv_eds", shardId);
155+
ll.onResponse(ActionResponse.Empty.INSTANCE);
143156
}));
157+
158+
// indexShard.externalRefresh("refresh_mtv_eds", l.map(r -> {
159+
// logger.error("refreshed index shard [{}] due to mtv_eds", shardId);
160+
// return ActionResponse.Empty.INSTANCE;
161+
// }));
162+
// [2025-06-30T13:21:14,574][ERROR][o.e.a.t.TransportTermVectorsAction] [search-GyrIOXh] received locally id 1 for shard
163+
// [test_1][2]
164+
// [2025-06-30T13:21:14,579][ERROR][o.e.a.t.TransportEnsureDocsSearchableAction] [index-KgxlcuR] received locally
165+
// org.elasticsearch.action.termvectors.MultiTermVectorsShardRequest/unset with 1 sub requests
166+
// [2025-06-30T13:21:14,581][ERROR][o.e.a.t.TransportEnsureDocsSearchableAction] [index-KgxlcuR] doc id [1] (uid [[fe 1f]])
167+
// found in live version map of index shard [[test_1][2]]
168+
// [2025-06-30T13:21:14,582][ERROR][o.e.a.t.TransportEnsureDocsSearchableAction] [index-KgxlcuR] refreshing index shard
169+
// [[test_1][2]] due to mtv_eds
170+
// [2025-06-30T13:21:14,668][ERROR][o.e.a.t.TransportEnsureDocsSearchableAction] [index-KgxlcuR] refreshed index shard
171+
// [[test_1][2]] due to mtv_eds
144172
} else {
145173
// Notice that there cannot be a race between the document(s) being evicted from the live version map due to an
146174
// ongoing refresh and before the search shards being updated with the new commit, because the documents are
147175
// guaranteed to be the in the live version map archive until search shards are updated with the new commit.
148176
// Thus, we can safely respond immediately as a no-op.
149-
logger.debug("mts_eds does not require refresh of index shard [{}]", shardId);
177+
logger.error("mts_eds does not require refresh of index shard [{}]", shardId);
150178
l.onResponse(ActionResponse.Empty.INSTANCE);
151179
}
152180
}));

server/src/main/java/org/elasticsearch/action/termvectors/TransportShardMultiTermsVectorAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ protected void asyncShardOperation(
104104
ShardId shardId,
105105
ActionListener<MultiTermVectorsShardResponse> listener
106106
) throws IOException {
107-
boolean ensureDocsSearchable = DiscoveryNode.isStateless(clusterService.getSettings())
108-
&& request.requests.stream().anyMatch(r -> r.realtime() && r.id() != null && r.id().isEmpty() == false);
107+
boolean ensureDocsSearchable = DiscoveryNode.isStateless(clusterService.getSettings()) && request.requests.stream().anyMatch(r -> {
108+
logger.error("received locally sub-id {} for shard {}", r.id(), shardId);
109+
return r.realtime() && r.id() != null && r.id().isEmpty() == false;
110+
});
109111
if (ensureDocsSearchable) {
110112
client.executeLocally(
111113
TransportEnsureDocsSearchableAction.TYPE,
@@ -119,6 +121,7 @@ protected void asyncShardOperation(
119121

120122
@Override
121123
protected MultiTermVectorsShardResponse shardOperation(MultiTermVectorsShardRequest request, ShardId shardId) {
124+
logger.error("servicing locally {} for shard {}", request, shardId);
122125
final MultiTermVectorsShardResponse response = new MultiTermVectorsShardResponse();
123126
final IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
124127
final IndexShard indexShard = indexService.getShard(shardId.id());

server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ protected void asyncShardOperation(TermVectorsRequest request, ShardId shardId,
110110
boolean ensureDocSearchable = DiscoveryNode.isStateless(clusterService.getSettings())
111111
&& request.id() != null
112112
&& request.id().isEmpty() == false;
113+
logger.error("received locally id {} for shard {}", request.id(), shardId);
113114
if (ensureDocSearchable) {
114115
// Ensure that the document is searchable before we execute the term vectors request
115116
MultiTermVectorsShardRequest ensureDocSearchableRequest = new MultiTermVectorsShardRequest(request.index(), shardId.id());
@@ -137,6 +138,7 @@ protected void asyncShardOperation(TermVectorsRequest request, ShardId shardId,
137138

138139
@Override
139140
protected TermVectorsResponse shardOperation(TermVectorsRequest request, ShardId shardId) {
141+
logger.error("servicing locally id {} for shard {}", request.id(), shardId);
140142
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
141143
IndexShard indexShard = indexService.getShard(shardId.id());
142144
return TermVectorsService.getTermVectors(indexShard, request);

0 commit comments

Comments
 (0)