Skip to content

Commit 67fafbf

Browse files
GeekGliderPradeep L
authored andcommitted
Add skeleton structure for WritableWarm Directories and IndexInputs (opensearch-project#21082)
Signed-off-by: Kavya Aggarwal <kavyaagg@amazon.com>
1 parent 240e2e3 commit 67fafbf

10 files changed

Lines changed: 687 additions & 0 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.storage.directory;
10+
11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
13+
import org.apache.lucene.store.Directory;
14+
import org.opensearch.index.store.CompositeDirectory;
15+
import org.opensearch.index.store.remote.filecache.FileCache;
16+
import org.opensearch.threadpool.ThreadPool;
17+
18+
/**
19+
* Extension of CompositeDirectory to support writable warm and other related features.
20+
* TieredStoragePrefetchSettings dependency will be added in the implementation PR.
21+
* Directory overrides (listAll, deleteFile, rename, openInput, close, sync, afterSyncToRemote),
22+
* file caching, and full-file-to-block switching logic will be added in the implementation PR.
23+
*/
24+
public class TieredDirectory extends CompositeDirectory {
25+
26+
private static final Logger logger = LogManager.getLogger(TieredDirectory.class);
27+
28+
/**
29+
* Constructs a new TieredDirectory.
30+
* @param localDirectory the local directory
31+
* @param remoteDirectory the remote directory
32+
* @param fileCache the file cache
33+
* @param threadPool the thread pool
34+
*/
35+
public TieredDirectory(Directory localDirectory, Directory remoteDirectory, FileCache fileCache, ThreadPool threadPool) {
36+
super(localDirectory, remoteDirectory, fileCache, threadPool);
37+
}
38+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.storage.directory;
10+
11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
13+
import org.apache.lucene.store.Directory;
14+
import org.opensearch.index.IndexSettings;
15+
import org.opensearch.index.shard.ShardPath;
16+
import org.opensearch.index.store.remote.filecache.FileCache;
17+
import org.opensearch.plugins.IndexStorePlugin;
18+
import org.opensearch.threadpool.ThreadPool;
19+
20+
import java.io.IOException;
21+
22+
/**
23+
* Factory to create TieredDirectory.
24+
* TieredStoragePrefetchSettings dependency will be added in the implementation PR.
25+
* The newDirectory implementation will be added in the implementation PR.
26+
*/
27+
public class TieredDirectoryFactory implements IndexStorePlugin.CompositeDirectoryFactory {
28+
29+
private static final Logger logger = LogManager.getLogger(TieredDirectoryFactory.class);
30+
31+
/** Constructs a new TieredDirectoryFactory. */
32+
public TieredDirectoryFactory() {}
33+
34+
@Override
35+
public Directory newDirectory(
36+
IndexSettings indexSettings,
37+
ShardPath shardPath,
38+
IndexStorePlugin.DirectoryFactory directoryFactory,
39+
Directory directory,
40+
FileCache fileCache,
41+
ThreadPool threadPool
42+
) throws IOException {
43+
throw new UnsupportedOperationException("Not yet implemented");
44+
}
45+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/** Directory implementations for tiered storage. */
10+
package org.opensearch.storage.directory;
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.storage.indexinput;
10+
11+
import org.apache.lucene.store.Directory;
12+
import org.apache.lucene.store.FSDirectory;
13+
import org.opensearch.common.annotation.ExperimentalApi;
14+
15+
import java.nio.file.Path;
16+
17+
/**
18+
* Class to represent a fetch request for a block of a file.
19+
* Field names: directory, fileName, blockFileName, blockStart, blockSize, filePath.
20+
* Builder pattern and getters will be added in the implementation PR.
21+
*/
22+
@ExperimentalApi
23+
public class BlockFetchRequest {
24+
25+
private final Directory directory;
26+
private final String fileName;
27+
private final String blockFileName;
28+
private final long blockStart;
29+
private final long blockSize;
30+
private final Path filePath;
31+
32+
private BlockFetchRequest(Builder builder) {
33+
this.fileName = builder.fileName;
34+
this.blockFileName = builder.blockFileName;
35+
this.filePath = builder.directory.getDirectory().resolve(blockFileName);
36+
this.directory = builder.directory;
37+
this.blockSize = builder.blockSize;
38+
this.blockStart = builder.blockStart;
39+
}
40+
41+
/**
42+
* Creates a new Builder.
43+
* @return a new Builder
44+
*/
45+
public static Builder builder() {
46+
return new Builder();
47+
}
48+
49+
/**
50+
* Returns the file path.
51+
* @return the file path
52+
*/
53+
public Path getFilePath() {
54+
return filePath;
55+
}
56+
57+
/**
58+
* Returns the directory.
59+
* @return the directory
60+
*/
61+
public Directory getDirectory() {
62+
return directory;
63+
}
64+
65+
/**
66+
* Returns the file name.
67+
* @return the file name
68+
*/
69+
public String getFileName() {
70+
return fileName;
71+
}
72+
73+
/**
74+
* Returns the block file name.
75+
* @return the block file name
76+
*/
77+
public String getBlockFileName() {
78+
return blockFileName;
79+
}
80+
81+
/**
82+
* Returns the block size.
83+
* @return the block size
84+
*/
85+
public long getBlockSize() {
86+
return blockSize;
87+
}
88+
89+
/**
90+
* Returns the block start.
91+
* @return the block start
92+
*/
93+
public long getBlockStart() {
94+
return blockStart;
95+
}
96+
97+
/**
98+
* Builder for BlobFetchRequest
99+
*/
100+
@ExperimentalApi
101+
public static final class Builder {
102+
private FSDirectory directory;
103+
private String fileName;
104+
private String blockFileName;
105+
private long blockSize;
106+
private long blockStart;
107+
108+
private Builder() {}
109+
110+
/**
111+
* Sets the directory.
112+
* @param directory the directory
113+
* @return this builder
114+
*/
115+
public Builder directory(FSDirectory directory) {
116+
this.directory = directory;
117+
return this;
118+
}
119+
120+
/**
121+
* Sets the file name.
122+
* @param fileName the file name
123+
* @return this builder
124+
*/
125+
public Builder fileName(String fileName) {
126+
this.fileName = fileName;
127+
return this;
128+
}
129+
130+
/**
131+
* Sets the block file name.
132+
* @param blockFileName the block file name
133+
* @return this builder
134+
*/
135+
public Builder blockFileName(String blockFileName) {
136+
this.blockFileName = blockFileName;
137+
return this;
138+
}
139+
140+
/**
141+
* Sets the block size.
142+
* @param blockSize the block size
143+
* @return this builder
144+
*/
145+
public Builder blockSize(long blockSize) {
146+
this.blockSize = blockSize;
147+
return this;
148+
}
149+
150+
/**
151+
* Sets the block start.
152+
* @param blockStart the block start
153+
* @return this builder
154+
*/
155+
public Builder blockStart(long blockStart) {
156+
this.blockStart = blockStart;
157+
return this;
158+
}
159+
160+
/** Builds the BlockFetchRequest. @return the built request */
161+
public BlockFetchRequest build() {
162+
return new BlockFetchRequest(this);
163+
}
164+
}
165+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.storage.indexinput;
10+
11+
import org.apache.lucene.store.FSDirectory;
12+
import org.apache.lucene.store.IOContext;
13+
import org.apache.lucene.store.IndexInput;
14+
import org.opensearch.index.store.remote.file.AbstractBlockIndexInput;
15+
16+
/**
17+
* A virtual index input backed by block files downloaded from remote store.
18+
* Block files are a sequence of bytes of fixed block size belonging to a segment file.
19+
* Clone, slice, fetchBlock, and Builder will be added in the implementation PR.
20+
*/
21+
public class BlockIndexInput extends AbstractBlockIndexInput {
22+
23+
/** The file name. */
24+
protected final String fileName;
25+
/** The size of the file. */
26+
protected final long fileSize;
27+
/** The underlying Lucene directory. */
28+
protected final FSDirectory directory;
29+
/** The IO context. */
30+
protected final IOContext context;
31+
32+
// Placeholder constructor. Real constructor via Builder will be added in the implementation PR.
33+
BlockIndexInput(AbstractBlockIndexInput.Builder<?> builder) {
34+
super(builder);
35+
this.fileName = null;
36+
this.fileSize = 0;
37+
this.directory = null;
38+
this.context = null;
39+
}
40+
41+
@Override
42+
public BlockIndexInput clone() {
43+
throw new UnsupportedOperationException("Not yet implemented");
44+
}
45+
46+
@Override
47+
public IndexInput slice(String sliceDescription, long offset, long length) {
48+
throw new UnsupportedOperationException("Not yet implemented");
49+
}
50+
51+
@Override
52+
protected IndexInput fetchBlock(int blockId) {
53+
throw new UnsupportedOperationException("Not yet implemented");
54+
}
55+
56+
public BlockIndexInput buildSlice(String sliceDescription, long offset, long length) {
57+
throw new UnsupportedOperationException("Not yet implemented");
58+
}
59+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.storage.indexinput;
10+
11+
import org.apache.lucene.store.IndexInput;
12+
import org.opensearch.index.store.remote.filecache.CachedIndexInput;
13+
14+
import java.util.concurrent.atomic.AtomicBoolean;
15+
16+
/**
17+
* CachedIndexInput implementation that wraps a SwitchableIndexInput for use with FileCache.
18+
* Constructor will accept FileCache, fileName, localDirectory, remoteDirectory, transferManager,
19+
* cacheFromRemote flag, threadPool, and tieredStoragePrefetchSettingsSupplier.
20+
* getIndexInput, length, isClosed, and close will be added in the implementation PR.
21+
*/
22+
public class CachedSwitchableIndexInput implements CachedIndexInput {
23+
24+
private final SwitchableIndexInput switchableIndexInput;
25+
private final AtomicBoolean isClosed;
26+
27+
// Placeholder constructor. Real constructor will be added in the implementation PR.
28+
CachedSwitchableIndexInput() {
29+
this.switchableIndexInput = null;
30+
this.isClosed = new AtomicBoolean(false);
31+
}
32+
33+
@Override
34+
public IndexInput getIndexInput() {
35+
throw new UnsupportedOperationException("Not yet implemented");
36+
}
37+
38+
@Override
39+
public long length() {
40+
throw new UnsupportedOperationException("Not yet implemented");
41+
}
42+
43+
@Override
44+
public boolean isClosed() {
45+
throw new UnsupportedOperationException("Not yet implemented");
46+
}
47+
48+
@Override
49+
public void close() {
50+
throw new UnsupportedOperationException("Not yet implemented");
51+
}
52+
}

0 commit comments

Comments
 (0)