Perform file sync outside of lock on Commit

Signed-off-by: Xinyang Ge <xinyang.ge@databricks.com>
This commit is contained in:
Xinyang Ge
2024-04-24 13:38:51 -07:00
parent c4c3c6ea56
commit 4167416754
3 changed files with 27 additions and 0 deletions

View File

@@ -574,6 +574,13 @@ 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()
if err := update(ctx, nw.db, func(tx *bolt.Tx) error {
dgst, err := nw.commit(ctx, tx, size, expected, opts...)
if err != nil {
@@ -599,6 +606,13 @@ func (nw *namespacedWriter) Commit(ctx context.Context, size int64, expected dig
return innerErr
}
func (nw *namespacedWriter) Sync() error {
if syncer, ok := nw.w.(content.Syncer); ok {
return syncer.Sync()
}
return nil
}
func (nw *namespacedWriter) commit(ctx context.Context, tx *bolt.Tx, size int64, expected digest.Digest, opts ...content.Opt) (digest.Digest, error) {
var base content.Info
for _, opt := range opts {