Przeglądaj źródła

Ensure sparse files on windows during download

The file.Truncate call on windows will write the whole file
unless you set the sparse flag, leading to heavy I/O at the
beginning of download.  This should improve our
I/O behavior on windows and put less stress on the users disk.
Daniel Hiltgen 8 miesięcy temu
rodzic
commit
fc85f50a2b
3 zmienionych plików z 28 dodań i 0 usunięć
  1. 3 0
      server/download.go
  2. 9 0
      server/sparse_common.go
  3. 16 0
      server/sparse_windows.go

+ 3 - 0
server/download.go

@@ -216,6 +216,9 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *regis
 		return err
 	}
 	defer file.Close()
+	if err := setSparse(file); err != nil {
+		return err
+	}
 
 	_ = file.Truncate(b.Total)
 

+ 9 - 0
server/sparse_common.go

@@ -0,0 +1,9 @@
+//go:build !windows
+
+package server
+
+import "os"
+
+func setSparse(file *os.File) error {
+	return nil
+}

+ 16 - 0
server/sparse_windows.go

@@ -0,0 +1,16 @@
+package server
+
+import (
+	"os"
+
+	"golang.org/x/sys/windows"
+)
+
+func setSparse(file *os.File) error {
+	return windows.DeviceIoControl(
+		windows.Handle(file.Fd()), windows.FSCTL_SET_SPARSE,
+		nil, 0,
+		nil, 0,
+		nil, nil,
+	)
+}