Skip to content

Expose runtime connection info on PDK contexts - #221

Open
ply0011 wants to merge 2 commits into
mainfrom
ws/orp330-connection-context-info
Open

ply0011 wants to merge 2 commits into
mainfrom
ws/orp330-connection-context-info

Conversation

@ply0011

@ply0011 ply0011 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Expose per-instance runtime metadata through TapConnectionContext.getInfo(). Connection-test contexts and task connector contexts share the accessor. In the accompanying Engine change, a saved datasource supplies resourceId as a lowercase 24-character hex string. Before the first save the key is absent.

Connector authors can read context.getInfo().getString(TapConnectionContext.INFO_RESOURCE_ID) without adding any field to their JSON configuration. The SDK retains its existing constructors.

Verification

The focused API test verifies independent info maps for separate contexts, inheritance by task contexts, an absent key on a fresh context and unchanged connector configuration.

Release note

PDK connection and task contexts expose host-supplied runtime information to connectors.

Refs tapdata/tapdata#3622

@jarad0628 jarad0628 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI PR Review — ✅ 可通行

  • PR: #221
  • Head: 13d401fdd361e0692c08f7d26fdc7f923db76838
  • Reviewers: codexcli, claudecli, reasonix

最终总结

仲裁结论(tapdata/tapdata-common-lib #221,head 13d401f)

复核方式与证据边界

项 状态
评审员 codexcli(PASS,且实际跑通模块单测 1 例 0 失败)、claudecli(PASS)——两位独立扫描评审员结论一致,无 P0/P1/P2 报告
我的独立核对 工作区 shell 不可用(bwrap: Creating new namespace failed),故采用静态核对:TapConnectionContext.java、TapConnectionContextInfoTest.java、TapContext.java、TapConnectorContext.java、模块 pom.xml、根 pom.xml
改动范围 2 文件:TapConnectionContext.java(+12:INFO_CONNECTION_ID 常量、private final DataMap info、getInfo()、Javadoc)、新增 TapConnectionContextInfoTest.java(+21)

核对到的关键事实

  • info 为实例级 private final DataMap(LinkedHashMap),内联初始化 → 每个 context 实例各自独立,不会在连接间串数据;测试第 17–19 行确实能区分「task 写入 / test 为空 / connectionConfig 未被污染」,具备真实失败能力(若误加 static,第 18 行即失败)。
  • TapConnectorContext 未覆写 getInfo(),直接从父类继承访问器;TapContext 中不存在同名 info 字段,无字段遮蔽问题。
  • 常量值 "connectionId" 与测试读取的字符串 "connectionId" 一致;DataMap.getString 确实存在(tapdata-api 同仓模块)。
  • 编译兼容:根 pom.xml 中 jdk-17 为 activeByDefault(L97–107),模块 pom.xml 未硬编码 8;而本改动只用字段+getter,-Pjdk-8(source/target=8)同样可编译,不存在语言级别阻塞。
  • 该模块已有使用 org.junit.jupiter.api.Test 的既有测试(StreamReadConsumerTest),且 codexcli 实测 mvn test 通过,测试依赖无缺口。

已复核但未保留的报告点(附豁免理由)

  • claudecli 提到「测试使用 var(Java 10+)」与 head 实际代码不符(测试全部为显式类型声明),属描述瑕疵;其结论(编译无阻塞)经我用 activeByDefault=17 + 纯字段改动双重验证仍成立,不影响判定。
  • info 返回的是非线程安全的可变 LinkedHashMap:与既有 getConnectionConfig()/getNodeConfig() 同一模式,改动本身不引入并发写;无跨线程共享/并发写证据,按低危抑制,不作为内联评论下发。
  • INFO_CONNECTION_ID 的填充依赖引擎侧写入(本仓不写入):这是 API 预留约定,非缺陷;若引擎版本落后,getInfo() 返回空 map 属预期行为(Javadoc 已说明未保存数据源时无 connectionId)。

下一步

无需任何代码修复,可直接合入。建议后续(非阻塞、不进 FINDINGS):引擎侧接入时补一处「connectionId 已在真实连接/测试上下文中可读」的集成验证,避免该访问器长期为空。

FINAL_VERDICT: PASS

===FINDINGS===
===END===

codexcli review

No actionable defects found in the changed API or its test. The accessor is inherited by task contexts, each context gets its own map, and the change is compatible with the module’s Java 8 source level.

The focused Maven test passed: 1 test, 0 failures.

VERDICT: PASS

claudecli review

PR #221 Review: Expose runtime connection info on PDK contexts

I'll examine the diff and verify correctness, compatibility, and thread safety.The default-active profile sets maven.compiler.source/target=17, so the test using var (Java 10+) compiles fine. No compiler-level blocker here (unlike PR #1034's mongodb module which hard-coded source/target=8).

