github-actions[bot] commented on code in PR #62453:
URL: https://github.com/apache/doris/pull/62453#discussion_r3108222133
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java:
##########
@@ -281,6 +292,44 @@ 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>, AbstractTableStreamUpdate>
distinctUpdate =
+ new HashMap<>(tableStreamScanNodes.size());
+ for (ScanNode scanNode : tableStreamScanNodes) {
+ // only support OlapScanNode currently
+ Preconditions.checkArgument(scanNode instanceof
OlapScanNode);
+ OlapScanNode olapScanNode = (OlapScanNode) scanNode;
+ OlapTableStreamWrapper wrapper = (OlapTableStreamWrapper)
scanNode.getTableIf();
+ if (!distinctUpdate.containsKey(
+ Pair.of(wrapper.getStreamDbId(),
wrapper.getStreamId()))) {
+ distinctUpdate.put(Pair.of(wrapper.getStreamDbId(),
wrapper.getStreamId()),
+ new OlapTableStreamUpdate());
+ }
+ distinctUpdate.get(Pair.of(wrapper.getStreamDbId(),
wrapper.getStreamId()))
+ .merge(olapScanNode.getStreamUpdate());
+ }
+ List<TableStreamUpdateInfo> infos = new
ArrayList<>(distinctUpdate.size());
+ distinctUpdate.forEach((key, value) -> infos.add(new
TableStreamUpdateInfo(key.first,
+ key.second, value)));
+ // put offset into executor
+ insertExecutor.setStreamUpdateInfos(infos);
+ insertExecutor.registerListener(new InsertExecutorListener() {
+ @Override
+ public void beforeComplete(AbstractInsertExecutor
insertExecutor, StmtExecutor executor,
+ long jobId) throws Exception {
+ TransactionState transactionState =
Env.getCurrentGlobalTransactionMgr()
Review Comment:
`TransactionState` is shared by all statements in txn model, so this setter
overwrites the previous statement's stream offsets. A reachable case is `BEGIN;
INSERT INTO ... SELECT FROM s1; INSERT INTO ... SELECT FROM s2; COMMIT;`: the
second statement replaces `streamUpdateInfos`,
`TransactionEntry.beforeFinishTransaction()` does not merge them back, and
`DatabaseTransactionMgr` validates/persists only the last list at commit time.
The earlier stream consume in the same transaction is therefore not durably
recorded and can be replayed again after commit.
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/OlapTableStream.java:
##########
@@ -154,4 +163,56 @@ void fillTableStreamConsumptionInfo(List<TRow> dataBatch) {
}
}
}
+
+ public boolean hasData(Partition partition) {
+ // if all available visible data has been consumed, return false
+ // todo(TsukiokaKogane): change offset from partition version to
commit tso
+ return !partitionOffset.containsKey(partition.getId())
+ ||
!partitionOffset.get(partition.getId()).equals(partition.getVisibleVersion())
+ || historicalPartitionOffset.containsKey(partition.getId());
+ }
+
+ public OlapTableStreamUpdate getStreamUpdate(List<Long>
selectedPartitionIds) {
+ if (selectedPartitionIds.isEmpty()) {
+ return null;
+ }
+ Map<Long, Long> next = new HashMap<>();
+ Map<Long, Long> prev = new HashMap<>();
+ for (Long partitionId : selectedPartitionIds) {
Review Comment:
`next` becomes the scan version in `OlapScanNode`, but on the non-historical
path it is still populated from the **current stored offset** instead of the
version that was just observed on the base partition. That means a stream
created with `show_initial_rows=false`, or a stream after its first historical
backfill, will keep scanning the old version again. Because
`unprotectedUpdateStreamUpdate()` also writes that same value back unchanged,
the committed txn never advances `partitionOffset` either. A concrete case is:
create the stream at partition version `V`, commit new data so the partition
moves to `V+1`, then `INSERT INTO dst SELECT * FROM stream`; this code still
scans/persists `V`, so `V+1` is never consumed.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java:
##########
@@ -264,6 +267,27 @@ private LogicalPlan makeOlapScan(TableIf table,
UnboundRelation unboundRelation,
}
}
+ private LogicalPlan makeOlapTableStreamScan(TableIf table, UnboundRelation
unboundRelation,
+ List<String> qualifier,
CascadesContext cascadesContext) {
+ LogicalOlapTableStreamScan scan;
+ List<Long> partIds = getPartitionIds(table, unboundRelation,
qualifier);
+ List<Long> tabletIds = unboundRelation.getTabletIds();
+ if (!CollectionUtils.isEmpty(partIds) &&
!unboundRelation.getIndexName().isPresent()) {
+ scan = new
LogicalOlapTableStreamScan(unboundRelation.getRelationId(),
+ (OlapTable) table, qualifier, partIds, tabletIds,
unboundRelation.getHints(),
+ unboundRelation.getTableSample(), ImmutableList.of());
+ } else {
+ scan = new
LogicalOlapTableStreamScan(unboundRelation.getRelationId(),
+ (OlapTable) table, qualifier, tabletIds,
unboundRelation.getHints(),
+ unboundRelation.getTableSample(), ImmutableList.of());
+ }
+ if (!tabletIds.isEmpty()) {
+ // This tabletIds is set manually, so need to set
specifiedTabletIds
+ scan = scan.withManuallySpecifiedTabletIds(tabletIds);
Review Comment:
The normal OLAP path above returns `checkAndAddDeleteSignFilter(scan, ...)`,
but the stream path returns the raw scan directly. For any base table that
relies on hidden `__DORIS_DELETE_SIGN__` filtering, `SELECT * FROM stream` /
`INSERT INTO ... SELECT FROM stream` can therefore expose tombstoned rows. This
is especially hard to recover from here because
`LogicalOlapTableStreamScan.computeOutput()` hardcodes `getBaseSchema(false)`,
so the delete-sign column is not projected later either.
--
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]