github-actions[bot] commented on code in PR #62453:
URL: https://github.com/apache/doris/pull/62453#discussion_r3079255878


##########
fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java:
##########
@@ -815,7 +818,8 @@ public void commitTransaction(List<Table> tableList, long 
transactionId, List<Ta
             checkCommitStatus(tableList, transactionState, tabletCommitInfos, 
txnCommitAttachment, errorReplicaIds,
                     tableToPartition, totalInvolvedBackends);
         }
-
+        // check table stream offset if necessary
+        checkStreamOffset(transactionState);
         // before state transform

Review Comment:
   This validation only runs in the single-table 
`commitTransaction(List<Table>, ...)` overload. The transaction-model path 
(`commitTransaction(long transactionId, List<Table> tableList, 
List<SubTransactionState> subTransactionStates)`) still never validates the 
stored stream offsets, and 
`GlobalTransactionMgr.commitAndPublishTransaction(DatabaseIf, long, 
List<SubTransactionState>, ...)` still locks only the target tables. So 
`BEGIN/COMMIT` inserts can still race and both commit the same stream offsets, 
breaking exactly-once consumption on that path.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java:
##########
@@ -285,6 +294,50 @@ public AbstractInsertExecutor initPlan(ConnectContext ctx, 
StmtExecutor stmtExec
                 return insertExecutor;
             }
 
+            List<ScanNode> tableStreamScanNodes =
+                    buildResult.planner.getScanNodes().stream()
+                            .filter(s -> s.getTableIf() instanceof 
OlapTableStreamWrapper).collect(Collectors.toList());
+
+            if (!tableStreamScanNodes.isEmpty()) {
+                // stream id -> <partition id, offset>
+                Map<Pair<Long, Long>, Map<Long, Long>> 
distinctPartitionOffsets =
+                        new HashMap<>(tableStreamScanNodes.size());
+                Map<Pair<Long, Long>, Map<Long, Long>> 
distinctPartitionNextOffsets =
+                        new HashMap<>(tableStreamScanNodes.size());

Review Comment:
   `distinctPartitionNextOffsets` stays empty all the way through this method, 
but `OlapTableStream.unprotectedCheckStreamOffset()` now requires a 
`nextOffset` entry for every partition already tracked in `partitionOffset`. 
That means the normal `show_initial_rows = false` flow will fail every commit 
with `nextOffset missing for partition=...`, and even the historical path will 
fail once a partition has been consumed once. We need to compute the 
post-consumption offset for each scanned partition before building 
`TableStreamUpdateInfo`.



##########
fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java:
##########
@@ -432,6 +434,10 @@ private void addScanRangeLocations(Partition partition,
         // assign a snapshot version of all partitions.
         if (!(Config.isCloudMode() && Config.enable_cloud_snapshot_version)) {
             visibleVersion = partition.getVisibleVersion();
+            // if partition offset is set, use the offset to set the visible 
version
+            if (partitionOffset != null && 
partitionOffset.containsKey(partition.getId())) {
+                visibleVersion = partitionOffset.get(partition.getId());
+            }

Review Comment:
   Using the stored stream offset as the scan `visibleVersion` flips the 
semantics. Example: create a stream at partition version 10 with 
`show_initial_rows = false`, then publish new data at version 11. `hasData()` 
becomes true, but this code still scans snapshot version 10, so BE rereads the 
old data and never sees the new rows at 11. Since no lower-bound offset is 
passed anywhere in the FE/BE protocol, this cannot implement incremental 
consumption; it only overrides the snapshot upper bound.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to