Skip to content

chore(core): fix view table id is 0 after table registry reload without tables.d file#6612

Merged
bluestreak01 merged 4 commits intomasterfrom
ia_fix_views_table_id
Jan 8, 2026
Merged

chore(core): fix view table id is 0 after table registry reload without tables.d file#6612
bluestreak01 merged 4 commits intomasterfrom
ia_fix_views_table_id

Conversation

@glasstiger
Copy link
Copy Markdown
Contributor

@glasstiger glasstiger commented Jan 8, 2026

All views had their table id set as 0 after a restart without tables.d file.
When there is no tables.d file, we take table id from _meta file.
However, views do not have this file.
Table id was defaulted to 0.
Fix is to parse the table id from the table dir name instead of trying to load from _meta file.

required by https://github.com/questdb/questdb-enterprise/pull/850

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 8, 2026

Walkthrough

This PR adds view definition detection in table registry when metadata files are absent, introduces a utility method to extract table IDs from directory names, updates relevant tests to use derived directory naming, and extends test coverage to validate view tokens, dependencies, and endpoint responses across restart scenarios.

Changes

Cohort / File(s) Change Summary
View and Table ID Handling
core/src/main/java/io/questdb/cairo/TableNameRegistryStore.java, core/src/main/java/io/questdb/cairo/TableUtils.java
Adds logic to detect and handle view definitions during table ID reading when metadata is missing; introduces new public utility method to parse table IDs from directory names, extracting numeric suffixes after the system table name marker.
Test Coverage and Updates
core/src/test/java/io/questdb/test/cairo/TableNameRegistryTest.java, core/src/test/java/io/questdb/test/cairo/view/ViewBootstrapTest.java
Updates table creation test to use derived directory names with system table suffix; extends view bootstrap test with comprehensive validations for view tokens, sequence transaction IDs, dependencies, and HTTP endpoint responses across multiple restart scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

Bug

Suggested reviewers

  • bluestreak01
  • ideoma
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing view table IDs being set to 0 after registry reload without the tables.d file, which aligns with the primary purpose of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem (view table IDs defaulting to 0), the root cause (missing _meta files), and the solution (parsing table IDs from directory names).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jerrinot jerrinot self-requested a review January 8, 2026 16:09
@glasstiger
Copy link
Copy Markdown
Contributor Author

[PR Coverage check]

😍 pass : 9 / 12 (75.00%)

file detail

path covered line new line coverage
🔵 io/questdb/cairo/TableUtils.java 3 6 50.00%
🔵 io/questdb/cairo/TableNameRegistryStore.java 6 6 100.00%

@glasstiger
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 8, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @core/src/main/java/io/questdb/cairo/TableNameRegistryStore.java:
- Around line 313-325: In readTableId(), the call to
getTableIdFromTableDir(dirName) can throw NumericException for malformed view
dir names; wrap that call in a try-catch that catches
io.questdb.std.NumericException, log a concise warning including dirName and the
exception via the existing logger and return 0 (treat as non-table) instead of
letting the runtime exception propagate; keep behavior unchanged for valid IDs
and preserve the surrounding logic that checks
ViewDefinition.VIEW_DEFINITION_FILE_NAME.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d51a22 and f18460f.

📒 Files selected for processing (4)
  • core/src/main/java/io/questdb/cairo/TableNameRegistryStore.java
  • core/src/main/java/io/questdb/cairo/TableUtils.java
  • core/src/test/java/io/questdb/test/cairo/TableNameRegistryTest.java
  • core/src/test/java/io/questdb/test/cairo/view/ViewBootstrapTest.java
🧰 Additional context used
🧬 Code graph analysis (2)
core/src/main/java/io/questdb/cairo/TableUtils.java (3)
core/src/main/java/io/questdb/std/NumericException.java (1)
  • NumericException (34-132)
core/src/main/java/io/questdb/std/Chars.java (1)
  • Chars (43-1646)
