|
55 | 55 | import org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
|
56 | 56 | import org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
|
57 | 57 | import org.opensearch.cluster.service.ClusterService;
|
| 58 | +import org.opensearch.common.UUIDs; |
58 | 59 | import org.opensearch.common.compress.CompressedXContent;
|
59 | 60 | import org.opensearch.common.settings.ClusterSettings;
|
60 | 61 | import org.opensearch.common.settings.IndexScopedSettings;
|
61 | 62 | import org.opensearch.common.settings.Setting;
|
62 | 63 | import org.opensearch.common.settings.Settings;
|
63 | 64 | import org.opensearch.common.unit.TimeValue;
|
64 | 65 | import org.opensearch.common.util.BigArrays;
|
| 66 | +import org.opensearch.common.util.FeatureFlags; |
65 | 67 | import org.opensearch.common.xcontent.XContentFactory;
|
66 | 68 | import org.opensearch.core.index.Index;
|
67 | 69 | import org.opensearch.core.xcontent.NamedXContentRegistry;
|
|
81 | 83 | import org.opensearch.indices.SystemIndexDescriptor;
|
82 | 84 | import org.opensearch.indices.SystemIndices;
|
83 | 85 | import org.opensearch.indices.replication.common.ReplicationType;
|
| 86 | +import org.opensearch.node.remotestore.RemoteStoreNodeService; |
84 | 87 | import org.opensearch.snapshots.EmptySnapshotsInfoService;
|
85 | 88 | import org.opensearch.test.ClusterServiceUtils;
|
86 | 89 | import org.opensearch.test.OpenSearchTestCase;
|
|
135 | 138 | import static org.opensearch.cluster.metadata.MetadataCreateIndexService.getIndexNumberOfRoutingShards;
|
136 | 139 | import static org.opensearch.cluster.metadata.MetadataCreateIndexService.parseV1Mappings;
|
137 | 140 | import static org.opensearch.cluster.metadata.MetadataCreateIndexService.resolveAndValidateAliases;
|
| 141 | +import static org.opensearch.common.util.FeatureFlags.REMOTE_STORE_MIGRATION_EXPERIMENTAL; |
138 | 142 | import static org.opensearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
|
139 | 143 | import static org.opensearch.index.IndexSettings.INDEX_REFRESH_INTERVAL_SETTING;
|
140 | 144 | import static org.opensearch.index.IndexSettings.INDEX_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING;
|
|
149 | 153 | import static org.opensearch.node.Node.NODE_ATTRIBUTES;
|
150 | 154 | import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
|
151 | 155 | import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
|
| 156 | +import static org.opensearch.node.remotestore.RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING; |
| 157 | +import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING; |
152 | 158 | import static org.hamcrest.Matchers.containsString;
|
153 | 159 | import static org.hamcrest.Matchers.endsWith;
|
154 | 160 | import static org.hamcrest.Matchers.equalTo;
|
@@ -1550,6 +1556,132 @@ public void testRemoteStoreOverrideTranslogRepoIndexSettings() {
|
1550 | 1556 | }));
|
1551 | 1557 | }
|
1552 | 1558 |
|
| 1559 | + public void testNewIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode() { |
| 1560 | + FeatureFlags.initializeFeatureFlags(Settings.builder().put(REMOTE_STORE_MIGRATION_EXPERIMENTAL, "true").build()); |
| 1561 | + |
| 1562 | + // non-remote cluster manager node |
| 1563 | + DiscoveryNode nonRemoteClusterManagerNode = new DiscoveryNode( |
| 1564 | + UUIDs.base64UUID(), |
| 1565 | + buildNewFakeTransportAddress(), |
| 1566 | + emptyMap(), |
| 1567 | + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), |
| 1568 | + Version.CURRENT |
| 1569 | + ); |
| 1570 | + |
| 1571 | + DiscoveryNodes discoveryNodes = DiscoveryNodes.builder() |
| 1572 | + .add(nonRemoteClusterManagerNode) |
| 1573 | + .localNodeId(nonRemoteClusterManagerNode.getId()) |
| 1574 | + .build(); |
| 1575 | + |
| 1576 | + ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(discoveryNodes).build(); |
| 1577 | + |
| 1578 | + ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); |
| 1579 | + |
| 1580 | + request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test"); |
| 1581 | + |
| 1582 | + Settings indexSettings = aggregateIndexSettings( |
| 1583 | + clusterState, |
| 1584 | + request, |
| 1585 | + Settings.EMPTY, |
| 1586 | + null, |
| 1587 | + Settings.EMPTY, |
| 1588 | + IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, |
| 1589 | + randomShardLimitService(), |
| 1590 | + Collections.emptySet(), |
| 1591 | + clusterSettings |
| 1592 | + ); |
| 1593 | + |
| 1594 | + verifyRemoteStoreIndexSettings( |
| 1595 | + indexSettings, |
| 1596 | + null, |
| 1597 | + null, |
| 1598 | + null, |
| 1599 | + ReplicationType.DOCUMENT.toString(), |
| 1600 | + IndexSettings.DEFAULT_REMOTE_TRANSLOG_BUFFER_INTERVAL |
| 1601 | + ); |
| 1602 | + |
| 1603 | + // remote data node |
| 1604 | + Map<String, String> attributes = new HashMap<>(); |
| 1605 | + attributes.put(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-segment-repo-1"); |
| 1606 | + attributes.put(REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-translog-repo-1"); |
| 1607 | + DiscoveryNode remoteDataNode = new DiscoveryNode( |
| 1608 | + UUIDs.base64UUID(), |
| 1609 | + buildNewFakeTransportAddress(), |
| 1610 | + attributes, |
| 1611 | + Set.of(DiscoveryNodeRole.INGEST_ROLE, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE, DiscoveryNodeRole.DATA_ROLE), |
| 1612 | + Version.CURRENT |
| 1613 | + ); |
| 1614 | + |
| 1615 | + discoveryNodes = DiscoveryNodes.builder(discoveryNodes).add(remoteDataNode).localNodeId(remoteDataNode.getId()).build(); |
| 1616 | + |
| 1617 | + clusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(discoveryNodes).build(); |
| 1618 | + |
| 1619 | + Settings remoteStoreMigrationSettings = Settings.builder() |
| 1620 | + .put(REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), RemoteStoreNodeService.CompatibilityMode.MIXED) |
| 1621 | + .put(MIGRATION_DIRECTION_SETTING.getKey(), RemoteStoreNodeService.Direction.REMOTE_STORE) |
| 1622 | + .build(); |
| 1623 | + |
| 1624 | + clusterSettings = new ClusterSettings(remoteStoreMigrationSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); |
| 1625 | + |
| 1626 | + indexSettings = aggregateIndexSettings( |
| 1627 | + clusterState, |
| 1628 | + request, |
| 1629 | + Settings.EMPTY, |
| 1630 | + null, |
| 1631 | + Settings.EMPTY, |
| 1632 | + IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, |
| 1633 | + randomShardLimitService(), |
| 1634 | + Collections.emptySet(), |
| 1635 | + clusterSettings |
| 1636 | + ); |
| 1637 | + |
| 1638 | + verifyRemoteStoreIndexSettings( |
| 1639 | + indexSettings, |
| 1640 | + "true", |
| 1641 | + "my-segment-repo-1", |
| 1642 | + "my-translog-repo-1", |
| 1643 | + ReplicationType.SEGMENT.toString(), |
| 1644 | + IndexSettings.DEFAULT_REMOTE_TRANSLOG_BUFFER_INTERVAL |
| 1645 | + ); |
| 1646 | + |
| 1647 | + Map<String, String> missingTranslogAttribute = Map.of(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-segment-repo-1"); |
| 1648 | + |
| 1649 | + DiscoveryNodes finalDiscoveryNodes = DiscoveryNodes.builder() |
| 1650 | + .add(nonRemoteClusterManagerNode) |
| 1651 | + .add( |
| 1652 | + new DiscoveryNode( |
| 1653 | + UUIDs.base64UUID(), |
| 1654 | + buildNewFakeTransportAddress(), |
| 1655 | + missingTranslogAttribute, |
| 1656 | + Set.of(DiscoveryNodeRole.INGEST_ROLE, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE, DiscoveryNodeRole.DATA_ROLE), |
| 1657 | + Version.CURRENT |
| 1658 | + ) |
| 1659 | + ) |
| 1660 | + .build(); |
| 1661 | + |
| 1662 | + ClusterState finalClusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(finalDiscoveryNodes).build(); |
| 1663 | + ClusterSettings finalClusterSettings = clusterSettings; |
| 1664 | + |
| 1665 | + final IndexCreationException error = expectThrows(IndexCreationException.class, () -> { |
| 1666 | + aggregateIndexSettings( |
| 1667 | + finalClusterState, |
| 1668 | + request, |
| 1669 | + Settings.EMPTY, |
| 1670 | + null, |
| 1671 | + Settings.EMPTY, |
| 1672 | + IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, |
| 1673 | + randomShardLimitService(), |
| 1674 | + Collections.emptySet(), |
| 1675 | + finalClusterSettings |
| 1676 | + ); |
| 1677 | + }); |
| 1678 | + |
| 1679 | + assertThat( |
| 1680 | + error.getCause().getMessage(), |
| 1681 | + containsString("Cluster is migrating to remote store but no remote node found, failing index creation") |
| 1682 | + ); |
| 1683 | + } |
| 1684 | + |
1553 | 1685 | public void testBuildIndexMetadata() {
|
1554 | 1686 | IndexMetadata sourceIndexMetadata = IndexMetadata.builder("parent")
|
1555 | 1687 | .settings(Settings.builder().put("index.version.created", Version.CURRENT).build())
|
|
0 commit comments