Skip to content

Keep CA journal in-memory state after datastore save failures - #6964

Merged
amartinezfayo merged 3 commits into
spiffe:mainfrom
c4rlo:journal-no-backup
May 19, 2026
Merged

amartinezfayo merged 3 commits into
spiffe:mainfrom
c4rlo:journal-no-backup

Conversation

@c4rlo

@c4rlo c4rlo commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Callers of journal mutation methods (i.e. CA managers) treat journal save failures as non-fatal: they log the error and continue using the newly prepared or activated authority/key. Rolling back only the in-memory journal makes it diverge from the manager’s live slot state, and it does not fix the already-stale persisted journal.

Therefore, stop rolling back in-memory journal mutations when datastore saves fail. Keeping the in-memory journal advanced lets a later successful save persist the latest known manager state.

The previous rollback logic was actually flawed even on its own terms: the backup value used was only a reference, not its own independent copy. We also weren't restoring the AuthorityId field in UpdateJWTKeyStatus etc.

Also:

  • simplify journal size trimming with slices.Clone
  • update outdated journal comments and add missing journal test coverage for WITs

c4rlo added 3 commits May 17, 2026 12:53
Journal save failures are treated as non-fatal by the CA manager. The
manager logs the error and continues using the newly prepared or
activated authority/key, so rolling back only the in-memory journal
leaves it behind the manager's live slot state.

That rollback also does not make the operation crash-consistent. If the
datastore save failed, the persisted journal is already stale; reverting
the in-memory copy only prevents a later successful journal save from
catching up to the state the manager is actually using.

Leave journal mutations in memory when persistence fails, and continue
to return the save error so callers can log it. This keeps the journal
aligned with the running manager and lets subsequent successful saves
persist the latest known state.

Signed-off-by: Carlo Teubner <[email protected]>
Signed-off-by: Carlo Teubner <[email protected]>
@c4rlo
c4rlo force-pushed the journal-no-backup branch from 9903a9d to 33aaa68 Compare May 17, 2026 11:53
@c4rlo c4rlo changed the title Keep CA journal state after save failures Keep CA journal in-memory state after datastore save failures May 17, 2026
@c4rlo
c4rlo marked this pull request as ready for review May 17, 2026 14:30

@amartinezfayo amartinezfayo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you so much @c4rlo for this fix! Great cleanup also.

@amartinezfayo amartinezfayo added this to the 1.15.1 milestone May 19, 2026
@amartinezfayo
amartinezfayo added this pull request to the merge queue May 19, 2026
Merged via the queue into spiffe:main with commit 1a2b3e9 May 19, 2026
50 checks passed
MikeZappa87 pushed a commit to MikeZappa87/spire that referenced this pull request May 29, 2026
…#6964)

* Keep journal state on save failure

Journal save failures are treated as non-fatal by the CA manager. The
manager logs the error and continues using the newly prepared or
activated authority/key, so rolling back only the in-memory journal
leaves it behind the manager's live slot state.

That rollback also does not make the operation crash-consistent. If the
datastore save failed, the persisted journal is already stale; reverting
the in-memory copy only prevents a later successful journal save from
catching up to the state the manager is actually using.

Leave journal mutations in memory when persistence fails, and continue
to return the save error so callers can log it. This keeps the journal
aligned with the running manager and lets subsequent successful saves
persist the latest known state.

Signed-off-by: Carlo Teubner <[email protected]>

* Simplify journal cap trimming

Signed-off-by: Carlo Teubner <[email protected]>

* Refresh journal docs and WIT test coverage

Signed-off-by: Carlo Teubner <[email protected]>

---------

Signed-off-by: Carlo Teubner <[email protected]>
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