Search in sources :

Example 96 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class SearchRequestTests method testRandomVersionSerialization.

public void testRandomVersionSerialization() throws IOException {
    SearchRequest searchRequest = createSearchRequest();
    Version version = VersionUtils.randomVersion(random());
    SearchRequest deserializedRequest = copyWriteable(searchRequest, namedWriteableRegistry, SearchRequest::new, version);
    if (version.before(LegacyESVersion.V_7_0_0)) {
        assertTrue(deserializedRequest.isCcsMinimizeRoundtrips());
    } else {
        assertEquals(searchRequest.isCcsMinimizeRoundtrips(), deserializedRequest.isCcsMinimizeRoundtrips());
    }
    assertEquals(searchRequest.getLocalClusterAlias(), deserializedRequest.getLocalClusterAlias());
    assertEquals(searchRequest.getAbsoluteStartMillis(), deserializedRequest.getAbsoluteStartMillis());
    assertEquals(searchRequest.isFinalReduce(), deserializedRequest.isFinalReduce());
    if (version.onOrAfter(Version.V_1_1_0)) {
        assertEquals(searchRequest.getCancelAfterTimeInterval(), deserializedRequest.getCancelAfterTimeInterval());
    } else {
        assertNull(deserializedRequest.getCancelAfterTimeInterval());
    }
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion)

Example 97 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class SearchContextIdTests method testEncode.

public void testEncode() {
    final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Arrays.asList(new NamedWriteableRegistry.Entry(QueryBuilder.class, TermQueryBuilder.NAME, TermQueryBuilder::new), new NamedWriteableRegistry.Entry(QueryBuilder.class, MatchAllQueryBuilder.NAME, MatchAllQueryBuilder::new), new NamedWriteableRegistry.Entry(QueryBuilder.class, IdsQueryBuilder.NAME, IdsQueryBuilder::new)));
    final AtomicArray<SearchPhaseResult> queryResults = TransportSearchHelperTests.generateQueryResults();
    final Version version = Version.CURRENT;
    final Map<String, AliasFilter> aliasFilters = new HashMap<>();
    for (SearchPhaseResult result : queryResults.asList()) {
        final AliasFilter aliasFilter;
        if (randomBoolean()) {
            aliasFilter = new AliasFilter(randomQueryBuilder());
        } else if (randomBoolean()) {
            aliasFilter = new AliasFilter(randomQueryBuilder(), "alias-" + between(1, 10));
        } else {
            aliasFilter = AliasFilter.EMPTY;
        }
        if (randomBoolean()) {
            aliasFilters.put(result.getSearchShardTarget().getShardId().getIndex().getUUID(), aliasFilter);
        }
    }
    final String id = SearchContextId.encode(queryResults.asList(), aliasFilters, version);
    final SearchContextId context = SearchContextId.decode(namedWriteableRegistry, id);
    assertThat(context.shards().keySet(), hasSize(3));
    assertThat(context.aliasFilter(), equalTo(aliasFilters));
    SearchContextIdForNode node1 = context.shards().get(new ShardId("idx", "uuid1", 2));
    assertThat(node1.getClusterAlias(), equalTo("cluster_x"));
    assertThat(node1.getNode(), equalTo("node_1"));
    assertThat(node1.getSearchContextId().getId(), equalTo(1L));
    assertThat(node1.getSearchContextId().getSessionId(), equalTo("a"));
    SearchContextIdForNode node2 = context.shards().get(new ShardId("idy", "uuid2", 42));
    assertThat(node2.getClusterAlias(), equalTo("cluster_y"));
    assertThat(node2.getNode(), equalTo("node_2"));
    assertThat(node2.getSearchContextId().getId(), equalTo(12L));
    assertThat(node2.getSearchContextId().getSessionId(), equalTo("b"));
    SearchContextIdForNode node3 = context.shards().get(new ShardId("idy", "uuid2", 43));
    assertThat(node3.getClusterAlias(), nullValue());
    assertThat(node3.getNode(), equalTo("node_3"));
    assertThat(node3.getSearchContextId().getId(), equalTo(42L));
    assertThat(node3.getSearchContextId().getSessionId(), equalTo("c"));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) AliasFilter(org.opensearch.search.internal.AliasFilter) IdsQueryBuilder(org.opensearch.index.query.IdsQueryBuilder) HashMap(java.util.HashMap) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) ShardId(org.opensearch.index.shard.ShardId) Version(org.opensearch.Version) SearchPhaseResult(org.opensearch.search.SearchPhaseResult) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder)

