lucasbru commented on code in PR #15219:
URL: https://github.com/apache/kafka/pull/15219#discussion_r1492366369


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/AbstractDualSchemaRocksDBSegmentedBytesStore.java:
##########
@@ -193,17 +194,22 @@ public void put(final Bytes rawBaseKey,
             expiredRecordSensor.record(1.0d, context.currentSystemTimeMs());
             LOG.warn("Skipping record for expired segment.");
         } else {
-            StoreQueryUtils.updatePosition(position, stateStoreContext);
-
-            // Put to index first so that if put to base failed, when we 
iterate index, we will
-            // find no base value. If put to base first but putting to index 
fails, when we iterate
-            // index, we can't find the key but if we iterate over base store, 
we can find the key
-            // which lead to inconsistency.
-            if (hasIndex()) {
-                final KeyValue<Bytes, byte[]> indexKeyValue = 
getIndexKeyValue(rawBaseKey, value);
-                segment.put(indexKeyValue.key, indexKeyValue.value);
+            position.lock();

Review Comment:
   Have you considered doing the same without `SynchronizedPosition` and 
instead just using the object monitor of position
   
   ```
   synchronized(position) {
   
   
   }
   ```
   ?



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/StoreQueryUtilsTest.java:
##########
@@ -70,7 +71,7 @@ public void shouldReturnErrorOnBoundViolation() {
             PositionBound.at(Position.emptyPosition().withComponent("topic", 
0, 1)),
             new QueryConfig(false),
             store,
-            Position.emptyPosition().withComponent("topic", 0, 0),
+            (SynchronizedPosition) 
Position.emptyPosition().withComponent("topic", 0, 0),

Review Comment:
   That cast won't work



##########
streams/src/main/java/org/apache/kafka/streams/query/internals/SynchronizedPosition.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.kafka.streams.query.internals;
+
+import org.apache.kafka.streams.query.Position;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class SynchronizedPosition extends Position {
+    private final ReentrantLock lock = new ReentrantLock();
+
+    public SynchronizedPosition(final ConcurrentHashMap<String, 
ConcurrentHashMap<Integer, Long>> position) {
+        super(position);
+    }
+
+    public static SynchronizedPosition emptyPosition() {
+        return new SynchronizedPosition(new ConcurrentHashMap<>());
+    }
+
+    public static SynchronizedPosition fromMap(final Map<String, ? extends 
Map<Integer, Long>> map) {
+        return new SynchronizedPosition(deepCopy(map));
+    }
+
+    public static ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>> 
deepCopy(

Review Comment:
   Why did you move this static method? Since it's also accessed by `Position`, 
I'd rather leave it there.



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