Ver Fonte

Merge pull request #5572 from heyitsanthony/fallocate-eintr-fallback

pkg/fileutil: fall back to truncate() if fallocate is interrupted
Anthony Romano há 9 anos atrás
pai
commit
7f461b2df9
2 ficheiros alterados com 3 adições e 9 exclusões
  1. 3 2
      pkg/fileutil/preallocate_unix.go
  2. 0 7
      wal/wal.go

+ 3 - 2
pkg/fileutil/preallocate_unix.go

@@ -26,8 +26,9 @@ func preallocExtend(f *os.File, sizeInBytes int64) error {
 	err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes)
 	if err != nil {
 		errno, ok := err.(syscall.Errno)
-		// treat not support as nil error
-		if ok && errno == syscall.ENOTSUP {
+		// not supported; fallback
+		// fallocate EINTRs frequently in some enviroments; fallback
+		if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) {
 			return preallocExtendTrunc(f, sizeInBytes)
 		}
 	}

+ 0 - 7
wal/wal.go

@@ -207,17 +207,10 @@ func openAtIndex(dirpath string, snap walpb.Snapshot, write bool) (*WAL, error)
 		// write reuses the file descriptors from read; don't close so
 		// WAL can append without dropping the file lock
 		w.readClose = nil
-
 		if _, _, err := parseWalName(path.Base(w.tail().Name())); err != nil {
 			closer()
 			return nil, err
 		}
-		// don't resize file for preallocation in case tail is corrupted
-		if err := fileutil.Preallocate(w.tail().File, segmentSizeBytes, false); err != nil {
-			closer()
-			plog.Errorf("failed to allocate space when creating new wal file (%v)", err)
-			return nil, err
-		}
 		w.fp = newFilePipeline(w.dir, segmentSizeBytes)
 	}