Skip to content

Commit

Permalink
Address comments on PR.
Browse files Browse the repository at this point in the history
Signed-off-by: Rishikesh1159 <[email protected]>
  • Loading branch information
Rishikesh1159 committed Sep 8, 2023
1 parent 5d9ccb4 commit b71681f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1664,13 +1664,7 @@ public void testRealtimeTermVectorRequestsSuccessful() throws IOException {
// index doc 1
client().prepareIndex(INDEX_NAME)
.setId(Integer.toString(1))
.setSource(
jsonBuilder().startObject()
.field("field", "the quick brown fox jumps over the lazy dog")
// 0the3 4quick9 10brown15 16fox19 20jumps25 26over30
// 31the34 35lazy39 40dog43
.endObject()
)
.setSource(jsonBuilder().startObject().field("field", "the quick brown fox jumps over the lazy dog").endObject())
.execute()
.actionGet();

Expand All @@ -1683,6 +1677,7 @@ public void testRealtimeTermVectorRequestsSuccessful() throws IOException {
.setPayloads(true)
.setOffsets(true)
.setPositions(true)
.setRealtime(true)
.setSelectedFields();
response = resp.execute().actionGet();
assertThat(response.getIndex(), equalTo(INDEX_NAME));
Expand All @@ -1694,13 +1689,7 @@ public void testRealtimeTermVectorRequestsSuccessful() throws IOException {
client().prepareIndex(INDEX_NAME)
.setId(Integer.toString(2))
.setRouting(id)
.setSource(
jsonBuilder().startObject()
.field("field", "the quick brown fox jumps over the lazy dog")
// 0the3 4quick9 10brown15 16fox19 20jumps25 26over30
// 31the34 35lazy39 40dog43
.endObject()
)
.setSource(jsonBuilder().startObject().field("field", "the quick brown fox jumps over the lazy dog").endObject())
.execute()
.actionGet();

Expand Down Expand Up @@ -1752,13 +1741,7 @@ public void testRealtimeTermVectorRequestsUnSuccessful() throws IOException {
// index doc 1
client().prepareIndex(INDEX_NAME)
.setId(Integer.toString(1))
.setSource(
jsonBuilder().startObject()
.field("field", "the quick brown fox jumps over the lazy dog")
// 0the3 4quick9 10brown15 16fox19 20jumps25 26over30
// 31the34 35lazy39 40dog43
.endObject()
)
.setSource(jsonBuilder().startObject().field("field", "the quick brown fox jumps over the lazy dog").endObject())
.setRouting(id)
.execute()
.actionGet();
Expand All @@ -1773,6 +1756,7 @@ public void testRealtimeTermVectorRequestsUnSuccessful() throws IOException {
.setOffsets(true)
.setPositions(true)
.setPreference(Preference.REPLICA.type())
.setRealtime(true)
.setSelectedFields();
response = resp.execute().actionGet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected boolean resolveIndex(GetRequest request) {
/**
* Returns true if GET request should be routed to primary shards, else false.
*/
public static boolean shouldForcePrimaryRouting(Metadata metadata, boolean realtime, String preference, String indexName) {
protected static boolean shouldForcePrimaryRouting(Metadata metadata, boolean realtime, String preference, String indexName) {
return metadata.isSegmentReplicationEnabled(indexName) && realtime && preference == null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class MultiTermVectorsRequest extends ActionRequest
RealtimeRequest {

String preference;

List<TermVectorsRequest> requests = new ArrayList<>();

final Set<String> ids = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

import java.io.IOException;

import static org.opensearch.action.get.TransportGetAction.shouldForcePrimaryRouting;

/**
* Performs the get operation.
*
Expand Down Expand Up @@ -91,18 +89,12 @@ public TransportTermVectorsAction(
@Override
protected ShardIterator shards(ClusterState state, InternalRequest request) {

final String preference;
// route realtime TermVector requests when segment replication is enabled to primary shards,
// iff there are no other preferences/routings enabled for routing to a specific shard
if (shouldForcePrimaryRouting(
state.getMetadata(),
request.request().realtime(),
request.request().preference(),
request.concreteIndex()
)) {
String preference = request.request().preference;
// For a real time request on a seg rep index, use primary shard as the preferred query shard.
if (request.request().realtime()
&& preference == null
&& state.getMetadata().isSegmentReplicationEnabled(request.concreteIndex())) {
preference = Preference.PRIMARY.type();
} else {
preference = request.request().preference();
}

if (request.request().doc() != null && request.request().routing() == null) {
Expand Down

0 comments on commit b71681f

Please sign in to comment.