Skip to content

Commit

Permalink
Fix bug to find node id
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Bafna <gbbafna@amazon.com>
  • Loading branch information
gbbafna committed Sep 26, 2023
1 parent e1ff550 commit d38757b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public String getFileName() {

public static Tuple<Tuple<Long, Long>, String> getNodeIdByPrimaryTermAndGeneration(String filename) {
String[] tokens = filename.split(METADATA_SEPARATOR);
if (tokens.length < 5) {
if (tokens.length < 6) {
// For versions < 2.11, we don't have node id
return null;
}
return new Tuple<>(new Tuple<>(RemoteStoreUtils.invertLong(tokens[1]), RemoteStoreUtils.invertLong(tokens[2])), tokens[4]);
return new Tuple<>(new Tuple<>(RemoteStoreUtils.invertLong(tokens[1]), RemoteStoreUtils.invertLong(tokens[2])), tokens[5]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.concurrent.atomic.AtomicLong;

import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;
import static org.opensearch.index.store.RemoteSegmentStoreDirectory.METADATA_FILES_TO_FETCH;
import static org.opensearch.test.RemoteStoreTestUtils.createMetadataFileBytes;
import static org.opensearch.test.RemoteStoreTestUtils.getDummyMetadata;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -138,7 +139,7 @@ public void testRemoteDirectoryInitThrowsException() throws IOException {
return Collections.singletonList("dummy string");
}
throw new IOException();
}).when(remoteMetadataDirectory).listFilesByPrefixInLexicographicOrder(MetadataFilenameUtils.METADATA_PREFIX, 1);
}).when(remoteMetadataDirectory).listFilesByPrefixInLexicographicOrder(MetadataFilenameUtils.METADATA_PREFIX, METADATA_FILES_TO_FETCH);

SegmentInfos segmentInfos;
try (Store indexShardStore = indexShard.store()) {
Expand All @@ -165,7 +166,7 @@ public void testRemoteDirectoryInitThrowsException() throws IOException {
// Validate that the stream of metadata file of remoteMetadataDirectory has been opened only once and the
// listFilesByPrefixInLexicographicOrder has been called twice.
verify(remoteMetadataDirectory, times(1)).getBlobStream(any());
verify(remoteMetadataDirectory, times(2)).listFilesByPrefixInLexicographicOrder(MetadataFilenameUtils.METADATA_PREFIX, 1);
verify(remoteMetadataDirectory, times(2)).listFilesByPrefixInLexicographicOrder(MetadataFilenameUtils.METADATA_PREFIX, METADATA_FILES_TO_FETCH);
}

public void testAfterRefresh() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package org.opensearch.index.store;

import org.apache.lucene.store.Directory;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.opensearch.action.LatchedActionListener;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.blobstore.BlobContainer;
Expand All @@ -26,22 +28,20 @@
import org.opensearch.test.IndexSettingsModule;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.threadpool.ThreadPool;
import org.junit.Before;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Supplier;

import org.mockito.ArgumentCaptor;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opensearch.index.store.RemoteSegmentStoreDirectory.METADATA_FILES_TO_FETCH;

public class RemoteSegmentStoreDirectoryFactoryTests extends OpenSearchTestCase {

Expand Down Expand Up @@ -78,7 +78,7 @@ public void testNewDirectory() throws IOException {
latchedActionListener.onResponse(List.of());
return null;
}).when(blobContainer)
.listBlobsByPrefixInSortedOrder(any(), eq(1), eq(BlobContainer.BlobNameSortOrder.LEXICOGRAPHIC), any(ActionListener.class));
.listBlobsByPrefixInSortedOrder(any(), eq(METADATA_FILES_TO_FETCH), eq(BlobContainer.BlobNameSortOrder.LEXICOGRAPHIC), any(ActionListener.class));

when(repositoriesService.repository("remote_store_repository")).thenReturn(repository);

Expand All @@ -93,7 +93,7 @@ public void testNewDirectory() throws IOException {

verify(blobContainer).listBlobsByPrefixInSortedOrder(
eq(RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX),
eq(1),
eq(METADATA_FILES_TO_FETCH),
eq(BlobContainer.BlobNameSortOrder.LEXICOGRAPHIC),
any()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
package org.opensearch.index.translog.transfer;

import org.apache.lucene.tests.util.LuceneTestCase;
import org.mockito.Mockito;
import org.opensearch.action.LatchedActionListener;
import org.opensearch.common.blobstore.BlobContainer;
import org.opensearch.common.blobstore.BlobMetadata;
import org.opensearch.common.blobstore.BlobPath;
import org.opensearch.common.blobstore.BlobStore;
import org.opensearch.common.blobstore.stream.write.WritePriority;
import org.opensearch.common.blobstore.support.PlainBlobMetadata;
import org.opensearch.common.collect.Tuple;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.index.Index;
import org.opensearch.core.index.shard.ShardId;
Expand All @@ -42,8 +42,6 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import org.mockito.Mockito;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anySet;
Expand Down Expand Up @@ -504,7 +502,7 @@ private void assertTlogCkpDownloadStats() {

public void testGetPrimaryTermAndGeneration() {
String tm = new TranslogTransferMetadata(1, 2, 1, 2).getFileName();
assertEquals(new Tuple<>(1L, 2L), TranslogTransferMetadata.getNodeIdByPrimaryTermAndGeneration(tm));
assertEquals(null, TranslogTransferMetadata.getNodeIdByPrimaryTermAndGeneration(tm));
}

public void testMetadataConflict() throws InterruptedException {
Expand Down

0 comments on commit d38757b

Please sign in to comment.