Skip to content

Fix Metadata locking and Reading for decomposedfs and align defaults with OpenCloud - #722

Merged
aduffeck merged 12 commits into
opencloud-eu:mainfrom
rhafer:ocissue/3059
Jul 14, 2026
Merged

aduffeck merged 12 commits into
opencloud-eu:mainfrom
rhafer:ocissue/3059

Conversation

@rhafer

@rhafer rhafer commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

This reworks the metadata interfaces to prevent misuse of the LockAndRead and AllWithLockedSource methods.

The LockAndRead method is removed completely. It returned an io.Reader object that seemed to be useful for reading the Nodes Attributes from it. That was however misleading. For most of the current backed the
Reader is pointing to the metadata lockfile instead of the metadata source itself.

The AllWithLockedSource is replaced with the new method AllWhileLocked it does require the reader parameter. But requires the caller to take care that the Metadata was locked with Lock() before calling.

All of the callers where adjusted to no longer pass the reader around. And the unused ParentWithReader method.

This switches the default metadata backend for decomposedfs to "messagepack" to align with the hardcoded default in OpenCloud, which is force to "messagepack" for all decomposedfs setups.

This switches the default metadata backend for decomposedfs to
"messagepack" to align with the hardcoded default in OpenCloud, which is
force to "messagepack" for all decomposedfs setups.
@rhafer rhafer self-assigned this Jul 2, 2026
…lockfiles

This reworks the metadata interfaces to prevent misuse of the
`LockAndRead` and `AllWithLockedSource` methods.

The `LockAndRead` method is removed completely. It returned an io.Reader
object that seemed to be useful for reading the Nodes  Attributes from
it. That was however misleading. For most of the current backed the
Reader is pointing to the metadata lockfile instead of the metadata
source itself.

The `AllWithLockedSource` is replaced with the new method
`AllWhileLocked` it does require the reader parameter. But requires the
caller to take care that the Metadata was locked with `Lock()` before
calling.

All of the callers where adjusted to no longer pass the reader
around. And the unused ParentWithReader method.

Fixes: opencloud-eu/opencloud#3059
@rhafer rhafer changed the title chore(decomposedfs): Align defaults with OpenCloud Fix Metadata locking and Reading for decomposedfs and align defaults with OpenCloud Jul 2, 2026
@rhafer rhafer added the Type:Bug label Jul 2, 2026
@rhafer
rhafer requested a review from aduffeck July 2, 2026 15:22
@rhafer
rhafer marked this pull request as ready for review July 3, 2026 06:36
aduffeck added 4 commits July 7, 2026 10:39
Each node now knows whether it has already been locked or not, allowing
for conditional locking and simplifying of the code because of less
special handling of locked/unlocked cases.
aduffeck added 4 commits July 8, 2026 10:56
This prevents leaking lock-state into goroutines.
This is used to hold node locks only in the scope of a goroutine. If a
locked node was to leak into another goroutine the goroutinelock Lock
would return false and thus make the other goroutine lock the node for
themselves.
@@ -397,14 +392,14 @@ func (session *DecomposedFsSession) createRevisionNodeForUpload(ctx context.Cont

err = session.store.lu.TimeManager().OverrideMtime(ctx, revisionNode, &attrs, mtime)
if err != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess new need to call unlock() here?

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.

nice catch 👍

}
err = revisionNode.SetXattrsWithContext(ctx, attrs, false)
err = revisionNode.SetXattrsWithContext(ctx, attrs)
if err != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess new need to call unlock() here?

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.

👍


func goid() uint64 {
var buf [64]byte
n := runtime.Stack(buf[:], false)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

opencode (model: opus 4.8) had to say this about goid():

  1. goid() performance — goroutinelock/lock.go: Held() runs runtime.Stack + header parse on every metadata call (All, SetMultiple, Remove, Lock). Potential regression on metadata-heavy paths; worth benchmarking.
  2. goid() returning 0 collides with Release()'s stored 0. If parse ever fails, Held() falsely reports held. Very low risk but a non-zero sentinel would be safer.

I am not sure about 2. Can the goroutine id actually be 0? But IMO 1 is certainly worth a thought. Is it maybe good enough to document the convention that locked nodes cannot be shared between goroutines?

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.

The performance impact seems to be neglectable (2.4µs per call) according to this benchmark test output:

BenchmarkGoID-32    	  495104	      2432 ns/op	     160 B/op	       2 allocs/op

After a discussion in person we decided to leave the code in as it adds a safety net for sneaky deadlock issues.

@@ -397,14 +392,14 @@ func (session *DecomposedFsSession) createRevisionNodeForUpload(ctx context.Cont

err = session.store.lu.TimeManager().OverrideMtime(ctx, revisionNode, &attrs, mtime)
if err != nil {

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.

nice catch 👍

}
err = revisionNode.SetXattrsWithContext(ctx, attrs, false)
err = revisionNode.SetXattrsWithContext(ctx, attrs)
if err != nil {

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.

👍


func goid() uint64 {
var buf [64]byte
n := runtime.Stack(buf[:], false)

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.

The performance impact seems to be neglectable (2.4µs per call) according to this benchmark test output:

BenchmarkGoID-32    	  495104	      2432 ns/op	     160 B/op	       2 allocs/op

After a discussion in person we decided to leave the code in as it adds a safety net for sneaky deadlock issues.

@aduffeck
aduffeck merged commit 762fd45 into opencloud-eu:main Jul 14, 2026
18 of 19 checks passed
@openclouders openclouders mentioned this pull request Jul 13, 2026
1 task
rhafer pushed a commit that referenced this pull request Jul 27, 2026
Fix Metadata locking and Reading for decomposedfs and align defaults with OpenCloud

(cherry picked from commit 762fd45)
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.

2 participants