-
Notifications
You must be signed in to change notification settings - Fork 183
Optimize header reading #1449
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
Optimize header reading #1449
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0bf8ffb
Header Optimization
scottf 7eaa83a
Header Optimization
scottf ecced55
Header Optimization
scottf dde54f5
added tests and more known keys
scottf e29ad99
added tests and more known keys
scottf 0d83f57
added tests and more known keys
scottf 8ad6422
made constants final
scottf 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
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 |
---|---|---|
|
@@ -30,7 +30,7 @@ public IncomingHeadersProcessor(byte[] serialized) { | |
throw new IllegalArgumentException(SERIALIZED_HEADER_CANNOT_BE_NULL_OR_EMPTY); | ||
} | ||
|
||
// is tis the correct version | ||
// is this the correct version | ||
for (int x = 0; x < HEADER_VERSION_BYTES_LEN; x++) { | ||
if (serialized[x] != HEADER_VERSION_BYTES[x]) { | ||
throw new IllegalArgumentException(INVALID_HEADER_VERSION); | ||
|
@@ -42,17 +42,15 @@ public IncomingHeadersProcessor(byte[] serialized) { | |
Token terminus = new Token(serialized, serializedLength, serializedLength - 2, TokenType.CRLF); | ||
Token token = new Token(serialized, serializedLength, HEADER_VERSION_BYTES_LEN, null); | ||
|
||
boolean hadStatus = false; | ||
if (token.isType(TokenType.SPACE)) { | ||
token = initStatus(serialized, serializedLength, token); | ||
if (token.samePoint(terminus)) { | ||
return; // status only | ||
} | ||
hadStatus = true; | ||
} | ||
|
||
if (token.isType(TokenType.CRLF)) { | ||
initHeader(serialized, serializedLength, token, hadStatus); | ||
initHeader(serialized, serializedLength, token); | ||
} | ||
else { | ||
throw new IllegalArgumentException(INVALID_HEADER_COMPOSITION); | ||
|
@@ -71,7 +69,7 @@ public Status getStatus() { | |
return inlineStatus; | ||
} | ||
|
||
private void initHeader(byte[] serialized, int len, Token tCrlf, boolean hadStatus) { | ||
private void initHeader(byte[] serialized, int len, Token tCrlf) { | ||
// REGULAR HEADER | ||
Token peek = new Token(serialized, len, tCrlf, null); | ||
while (peek.isType(TokenType.TEXT)) { | ||
|
@@ -90,7 +88,7 @@ private void initHeader(byte[] serialized, int len, Token tCrlf, boolean hadStat | |
if (headers == null) { | ||
headers = new Headers(); | ||
} | ||
headers.add(tKey.getValue(), tVal.getValue()); | ||
headers.add(tKey.getValueCheckKnownKeys(), tVal.getValue()); | ||
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. use the new function to get the key, checking against known keys. |
||
peek = new Token(serialized, len, tCrlf, null); | ||
} | ||
peek.mustBe(TokenType.CRLF); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ private NatsKeyValueUtil() {} /* ensures cannot be constructed */ | |
public static final int KV_STREAM_PREFIX_LEN = KV_STREAM_PREFIX.length(); | ||
public static final String KV_SUBJECT_PREFIX = "$KV."; | ||
public static final String KV_SUBJECT_SUFFIX = ".>"; | ||
public static final String KV_OPERATION_HEADER_KEY = "KV-Operation"; | ||
public static final String KV_OPERATION_HEADER_KEY = NatsJetStreamConstants.KV_OPERATION_HEADER_KEY; | ||
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. Putting in NatsJetStreamConstants to be able to not depend on KV in non kv code |
||
|
||
@NonNull | ||
public static String extractBucketName(String streamName) { | ||
|
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.
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.
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.
variable was never used in the initHeader function that it was passed to and there are no other uses, so it was removed.