nicktelford commented on code in PR #22682:
URL: https://github.com/apache/kafka/pull/22682#discussion_r3491368537


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/LogicalKeyValueSegment.java:
##########
@@ -60,26 +61,53 @@ public class LogicalKeyValueSegment implements Segment, 
VersionedStoreSegment {
     private final String name;
     private final RocksDBStore physicalStore;
     private final PrefixKeyFormatter prefixKeyFormatter;
+    // Non-null for read-only views produced by {@link 
#readOnly(IsolationLevel)}: all reads go
+    // through this accessor (bypassing any transaction buffer for 
READ_COMMITTED); writes are
+    // disallowed. Null for regular segments, which use the physicalStore's 
current accessor.
+    private final RocksDBStore.DBAccessor readAccessor;
 
     final Set<KeyValueIterator<Bytes, byte[]>> openIterators = 
Collections.synchronizedSet(new HashSet<>());
 
     LogicalKeyValueSegment(final long id,
                            final String name,
                            final RocksDBStore physicalStore) {
+        this(id, name, physicalStore, null);
+    }
+
+    private LogicalKeyValueSegment(final long id,
+                                   final String name,
+                                   final RocksDBStore physicalStore,
+                                   final RocksDBStore.DBAccessor readAccessor) 
{
         this.id = id;
         this.name = name;
         this.physicalStore = Objects.requireNonNull(physicalStore);
-
+        this.readAccessor = readAccessor;
         this.prefixKeyFormatter = new 
PrefixKeyFormatter(serializeLongToBytes(id));
     }
 
+    /**
+     * Returns a read-only view of this segment bound to the given isolation 
level. Reads go
+     * through the accessor appropriate for {@code level}; mutating calls 
throw.
+     */
+    @Override
+    public LogicalKeyValueSegment readOnly(final IsolationLevel level) {
+        return new LogicalKeyValueSegment(id, name, physicalStore, 
physicalStore.viewAccessor(level));
+    }
+
+    private void rejectIfReadOnly() {
+        if (readAccessor != null) {
+            throw new UnsupportedOperationException("Write operations are not 
supported on a read-only segment view");
+        }
+    }
+
     @Override
     public long id() {
         return id;
     }
 
     @Override
     public synchronized void destroy() {

Review Comment:
   `destroy` isn't called by Interactive Queries or read-only views, so it 
shouldn't be an issue. Unless that's not what you were asking?



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