From 99ad11a00a4a273bef467272787240b7440278f3 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Sat, 4 May 2024 17:24:00 +0800 Subject: [PATCH] core/metadata: failfast on content.Commit Close: #10158 Signed-off-by: Wei Fu --- core/metadata/content.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/metadata/content.go b/core/metadata/content.go index 2877fa665..7768332f6 100644 --- a/core/metadata/content.go +++ b/core/metadata/content.go @@ -574,12 +574,17 @@ func (nw *namespacedWriter) Commit(ctx context.Context, size int64, expected dig var innerErr error - // We pre-sync the in-flight writes to the disk. This avoids the [subsequent fp.Sync() call] - // (https://github.com/containerd/containerd/blob/c4c3c6ea568ce0cfbcf754863abadeea37d77c8f/plugins/content/local/writer.go#L95) - // from taking too long (10s+) while holding the metadata database lock as in the following - // `update` transaction. We intentionally ignore any error on Sync() because it will be - // handled by the subsequent `fp.Sync` anyway. - nw.Sync() + // We pre-sync the in-flight writes to the disk. This avoids the + // subsequent fp.Sync() call[1] from taking too long (10s+) while + // holding the metadata database lock as in the following `update` + // transaction. + // + // 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 { dgst, err := nw.commit(ctx, tx, size, expected, opts...)