Example 98 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class ClusterSerializationTests method testSnapshotDeletionsInProgressSerialization.

public void testSnapshotDeletionsInProgressSerialization() throws Exception {
    boolean includeRestore = randomBoolean();
    ClusterState.Builder builder = ClusterState.builder(ClusterState.EMPTY_STATE).putCustom(SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress.of(Collections.singletonList(new SnapshotDeletionsInProgress.Entry(Collections.singletonList(new SnapshotId("snap1", UUIDs.randomBase64UUID())), "repo1", randomNonNegativeLong(), randomNonNegativeLong(), SnapshotDeletionsInProgress.State.STARTED))));
    if (includeRestore) {
        builder.putCustom(RestoreInProgress.TYPE, new RestoreInProgress.Builder().add(new RestoreInProgress.Entry(UUIDs.randomBase64UUID(), new Snapshot("repo2", new SnapshotId("snap2", UUIDs.randomBase64UUID())), RestoreInProgress.State.STARTED, Collections.singletonList("index_name"), ImmutableOpenMap.of())).build());
    }
    ClusterState clusterState = builder.incrementVersion().build();
    Diff<ClusterState> diffs = clusterState.diff(ClusterState.EMPTY_STATE);
    // serialize with current version
    BytesStreamOutput outStream = new BytesStreamOutput();
    Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
    outStream.setVersion(version);
    diffs.writeTo(outStream);
    StreamInput inStream = outStream.bytes().streamInput();
    inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
    inStream.setVersion(version);
    Diff<ClusterState> serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
    ClusterState stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
    assertThat(stateAfterDiffs.custom(RestoreInProgress.TYPE), includeRestore ? notNullValue() : nullValue());
    assertThat(stateAfterDiffs.custom(SnapshotDeletionsInProgress.TYPE), notNullValue());
    // remove the custom and try serializing again
    clusterState = ClusterState.builder(clusterState).removeCustom(SnapshotDeletionsInProgress.TYPE).incrementVersion().build();
    outStream = new BytesStreamOutput();
    outStream.setVersion(version);
    diffs.writeTo(outStream);
    inStream = outStream.bytes().streamInput();
    inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
    inStream.setVersion(version);
    serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
    stateAfterDiffs = serializedDiffs.apply(stateAfterDiffs);
    assertThat(stateAfterDiffs.custom(RestoreInProgress.TYPE), includeRestore ? notNullValue() : nullValue());
    assertThat(stateAfterDiffs.custom(SnapshotDeletionsInProgress.TYPE), notNullValue());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ClusterState(org.opensearch.cluster.ClusterState) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) SnapshotDeletionsInProgress(org.opensearch.cluster.SnapshotDeletionsInProgress) SnapshotId(org.opensearch.snapshots.SnapshotId) Snapshot(org.opensearch.snapshots.Snapshot) RestoreInProgress(org.opensearch.cluster.RestoreInProgress) Version(org.opensearch.Version) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)

Example 99 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class ClusterSerializationTests method testCustomSerialization.

