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


##########
be/src/exec/operator/set_sink_operator.cpp:
##########
@@ -42,17 +42,8 @@ Status SetSinkLocalState<is_intersect>::close(RuntimeState* 
state, Status exec_s
         return Status::OK();
     }
 
-    if (!_terminated && _runtime_filter_producer_helper && 
!state->is_cancelled()) {
-        try {
-            RETURN_IF_ERROR(_runtime_filter_producer_helper->process(
-                    state, &_shared_state->build_block, 
_shared_state->get_hash_table_size()));
-        } catch (Exception& e) {
-            return Status::InternalError(
-                    "rf process meet error: {}, _terminated: {}, 
_finish_dependency: {}",
-                    e.to_string(), _terminated,
-                    _finish_dependency ? _finish_dependency->debug_string() : 
"null");
-        }
-    }
+    // RF process() is handled in sink(eos) before set_ready(), not here.

Review Comment:
   This reorder fixes the pure `IN_FILTER` race, but it also changes behavior 
for the default `BLOOM` / `IN_OR_BLOOM` set runtime-filter path. 
`RuntimeFilterProducer::init()` uses `_synced_size` only if the async 
`send_filter_size()` round-trip has already completed; otherwise it falls back 
to `local_size` 
(`be/src/exec/runtime_filter/runtime_filter_producer.cpp:260-261`). After 
moving `process()` here, `init()` now always runs *before* 
`send_filter_size()`, so every instance sizes its bloom filter from its local 
cardinality. In a multi-instance INTERSECT/EXCEPT with skewed build 
cardinalities, the local/global merge then hits 
`BloomFilterFuncBase::merge()`'s equal-size check and fails with `bloom filter 
size not the same` (`be/src/exprs/bloom_filter_func.h:92-97`). That means the 
fix regresses the default runtime-filter type while solving the pure 
`IN_FILTER` case.



##########
regression-test/suites/query_p0/runtime_filter/set_operator_in_filter.groovy:
##########
@@ -0,0 +1,146 @@
+// 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.
+
+// Regression test for race condition in Set operator (INTERSECT/EXCEPT) with
+// IN_FILTER runtime filter type.
+//
+// Before the fix, when runtime_filter_type=1 (IN) and 
runtime_filter_max_in_num
+// was small, a race between the build sink's close() and the probe's hash 
table
+// refresh could cause RuntimeFilterWrapper::insert() to fail with 
InternalError.
+// The fix moves RF processing to sink(eos) before set_ready(), ensuring the 
hash
+// table size is read before the probe side can modify it.
+
+suite("set_operator_in_filter") {
+    sql "DROP TABLE IF EXISTS set_rf_t1"
+    sql "DROP TABLE IF EXISTS set_rf_t2"
+    sql "DROP TABLE IF EXISTS set_rf_t3"
+
+    sql """
+        CREATE TABLE set_rf_t1 (
+            k1 INT NOT NULL,
+            v1 VARCHAR(64) NOT NULL
+        )
+        DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 3
+        PROPERTIES("replication_num" = "1");
+    """
+
+    sql """
+        CREATE TABLE set_rf_t2 (
+            k1 INT NOT NULL,
+            v1 VARCHAR(64) NOT NULL
+        )
+        DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 3
+        PROPERTIES("replication_num" = "1");
+    """
+
+    sql """
+        CREATE TABLE set_rf_t3 (
+            k1 INT NOT NULL,
+            v1 VARCHAR(64) NOT NULL
+        )
+        DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 3
+        PROPERTIES("replication_num" = "1");
+    """
+
+    // Insert >10 unique values into t1 so that with max_in_num=10 the IN 
filter
+    // would overflow. This is the key condition that triggers the original 
bug.
+    sql """
+        INSERT INTO set_rf_t1 VALUES
+        (1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),
+        (6,'f'),(7,'g'),(8,'h'),(9,'i'),(10,'j'),
+        (11,'k'),(12,'l'),(13,'m'),(14,'n'),(15,'o'),
+        (16,'p'),(17,'q'),(18,'r'),(19,'s'),(20,'t');
+    """
+
+    // t2 shares some values with t1 (for INTERSECT) and has extras (for 
EXCEPT)
+    sql """
+        INSERT INTO set_rf_t2 VALUES
+        (1,'a'),(3,'c'),(5,'e'),(7,'g'),(9,'i'),
+        (11,'k'),(13,'m'),(15,'o'),(17,'q'),(19,'s'),
+        (21,'u'),(22,'v');
+    """
+
+    // t3 is the probe-side table for the join that triggers RF generation
+    sql """
+        INSERT INTO set_rf_t3 VALUES
+        (1,'x'),(3,'x'),(5,'x'),(7,'x'),(9,'x'),
+        (11,'x'),(13,'x'),(15,'x'),(100,'x'),(200,'x');
+    """
+
+    sql "sync"
+
+    // Use pure IN_FILTER type with a small max_in_num to reproduce the 
conditions
+    // that triggered the race condition bug.
+    sql "set runtime_filter_type = 1"
+    sql "set runtime_filter_max_in_num = 10"
+    sql "set disable_join_reorder = true"
+
+    // INTERSECT with join: the INTERSECT probe shrinks the hash table, which
+    // previously could race with RF processing in the build sink's close().
+    order_qt_intersect_in_rf """
+        SELECT T.k1 FROM (
+            SELECT k1 FROM set_rf_t1
+            INTERSECT
+            SELECT k1 FROM set_rf_t2
+        ) T JOIN set_rf_t3 ON T.k1 = set_rf_t3.k1;
+    """
+
+    // EXCEPT with join: similar scenario but with EXCEPT semantics.
+    order_qt_except_in_rf """
+        SELECT T.k1 FROM (
+            SELECT k1 FROM set_rf_t1
+            EXCEPT
+            SELECT k1 FROM set_rf_t2
+        ) T JOIN set_rf_t3 ON T.k1 = set_rf_t3.k1;
+    """
+
+    // Run INTERSECT query multiple times to increase coverage of the timing
+    // window. Before the fix, this would intermittently fail.
+    for (int i = 0; i < 5; i++) {
+        sql """
+            SELECT T.k1 FROM (
+                SELECT k1 FROM set_rf_t1
+                INTERSECT
+                SELECT k1 FROM set_rf_t2
+            ) T JOIN set_rf_t3 ON T.k1 = set_rf_t3.k1
+            ORDER BY T.k1;
+        """
+    }
+
+    // Also test with max_in_num=0 (always overflow immediately)
+    sql "set runtime_filter_max_in_num = 0"
+
+    order_qt_intersect_in_rf_zero """
+        SELECT T.k1 FROM (
+            SELECT k1 FROM set_rf_t1
+            INTERSECT
+            SELECT k1 FROM set_rf_t2
+        ) T JOIN set_rf_t3 ON T.k1 = set_rf_t3.k1;
+    """
+
+    // Restore session variables to defaults
+    sql "set runtime_filter_type = 12"
+    sql "set runtime_filter_max_in_num = 40960"
+    sql "set disable_join_reorder = false"
+
+    sql "DROP TABLE IF EXISTS set_rf_t1"

Review Comment:
   `AGENTS.md` says regression cases should drop tables before use and keep 
them afterward for debugging. These final cleanup statements violate that rule 
and make post-failure inspection harder.



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