Skip to content

[To dev/1.3] Enforce REST query row limit as hard cap (#18149)#18197

Merged
JackieTien97 merged 2 commits into
dev/1.3from
codex/backport-pr-18149-dev-1.3
Jul 14, 2026
Merged

[To dev/1.3] Enforce REST query row limit as hard cap (#18149)#18197
JackieTien97 merged 2 commits into
dev/1.3from
codex/backport-pr-18149-dev-1.3

Conversation

@JackieTien97

Copy link
Copy Markdown
Contributor

Description

Backport #18149 to dev/1.3.

Enforce the configured REST response limit

  • Treat rest_query_default_row_size_limit as a hard upper bound for REST v1/v2 query responses.
  • Clamp caller-provided rowLimit / row_limit to the configured limit.
  • Fall back to the built-in default of 10,000 rows when the configured value is non-positive.
  • Check incoming TsBlocks before materializing them, while allowing results exactly at the limit.

Cover Grafana and fast-last paths

  • Apply the same hard limit to Grafana variables, node, and expression endpoints.
  • Limit the v2 fast-last cache-hit path, which previously built the response directly.
  • Centralize limit resolution and exceeded-limit responses in QueryRowLimitUtils.

dev/1.3 adaptations

The original PR targets the newer standalone REST module. This backport preserves the dev/1.3 layout and APIs:

  • Uses iotdb-core/datanode, org.apache.iotdb.db.protocol.rest.*, and javax.ws.rs.
  • Adapts fast-last handling to the 1.3 cache shape: Map<PartialPath, Map<String, TimeValuePair>>.
  • Omits the newer table-v1 REST and REST i18n files because those components do not exist on dev/1.3.

Validation

  • mvn spotless:apply -pl iotdb-core/datanode
  • mvn -q clean test -pl iotdb-core/datanode -am -Dtest=QueryRowLimitUtilsTest,QueryDataSetHandlerTest,FastLastHandlerTest -Dsurefire.failIfNoSpecifiedTests=false
    • 8 tests passed, 0 failures, 0 errors.
  • git diff --check origin/dev/1.3...HEAD

This PR has:

  • been self-reviewed.
  • added documentation for modified behavior.
  • added comments explaining non-obvious behavior.
  • added unit tests for the new code paths.

Key changed/added classes
  • QueryRowLimitUtils
  • REST v1/v2 QueryDataSetHandler
  • REST v1/v2 RestApiServiceImpl
  • Grafana v1/v2 GrafanaApiServiceImpl
  • v2 FastLastHandler

…n tests

A non-positive rest_query_default_row_size_limit used to mean "unlimited";
the hard-cap handling clamped it down to 1, silently capping every REST
response to a single row. Remap non-positive values to the built-in
default (10000) so existing deployments are not degraded, while still
guaranteeing a finite cap.

Add regression coverage:
- QueryRowLimitUtilsTest: an oversized caller-provided rowLimit is clamped
  to the configured hard limit.
- FastLastHandlerTest: the fastLastQuery cache-hit path caps the number of
  materialized entries. The cache-hit loop is extracted into
  FastLastHandler.fillLastValueDataSet so it is unit-testable.
@JackieTien97 JackieTien97 marked this pull request as ready for review July 14, 2026 01:41
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
15.6% Duplication on New Code (required ≤ 5%)

See analysis details on SonarQube Cloud

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 32.16783% with 97 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.53%. Comparing base (9b66d5e) to head (3c20c25).
⚠️ Report is 1 commits behind head on dev/1.3.

Files with missing lines Patch % Lines
.../protocol/rest/v2/handler/QueryDataSetHandler.java 0.00% 38 Missing ⚠️
.../protocol/rest/v1/handler/QueryDataSetHandler.java 7.89% 35 Missing ⚠️
...b/protocol/rest/v1/impl/GrafanaApiServiceImpl.java 0.00% 8 Missing ⚠️
...b/protocol/rest/v2/impl/GrafanaApiServiceImpl.java 0.00% 8 Missing ⚠️
...b/db/protocol/rest/v2/impl/RestApiServiceImpl.java 0.00% 5 Missing ⚠️
...b/db/protocol/rest/v1/impl/RestApiServiceImpl.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev/1.3   #18197      +/-   ##
=============================================
- Coverage      43.54%   43.53%   -0.01%     
  Complexity       198      198              
=============================================
  Files           3630     3631       +1     
  Lines         243741   243791      +50     
  Branches       29741    29753      +12     
=============================================
+ Hits          106127   106141      +14     
- Misses        137614   137650      +36     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JackieTien97 JackieTien97 merged commit f0e8ba2 into dev/1.3 Jul 14, 2026
17 of 19 checks passed
@JackieTien97 JackieTien97 deleted the codex/backport-pr-18149-dev-1.3 branch July 14, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant