Repository navigation
fix: make lazy chunking opt-in (default: false) - #1172
Conversation
Lazy chunking was made the default in #1099, but enabling it silently on upgrade is a behavior change: it starts background workers, a cleanup cron job, and delays compressed NAR deletion without user consent. Revert the default to false so users must explicitly opt in. Changes: - pkg/ncps/serve.go: Value true->false, fix usage string - charts/ncps/values.yaml: lazyChunkingEnabled true->false - charts/ncps/tests/configmap_test.yaml: fix default assertion - docs: update all references from default true to false
|
This change is part of the following stack: Change managed by git-spice. |
There was a problem hiding this comment.
Code Review
This pull request reverts the default setting for Content-Defined Chunking (CDC) lazy chunking from true to false across the CLI, Helm chart, and documentation, making it an opt-in feature. Feedback indicates that while configuration tables were updated, some descriptive text in the CDC feature documentation still incorrectly refers to it as being enabled by default, which needs to be corrected for consistency.
|
Documentation Updates 2 document(s) were updated by changes in this PR: Cache and Storage Configuration FlagsView Changes@@ -196,7 +196,7 @@
**Flags:**
-- `--cache-cdc-lazy-chunking-enabled` (boolean): Enable lazy chunking. Default: `true`
+- `--cache-cdc-lazy-chunking-enabled` (boolean): Enable lazy chunking. Default: `false`
- Environment variable: `CACHE_CDC_LAZY_CHUNKING_ENABLED`
- YAML key: `cache.cdc.lazy-chunking-enabled`
@@ -229,7 +229,7 @@
**Behavior:**
-When lazy chunking is enabled (the default), NAR files are stored in their original compressed format first, then chunked in the background. When a new NAR is added to the cache:
+When lazy chunking is enabled, NAR files are stored in their original compressed format first, then chunked in the background. When a new NAR is added to the cache:
1. The NAR is downloaded from upstream and stored in its original compressed form (e.g., xz, zstd) in a temporary location
2. The associated narinfo is immediately normalized to `compression: none` and stored in the database, signaling that the NAR will eventually be served from chunks
@@ -245,7 +245,7 @@
**CLI Example (using defaults):**
```bash
ncps serve --cache-cdc-enabled
-# Lazy chunking is enabled by default with CPU-count workers
+# Lazy chunking is disabled by default; enable with --cache-cdc-lazy-chunking-enabled
```
**CLI Example (disabling lazy chunking):**
@@ -253,12 +253,14 @@
ncps serve \
--cache-cdc-enabled \
--cache-cdc-lazy-chunking-enabled=false
+# Lazy chunking is already disabled by default; flag shown for explicitness
```
**CLI Example (custom worker count):**
```bash
ncps serve \
--cache-cdc-enabled \
+ --cache-cdc-lazy-chunking-enabled \
--cache-cdc-background-workers 4
```
@@ -266,6 +268,7 @@
```bash
ncps serve \
--cache-cdc-enabled \
+ --cache-cdc-lazy-chunking-enabled \
--cache-cdc-delete-delay 48h
```
@@ -273,6 +276,7 @@
```bash
ncps serve \
--cache-cdc-enabled \
+ --cache-cdc-lazy-chunking-enabled \
--cache-cdc-lazy-cleanup-schedule "@every 30m"
```
@@ -281,7 +285,7 @@
cache:
cdc:
enabled: true
- # lazy-chunking-enabled defaults to true
+ # lazy-chunking-enabled defaults to false
# background-workers defaults to CPU count
# delete-delay defaults to 24h
```
@@ -291,7 +295,7 @@
cache:
cdc:
enabled: true
- lazy-chunking-enabled: false
+ lazy-chunking-enabled: false # Explicit false (already the default)
```
**YAML Example (custom configuration):**NAR File Download and StreamingView Changes@@ -83,7 +83,7 @@
When CDC is enabled and a compressed NAR needs to be decompressed, the system implements a single-decompression mechanism that prevents multiple concurrent decompression operations. This mechanism ensures that only the first request performs the decompression, while subsequent concurrent requests share the same decompressed stream.
-**Note:** This mechanism applies only when lazy chunking is disabled (via `--cache-cdc-lazy-chunking-enabled=false`). With lazy chunking enabled (the default), compressed NAR files are stored directly without decompression or chunking, and background workers perform chunking asynchronously after storage completes.
+**Note:** This mechanism applies only when lazy chunking is disabled (the default via `--cache-cdc-lazy-chunking-enabled=false`). With lazy chunking enabled, compressed NAR files are stored directly without decompression or chunking, and background workers perform chunking asynchronously after storage completes.
The system uses an `io.Pipe` and a single temporary file when handling a compressed NAR that requires decompression:
@@ -114,7 +114,7 @@
- **Fully chunked**: Records with `total_chunks > 0` and `chunking_started_at` set. These records represent NAR files that have been successfully chunked and are ready for CDC streaming.
- **Actively chunking**: Records with `chunking_started_at` set but `total_chunks = 0`. These records indicate that chunking is in progress. When lazy chunking is disabled, the `chunking_started_at` timestamp is set within milliseconds of download start (before decompression completes), allowing other HA instances to immediately detect active chunking operations and use progressive streaming. The system uses progressive streaming to serve these NARs while chunking completes.
-- **Pending migration (lazy chunking)**: Records with `total_chunks = 0` and `chunking_started_at = NULL`. When lazy chunking is enabled (the default), these records represent compressed NAR files stored without chunking that are awaiting background migration. Background workers asynchronously chunk these files using the `migrate-nar-to-chunks` infrastructure. If ncps is restarted before background chunking completes, these records can become "stuck" and will be recovered by the periodic recovery cron job (see "Recovery of Stuck NARs" in the lazy chunking section).
+- **Pending migration (lazy chunking)**: Records with `total_chunks = 0` and `chunking_started_at = NULL`. When lazy chunking is enabled, these records represent compressed NAR files stored without chunking that are awaiting background migration. Background workers asynchronously chunk these files using the `migrate-nar-to-chunks` infrastructure. If ncps is restarted before background chunking completes, these records can become "stuck" and will be recovered by the periodic recovery cron job (see "Recovery of Stuck NARs" in the lazy chunking section).
- **Placeholder/Failed**: Records with `total_chunks = 0` and `chunking_started_at = NULL` can also represent placeholder records created during narinfo storage (via `storeInDatabase`) to link the narinfo to its eventual NAR file. If the subsequent background NAR download fails (e.g., temporary directory missing), or if a chunking operation fails partway through (e.g., "no space left on device"), these placeholder records persist in the database without actual chunked data. When chunking fails, the system automatically clears the `chunking_started_at` lock via the `ClearNarFileChunkingStarted` database operation to prevent subsequent requests from waiting indefinitely for chunks that will never arrive.
When determining whether to use CDC streaming for `GetNar` requests, the system first checks for active local download jobs using `hasActiveLocalJob`. If a local download is active, it uses the faster temp-file streaming path rather than progressive CDC streaming. Otherwise, the system checks both `total_chunks > 0` AND `chunking_started_at IS NOT NULL` to ensure the record represents actual chunked data rather than a placeholder or pending migration. The `prePullNar` function distinguishes these states to decide whether to serve from existing chunks, wait for progressive streaming, or trigger a fresh download from upstream.
@@ -127,7 +127,7 @@
If CDC is not enabled in the database, the command will return an error: "migrate-nar-to-chunks command requires CDC to be enabled in the database; please run 'ncps serve' with CDC enabled first". This ensures that the migration infrastructure is properly configured before attempting to migrate existing NAR files to the chunked storage format.
-When lazy chunking is enabled (the default via `--cache-cdc-lazy-chunking-enabled=true`), compressed NAR files are stored without immediate chunking, and background workers automatically perform migration using the same infrastructure as the `migrate-nar-to-chunks` command. The background workers can be configured via `--cache-cdc-background-workers` (default: number of CPUs).
+When lazy chunking is enabled (via `--cache-cdc-lazy-chunking-enabled=true`), compressed NAR files are stored without immediate chunking, and background workers automatically perform migration using the same infrastructure as the `migrate-nar-to-chunks` command. The background workers can be configured via `--cache-cdc-background-workers` (default: number of CPUs).
> **⚠️ CDC Configuration Enforcement**
>
@@ -246,7 +246,7 @@
#### Lazy Chunking and TTFB Optimization
-When CDC is enabled with lazy chunking (the default via `--cache-cdc-lazy-chunking-enabled=true`), the system optimizes Time-To-First-Byte (TTFB) by storing compressed NAR files directly without immediate decompression or chunking. This approach provides significant performance benefits:
+When CDC is enabled with lazy chunking (via `--cache-cdc-lazy-chunking-enabled=true`), the system optimizes Time-To-First-Byte (TTFB) by storing compressed NAR files directly without immediate decompression or chunking. This approach provides significant performance benefits:
**Benefits:**
- **Faster cache miss TTFB**: Avoids expensive decompression and chunking operations during download, allowing the HTTP response to complete as soon as the compressed file is stored
@@ -254,7 +254,7 @@
- **Seamless serving**: The system intelligently serves from chunks when available (`total_chunks > 0`) or falls back to the raw compressed NAR from storage when not yet chunked (`total_chunks = 0`)
**Configuration:**
-- `--cache-cdc-lazy-chunking-enabled` (default: `true`): Enable lazy chunking for optimal TTFB
+- `--cache-cdc-lazy-chunking-enabled` (default: `false`): Enable lazy chunking for optimal TTFB
- `--cache-cdc-background-workers` (default: number of CPUs): Number of background workers for asynchronous chunking
- `--cache-cdc-delete-delay` (default: `24h`): Delay before deleting compressed NAR files after chunking completes
- `--cache-cdc-lazy-cleanup-schedule` (default: `@every 1h`): Cron schedule for running the cleanup job that removes old compressed NAR files
@@ -311,7 +311,7 @@
### Diagram: Streaming Download Flow with CDC
-#### Lazy Chunking Enabled (Default)
+#### Lazy Chunking Enabled
```mermaid
sequenceDiagram
participant Client |
The section header said lazy chunking was enabled by default. Updated to clarify it is opt-in and disabled by default, consistent with the table default value corrected in the previous commit. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1172 +/- ##
=====================================
Coverage 5.04% 5.04%
=====================================
Files 6 6
Lines 436 436
=====================================
Hits 22 22
Misses 410 410
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Lazy chunking was made the default in #1099, but enabling it
silently on upgrade is a behavior change: it starts background
workers, a cleanup cron job, and delays compressed NAR deletion
without user consent. Revert the default to false so users must
explicitly opt in.
Changes: