-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Remote Store] Add Lock Manager in Remote Segment Store to persist data #6787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
server/src/main/java/org/opensearch/index/store/RemoteBufferedIndexOutput.java
This file contains hidden or 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,107 @@ | ||
| /* | ||
| * 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.DataInput; | ||
| import org.apache.lucene.store.OutputStreamIndexOutput; | ||
| import org.opensearch.common.blobstore.BlobContainer; | ||
| import org.opensearch.common.io.stream.BytesStreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
|
|
||
| /** | ||
| * Class for output to a file in a {@link RemoteBufferedOutputDirectory}. This is right now used only for writing locks | ||
| * in remote store. in the future, we can use it for other operations as well. | ||
| * The current limitation of this is we keep all the file content in memory till we call close(), | ||
| * So this class should be used to write small files (in MBs). | ||
| * TODO: extend the class to continously write to the store if content size in buffer gets higher than a specific size. | ||
| * @see RemoteBufferedOutputDirectory | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class RemoteBufferedIndexOutput extends RemoteIndexOutput { | ||
| private final BytesStreamOutput out; | ||
| private final OutputStreamIndexOutput indexOutputBuffer; | ||
| // visible for testing | ||
| static final int BUFFER_SIZE = 4096; | ||
|
|
||
| public RemoteBufferedIndexOutput(String name, BlobContainer blobContainer, int bufferSize) { | ||
| super(name, blobContainer); | ||
| out = new BytesStreamOutput(); | ||
| indexOutputBuffer = new OutputStreamIndexOutput(name, name, out, bufferSize); | ||
| } | ||
|
|
||
| public RemoteBufferedIndexOutput(String name, BlobContainer blobContainer) { | ||
| this(name, blobContainer, BUFFER_SIZE); | ||
| } | ||
|
|
||
| // Visible for testing | ||
| RemoteBufferedIndexOutput(String name, BlobContainer blobContainer, BytesStreamOutput out, OutputStreamIndexOutput indexOutputBuffer) { | ||
| super(name, blobContainer); | ||
| this.out = out; | ||
| this.indexOutputBuffer = indexOutputBuffer; | ||
| } | ||
|
|
||
| @Override | ||
| public void copyBytes(DataInput input, long numBytes) throws IOException { | ||
| indexOutputBuffer.copyBytes(input, numBytes); | ||
| } | ||
harishbhakuni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * when we trigger close() to close the stream, we will first flush the buffer to output stream and then write all | ||
| * data to blob container and close the output stream. | ||
| * | ||
| */ | ||
| @Override | ||
| public void close() throws IOException { | ||
|
|
||
| try (final BytesStreamOutput outStream = out; InputStream stream = out.bytes().streamInput()) { | ||
| indexOutputBuffer.close(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
| blobContainer.writeBlob(getName(), stream, out.bytes().length(), false); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * This method will write Bytes to the stream we are maintaining. | ||
| * | ||
| */ | ||
| @Override | ||
| public void writeByte(byte b) throws IOException { | ||
| indexOutputBuffer.writeByte(b); | ||
| } | ||
|
|
||
| /** | ||
| * This method will write a byte array to the stream we are maintaining. | ||
| * | ||
| */ | ||
| @Override | ||
| public void writeBytes(byte[] byteArray, int offset, int length) throws IOException { | ||
| indexOutputBuffer.writeBytes(byteArray, offset, length); | ||
| } | ||
gbbafna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * This method will return the file pointer to the current position in the stream. | ||
| * | ||
| */ | ||
| @Override | ||
| public long getFilePointer() { | ||
| return indexOutputBuffer.getFilePointer(); | ||
| } | ||
|
|
||
| /** | ||
| * This method will return checksum | ||
| * | ||
| */ | ||
| @Override | ||
| public long getChecksum() throws IOException { | ||
| return indexOutputBuffer.getChecksum(); | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
server/src/main/java/org/opensearch/index/store/RemoteBufferedOutputDirectory.java
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * 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.IOContext; | ||
| import org.apache.lucene.store.IndexOutput; | ||
| import org.opensearch.common.blobstore.BlobContainer; | ||
|
|
||
| /** | ||
| * A {@code RemoteBufferedOutputDirectory} is an extension of RemoteDirectory which also provides an abstraction layer | ||
| * for storing a list of files to a remote store. | ||
| * Additionally, with this implementation, creation of new files is also allowed. | ||
| * A remoteDirectory contains only files (no sub-folder hierarchy). | ||
harishbhakuni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class RemoteBufferedOutputDirectory extends RemoteDirectory { | ||
| public RemoteBufferedOutputDirectory(BlobContainer blobContainer) { | ||
| super(blobContainer); | ||
| } | ||
|
|
||
| @Override | ||
| public IndexOutput createOutput(String name, IOContext context) { | ||
| return new RemoteBufferedIndexOutput(name, this.blobContainer); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.