github-actions[bot] commented on code in PR #70884:
URL: https://github.com/apache/doris/pull/70884#discussion_r4676578415
##########
fe/fe-connector/fe-connector-paimon/src/main/java/org/apache/doris/connector/paimon/PaimonSchemaPin.java:
##########
@@ -245,6 +250,197 @@ static long fallbackSchemaId(Map<String, String> options,
String path, LongSuppl
return pinned == null ? defaultId.getAsLong() : Long.parseLong(pinned);
}
+ static Optional<ConnectorSqlCacheVersion> resolveSqlCacheVersion(
+ Table table, String branchName, Map<String, String> scanOptions) {
+ if (!PaimonScanParams.hasPinnedVersion(scanOptions)) {
+ return Optional.empty();
+ }
+ if (hasQueryAuth(table)) {
+ // Dynamic server-side row/column authorization runs in
scan.plan(); do not serve cached results.
+ return Optional.empty();
+ }
+ if (!coordinates(scanOptions).isEmpty()) {
+ validate(table, scanOptions);
+ }
+ Optional<ResolvedVersion> resolved = resolveTableVersion(table,
scanOptions, "");
+ if (!resolved.isPresent()) {
+ return Optional.empty();
+ }
+ String branch = branchName == null ? "main" : branchName;
+ String payload = "branch=" + branch
+ + "|options=" +
PaimonScanParams.canonicalCacheOptions(scanOptions)
+ + "|table=" + resolved.get().token;
+ return Optional.of(new ConnectorSqlCacheVersion(digest(payload),
resolved.get().updateTimeMillis));
+ }
+
+ private static boolean hasQueryAuth(Table table) {
+ if (table instanceof FallbackReadFileStoreTable) {
+ FallbackReadFileStoreTable pair = (FallbackReadFileStoreTable)
table;
+ return hasQueryAuth(pair.wrapped()) || hasQueryAuth(pair.other());
+ }
+ if (table instanceof DelegatedFileStoreTable) {
+ return hasQueryAuth(((DelegatedFileStoreTable) table).wrapped());
+ }
+ return table instanceof FileStoreTable && ((FileStoreTable)
table).coreOptions().queryAuthEnabled();
+ }
+
+ private static Optional<ResolvedVersion> resolveTableVersion(
+ Table table, Map<String, String> scanOptions, String path) {
+ if (table instanceof FallbackReadFileStoreTable) {
+ FallbackReadFileStoreTable pair = (FallbackReadFileStoreTable)
table;
+ Optional<ResolvedVersion> main =
resolveTableVersion(pair.wrapped(), scanOptions, path);
+ if (!main.isPresent()) {
+ return Optional.empty();
+ }
+ Optional<ResolvedVersion> fallback = resolveFallbackBranchVersion(
+ pair.other(), scanOptions, path + "fallback.",
main.get().mainSnapshotMillis);
+ if (!fallback.isPresent()) {
+ return Optional.empty();
+ }
+ return Optional.of(new ResolvedVersion(
+ "fallback(" + main.get().token + "," +
fallback.get().token + ")",
+ Math.max(main.get().updateTimeMillis,
fallback.get().updateTimeMillis),
+ main.get().mainSnapshotMillis));
+ }
+ if (table instanceof DelegatedFileStoreTable) {
+ return resolveTableVersion(((DelegatedFileStoreTable)
table).wrapped(), scanOptions, path);
+ }
+ if (!(table instanceof DataTable)) {
+ return Optional.empty();
+ }
+ return resolveDataTableVersion((DataTable) table, scanOptions);
+ }
+
+ private static Optional<ResolvedVersion> resolveDataTableVersion(
+ DataTable data, Map<String, String> scanOptions) {
+ OptionalLong boundSchema = PaimonScanParams.boundSchemaId(scanOptions);
+ String tagName = scanOptions.get(CoreOptions.SCAN_TAG_NAME.key());
+ if (tagName != null) {
+ Optional<Tag> tagOpt = data.tagManager().get(tagName);
+ if (!tagOpt.isPresent()) {
+ return Optional.empty();
+ }
+ Tag tag = tagOpt.get();
+ long schemaId = boundSchema.orElse(tag.schemaId());
+ Optional<TableSchema> schema = readSchema(data.schemaManager(),
schemaId);
+ if (!schema.isPresent()) {
+ return Optional.empty();
+ }
+ String token = data.location() + "|schema:" + schemaId + ":" +
schemaDigest(schema.get())
+ + "|tag:" + tagName + ":" + tag.id() + ":" +
digest(tag.toJson());
+ return Optional.of(new ResolvedVersion(token, tag.timeMillis(),
OptionalLong.of(tag.timeMillis())));
+ }
+ if (PaimonScanParams.isPinnedEmptyScan(scanOptions)) {
+ Optional<TableSchema> schema = boundSchema.isPresent()
+ ? readSchema(data.schemaManager(), boundSchema.getAsLong())
+ : data.schemaManager().latest();
+ if (!schema.isPresent()) {
+ return Optional.empty();
+ }
+ String token = data.location() + "|schema:" + schema.get().id() +
":"
+ + schemaDigest(schema.get()) + "|empty";
+ return Optional.of(new ResolvedVersion(token, 0L,
OptionalLong.empty()));
+ }
+ String snapshotIdValue =
scanOptions.get(CoreOptions.SCAN_SNAPSHOT_ID.key());
+ if (snapshotIdValue == null) {
+ return Optional.empty();
+ }
+ long snapshotId = Long.parseLong(snapshotIdValue);
+ if (!data.snapshotManager().snapshotExists(snapshotId)) {
+ return Optional.empty();
+ }
+ Snapshot snap = snapshot(data, snapshotId);
+ long schemaId = boundSchema.orElse(snap.schemaId());
+ Optional<TableSchema> schema = readSchema(data.schemaManager(),
schemaId);
+ if (!schema.isPresent()) {
+ return Optional.empty();
+ }
+ String token = data.location() + "|schema:" + schemaId + ":" +
schemaDigest(schema.get())
+ + "|snap:" + snapshotId + ":" + digest(snap.toJson());
+ return Optional.of(new ResolvedVersion(token, snap.timeMillis(),
OptionalLong.of(snap.timeMillis())));
+ }
+
+ private static Optional<ResolvedVersion> resolveFallbackBranchVersion(
+ FileStoreTable other, Map<String, String> scanOptions, String
fallbackPath,
+ OptionalLong mainSnapshotMillis) {
+ if (other instanceof FallbackReadFileStoreTable) {
+ // Chain tables nest a ChainGroupReadTable (snapshotBranch,
deltaBranch) as pair.other();
+ // mirror capture() by walking both branches so delta-branch
commits invalidate SQL cache.
+ FallbackReadFileStoreTable nested = (FallbackReadFileStoreTable)
other;
+ Optional<ResolvedVersion> first = resolveFallbackBranchVersion(
+ nested.wrapped(), scanOptions, fallbackPath,
mainSnapshotMillis);
+ if (!first.isPresent()) {
+ return Optional.empty();
+ }
+ Optional<ResolvedVersion> second = resolveFallbackBranchVersion(
+ nested.other(), scanOptions, fallbackPath + "fallback.",
first.get().mainSnapshotMillis);
+ if (!second.isPresent()) {
+ return Optional.empty();
+ }
+ return Optional.of(new ResolvedVersion(
+ "fallback(" + first.get().token + "," + second.get().token
+ ")",
+ Math.max(first.get().updateTimeMillis,
second.get().updateTimeMillis),
+ first.get().mainSnapshotMillis));
+ }
+ if (other instanceof DelegatedFileStoreTable) {
+ return resolveFallbackBranchVersion(
+ ((DelegatedFileStoreTable) other).wrapped(), scanOptions,
fallbackPath, mainSnapshotMillis);
+ }
+ String pinnedFallbackSchema = scanOptions.get(PREFIX + fallbackPath +
"schema-id");
+ Optional<TableSchema> schema = pinnedFallbackSchema != null
+ ? readSchema(other.schemaManager(),
Long.parseLong(pinnedFallbackSchema))
+ : other.schemaManager().latest();
+ if (!schema.isPresent()) {
+ return Optional.empty();
+ }
+ SnapshotManager manager = other.snapshotManager();
+ String pinnedFallbackSnapshot = fallbackSnapshotId(scanOptions,
fallbackPath);
+ Long selectedSnapshotId;
+ if (pinnedFallbackSnapshot != null) {
+ selectedSnapshotId = Long.parseLong(pinnedFallbackSnapshot);
+ } else if (Boolean.parseBoolean(scanOptions.get(PREFIX + fallbackPath
+ "snapshot-absent"))) {
+ selectedSnapshotId = null;
+ } else if (mainSnapshotMillis.isPresent()) {
+ Snapshot eligible =
manager.earlierOrEqualTimeMills(mainSnapshotMillis.getAsLong());
Review Comment:
[P1] Include the fallback branch's selected tag in the cache version
For a table using `scan.fallback-branch`, a tag read passes `scan.tag-name`
to both branches: `copyWithHistoricalSchema` uses `otherOptions`, whose SDK
rewrite only timestamp-translates snapshot IDs. This version resolver instead
selects the fallback snapshot at the main tag's timestamp and never reads the
fallback tag. Keep the main `v1` tag fixed, then replace the fallback branch's
`v1` tag with a snapshot containing different fallback-only rows: the scan
result changes, but both cache-version calls still hash the same
timestamp-selected snapshot. With external SQL caching enabled,
admission/lookup therefore accept the old result. Resolve and hash the
fallback's actual tag and schema (including retained metadata), or decline
versioning for this shape.
##########
fe/fe-connector/fe-connector-paimon/src/main/java/org/apache/doris/connector/paimon/PaimonSchemaPin.java:
##########
@@ -245,6 +250,197 @@ static long fallbackSchemaId(Map<String, String> options,
String path, LongSuppl
return pinned == null ? defaultId.getAsLong() : Long.parseLong(pinned);
}
+ static Optional<ConnectorSqlCacheVersion> resolveSqlCacheVersion(
+ Table table, String branchName, Map<String, String> scanOptions) {
+ if (!PaimonScanParams.hasPinnedVersion(scanOptions)) {
+ return Optional.empty();
+ }
+ if (hasQueryAuth(table)) {
Review Comment:
[P1] Check query-auth eligibility on the effective pinned schema
`resolveTable` can return a cached table at schema 0 with
`query-auth.enabled=false`, while `latestSchema` deliberately reads the live
schema directory. After an external schema-only ALTER enables query auth at
schema 1, `beginQuerySnapshot` binds schema 1 and the scan's
`applyOptionsWithoutTimeTravel` restores its enabled options. This guard still
checks the raw schema-0 table and supplies a cache version for that dynamically
authorized scan. Later catalog filter/mask changes leave the snapshot/schema
digest unchanged, so the SQL cache can return obsolete rows without running
`scan.plan()` again. Determine eligibility from the schema/options each pinned
physical branch actually uses, and cover stale cached handles in the test.
##########
fe/fe-connector/fe-connector-paimon/src/main/java/org/apache/doris/connector/paimon/PaimonSchemaPin.java:
##########
@@ -245,6 +250,197 @@ static long fallbackSchemaId(Map<String, String> options,
String path, LongSuppl
return pinned == null ? defaultId.getAsLong() : Long.parseLong(pinned);
}
+ static Optional<ConnectorSqlCacheVersion> resolveSqlCacheVersion(
+ Table table, String branchName, Map<String, String> scanOptions) {
+ if (!PaimonScanParams.hasPinnedVersion(scanOptions)) {
+ return Optional.empty();
+ }
+ if (hasQueryAuth(table)) {
+ // Dynamic server-side row/column authorization runs in
scan.plan(); do not serve cached results.
+ return Optional.empty();
+ }
+ if (!coordinates(scanOptions).isEmpty()) {
+ validate(table, scanOptions);
+ }
+ Optional<ResolvedVersion> resolved = resolveTableVersion(table,
scanOptions, "");
+ if (!resolved.isPresent()) {
+ return Optional.empty();
+ }
+ String branch = branchName == null ? "main" : branchName;
+ String payload = "branch=" + branch
+ + "|options=" +
PaimonScanParams.canonicalCacheOptions(scanOptions)
+ + "|table=" + resolved.get().token;
+ return Optional.of(new ConnectorSqlCacheVersion(digest(payload),
resolved.get().updateTimeMillis));
+ }
+
+ private static boolean hasQueryAuth(Table table) {
+ if (table instanceof FallbackReadFileStoreTable) {
+ FallbackReadFileStoreTable pair = (FallbackReadFileStoreTable)
table;
+ return hasQueryAuth(pair.wrapped()) || hasQueryAuth(pair.other());
+ }
+ if (table instanceof DelegatedFileStoreTable) {
+ return hasQueryAuth(((DelegatedFileStoreTable) table).wrapped());
+ }
+ return table instanceof FileStoreTable && ((FileStoreTable)
table).coreOptions().queryAuthEnabled();
+ }
+
+ private static Optional<ResolvedVersion> resolveTableVersion(
+ Table table, Map<String, String> scanOptions, String path) {
+ if (table instanceof FallbackReadFileStoreTable) {
+ FallbackReadFileStoreTable pair = (FallbackReadFileStoreTable)
table;
+ Optional<ResolvedVersion> main =
resolveTableVersion(pair.wrapped(), scanOptions, path);
+ if (!main.isPresent()) {
+ return Optional.empty();
+ }
+ Optional<ResolvedVersion> fallback = resolveFallbackBranchVersion(
+ pair.other(), scanOptions, path + "fallback.",
main.get().mainSnapshotMillis);
+ if (!fallback.isPresent()) {
+ return Optional.empty();
+ }
+ return Optional.of(new ResolvedVersion(
+ "fallback(" + main.get().token + "," +
fallback.get().token + ")",
+ Math.max(main.get().updateTimeMillis,
fallback.get().updateTimeMillis),
+ main.get().mainSnapshotMillis));
+ }
+ if (table instanceof DelegatedFileStoreTable) {
+ return resolveTableVersion(((DelegatedFileStoreTable)
table).wrapped(), scanOptions, path);
+ }
+ if (!(table instanceof DataTable)) {
+ return Optional.empty();
+ }
+ return resolveDataTableVersion((DataTable) table, scanOptions);
+ }
+
+ private static Optional<ResolvedVersion> resolveDataTableVersion(
+ DataTable data, Map<String, String> scanOptions) {
+ OptionalLong boundSchema = PaimonScanParams.boundSchemaId(scanOptions);
+ String tagName = scanOptions.get(CoreOptions.SCAN_TAG_NAME.key());
+ if (tagName != null) {
+ Optional<Tag> tagOpt = data.tagManager().get(tagName);
Review Comment:
[P2] Freeze the tagged snapshot used by a cacheable scan
A direct tag pin retains only `scan.tag-name`; this lookup does not bind the
returned Tag/Snapshot to the later scan. With external SQL caching enabled, let
`v1` point to A when `BindRelation` records this digest, replace it with
same-schema B before split planning, then restore A after B's splits are
planned but before cache admission. `StaticFromTagStartingScanner` rereads the
name and produces B's rows, while `publishIfDependenciesValid` sees A again and
accepts those rows under A's digest. Subsequent queries at A can therefore
receive B's cached answer. Bind the digest and scan to the same retained tagged
metadata, or decline SQL caching for mutable name-only pins.
--
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]