[Refactor] StreamInput, StreamOutput, Writeable to core library#7783
[Refactor] StreamInput, StreamOutput, Writeable to core library#7783nknize wants to merge 13 commits intoopensearch-project:mainfrom
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 <nknize@apache.org>
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 <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Gradle Check (Jenkins) Run Completed with:
|
| 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.
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.
| 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.
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.
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.
InputStream::readNBytes does exactly that, no need for additional utils:
reader.readNBytes(dest, offset, len);
| return new BytesRef(bytes, 0, length); | ||
| } | ||
|
|
||
| public void readFully(byte[] b) throws IOException { |
There was a problem hiding this comment.
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)
|
|
||
| @Override | ||
| protected void ensureCanReadBytes(int bytesToRead) throws EOFException { | ||
| public void ensureCanReadBytes(int bytesToRead) throws EOFException { |
There was a problem hiding this comment.
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.
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.
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