You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/06/10 02:43:49 UTC
[GitHub] [geode] DonalEvans opened a new pull request #6599: [WIP] GEODE-9287: Always use Coder for Radish String/byte[] conversion
DonalEvans opened a new pull request #6599:
URL: https://github.com/apache/geode/pull/6599
- Replace uses of new String(byte[]) and String.getBytes() with
Coder.bytesToString() and Coder.stringToBytes() respectively
- Change bytesToString() and stringToBytes() to use the CHARSET defined
in Coder (UTF-8)
- Throw IllegalStateException if UTF-8 charset is not supported
- Introduce StringBytesGlossary class to hold commonly-used byte array
values to reduce the need to create new Strings
- Replace as many calls to bytesToString() as possible in Executor
classes with byte array comparisons using StringBytesGlossary values
- Introduce methods in Coder to allow case-insensitive byte array
comparisons
Authored-by: Donal Evans <do...@vmware.com>
Thank you for submitting a contribution to Apache Geode.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
- [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
- [ ] Is your initial contribution a single, squashed commit?
- [ ] Does `gradlew build` run cleanly?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
### Note:
Please ensure that once the PR is submitted, check Concourse for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #6599: GEODE-9287: Always use Coder for Radish String/byte[] conversion
Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6599:
URL: https://github.com/apache/geode/pull/6599#discussion_r652009305
##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/InfoExecutor.java
##########
@@ -50,44 +61,29 @@ private boolean containsSectionParameter(List<byte[]> commands) {
return commands.size() == 2;
}
- private String getSpecifiedSection(ExecutionHandlerContext context,
- List<byte[]> commands) {
- String result;
- String section = Coder.bytesToString(commands.get(1)).toLowerCase();
- switch (section) {
- case "server":
- result = getServerSection(context);
- break;
- case "cluster":
- result = getClusterSection();
- break;
- case "persistence":
- result = getPersistenceSection();
- break;
- case "replication":
- result = getReplicationSection();
- break;
- case "stats":
- result = getStatsSection(context);
- break;
- case "clients":
- result = getClientsSection(context);
- break;
- case "memory":
- result = getMemorySection(context);
- break;
- case "keyspace":
- result = getKeyspaceSection(context);
- break;
- case "default":
- case "all":
- result = getAllSections(context);
- break;
- default:
- result = "";
- break;
+ private String getSpecifiedSection(ExecutionHandlerContext context, List<byte[]> commands) {
Review comment:
I was curious about this too. It looks like `switch` still ends up calling `String.equals` for each case, although it might seem that this should only be necessary once. Worst case for the new code is if the most common case is the last check as each `if` needs to be evaluated. However, doing a quick jmh benchmark with an even distribution, seems to show that the new code would be about 8x faster than the old code. For more details: https://blog.jamesdbloom.com/JavaCodeToByteCode_PartOne.html#switch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] DonalEvans merged pull request #6599: GEODE-9287: Always use Coder for Radish String/byte[] conversion
Posted by GitBox <gi...@apache.org>.
DonalEvans merged pull request #6599:
URL: https://github.com/apache/geode/pull/6599
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] onichols-pivotal commented on pull request #6599: GEODE-9287: Always use Coder for Radish String/byte[] conversion
Posted by GitBox <gi...@apache.org>.
onichols-pivotal commented on pull request #6599:
URL: https://github.com/apache/geode/pull/6599#issuecomment-861062258
> oops I meant to just comment, not to approve. I don't think you can change a review once you make it
you can change your +1 to a -1, but you are correct, you can never walk back your review state to "comment only" once you've given a +1 or -1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] nonbinaryprogrammer commented on pull request #6599: GEODE-9287: Always use Coder for Radish String/byte[] conversion
Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer commented on pull request #6599:
URL: https://github.com/apache/geode/pull/6599#issuecomment-861061519
oops I meant to just comment, not to approve. I don't think you can change a review once you make it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] nonbinaryprogrammer commented on a change in pull request #6599: GEODE-9287: Always use Coder for Radish String/byte[] conversion
Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer commented on a change in pull request #6599:
URL: https://github.com/apache/geode/pull/6599#discussion_r651310648
##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/SlowlogExecutor.java
##########
@@ -24,18 +29,16 @@
public class SlowlogExecutor extends AbstractExecutor {
@Override
- public RedisResponse executeCommand(Command command,
- ExecutionHandlerContext context) {
- String subCommand = command.getStringKey().toLowerCase();
- switch (subCommand) {
- case "get":
- return RedisResponse.emptyArray();
- case "len":
- return RedisResponse.integer(0);
- case "reset":
- return RedisResponse.ok();
- default:
- return null; // Should never happen
+ public RedisResponse executeCommand(Command command, ExecutionHandlerContext context) {
Review comment:
same comment here as above
##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/server/InfoExecutor.java
##########
@@ -50,44 +61,29 @@ private boolean containsSectionParameter(List<byte[]> commands) {
return commands.size() == 2;
}
- private String getSpecifiedSection(ExecutionHandlerContext context,
- List<byte[]> commands) {
- String result;
- String section = Coder.bytesToString(commands.get(1)).toLowerCase();
- switch (section) {
- case "server":
- result = getServerSection(context);
- break;
- case "cluster":
- result = getClusterSection();
- break;
- case "persistence":
- result = getPersistenceSection();
- break;
- case "replication":
- result = getReplicationSection();
- break;
- case "stats":
- result = getStatsSection(context);
- break;
- case "clients":
- result = getClientsSection(context);
- break;
- case "memory":
- result = getMemorySection(context);
- break;
- case "keyspace":
- result = getKeyspaceSection(context);
- break;
- case "default":
- case "all":
- result = getAllSections(context);
- break;
- default:
- result = "";
- break;
+ private String getSpecifiedSection(ExecutionHandlerContext context, List<byte[]> commands) {
Review comment:
this seems to be less efficient because it results in lots of calls to changing the case of the letters, instead of just the one conversion on the left
##########
File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/ZAddExecutor.java
##########
@@ -69,39 +75,28 @@ private int findAndValidateZAddOptions(Command command, Iterator<byte[]> command
int optionsFoundCount = 0;
while (commandIterator.hasNext() && !scoreFound) {
- String subCommandString = Coder.bytesToString(commandIterator.next()).toLowerCase();
- switch (subCommandString) {
- case "nx":
- executorState.nxFound = true;
- optionsFoundCount++;
- break;
- case "xx":
- executorState.xxFound = true;
- optionsFoundCount++;
- break;
- case "ch":
- executorState.chFound = true;
- optionsFoundCount++;
- break;
- case "inf":
- case "+inf":
- case "-inf":
- case "infinity":
- case "+infinity":
- case "-infinity":
- scoreFound = true;
- break;
- case "incr":
- executorState.incrFound = true;
- optionsFoundCount++;
- break;
- default:
- try {
- Double.valueOf(subCommandString);
- } catch (NumberFormatException nfe) {
- executorState.exceptionMessage = ERROR_NOT_A_VALID_FLOAT;
- }
- scoreFound = true;
+ byte[] subCommand = commandIterator.next();
Review comment:
also concerned about all the changing case here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] DonalEvans commented on pull request #6599: GEODE-9287: Always use Coder for Radish String/byte[] conversion
Posted by GitBox <gi...@apache.org>.
DonalEvans commented on pull request #6599:
URL: https://github.com/apache/geode/pull/6599#issuecomment-861080058
> oops I meant to just comment, not to approve. I don't think you can change a review once you make it
I'll dismiss your approval since it was made in error
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org