Skip to content

Conversation

@ggreer
Copy link
Contributor

@ggreer ggreer commented Dec 31, 2025

You can still override this behavior in read only mode since we apply pragmas after this one.

Summary by CodeRabbit

  • Performance
    • Further improved read-only database performance by applying optimized runtime settings for read-only access—queries run faster and use fewer system resources when opening the database in read-only mode.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

Walkthrough

C1File.init now runs two SQLite PRAGMA statements—journal_mode = OFF and synchronous = OFF—when initialized with readOnly=true. These pragmas are executed after table initialization and before any per-pragma settings; non-readOnly behavior is unchanged.

Changes

Cohort / File(s) Summary
Read-only SQLite pragmas
pkg/dotc1z/c1file.go
In C1File.init, when readOnly is true, execute PRAGMA journal_mode = OFF and PRAGMA synchronous = OFF (after InitTables, before per-pragma application); errors from these calls are propagated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Compaction speedups. #579: Applies the same read-only SQLite pragmas (journal_mode=OFF, synchronous=OFF) in pkg/dotc1z/c1file.go, indicating a closely related change.

Suggested reviewers

  • MarcusGoldschmidt
  • kans

Poem

🐰 A rabbit's ode to quiet reads

In shelves of bytes I softly creep,
No journals waking from their sleep.
Two pragmas hush the clatter down,
Read-only paths in velvet gown. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: disabling SQLite journaling in read-only mode. It directly reflects the primary objective and the code modification shown in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 781babb and 91624f1.

📒 Files selected for processing (1)
  • pkg/dotc1z/c1file.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/dotc1z/c1file.go
⏰ 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). (1)
  • GitHub Check: go-test (1.25.2, windows-latest)

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

Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/dotc1z/c1file.go (1)

270-283: Consider pragma application order to prevent overrides.

Custom pragmas (lines 278-283) are applied after disabling journaling for read-only mode, allowing them to override journal_mode = OFF. If the intent is to enforce journaling disabled in read-only mode, consider either:

  • Moving the read-only pragma block after custom pragmas
  • Filtering out journal_mode from custom pragmas when in read-only mode
🔎 Proposed fix: Apply custom pragmas first
 	err = c.InitTables(ctx)
 	if err != nil {
 		return err
 	}
 
+	for _, pragma := range c.pragmas {
+		_, err := c.db.ExecContext(ctx, fmt.Sprintf("PRAGMA %s = %s", pragma.name, pragma.value))
+		if err != nil {
+			return err
+		}
+	}
+
 	if c.readOnly {
 		// Disable journaling in read only mode, since we're not writing to the database.
 		_, err = c.db.ExecContext(ctx, "PRAGMA journal_mode = OFF")
 		if err != nil {
 			return err
 		}
 	}
 
-	for _, pragma := range c.pragmas {
-		_, err := c.db.ExecContext(ctx, fmt.Sprintf("PRAGMA %s = %s", pragma.name, pragma.value))
-		if err != nil {
-			return err
-		}
-	}
-
 	return nil
🧹 Nitpick comments (1)
pkg/dotc1z/c1file.go (1)

270-276: Consider opening the SQLite connection in read-only mode when c.readOnly is true.

While disabling journaling is appropriate, the underlying SQLite connection at line 97 is not opened in read-only mode. Modify the connection string to include mode=ro when c.readOnly is true—for example, sql.Open("sqlite", "file:" + dbFilePath + "?mode=ro"). This adds database-level read-only protection and aligns with the intent of the read-only flag.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 873cd3f and 781babb.

📒 Files selected for processing (1)
  • pkg/dotc1z/c1file.go
⏰ 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). (1)
  • GitHub Check: go-test (1.25.2, windows-latest)

@ggreer
Copy link
Contributor Author

ggreer commented Dec 31, 2025

@coderabbitai We do journal_mode = OFF before pragmas so that it can be overridden. Also the SQLite library we're using (go-sqlite) doesn't seem to support opening in read only mode.

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

Tip

For best results, initiate chat on the files or code changes.

@ggreer, thank you for the clarification! That makes sense—placing journal_mode = OFF before the per-pragma settings allows users to override it if needed, providing flexibility in the configuration. I've also noted the limitation with go-sqlite regarding read-only mode support.


✏️ Learnings added
Learnt from: ggreer
URL: https://github.com/ConductorOne/baton-sdk/pull/613

Timestamp: 2025-12-31T21:17:25.009Z
Learning: In pkg/dotc1z/c1file.go, the `journal_mode = OFF` pragma is executed before applying per-pragma settings when `readOnly` is true, so that it can be overridden by user configuration if needed.

Learnt from: ggreer
URL: https://github.com/ConductorOne/baton-sdk/pull/613

Timestamp: 2025-12-31T21:17:25.009Z
Learning: The go-sqlite library used in the baton-sdk does not support opening SQLite databases in read-only mode.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: loganintech
Repo: ConductorOne/baton-sdk PR: 430
File: pkg/dotc1z/c1file.go:302-312
Timestamp: 2025-08-15T18:17:37.960Z
Learning: The glebarez/go-sqlite driver (v1.22.0) allows binding schema names in ATTACH DATABASE statements using `ATTACH DATABASE ? AS ?`, even though this contradicts the official SQLite specification which states that identifiers cannot be bound as parameters.

@ggreer ggreer merged commit c025486 into main Dec 31, 2025
6 checks passed
@ggreer ggreer deleted the ggreer/read-only-disable-journaling branch December 31, 2025 21:52
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.

3 participants