Repository navigation
Fix Metadata locking and Reading for decomposedfs and align defaults with OpenCloud - #722
Conversation
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.
…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
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.
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 { | |||
There was a problem hiding this comment.
I guess new need to call unlock() here?
| } | ||
| err = revisionNode.SetXattrsWithContext(ctx, attrs, false) | ||
| err = revisionNode.SetXattrsWithContext(ctx, attrs) | ||
| if err != nil { |
There was a problem hiding this comment.
I guess new need to call unlock() here?
|
|
||
| func goid() uint64 { | ||
| var buf [64]byte | ||
| n := runtime.Stack(buf[:], false) |
There was a problem hiding this comment.
opencode (model: opus 4.8) had to say this about goid():
- 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.
- 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?
There was a problem hiding this comment.
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 { | |||
| } | ||
| err = revisionNode.SetXattrsWithContext(ctx, attrs, false) | ||
| err = revisionNode.SetXattrsWithContext(ctx, attrs) | ||
| if err != nil { |
|
|
||
| func goid() uint64 { | ||
| var buf [64]byte | ||
| n := runtime.Stack(buf[:], false) |
There was a problem hiding this comment.
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.
Fix Metadata locking and Reading for decomposedfs and align defaults with OpenCloud (cherry picked from commit 762fd45)
This reworks the metadata interfaces to prevent misuse of the
LockAndReadandAllWithLockedSourcemethods.The
LockAndReadmethod 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 theReader is pointing to the metadata lockfile instead of the metadata source itself.
The
AllWithLockedSourceis replaced with the new methodAllWhileLockedit does require the reader parameter. But requires the caller to take care that the Metadata was locked withLock()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.