[
https://issues.apache.org/jira/browse/BEAM-8511?focusedWorklogId=360697&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-360697
]
ASF GitHub Bot logged work on BEAM-8511:
----------------------------------------
Author: ASF GitHub Bot
Created on: 17/Dec/19 05:20
Start Date: 17/Dec/19 05:20
Worklog Time Spent: 10m
Work Description: jfarr commented on pull request #9899: [BEAM-8511]
[WIP] KinesisIO.Read enhanced fanout
URL: https://github.com/apache/beam/pull/9899#discussion_r358600261
##########
File path:
sdks/java/io/kinesis2/src/main/java/org/apache/beam/sdk/io/kinesis2/KinesisRecord.java
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.kinesis2;
+
+import static
org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.joda.time.Instant;
+import software.amazon.kinesis.retrieval.KinesisClientRecord;
+import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
+
+/** {@link KinesisClientRecord} enhanced with utility methods. */
+public class KinesisRecord {
+
+ private Instant readTime;
+ private String streamName;
+ private String shardId;
+ private long subSequenceNumber;
+ private String sequenceNumber;
+ private Instant approximateArrivalTimestamp;
+ private ByteBuffer data;
+ private String partitionKey;
+
+ public KinesisRecord(KinesisClientRecord record, String streamName, String
shardId) {
+ this(
+ record.data(),
+ record.sequenceNumber(),
+ record.subSequenceNumber(),
+ record.partitionKey(),
+ TimeUtil.toJoda(record.approximateArrivalTimestamp()),
+ Instant.now(),
+ streamName,
+ shardId);
+ }
+
+ public KinesisRecord(
+ ByteBuffer data,
+ String sequenceNumber,
+ long subSequenceNumber,
+ String partitionKey,
+ Instant approximateArrivalTimestamp,
+ Instant readTime,
+ String streamName,
+ String shardId) {
+ this.data = copyData(data);
Review comment:
The deep copy here is because of the call to KinesisClientRecord::fromRecord
here:
https://github.com/jfarr/beam/blob/c514ebe7bfbdbc9335809446ff8a7716e46cb923/sdks/java/io/kinesis2/src/main/java/org/apache/beam/sdk/io/kinesis2/SimplifiedKinesisClient.java#L202
This converts the AWS SDK `Record` to a KCL `KinesisClientRecord` so we can
call deaggregate(), but also causes KinesisClientRecord's `data` to be
converted to a read-only HeapByteBuffer, which then throws
ReadOnlyBufferException when we call array() here:
https://github.com/jfarr/beam/blob/c514ebe7bfbdbc9335809446ff8a7716e46cb923/sdks/java/io/kinesis2/src/main/java/org/apache/beam/sdk/io/kinesis2/KinesisRecord.java#L102
As far as I can tell a read-only byte buffer will not allow direct access to
the backing array which I think is kind of the point. If I'm mistaken please
let me know and I can change this. Initially I had fixed it by copying the data
to a new byte array in getDataAsBytes() but it seemed more efficient to take
the hit only once in the constructor.
I will add a comment here to explain the reason for the deep copy.
Alternately, we could probably roll our own version of
KinesisClientRecord::fromRecord that doesn't convert the data to a read-only
buffer if you'd rather do that.
----------------------------------------------------------------
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 360697)
Time Spent: 3h 40m (was: 3.5h)
> Support for enhanced fan-out in KinesisIO.Read
> ----------------------------------------------
>
> Key: BEAM-8511
> URL: https://issues.apache.org/jira/browse/BEAM-8511
> Project: Beam
> Issue Type: New Feature
> Components: io-java-kinesis
> Reporter: Jonothan Farr
> Assignee: Jonothan Farr
> Priority: Major
> Time Spent: 3h 40m
> Remaining Estimate: 0h
>
> Add support for reading from an enhanced fan-out consumer using KinesisIO.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)