forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RemoteDirectoryFactory and use RemoteDirectory instance in Refres…
…hListener (opensearch-project#3285) Co-authored-by: Sachin Kale <[email protected]> Signed-off-by: Sachin Kale <[email protected]>
- Loading branch information
1 parent
07f6f6c
commit f2a3889
Showing
11 changed files
with
211 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
server/src/main/java/org/opensearch/index/shard/RemoteStoreRefreshListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.shard; | ||
|
||
import org.apache.lucene.search.ReferenceManager; | ||
import org.apache.lucene.store.Directory; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* RefreshListener implementation to upload newly created segment files to the remote store | ||
*/ | ||
public class RemoteStoreRefreshListener implements ReferenceManager.RefreshListener { | ||
|
||
private final Directory storeDirectory; | ||
private final Directory remoteDirectory; | ||
|
||
public RemoteStoreRefreshListener(Directory storeDirectory, Directory remoteDirectory) { | ||
this.storeDirectory = storeDirectory; | ||
this.remoteDirectory = remoteDirectory; | ||
} | ||
|
||
@Override | ||
public void beforeRefresh() throws IOException { | ||
// ToDo Add implementation | ||
} | ||
|
||
@Override | ||
public void afterRefresh(boolean didRefresh) throws IOException { | ||
// ToDo Add implementation | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
server/src/main/java/org/opensearch/index/store/RemoteDirectoryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store; | ||
|
||
import org.apache.lucene.store.Directory; | ||
import org.opensearch.common.blobstore.BlobContainer; | ||
import org.opensearch.common.blobstore.BlobPath; | ||
import org.opensearch.index.IndexSettings; | ||
import org.opensearch.index.shard.ShardPath; | ||
import org.opensearch.plugins.IndexStorePlugin; | ||
import org.opensearch.repositories.Repository; | ||
import org.opensearch.repositories.blobstore.BlobStoreRepository; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Factory for a remote store directory | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class RemoteDirectoryFactory implements IndexStorePlugin.RemoteDirectoryFactory { | ||
|
||
@Override | ||
public Directory newDirectory(IndexSettings indexSettings, ShardPath path, Repository repository) throws IOException { | ||
assert repository instanceof BlobStoreRepository : "repository should be instance of BlobStoreRepository"; | ||
BlobPath blobPath = new BlobPath(); | ||
blobPath = blobPath.add(indexSettings.getIndex().getName()).add(String.valueOf(path.getShardId().getId())); | ||
BlobContainer blobContainer = ((BlobStoreRepository) repository).blobStore().blobContainer(blobPath); | ||
return new RemoteDirectory(blobContainer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
server/src/test/java/org/opensearch/index/store/RemoteDirectoryFactoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store; | ||
|
||
import org.apache.lucene.store.Directory; | ||
import org.junit.Before; | ||
import org.mockito.ArgumentCaptor; | ||
import org.opensearch.common.blobstore.BlobContainer; | ||
import org.opensearch.common.blobstore.BlobPath; | ||
import org.opensearch.common.blobstore.BlobStore; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.index.IndexSettings; | ||
import org.opensearch.index.shard.ShardId; | ||
import org.opensearch.index.shard.ShardPath; | ||
import org.opensearch.repositories.blobstore.BlobStoreRepository; | ||
import org.opensearch.test.IndexSettingsModule; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class RemoteDirectoryFactoryTests extends OpenSearchTestCase { | ||
|
||
private RemoteDirectoryFactory remoteDirectoryFactory; | ||
|
||
@Before | ||
public void setup() { | ||
remoteDirectoryFactory = new RemoteDirectoryFactory(); | ||
} | ||
|
||
public void testNewDirectory() throws IOException { | ||
Settings settings = Settings.builder().build(); | ||
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); | ||
Path tempDir = createTempDir().resolve(indexSettings.getUUID()).resolve("0"); | ||
ShardPath shardPath = new ShardPath(false, tempDir, tempDir, new ShardId(indexSettings.getIndex(), 0)); | ||
BlobStoreRepository repository = mock(BlobStoreRepository.class); | ||
BlobStore blobStore = mock(BlobStore.class); | ||
BlobContainer blobContainer = mock(BlobContainer.class); | ||
when(repository.blobStore()).thenReturn(blobStore); | ||
when(blobStore.blobContainer(any())).thenReturn(blobContainer); | ||
when(blobContainer.listBlobs()).thenReturn(Collections.emptyMap()); | ||
|
||
Directory directory = remoteDirectoryFactory.newDirectory(indexSettings, shardPath, repository); | ||
assertTrue(directory instanceof RemoteDirectory); | ||
ArgumentCaptor<BlobPath> blobPathCaptor = ArgumentCaptor.forClass(BlobPath.class); | ||
verify(blobStore).blobContainer(blobPathCaptor.capture()); | ||
BlobPath blobPath = blobPathCaptor.getValue(); | ||
assertEquals("foo/0/", blobPath.buildAsString()); | ||
|
||
directory.listAll(); | ||
verify(blobContainer).listBlobs(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters