use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.
the class GatewayMetaStatePersistedStateTests method testStatePersistedOnLoad.
public void testStatePersistedOnLoad() throws IOException {
// open LucenePersistedState to make sure that cluster state is written out to each data path
final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), getBigArrays(), new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L);
final ClusterState state = createClusterState(randomNonNegativeLong(), Metadata.builder().clusterUUID(randomAlphaOfLength(10)).build());
try (GatewayMetaState.LucenePersistedState ignored = new GatewayMetaState.LucenePersistedState(persistedClusterStateService, 42L, state)) {
}
nodeEnvironment.close();
// verify that the freshest state was rewritten to each data path
for (Path path : nodeEnvironment.nodeDataPaths()) {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()).put(Environment.PATH_DATA_SETTING.getKey(), path.getParent().getParent().toString()).build();
try (NodeEnvironment nodeEnvironment = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings))) {
final PersistedClusterStateService newPersistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), getBigArrays(), new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L);
final PersistedClusterStateService.OnDiskState onDiskState = newPersistedClusterStateService.loadBestOnDiskState();
assertFalse(onDiskState.empty());
assertThat(onDiskState.currentTerm, equalTo(42L));
assertClusterStateEqual(state, ClusterState.builder(ClusterName.DEFAULT).version(onDiskState.lastAcceptedVersion).metadata(onDiskState.metadata).build());
}
}
}
use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.
the class DanglingIndicesStateTests method testClusterStateListenerNotRegisterWhenSettingDisabled.
/**
* Check that when auto-imports are disabled, then no change listener is registered with the cluster state.
*/
public void testClusterStateListenerNotRegisterWhenSettingDisabled() throws Exception {
try (NodeEnvironment env = newNodeEnvironment()) {
MetaStateService metaStateService = new MetaStateService(env, xContentRegistry());
LocalAllocateDangledIndices localAllocateDangledIndices = mock(LocalAllocateDangledIndices.class);
final Settings allocateSettings = Settings.builder().put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), false).build();
final ClusterService clusterServiceMock = mock(ClusterService.class);
when(clusterServiceMock.getSettings()).thenReturn(allocateSettings);
new DanglingIndicesState(env, metaStateService, localAllocateDangledIndices, clusterServiceMock);
verify(clusterServiceMock, never()).addListener(any());
}
}
use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.
the class DanglingIndicesStateTests method testInvalidIndexFolder.
public void testInvalidIndexFolder() throws Exception {
try (NodeEnvironment env = newNodeEnvironment()) {
MetaStateService metaStateService = new MetaStateService(env, xContentRegistry());
DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
Metadata metadata = Metadata.builder().build();
final String uuid = "test1UUID";
final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetadata.SETTING_INDEX_UUID, uuid);
IndexMetadata dangledIndex = IndexMetadata.builder("test1").settings(settings).build();
metaStateService.writeIndex("test_write", dangledIndex);
for (Path path : env.resolveIndexFolder(uuid)) {
if (Files.exists(path)) {
Files.move(path, path.resolveSibling("invalidUUID"), StandardCopyOption.ATOMIC_MOVE);
}
}
try {
danglingState.findNewDanglingIndices(emptyMap(), metadata);
fail("no exception thrown for invalid folder name");
} catch (IllegalStateException e) {
assertThat(e.getMessage(), equalTo("[invalidUUID] invalid index folder name, rename to [test1UUID]"));
}
}
}
use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.
the class DanglingIndicesStateTests method testDanglingIndicesDiscovery.
public void testDanglingIndicesDiscovery() throws Exception {
try (NodeEnvironment env = newNodeEnvironment()) {
MetaStateService metaStateService = new MetaStateService(env, xContentRegistry());
DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
assertTrue(danglingState.getDanglingIndices().isEmpty());
Metadata metadata = Metadata.builder().build();
final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetadata.SETTING_INDEX_UUID, "test1UUID");
IndexMetadata dangledIndex = IndexMetadata.builder("test1").settings(settings).build();
metaStateService.writeIndex("test_write", dangledIndex);
Map<Index, IndexMetadata> newDanglingIndices = danglingState.findNewDanglingIndices(emptyMap(), metadata);
assertTrue(newDanglingIndices.containsKey(dangledIndex.getIndex()));
metadata = Metadata.builder().put(dangledIndex, false).build();
newDanglingIndices = danglingState.findNewDanglingIndices(emptyMap(), metadata);
assertFalse(newDanglingIndices.containsKey(dangledIndex.getIndex()));
}
}
use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.
the class DanglingIndicesStateTests method testDanglingProcessing.
public void testDanglingProcessing() throws Exception {
try (NodeEnvironment env = newNodeEnvironment()) {
MetaStateService metaStateService = new MetaStateService(env, xContentRegistry());
DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
Metadata metadata = Metadata.builder().build();
final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetadata.SETTING_INDEX_UUID, "test1UUID");
IndexMetadata dangledIndex = IndexMetadata.builder("test1").settings(settings).build();
metaStateService.writeIndex("test_write", dangledIndex);
// check that several runs when not in the metadata still keep the dangled index around
int numberOfChecks = randomIntBetween(1, 10);
for (int i = 0; i < numberOfChecks; i++) {
Map<Index, IndexMetadata> newDanglingIndices = danglingState.findNewDanglingIndices(emptyMap(), metadata);
assertThat(newDanglingIndices.size(), equalTo(1));
assertThat(newDanglingIndices.keySet(), Matchers.hasItems(dangledIndex.getIndex()));
assertTrue(danglingState.getDanglingIndices().isEmpty());
}
for (int i = 0; i < numberOfChecks; i++) {
danglingState.findNewAndAddDanglingIndices(metadata);
assertThat(danglingState.getDanglingIndices().size(), equalTo(1));
assertThat(danglingState.getDanglingIndices().keySet(), Matchers.hasItems(dangledIndex.getIndex()));
}
// simulate allocation to the metadata
metadata = Metadata.builder(metadata).put(dangledIndex, true).build();
// check that several runs when in the metadata, but not cleaned yet, still keeps dangled
for (int i = 0; i < numberOfChecks; i++) {
Map<Index, IndexMetadata> newDanglingIndices = danglingState.findNewDanglingIndices(emptyMap(), metadata);
assertTrue(newDanglingIndices.isEmpty());
assertThat(danglingState.getDanglingIndices().size(), equalTo(1));
assertThat(danglingState.getDanglingIndices().keySet(), Matchers.hasItems(dangledIndex.getIndex()));
}
danglingState.cleanupAllocatedDangledIndices(metadata);
assertTrue(danglingState.getDanglingIndices().isEmpty());
}
}
Aggregations