vldpyatkov commented on a change in pull request #118:
URL: https://github.com/apache/ignite-3/pull/118#discussion_r640458444
##########
File path:
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionCommandListener.java
##########
@@ -90,38 +123,150 @@ else if (clo.command() instanceof ReplaceCommand) {
clo.success(false);
}
else if (clo.command() instanceof UpsertCommand) {
- storage.put(
- extractAndWrapKey(((UpsertCommand)clo.command()).getRow()),
- ((UpsertCommand)clo.command()).getRow()
- );
+ BinaryRow row = ((UpsertCommand)clo.command()).getRow();
+
+ assert row.hasValue() : "Upsert command should have a value.";
+
+ storage.put(extractAndWrapKey(row), row);
clo.success(null);
}
- else
- assert false : "Command was not found [cmd=" + clo.command() +
']';
- }
- }
+ else if (clo.command() instanceof InsertAllCommand) {
+ Set<BinaryRow> rows =
((InsertAllCommand)clo.command()).getRows();
- /**
- * @param row Row.
- * @return Extracted key.
- */
- @NotNull private boolean equalValues(@NotNull BinaryRow row, @NotNull
BinaryRow row2) {
- if (row.hasValue() ^ row2.hasValue())
- return false;
+ assert rows != null && !rows.isEmpty();
- return row.valueSlice().compareTo(row2.valueSlice()) == 0;
- }
+ final Set<BinaryRow> res = rows.stream()
+ .map(k -> storage.putIfAbsent(extractAndWrapKey(k), k) ==
null ? null : k)
+ .filter(Objects::nonNull)
+ .filter(BinaryRow::hasValue)
+ .collect(Collectors.toSet());
- /**
- * @param row Row.
- * @return Extracted key.
- */
- @NotNull private KeyWrapper extractAndWrapKey(@NotNull BinaryRow row) {
- final byte[] bytes = new byte[row.keySlice().capacity()];
- row.keySlice().get(bytes);
+ clo.success(new MultiRowsResponse(res));
+ }
+ else if (clo.command() instanceof UpsertAllCommand) {
+ Set<BinaryRow> rows =
((UpsertAllCommand)clo.command()).getRows();
- return new KeyWrapper(bytes, row.hash());
+ assert rows != null && !rows.isEmpty();
+
+ rows.stream()
Review comment:
Done.
##########
File path:
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionCommandListener.java
##########
@@ -90,38 +123,150 @@ else if (clo.command() instanceof ReplaceCommand) {
clo.success(false);
}
else if (clo.command() instanceof UpsertCommand) {
- storage.put(
- extractAndWrapKey(((UpsertCommand)clo.command()).getRow()),
- ((UpsertCommand)clo.command()).getRow()
- );
+ BinaryRow row = ((UpsertCommand)clo.command()).getRow();
+
+ assert row.hasValue() : "Upsert command should have a value.";
+
+ storage.put(extractAndWrapKey(row), row);
clo.success(null);
}
- else
- assert false : "Command was not found [cmd=" + clo.command() +
']';
- }
- }
+ else if (clo.command() instanceof InsertAllCommand) {
+ Set<BinaryRow> rows =
((InsertAllCommand)clo.command()).getRows();
- /**
- * @param row Row.
- * @return Extracted key.
- */
- @NotNull private boolean equalValues(@NotNull BinaryRow row, @NotNull
BinaryRow row2) {
- if (row.hasValue() ^ row2.hasValue())
- return false;
+ assert rows != null && !rows.isEmpty();
- return row.valueSlice().compareTo(row2.valueSlice()) == 0;
- }
+ final Set<BinaryRow> res = rows.stream()
+ .map(k -> storage.putIfAbsent(extractAndWrapKey(k), k) ==
null ? null : k)
+ .filter(Objects::nonNull)
+ .filter(BinaryRow::hasValue)
+ .collect(Collectors.toSet());
- /**
- * @param row Row.
- * @return Extracted key.
- */
- @NotNull private KeyWrapper extractAndWrapKey(@NotNull BinaryRow row) {
- final byte[] bytes = new byte[row.keySlice().capacity()];
- row.keySlice().get(bytes);
+ clo.success(new MultiRowsResponse(res));
+ }
+ else if (clo.command() instanceof UpsertAllCommand) {
+ Set<BinaryRow> rows =
((UpsertAllCommand)clo.command()).getRows();
- return new KeyWrapper(bytes, row.hash());
+ assert rows != null && !rows.isEmpty();
+
+ rows.stream()
Review comment:
Done.
--
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:
[email protected]