robertwb commented on code in PR #26370:
URL: https://github.com/apache/beam/pull/26370#discussion_r1182890732
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/BagUserState.java:
##########
@@ -130,13 +132,31 @@ public void asyncClose() throws Exception {
if (!newValues.isEmpty()) {
ByteStringOutputStream out = new ByteStringOutputStream();
for (T newValue : newValues) {
- // TODO: Replace with chunking output stream
+ int previousSize = out.size();
valueCoder.encode(newValue, out);
+ if (out.size() > BAG_APPEND_BATCHING_LIMIT && previousSize > 0) {
+ // Respect the limit by outputting the previous batch of elements.
+ beamFnStateClient.handle(
+ request
+ .toBuilder()
+ .setAppend(
+ StateAppendRequest.newBuilder()
+
.setData(out.consumePrefixToByteString(previousSize))));
+ }
+ if (out.size() > BAG_APPEND_BATCHING_LIMIT) {
Review Comment:
I was thinking of just having the loop
```
for (T newValue : newValues) {
valueCoder.encode(newValue, out);
if (out.size() > BAG_APPEND_BATCHING_LIMIT) {
[send out.toByteStringAndReset()]
}
}
...
```
rather than introducing the (I think correct, but complex to reason about)
`consumePrefixToByteString`. True, we will fail on a element of size 100-x MB
after writing x MB, for x < 10, but the question is whether that corner case is
worth the additional complexity.
--
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]