Let me finish the remaining checks:No Serializable concerns (the context isn't serialized), and TapConnectorContext inherits getInfo() cleanly from its parent since info is a private final field exposed via the inherited accessor.

Review Summary

I reviewed both files in the merge-base..head range (b3a4dc7..13d401f): TapConnectionContext.java (+12) and the new TapConnectionContextInfoTest.java (+21).

Correctness

  • info is private final DataMap, initialized inline — each context instance gets its own independent map. The test verifies this: writing to task.getInfo() doesn't affect test.getInfo().
  • TapConnectorContext extends TapConnectionContext and inherits getInfo() without override, so task contexts share the accessor. Correct.
  • getInfo() returns the live mutable map, consistent with the existing getConnectionConfig()/getNodeConfig() accessors in this class — not a new pattern.
  • INFO_CONNECTION_ID = "connectionId" matches the literal key the test reads back via getString("connectionId").

Build/compatibility

  • The default-active Maven profile sets source/target=17 (root pom.xml:99-105), so the test's var (Java 10+) compiles cleanly. No hard-coded Java 8 constraint in this module's POM. No --release/testRelease boundary issue here.
  • No dependency or version changes. DataMap (extends LinkedHashMap) is an existing API in the same artifact.

Thread safety

  • info is a per-instance LinkedHashMap (not thread-safe), but the OCR rule guidance explicitly suppresses findings for single-threaded/per-instance usage with no evidence of concurrent invocation. TapConnectionContext instances are scoped to a single connector/connection and there's no evidence of cross-thread sharing of the info map. Not a reportable defect.

Tests

  • The test exercises the four claims in the PR description: independent info maps, inheritance by task contexts, absent key on fresh context, unchanged connector configuration. It can fail (e.g., if info were accidentally static, test.getInfo() would be non-empty).
  • The assertTrue(config.isEmpty()) guard catches the design intent that info stays separate from connectionConfig.

No actionable P0–P2 defects.

VERDICT: PASS

reasonix review

仲裁结论(tapdata/tapdata-common-lib #221,head 13d401f)

复核方式与证据边界

项 状态
评审员 codexcli(PASS,且实际跑通模块单测 1 例 0 失败)、claudecli(PASS)——两位独立扫描评审员结论一致,无 P0/P1/P2 报告
我的独立核对 工作区 shell 不可用(bwrap: Creating new namespace failed),故采用静态核对:TapConnectionContext.java、TapConnectionContextInfoTest.java、TapContext.java、TapConnectorContext.java、模块 pom.xml、根 pom.xml
改动范围 2 文件:TapConnectionContext.java(+12:INFO_CONNECTION_ID 常量、private final DataMap info、getInfo()、Javadoc)、新增 TapConnectionContextInfoTest.java(+21)

核对到的关键事实

  • info 为实例级 private final DataMap(LinkedHashMap),内联初始化 → 每个 context 实例各自独立,不会在连接间串数据;测试第 17–19 行确实能区分「task 写入 / test 为空 / connectionConfig 未被污染」,具备真实失败能力(若误加 static,第 18 行即失败)。
  • TapConnectorContext 未覆写 getInfo(),直接从父类继承访问器;TapContext 中不存在同名 info 字段,无字段遮蔽问题。
  • 常量值 "connectionId" 与测试读取的字符串 "connectionId" 一致;DataMap.getString 确实存在(tapdata-api 同仓模块)。
  • 编译兼容:根 pom.xml 中 jdk-17 为 activeByDefault(L97–107),模块 pom.xml 未硬编码 8;而本改动只用字段+getter,-Pjdk-8(source/target=8)同样可编译,不存在语言级别阻塞。
  • 该模块已有使用 org.junit.jupiter.api.Test 的既有测试(StreamReadConsumerTest),且 codexcli 实测 mvn test 通过,测试依赖无缺口。

已复核但未保留的报告点(附豁免理由)

  • claudecli 提到「测试使用 var(Java 10+)」与 head 实际代码不符(测试全部为显式类型声明),属描述瑕疵;其结论(编译无阻塞)经我用 activeByDefault=17 + 纯字段改动双重验证仍成立,不影响判定。
  • info 返回的是非线程安全的可变 LinkedHashMap:与既有 getConnectionConfig()/getNodeConfig() 同一模式,改动本身不引入并发写;无跨线程共享/并发写证据,按低危抑制,不作为内联评论下发。
  • INFO_CONNECTION_ID 的填充依赖引擎侧写入(本仓不写入):这是 API 预留约定,非缺陷;若引擎版本落后,getInfo() 返回空 map 属预期行为(Javadoc 已说明未保存数据源时无 connectionId)。

下一步

无需任何代码修复,可直接合入。建议后续(非阻塞、不进 FINDINGS):引擎侧接入时补一处「connectionId 已在真实连接/测试上下文中可读」的集成验证,避免该访问器长期为空。

FINAL_VERDICT: PASS

===FINDINGS===
===END===

标记:✅ 可通行

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.

2 participants