core/src/main/java/io/questdb/std/Numbers.java (1)
  • Numbers (44-3523)
core/src/test/java/io/questdb/test/cairo/view/ViewBootstrapTest.java (2)
core/src/main/java/io/questdb/std/str/Path.java (1)
  • Path (51-533)
core/src/main/java/io/questdb/cutlass/http/client/HttpClientFactory.java (1)
  • HttpClientFactory (35-66)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (36)
  • GitHub Check: New pull request (Trigger Enterprise CI Trigger Enterprise Pipeline)
  • GitHub Check: New pull request (Coverage Report Coverage Report)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-other)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-pgwire)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-root)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz2)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz1)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-root)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-1)
  • GitHub Check: New pull request (Hosted Running tests on windows-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-1)
  • GitHub Check: New pull request (Hosted Running tests on windows-fuzz2)
  • GitHub Check: New pull request (Hosted Running tests on windows-fuzz1)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-sub)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-base)
  • GitHub Check: New pull request (Hosted Running tests on mac-other)
  • GitHub Check: New pull request (Hosted Running tests on mac-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo-fuzz)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
  • GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
  • GitHub Check: New pull request (Hosted Running tests on mac-griffin)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
  • GitHub Check: New pull request (Trigger Enterprise CI Trigger Enterprise Pipeline)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
  • GitHub Check: New pull request (Check Changes Check changes)
🔇 Additional comments (9)
core/src/main/java/io/questdb/cairo/TableUtils.java (2)

65-65: LGTM: Import supports new parsing functionality.

The NumericException import is correctly added to support the new getTableIdFromTableDir method.


874-882: LGTM: Table ID parsing logic is sound.

The method correctly extracts the table ID from directory names with the ~ suffix. The error handling is appropriate, throwing NumericException when the suffix is absent or the numeric portion is malformed.

core/src/test/java/io/questdb/test/cairo/TableNameRegistryTest.java (2)

394-395: LGTM: Directory naming aligns with WAL table structure.

The test correctly constructs directory names with the ~<id> suffix pattern, matching the directory structure used for WAL tables and views.


409-409: LGTM: Correctly uses directory name for file operations.

Using tableToken.getDirName() ensures the path matches the actual directory structure, which is essential for proper cleanup.

core/src/main/java/io/questdb/cairo/TableNameRegistryStore.java (1)

27-27: LGTM: Import supports view detection logic.

The ViewDefinition import is correctly added to support checking for view definition files in the updated readTableId method.

core/src/test/java/io/questdb/test/cairo/view/ViewBootstrapTest.java (4)

31-31: LGTM: Imports support extended test coverage.

The new imports are used in the test scenario that validates view behavior when the tables.d file is missing (lines 487-490), which is the primary use case this PR addresses.

Also applies to: 46-46


339-362: LGTM: Comprehensive view metadata validation.

The assertions thoroughly validate view definitions including table IDs, dependencies, and column-level dependencies. The hardcoded table IDs (6, 7) rely on predictable creation order in this isolated test, which is acceptable.


364-384: LGTM: HTTP endpoint validation ensures API stability.

The assertion validates the complete JSON response from the views() endpoint, including schema, dataset, and count. This ensures the API contract is maintained across restarts.


486-555: LGTM: Critical test scenario validates the PR's core fix.

This test section addresses the main issue described in the PR: views losing their table ID (defaulting to 0) after restart when tables.d is absent. The test:

  1. Removes the tables.d.0 file to simulate the scenario
  2. Restarts QuestDB to trigger table registry reload from the file system
  3. Re-validates all view metadata to ensure table IDs are correctly derived from directory names

This comprehensive validation ensures the fix works as intended.

@bluestreak01 bluestreak01 merged commit 49835d9 into master Jan 8, 2026
43 checks passed
@bluestreak01 bluestreak01 deleted the ia_fix_views_table_id branch January 8, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants