Repository navigation
Conversation
b8aaeec to
30a7807
Compare
f5ab8c7 to
3feda3f
Compare
8bbfc22 to
60cddd2
Compare
|
Heads-up: this PR has been re-scoped as part of a 3-PR split of the metrics work agreed in the community sync. The branch was force-pushed with the re-sliced content, so earlier line comments now point at superseded commits.
This PR depends on #4115 (and #5068); until they merge the diff here also includes their changes. See the updated description for details. |
0cd9d14 to
13acd2f
Compare
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.persistence.relational.jdbc.pagination; |
There was a problem hiding this comment.
should it be very specific to metrics extensions namespace or it should be general to all jdbc pagination?
either way placement needs to be matching
There was a problem hiding this comment.
Moved MetricsReportToken to org.apache.polaris.extension.metrics.jdbc.pagination (28f42dd), matching the package used by its sibling JdbcMetricsPersistence/PersistingMetricsReporter classes in this module rather than the generic JDBC persistence namespace. Also picked up a missing Jackson 3 @JsonSerialize/@JsonDeserialize pair while I was there — every other Token impl has it and its absence broke cursor round-tripping, caught by the new contract test.
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** Unit tests for metrics model conversion methods (SPI record ↔ JDBC model). */ | ||
| class SpiModelConverterTest { |
There was a problem hiding this comment.
Bigger ask than coverage: can we put the behavioral tests behind an abstract contract test next to the SPI so the no-op and any future backend run the same suite.
Minimum cases: two pages, a tie on equal timestamp_ms, realm isolation with identical catalog/table ids in two realms, empty result, foreign cursor.
There was a problem hiding this comment.
Added AbstractMetricsQuerySpiContractTest in the spi module's test fixtures (5cf3fef), covering exactly the cases you listed: two-page pagination, a timestamp_ms tie broken by report_id, realm isolation for identical catalog/table ids, empty results, and a foreign cursor token type. NoOpMetricsQueryContractTest and JdbcMetricsQuerySpiContractTest both run the same suite against the no-op default and the H2-backed JDBC impl; cases needing persisted rows are skipped for the no-op backend via supportsPersistence().
| params.add(timestampTo); | ||
| } | ||
|
|
||
| if (pageToken.paginationRequested()) { |
There was a problem hiding this comment.
The wrong-token-type guard is inside if (pageToken.paginationRequested()), and that's just pageSize().isPresent(). So a token carrying a cursor but no page size skips both the guard and the keyset predicate: the cursor is dropped and page one comes back with 200. A caller paging through results gets silently reset to the start with no signal, which is worse than an error. Worth noting what this guard is actually for. Token type ids are a global registry, and this check is what stops a cursor minted by one MetricsQuerySpi backend from being fed to another. With one backend that barely matters.
The moment this SPI has two, for example, during a migration with both on the classpath for instance, it's the only thing standing between a foreign cursor and a wrong answer. IMO that makes it worth moving the type check outside the paginationRequested() branch so a bad cursor always throws, regardless of whether page size was supplied.
There was a problem hiding this comment.
Good point — moved the wrong-token-type guard outside paginationRequested() (52fa131) so any cursor of the wrong type is rejected regardless of whether a page size was supplied, and added a doc comment explaining the guard is what stops a cursor minted by one MetricsQuerySpi backend from being fed to another.
13acd2f to
5cf3fef
Compare
5cf3fef to
8a78198
Compare
27ed6c5 to
6a64e1f
Compare
|
Heads-up: #5967 has been merged, so Could you rebase onto |
6a64e1f to
71b16a4
Compare
|
Thanks for the heads-up. I rebased onto main, on top of the updated #4115 branch. This PR never touched I couldn't run the full Gradle build locally (the Spotless plugin won't resolve on my machine because of a certificate error), so I'm leaning on CI to confirm formatting and compilation. |
74faf60 to
8a370ca
Compare
596c0b6 to
9a39d15
Compare
9a39d15 to
ecf2134
Compare
| CREATE INDEX IF NOT EXISTS idx_scan_report_timestamp ON scan_metrics_report(realm_id, timestamp_ms); | ||
|
|
||
| -- Index for query lookups by catalog_id and table_id | ||
| CREATE INDEX IF NOT EXISTS idx_scan_report_lookup ON scan_metrics_report(realm_id, catalog_id, table_id, timestamp_ms); |
There was a problem hiding this comment.
The old index has been released 🤔 Should we bump the schema version and add upgrade docs (cf. Schema Upgrades in relational-jdbc.md)?
There was a problem hiding this comment.
Good catch. Rather than bump the schema version and ask everyone to run a manual index migration for a minor gain, I reverted the index change (f5e59f9). The lookup indexes are back to (realm_id, catalog_id, table_id, timestamp_ms), so this PR no longer touches persistence/relational-jdbc. Queries stay correct; ties on timestamp_ms just need a small extra sort. If we want the wider index later it can go in its own change with a version bump and upgrade notes.
| PageToken.fromLimit(10)); | ||
| assertThat(otherRealmPage.items()).isEmpty(); | ||
|
|
||
| if (supportsPersistence()) { |
There was a problem hiding this comment.
nit: Assumptions.assumeTrue()?
I suppose we do not need to call list() (line 98) if persistence is not supported.
There was a problem hiding this comment.
Done (0e47bd5). realmIsolationForIdenticalCatalogAndTableIds now starts with assumeTrue(supportsPersistence(), ...), which drops the if and skips the list() calls for the no-op backend.
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(MetricsModelUtils.class); | ||
|
|
||
| public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
|
|
||
| long getTotalDurationMs(); | ||
| /** | ||
| * Known compatibility limitation: an earlier iteration of this PR always wrote this column as |
There was a problem hiding this comment.
nit: "this PR" will stay in the code long after the PR is history 😅 Could you rephrase?
There was a problem hiding this comment.
Good point, reworded in 90c259b. The comments now refer to legacy rows written before NULL was used for an unknown duration (and before the field-names column was JSON-encoded) instead of to this PR.
|
Now that prerequisites have been merged and this PR has been rebased, let's keep itopen for a couple more days to give other interested reviewers time to post comments. |
What / Why
Part of the 3-PR split of the Iceberg metrics work (agreed with EJ, Dmitri, Anand):
Changes
JdbcMetricsPersistencealso implementsMetricsQuerySpi:listScanReports/listCommitReportsrun keyset-paginated queries (ordered bytimestamp_ms DESC, report_id DESC) with catalog/table scoping and optional snapshotId / principalName / timestamp filters.Converter/toRecord) + aMetricsModelUtilshelper.MetricsReportTokenkeyset cursor plus itsToken.TokenTypeservice registration for page-token round-tripping.MetricsReportsServicereturns real pages instead of the no-op empty page.Testing
./gradlew buildand:polaris-runtime-service:intTest(Quarkus) pass.