aweisberg commented on code in PR #3777:
URL: https://github.com/apache/cassandra/pull/3777#discussion_r1931246601
##########
src/java/org/apache/cassandra/service/accord/interop/AccordInteropRead.java:
##########
@@ -108,27 +132,76 @@ public LocalReadData deserialize(DataInputPlus in, int
version) throws IOExcepti
@Override
public long serializedSize(LocalReadData data, int version)
{
- return ReadResponse.serializer.serializedSize(data.response,
version);
+ data.ensureRemoteResponse();
+ return
ReadResponse.serializer.serializedSize(data.remoteResponse, version);
}
};
- final ReadResponse response;
+ // Will be null at coordinator
+ List<Pair<AccordRoutingKey, ReadResponse>> localResponses;
+ // Will be null at coordinator
+ final ReadCommand readCommand;
+ // Will be not null at coordinator, but null at the node creating the
response until it serialized
+ ReadResponse remoteResponse;
- public LocalReadData(ReadResponse response)
+ public LocalReadData(@Nullable AccordRoutingKey start, @Nonnull
ReadResponse response, @Nonnull ReadCommand readCommand)
{
- this.response = response;
+ checkNotNull(response, "response is null");
+ checkNotNull(readCommand, "readCommand is null");
+ localResponses = ImmutableList.of(Pair.create(start, response));
+ this.readCommand = readCommand;
+ this.remoteResponse = null;
+ }
+
+ public LocalReadData(@Nonnull ReadResponse remoteResponse)
+ {
+ checkNotNull(remoteResponse);
+ this.remoteResponse = remoteResponse;
+ readCommand = null;
}
@Override
public String toString()
{
- return "LocalReadData{" + response + '}';
+ if (localResponses != null)
+ return "LocalReadData{" + localResponses + '}';
+ else
+ return "LocalReadData{" + remoteResponse + '}';
}
@Override
public Data merge(Data data)
{
- throw new IllegalStateException("Should only ever be a single
partition");
+ checkState(remoteResponse == null, "Already serialized");
+ checkState(readCommand.isRangeRequest(), "Should only ever be a
single partition");
+ LocalReadData other = (LocalReadData)data;
+ checkState(readCommand == other.readCommand, "Should share the
same ReadCommand");
+ if (localResponses.size() == 1)
Review Comment:
In most common usage of `LocalReadData` (key reads) there is no merging so
no reason to allocate a larger list.
For range reads we pay that penalty once to inflate to a list and then keep
merging into the LHS so I just went with 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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]