-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Refactor] StreamInput, StreamOutput, Writeable to core library #7783
Conversation
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
1 similar comment
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
OpenSearchException uses an enumerator to create a handler for each serializable Exception implementation. The enumerator is to make it easy to store in an immutable map. The problem with this Hack is that it makes it difficult to unwind the tight coupling of StreamInput with the OpenSearchException class. This commit switches from using an enumerator to a registry in the opensearch-core library in order to support serverless and cloud native implementations outside of the server module. This commit also refactors base primitive serialization readers and writers from StreamInput and StreamOutput to BaseStreamInput and BaseStreamOutput, respectively. Signed-off-by: Nicholas Walter Knize <[email protected]>
This is a big commit as it refactors the StreamInput and StreamOutput core serialization and supporting classes from the server module to the core library such that it can be reused and overridden in cloud native and serverless applications. The majority of the changes in this commit are the import statements. Noteable refactors include: * StreamInput * StreamOutput * Writeable * NamedWriteable * NamedWriteableRegistry * Index * ShardId * BytesReference * ByteArray * BigArray * SecureString * Text * ParsingException * RestStatus Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Nicholas Walter Knize <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
@@ -107,8 +107,12 @@ public static class IndexResult { | |||
static { | |||
PARSER.declareBoolean(optionalConstructorArg(), new ParseField("closed")); | |||
PARSER.declareObject(optionalConstructorArg(), (p, c) -> { | |||
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, p.currentToken(), p); | |||
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p); | |||
org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the full import is there already:
org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken( | |
XContentParserUtils.ensureExpectedToken( |
p.currentToken(), | ||
p | ||
); | ||
org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p); | |
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p); |
static { | ||
registerExceptionHandle( | ||
new BaseOpenSearchExceptionHandle( | ||
org.opensearch.core.index.snapshots.IndexShardSnapshotFailedException.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why snapshots are moving core? I am not sure these functionality belong to it
* | ||
* @return an array of all registered handle IDs | ||
*/ | ||
static int[] ids() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to duplicate that vs calling OpenSearchExceptionHandleRegistry.ids()
?
* @opensearch.internal | ||
*/ | ||
public class StreamsUtil { | ||
public static int readFully(InputStream reader, byte[] dest, int offset, int len) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InputStream::readNBytes
does exactly that, no need for additional utils:
reader.readNBytes(dest, offset, len);
@@ -154,6 +186,10 @@ public BytesRef readBytesRef(int length) throws IOException { | |||
return new BytesRef(bytes, 0, length); | |||
} | |||
|
|||
public void readFully(byte[] b) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method won't consume full stream, it will consume up to b
length, I think readBytes
(overloaded version) would be a better name:
public void readBytes(byte[] b)
@@ -313,7 +313,7 @@ public int available() { | |||
} | |||
|
|||
@Override | |||
protected void ensureCanReadBytes(int bytesToRead) throws EOFException { | |||
public void ensureCanReadBytes(int bytesToRead) throws EOFException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving classes around may require changing access modifiers but comes with a security risk. This one seems harmless however we can move most the of consumers of this classes to lib:core
from server. I also see its unit tests are still in server.
If we are not intending to move unit tests and other consumers of this class here, then we should create a list of TODOs, to change them back to their original access modifiers once consumers are moved to lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah @rishabhmaurya, I actually like the idea of refactoring these classes as well. The reason I held off is because one of those inheritors, BufferedChecksumStreamInput, is inside the o.o.index.translog
namespace and we may want to consider having this in a dedicated :libs:opensearch-translog
library instead of core so we don't set a precedent of having translog logic in the core library. Especially since we're talking about scenarios where we don't have a translog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh by the way.. this PR is going to get closed in favor of #8157 so have a look at that one instead if you wouldn't mind.
superseded by #8035 |
This is a big commit as it refactors the StreamInput and StreamOutput core serialization and supporting classes from the server module to the core library such that it can be reused and overridden in cloud native and serverless applications. The majority of the changes in this commit are the import statements. Noteable refactors include:
NOTE: The below dependency PRs reduce the surface area of this commit. However, it will still be a large commit as reducing to incremental commits adds a substantial intermediate "generics" framework that only serves to complicate the implementation. Thus we instead opt to solve the refactor in one swooping change.
relates #5910
depends on #7646
depends on #7780
depends on #8035