Skip to content

chore(core): fix metadata cache trying to load view metadata on startup#6613

Merged
bluestreak01 merged 7 commits intomasterfrom
ia_fix_views_metadata_cache
Jan 8, 2026
Merged

chore(core): fix metadata cache trying to load view metadata on startup#6613
bluestreak01 merged 7 commits intomasterfrom
ia_fix_views_metadata_cache

Conversation

@glasstiger
Copy link
Copy Markdown
Contributor

@glasstiger glasstiger commented Jan 8, 2026

Summary

  • Prevent metadata cache from trying to load view metadata from _meta file (views don't have one)
  • View metadata is now hydrated when views are compiled at startup via a dedicated background thread
  • Remove 4-year-old no-op migration (427/Mig702) to improve startup time
  • Reduce startup/shutdown log noise by demoting various INFO messages to DEBUG

Changes

  • MetadataCache: Skip views in hydrateTableStartup() since views don't have _meta files
  • ServerMain: Add compileViewsThread to compile all views at startup, which initializes view state and hydrates metadata cache
  • ViewCompilerJob: Refactor compilation methods to static to allow reuse from startup thread; add compileAllViews() method
  • CairoEngine: Remove enqueueCompile() call from buildViewGraphs() - compilation now happens in dedicated startup thread
  • PropServerConfiguration: Increase default viewCompilerWorkerCount from 1 to 2
  • Logging: Demote various worker pool, table writer, and pool operation logs from INFO to DEBUG

Test plan

  • Existing ViewBootstrapTest updated to call awaitStartup()
  • Verify views are correctly compiled and metadata is available after server startup
  • Verify no errors when starting server with existing views

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 8, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce background view compilation during server startup via a new compileViewsThread in ServerMain. Views are now compiled asynchronously after metadata hydration. Metadata hydration is skipped for view tokens in MetadataCache, and view compilation tasks use an unlimited-capacity queue to prevent task loss during initialization.

Changes

Cohort / File(s) Summary
Server startup threading
core/src/main/java/io/questdb/ServerMain.java
Adds compileViewsThread field to manage background view compilation. Introduces joinThread utility for consistent thread joining with optional interrupt handling. Updates awaitStartup and close methods to manage both hydration and view compilation threads.
View compilation initialization
core/src/main/java/io/questdb/cairo/view/ViewCompilerJob.java
Adds new compileAllViews() public method that collects all table tokens, filters for views, and compiles each view with error handling and thread-local cleanup.
View load sequence
core/src/main/java/io/questdb/cairo/CairoEngine.java
Removes enqueueCompile(tableToken) call from buildViewGraphs() to defer compilation to background thread instead of during initial view discovery.
Metadata hydration
core/src/main/java/io/questdb/cairo/MetadataCache.java
Adds early return in hydrateTableStartup when token represents a view to skip metadata hydration for view tokens that lack _meta files.
View compilation task queue
core/src/main/java/io/questdb/cairo/view/ViewStateStoreImpl.java
Introduces unlimited-capacity taskQueue using ConcurrentQueue for view compilation tasks to prevent task loss during initialization with higher notification rates.
Test fixture
core/src/test/java/io/questdb/test/cairo/view/ViewBootstrapTest.java
Adds questdb.awaitStartup() call in startQuestDB() to ensure server startup completes before test proceeds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • bluestreak01
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 accurately describes the main change: preventing metadata cache from loading view metadata on startup, which is clearly reflected in the MetadataCache.java and ServerMain.java modifications.
Description check ✅ Passed The pull request description is directly related to the changeset, describing specific modifications to handle view metadata initialization and startup sequencing.

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


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.

@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: 0

🧹 Nitpick comments (1)
core/src/main/java/io/questdb/cairo/view/ViewStateStoreImpl.java (1)

44-47: Potential memory concern with unbounded queue.

The unlimited queue prevents dropped notifications, but could theoretically grow unbounded if schema changes vastly outpace the view compiler's consumption rate. This is likely acceptable given the documented expectation of low notification volume, but consider adding queue size monitoring/metrics for observability in production.

📜 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 5df5dea.

📒 Files selected for processing (6)
  • core/src/main/java/io/questdb/ServerMain.java
  • core/src/main/java/io/questdb/cairo/CairoEngine.java
  • core/src/main/java/io/questdb/cairo/MetadataCache.java
  • core/src/main/java/io/questdb/cairo/view/ViewCompilerJob.java
  • core/src/main/java/io/questdb/cairo/view/ViewStateStoreImpl.java
  • core/src/test/java/io/questdb/test/cairo/view/ViewBootstrapTest.java
💤 Files with no reviewable changes (1)
  • core/src/main/java/io/questdb/cairo/CairoEngine.java
⏰ 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 (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 (Rust Test and Lint on linux-jdk17)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
  • 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 (Trigger Enterprise CI Trigger Enterprise Pipeline)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
  • 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 (Hosted Running tests on mac-griffin)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
  • GitHub Check: New pull request (Check Changes Check changes)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (6)
core/src/main/java/io/questdb/cairo/MetadataCache.java (1)

154-158: LGTM!

The early return for view tokens correctly prevents attempting to read non-existent _meta files. The placement after the isTableDropped check is appropriate, and the comment clearly explains the rationale.

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

614-616: LGTM!

Adding awaitStartup() ensures the test waits for both metadata hydration and view compilation background threads to complete before proceeding with assertions, preventing potential race conditions.

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

87-111: LGTM!

The compileAllViews() method correctly follows the established pattern from MetadataCache.onStartupAsyncHydrator(). The exception handling appropriately catches CairoException from token retrieval/iteration, while compileView handles its own exceptions internally. The finally block properly clears thread-local state.

core/src/main/java/io/questdb/ServerMain.java (3)

468-480: Consider naming threads and verify startup ordering.

Two observations:

  1. Thread naming: Both background threads lack names, which makes debugging/profiling harder. Consider new Thread(() -> {...}, "questdb-hydrate-metadata") pattern.

  2. Potential race condition: hydrateMetadataThread and compileViewsThread run concurrently. If compileAllViews() attempts to compile a view before its underlying table's metadata is hydrated, could this cause issues? The view compilation may depend on table metadata from MetadataCache.

Suggested improvement for thread naming
         // metadata and write tracker hydration
-        hydrateMetadataThread = new Thread(() -> {
+        hydrateMetadataThread = new Thread(() -> {
             engine.getMetadataCache().onStartupAsyncHydrator();
             engine.hydrateRecentWriteTracker();
-        });
+        }, "questdb-hydrate-metadata");
         hydrateMetadataThread.start();

         // populate view state store and hydrate metadata cache with view metadata
-        compileViewsThread = new Thread(() -> {
+        compileViewsThread = new Thread(() -> {
             try (ViewCompilerJob viewCompiler = new ViewCompilerJob(-1, engine, 0)) {
                 viewCompiler.compileAllViews();
             }
-        });
+        }, "questdb-compile-views");
         compileViewsThread.start();

486-496: LGTM on the joinThread helper.

Clean utility method with proper interrupt handling. The ignoreInterrupt parameter appropriately distinguishes between awaiting startup (where interrupts should be propagated) and shutdown (where they should be suppressed).


474-478: sharedQueryWorkerCount=0 disables all view compilation parallelization.

The workerId=-1 is a documented pattern used throughout the codebase to indicate an owner thread not assigned to the worker pool, making it valid for this context. However, sharedQueryWorkerCount=0 has a concrete impact: it disables all query parallelization flags (parallelFilterEnabled, parallelGroupByEnabled, parallelTopKEnabled, parallelWindowJoinEnabled, parallelReadParquetEnabled) in the SQL execution context. This means views are compiled serially without worker-based parallelism, which may be intentional for startup but should be documented if this is a constraint.

@glasstiger
Copy link
Copy Markdown
Contributor Author

[PR Coverage check]

😍 pass : 111 / 126 (88.10%)

file detail

path covered line new line coverage
🔵 io/questdb/cairo/wal/WalPurgeJob.java 10 16 62.50%
🔵 io/questdb/cairo/CairoEngine.java 6 8 75.00%
🔵 io/questdb/ServerMain.java 14 17 82.35%
🔵 io/questdb/cairo/view/ViewCompilerJob.java 44 48 91.67%
🔵 io/questdb/mp/WorkerPool.java 1 1 100.00%
🔵 io/questdb/cutlass/line/tcp/LineTcpLegacyWriterJob.java 1 1 100.00%
🔵 io/questdb/cairo/wal/seq/TableSequencerAPI.java 1 1 100.00%
🔵 io/questdb/cairo/pool/AbstractMultiTenantPool.java 5 5 100.00%
🔵 io/questdb/cairo/TableWriter.java 1 1 100.00%
🔵 io/questdb/griffin/SqlCodeGenerator.java 1 1 100.00%
🔵 io/questdb/griffin/SqlOptimiser.java 15 15 100.00%
🔵 io/questdb/cairo/MetadataCache.java 2 2 100.00%
🔵 io/questdb/PropServerConfiguration.java 1 1 100.00%
🔵 io/questdb/WorkerPoolManager.java 4 4 100.00%
🔵 io/questdb/cairo/mv/MatViewRefreshJob.java 1 1 100.00%
🔵 io/questdb/cairo/pool/WriterPool.java 1 1 100.00%
🔵 io/questdb/mp/Worker.java 3 3 100.00%

@bluestreak01 bluestreak01 merged commit 626fc5d into master Jan 8, 2026
43 checks passed
@bluestreak01 bluestreak01 deleted the ia_fix_views_metadata_cache branch January 8, 2026 22:33
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