public void testCustomSerialization() throws Exception {
    ClusterState.Builder builder = ClusterState.builder(ClusterState.EMPTY_STATE).putCustom(TestCustomOne.TYPE, new TestCustomOne("test_custom_one")).putCustom(TestCustomTwo.TYPE, new TestCustomTwo(10));
    ClusterState clusterState = builder.incrementVersion().build();
    Diff<ClusterState> diffs = clusterState.diff(ClusterState.EMPTY_STATE);
    // Add the new customs to named writeables
    final List<NamedWriteableRegistry.Entry> entries = ClusterModule.getNamedWriteables();
    entries.add(new NamedWriteableRegistry.Entry(ClusterState.Custom.class, TestCustomOne.TYPE, TestCustomOne::new));
    entries.add(new NamedWriteableRegistry.Entry(NamedDiff.class, TestCustomOne.TYPE, TestCustomOne::readDiffFrom));
    entries.add(new NamedWriteableRegistry.Entry(ClusterState.Custom.class, TestCustomTwo.TYPE, TestCustomTwo::new));
    entries.add(new NamedWriteableRegistry.Entry(NamedDiff.class, TestCustomTwo.TYPE, TestCustomTwo::readDiffFrom));
    // serialize with current version
    BytesStreamOutput outStream = new BytesStreamOutput();
    Version version = Version.CURRENT;
    outStream.setVersion(version);
    diffs.writeTo(outStream);
    StreamInput inStream = outStream.bytes().streamInput();
    inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(entries));
    inStream.setVersion(version);
    Diff<ClusterState> serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
    ClusterState stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
    // Current version - Both the customs are non null
    assertThat(stateAfterDiffs.custom(TestCustomOne.TYPE), notNullValue());
    assertThat(stateAfterDiffs.custom(TestCustomTwo.TYPE), notNullValue());
    // serialize with minimum compatibile version
    outStream = new BytesStreamOutput();
    version = Version.CURRENT.minimumCompatibilityVersion();
    outStream.setVersion(version);
    diffs.writeTo(outStream);
    inStream = outStream.bytes().streamInput();
    inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(entries));
    inStream.setVersion(version);
    serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
    stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
    // Old version - TestCustomOne is null and TestCustomTwo is not null
    assertThat(stateAfterDiffs.custom(TestCustomOne.TYPE), nullValue());
    assertThat(stateAfterDiffs.custom(TestCustomTwo.TYPE), notNullValue());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ClusterState(org.opensearch.cluster.ClusterState) Custom(org.opensearch.cluster.ClusterState.Custom) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) NamedDiff(org.opensearch.cluster.NamedDiff) Version(org.opensearch.Version) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)

Example 100 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class VersionsTests method testLuceneVersionOnUnknownVersions.

public void testLuceneVersionOnUnknownVersions() {
    // between two known versions, should use the lucene version of the previous version
    Version version = LegacyESVersion.fromString("7.10.50");
    assertEquals(VersionUtils.getPreviousVersion(Version.fromString("7.10.3")).luceneVersion, version.luceneVersion);
    // too old version, major should be the oldest supported lucene version minus 1
    version = LegacyESVersion.fromString("5.2.1");
    assertEquals(VersionUtils.getFirstVersion().luceneVersion.major - 1, version.luceneVersion.major);
    // future version, should be the same version as today
    version = Version.fromString("2.77.1");
    assertEquals(Version.CURRENT.luceneVersion, version.luceneVersion);
}
Also used : Version(org.opensearch.Version) VersionsAndSeqNoResolver.loadDocIdAndVersion(org.opensearch.common.lucene.uid.VersionsAndSeqNoResolver.loadDocIdAndVersion) LegacyESVersion(org.opensearch.LegacyESVersion)

Aggregations

Version (org.opensearch.Version)242 Settings (org.opensearch.common.settings.Settings)86 LegacyESVersion (org.opensearch.LegacyESVersion)84 ArrayList (java.util.ArrayList)59 IOException (java.io.IOException)54 List (java.util.List)54 Map (java.util.Map)50 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)42 Collections (java.util.Collections)39 HashMap (java.util.HashMap)38 ClusterState (org.opensearch.cluster.ClusterState)38 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)37 HashSet (java.util.HashSet)36 BytesReference (org.opensearch.common.bytes.BytesReference)36 TimeValue (org.opensearch.common.unit.TimeValue)36 Set (java.util.Set)35 Collectors (java.util.stream.Collectors)34 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)33 StreamInput (org.opensearch.common.io.stream.StreamInput)32 BytesArray (org.opensearch.common.bytes.BytesArray)30