dariuszseweryn commented on code in PR #10077:
URL: https://github.com/apache/nifi/pull/10077#discussion_r2297439399


##########
nifi-extension-bundles/nifi-aws-bundle/nifi-aws-kinesis/src/main/java/org/apache/nifi/processors/aws/kinesis/RecordBuffer.java:
##########
@@ -0,0 +1,677 @@
+/*
+ * 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.nifi.processors.aws.kinesis;
+
+import jakarta.annotation.Nullable;
+import org.apache.nifi.logging.ComponentLog;
+import software.amazon.kinesis.exceptions.InvalidStateException;
+import software.amazon.kinesis.exceptions.KinesisClientLibDependencyException;
+import software.amazon.kinesis.exceptions.ShutdownException;
+import software.amazon.kinesis.exceptions.ThrottlingException;
+import software.amazon.kinesis.processor.RecordProcessorCheckpointer;
+import software.amazon.kinesis.retrieval.KinesisClientRecord;
+
+import java.nio.ByteBuffer;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Queue;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static java.util.Collections.emptyList;
+
+/**
+ * RecordBuffer keeps track of all created Shard buffers, including exclusive 
read access via leasing,
+ * and memory consumption tracking. It acts as the main interface between KCL 
callbacks and
+ * the {@link ConsumeKinesis} processor, routing events to appropriate 
ShardBuffers and ensuring
+ * thread-safe operations.
+ */
+final class RecordBuffer {
+
+    private final ComponentLog logger;
+
+    private final long checkpointIntervalMillis;
+    private final BlockingMemoryTracker memoryTracker;
+
+    private final AtomicLong bufferIdCounter = new AtomicLong(0);
+    private final ConcurrentMap<ShardBufferId, ShardBuffer> shardBuffers = new 
ConcurrentHashMap<>();
+
+    /**
+     * A queue with ids shard buffers available for leasing.
+     * <p>
+     * Note: when a buffer is invalidated its id is NOT removed from the queue 
immediately.
+     */
+    private final Queue<ShardBufferId> buffersToLease = new 
ConcurrentLinkedQueue<>();
+
+    RecordBuffer(final ComponentLog logger, final long maxMemoryBytes, final 
Duration checkpointInterval) {
+        this.logger = logger;
+        this.memoryTracker = new BlockingMemoryTracker(logger, maxMemoryBytes);
+        this.checkpointIntervalMillis = checkpointInterval.toMillis();
+    }
+
+    // ========== Methods called from Kinesis Client Library ==========

Review Comment:
   nit: these methods/functions could be defined in a RecordBufferForKCL 
interface. Similarly there could be RecordBufferForRecordProcessor interface so 
both places would know only the minimal API surface.



-- 
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]

Reply via email to