Skip to content

Commit

Permalink
Add javadocs for FullFileCachedIndexInput
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyansh Ray <rayshrey@amazon.com>
  • Loading branch information
rayshrey committed Jun 20, 2024
1 parent 74f9c29 commit 7fce3d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.opensearch.node.Node;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.junit.annotations.TestLogging;

import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -44,7 +43,7 @@
@ThreadLeakFilters(filters = CleanerDaemonThreadLeakFilter.class)
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, supportsDedicatedMasters = false)
// Uncomment the below line to enable trace level logs for this test for better debugging
@TestLogging(reason = "Getting trace logs from composite directory package", value = "org.opensearch.index.store:TRACE")
// @TestLogging(reason = "Getting trace logs from composite directory package", value = "org.opensearch.index.store:TRACE")
public class WritableWarmIT extends RemoteStoreBaseIntegTestCase {

protected static final String INDEX_NAME = "test-idx-1";
Expand All @@ -69,8 +68,8 @@ protected Settings featureFlagSettings() {
public void testWritableWarmFeatureFlagDisabled() {
Settings clusterSettings = Settings.builder().put(super.nodeSettings(0)).put(FeatureFlags.TIERED_REMOTE_INDEX, false).build();
InternalTestCluster internalTestCluster = internalCluster();
internalTestCluster.startClusterManagerOnlyNodes(3, clusterSettings);
internalTestCluster.startDataOnlyNodes(1, clusterSettings);
internalTestCluster.startClusterManagerOnlyNode(clusterSettings);
internalTestCluster.startDataOnlyNode(clusterSettings);

Settings indexSettings = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Implementation of the CachedIndexInput for NON_BLOCK files which takes in an IndexInput as parameter
* Implementation of the CachedIndexInput for full files which takes in an IndexInput as parameter
*
* @opensearch.experimental
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@
import org.apache.logging.log4j.Logger;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.IndexInput;
import org.opensearch.common.annotation.ExperimentalApi;

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;

/**
* Extension of {@link FileCachedIndexInput} for full files for handling clones and slices
* We maintain a clone map so that we can close them when the parent IndexInput is closed so that ref count is properly maintained in file cache
* Closing of clones explicitly is needed as Lucene does not guarantee that it will close the clones
* https://github.com/apache/lucene/blob/8340b01c3cc229f33584ce2178b07b8984daa6a9/lucene/core/src/java/org/apache/lucene/store/IndexInput.java#L32-L33
* @opensearch.experimental
*/
@ExperimentalApi
public class FullFileCachedIndexInput extends FileCachedIndexInput {
private static final Logger logger = LogManager.getLogger(FullFileCachedIndexInput.class);
private final Set<FullFileCachedIndexInput> clones;
Expand All @@ -31,6 +40,10 @@ public FullFileCachedIndexInput(FileCache cache, Path filePath, IndexInput under
clones = new HashSet<>();
}

/**
* Clones the index input and returns the clone
* Increase the ref count whenever the index input is cloned and add it to the clone map as well
*/
@Override
public FullFileCachedIndexInput clone() {
FullFileCachedIndexInput clonedIndexInput = new FullFileCachedIndexInput(cache, filePath, luceneIndexInput.clone(), true);
Expand All @@ -39,6 +52,10 @@ public FullFileCachedIndexInput clone() {
return clonedIndexInput;
}

/**
* Clones the index input and returns the slice
* Increase the ref count whenever the index input is sliced and add it to the clone map as well
*/
@Override
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
if (offset < 0 || length < 0 || offset + length > this.length()) {
Expand All @@ -62,6 +79,10 @@ public IndexInput slice(String sliceDescription, long offset, long length) throw
return slicedIndexInput;
}

/**
* Closes the index input and it's clones as well
* @throws IOException
*/
@Override
public void close() throws IOException {
if (!closed) {
Expand Down

0 comments on commit 7fce3d3

Please sign in to comment.