Merge pull request #10171 from fuweid/follow-up-10158

core/metadata: failfast on content.Commit
This commit is contained in:
Maksym Pavlenko 2024-05-06 19:23:52 +00:00 committed by GitHub
commit 6c72ad9565
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -574,12 +574,17 @@ func (nw *namespacedWriter) Commit(ctx context.Context, size int64, expected dig
var innerErr error var innerErr error
// We pre-sync the in-flight writes to the disk. This avoids the [subsequent fp.Sync() call] // We pre-sync the in-flight writes to the disk. This avoids the
// (https://github.com/containerd/containerd/blob/c4c3c6ea568ce0cfbcf754863abadeea37d77c8f/plugins/content/local/writer.go#L95) // subsequent fp.Sync() call[1] from taking too long (10s+) while
// from taking too long (10s+) while holding the metadata database lock as in the following // holding the metadata database lock as in the following `update`
// `update` transaction. We intentionally ignore any error on Sync() because it will be // transaction.
// handled by the subsequent `fp.Sync` anyway. //
nw.Sync() // REF:
// [1]: https://github.com/containerd/containerd/blob/c4c3c6ea568ce0cfbcf754863abadeea37d77c8f/plugins/content/local/writer.go#L95
if err := nw.Sync(); err != nil {
nw.Close()
return fmt.Errorf("failed to perform sync: %w", err)
}
if err := update(ctx, nw.db, func(tx *bolt.Tx) error { if err := update(ctx, nw.db, func(tx *bolt.Tx) error {
dgst, err := nw.commit(ctx, tx, size, expected, opts...) dgst, err := nw.commit(ctx, tx, size, expected, opts...)