contrueCT opened a new pull request, #3193:
URL: https://github.com/apache/hugegraph/pull/3193

   ## Purpose of the PR
   
   Closes #3190.
   
   `QueryResults` currently detects a query boundary by probing `hasNext()` and 
then checking whether the active query changed. That probe can activate the 
next index query or backend page before the current batch finishes processing. 
Ordering is also selected from the first active segment, so an unsorted batch 
`[1]` followed by a batch with input IDs `[3, 2]` can incorrectly produce `[1, 
2, 3]`.
   
   This change gives each batch its own results and captured processing 
context. Parsing, TTL checks, residual filtering and input-order restoration 
finish within that batch before the caller consumes a flattened stream.
   
   ## Main Changes
   
   - Introduce `QueryBatch` and `QueryResultContext` to carry the input IDs, 
ordering decision, visibility flags and effective results filter with the 
results that produced them.
   - Make `QueryResults`, `QueryList` and `PageEntryIterator` compose explicit 
batches. Remove `queryVersion`/`currentQueries` boundary inference and shared 
results-filter propagation.
   - Apply vertex and edge processing within each batch, preserving 
public/internal visibility, diagnostics and index-cleanup ownership. Keep 
native scans on their original single-batch path so backend page tokens and 
capacity checks remain intact.
   - Cache candidates before residual matching and reapply the current batch 
context on hits. Preserve mixed hit/miss input ordering, the original 
edge-cache request key, off-heap serialization, TASK/SERVER query types and the 
RamTable fast path.
   - Make batch wrappers close idempotently and preserve the primary exception 
when cleanup also fails. Native iterators that close themselves still rely on 
their existing backend close contract.
   
   The lifecycle is:
   
   ```mermaid
   flowchart LR
       A[Activate batch A] --> C[Capture IDs, order and filter context]
       C --> P[Parse and check TTL]
       P --> F[Apply residual filter]
       F --> O[Restore input order when needed]
       O --> V[Apply public visibility when applicable]
       V --> R[Return A results]
       R --> E[A exhausted and closed]
       E --> B[Activate batch B or next page]
   ```
   
   The flattened consumer can advance after A is exhausted; an iterator 
operating inside A never probes B to discover A's boundary. HStore partition 
merging, `ORDER_BY_KEY` and physical-key cursors are outside this change.
   
   ## Verifying these changes
   
   - [ ] Trivial rework / code cleanup without any test coverage. (No Need)
   - [x] Already covered by existing tests, including `VertexCoreTest`, 
`EdgeCoreTest` and cache regressions.
   - [x] Need tests and can be verified as follows:
   
   Three focused tests first failed on the old implementation: mixed ordering 
returned `[1, 2, 3]` instead of `[1, 3, 2]`, and the next-query and next-page 
fetch counters reached 2 when only 1 batch should have been activated. All now 
pass.
   
   Final verification on JDK 17 and Maven 3.9.16:
   
   | Scope | Selected | Skipped | Failures / errors |
   | --- | ---: | ---: | ---: |
   | Seven focused unit-test classes | 58 | 0 | 0 / 0 |
   | Memory: `VertexCoreTest`, `EdgeCoreTest` | 436 | 69 | 0 / 0 |
   | RocksDB: `VertexCoreTest`, `EdgeCoreTest` | 436 | 29 | 0 / 0 |
   | HStore: search/joint-index, input-order and paging regressions | 26 | 0 | 
0 / 0 |
   
   Coverage includes empty batches/holders, null and expanded mapper results, 
mixed ordering in both directions, real page-fetch counters and cursor 
metadata, limits, cross-batch materialization capacity, early close and 
suppressed exceptions, residual filtering on warm vertex caches, and an 
off-heap edge-cache hit with zero backend reads. The HStore selection also 
passed on the pre-change baseline using the same isolated PD/Store setup.
   
   <details>
   <summary>Reproduction commands</summary>
   
   ```bash
   mvn test -pl hugegraph-server/hugegraph-test -am -P unit-test \
     
-Dtest=QueryResultsTest,QueryListTest,GraphTransactionTest,CachedGraphTransactionTest,IdHolderTest,QueryTest,PageStateTest
 \
     -DfailIfNoTests=false -Drat.skip=true
   
   # Run once with memory, then with rocksdb
   mvn test -pl hugegraph-server/hugegraph-test -am -P core-test,memory \
     -Dtest=VertexCoreTest,EdgeCoreTest -DfailIfNoTests=false -Drat.skip=true
   
   # Requires an isolated, initialized PD/Store and an HStore properties file
   mvn test -pl hugegraph-server/hugegraph-test -am -P core-test,hstore \
     -Dbackend=hstore -Dconfig_path=/path/to/hstore-test.properties \
     
'-Dtest=VertexCoreTest#testQueryByJointIndexesWithSearch*+testQueryByTextContainsPropertyOrderByMatchedCount*+testQueryByRangeIndexKeeps*+testQueryByPage*+testQueryByMultiLabelInPage,EdgeCoreTest#testQueryEdgeByPage*+testQuery*EdgesOfVertexInPaging'
 \
     -DfailIfNoTests=false -Drat.skip=true
   
   mvn editorconfig:format
   mvn clean compile -Dmaven.javadoc.skip=true -Drat.skip=true
   git diff --check
   ```
   
   </details>
   
   Formatting and full reactor compilation passed. Verification used 
`-Drat.skip=true`; the complete UnitTestSuite, API and TinkerPop suites were 
not run. The tested Java files match this commit byte-for-byte.
   
   ## Does this PR potentially affect the following parts?
   
   - [ ] Dependencies
   - [ ] Modify configurations
   - [x] The public API (`QueryResults` Java helper methods; Gremlin/REST 
result semantics are preserved)
   - [x] Other affects (internal query iteration, paging and cache lifecycle)
   - [ ] Nope
   
   ## Documentation Status
   
   - [ ] `Doc - TODO`
   - [ ] `Doc - Done`
   - [x] `Doc - No Need`
   


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