You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.0 KiB

Revert "Refactor for Sync method (#3426)" This reverts commit 670cb759f82815461bc854569542582da51a6199. with the pr weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 18.486s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.025s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.864s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.110s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.414s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.203s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files] weed/storage () - (master) > weed/storage () - (master) > without the pr weed/storage () - (master) > weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 1.617s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.026s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.906s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.202s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.533s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.280s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files]
2 years ago
Revert "Refactor for Sync method (#3426)" This reverts commit 670cb759f82815461bc854569542582da51a6199. with the pr weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 18.486s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.025s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.864s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.110s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.414s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.203s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files] weed/storage () - (master) > weed/storage () - (master) > without the pr weed/storage () - (master) > weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 1.617s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.026s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.906s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.202s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.533s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.280s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files]
2 years ago
5 years ago
Revert "Refactor for Sync method (#3426)" This reverts commit 670cb759f82815461bc854569542582da51a6199. with the pr weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 18.486s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.025s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.864s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.110s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.414s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.203s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files] weed/storage () - (master) > weed/storage () - (master) > without the pr weed/storage () - (master) > weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 1.617s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.026s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.906s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.202s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.533s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.280s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files]
2 years ago
Revert "Refactor for Sync method (#3426)" This reverts commit 670cb759f82815461bc854569542582da51a6199. with the pr weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 18.486s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.025s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.864s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.110s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.414s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.203s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files] weed/storage () - (master) > weed/storage () - (master) > without the pr weed/storage () - (master) > weed/storage () - (master) > go test -count=1 ./... ok github.com/seaweedfs/seaweedfs/weed/storage 1.617s ? github.com/seaweedfs/seaweedfs/weed/storage/backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/backend/memory_map 0.026s ? github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding 0.906s ? github.com/seaweedfs/seaweedfs/weed/storage/idx [no test files] ok github.com/seaweedfs/seaweedfs/weed/storage/needle 0.202s ok github.com/seaweedfs/seaweedfs/weed/storage/needle_map 24.533s ok github.com/seaweedfs/seaweedfs/weed/storage/super_block 0.280s ? github.com/seaweedfs/seaweedfs/weed/storage/types [no test files] ? github.com/seaweedfs/seaweedfs/weed/storage/volume_info [no test files]
2 years ago
  1. package backend
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. . "github.com/seaweedfs/seaweedfs/weed/storage/types"
  5. "os"
  6. "runtime"
  7. "time"
  8. )
  9. var (
  10. _ BackendStorageFile = &DiskFile{}
  11. )
  12. const isMac = runtime.GOOS == "darwin"
  13. type DiskFile struct {
  14. File *os.File
  15. fullFilePath string
  16. fileSize int64
  17. modTime time.Time
  18. }
  19. func NewDiskFile(f *os.File) *DiskFile {
  20. stat, err := f.Stat()
  21. if err != nil {
  22. glog.Fatalf("stat file %s: %v", f.Name(), err)
  23. }
  24. offset := stat.Size()
  25. if offset%NeedlePaddingSize != 0 {
  26. offset = offset + (NeedlePaddingSize - offset%NeedlePaddingSize)
  27. }
  28. return &DiskFile{
  29. fullFilePath: f.Name(),
  30. File: f,
  31. fileSize: offset,
  32. modTime: stat.ModTime(),
  33. }
  34. }
  35. func (df *DiskFile) ReadAt(p []byte, off int64) (n int, err error) {
  36. if df.File == nil {
  37. return 0, os.ErrClosed
  38. }
  39. return df.File.ReadAt(p, off)
  40. }
  41. func (df *DiskFile) WriteAt(p []byte, off int64) (n int, err error) {
  42. if df.File == nil {
  43. return 0, os.ErrClosed
  44. }
  45. n, err = df.File.WriteAt(p, off)
  46. if err == nil {
  47. waterMark := off + int64(n)
  48. if waterMark > df.fileSize {
  49. df.fileSize = waterMark
  50. df.modTime = time.Now()
  51. }
  52. }
  53. return
  54. }
  55. func (df *DiskFile) Write(p []byte) (n int, err error) {
  56. return df.WriteAt(p, df.fileSize)
  57. }
  58. func (df *DiskFile) Truncate(off int64) error {
  59. if df.File == nil {
  60. return os.ErrClosed
  61. }
  62. err := df.File.Truncate(off)
  63. if err == nil {
  64. df.fileSize = off
  65. df.modTime = time.Now()
  66. }
  67. return err
  68. }
  69. func (df *DiskFile) Close() error {
  70. if df.File == nil {
  71. return nil
  72. }
  73. if err := df.Sync(); err != nil {
  74. return err
  75. }
  76. if err := df.File.Close(); err != nil {
  77. return err
  78. }
  79. df.File = nil
  80. return nil
  81. }
  82. func (df *DiskFile) GetStat() (datSize int64, modTime time.Time, err error) {
  83. if df.File == nil {
  84. err = os.ErrClosed
  85. }
  86. return df.fileSize, df.modTime, err
  87. }
  88. func (df *DiskFile) Name() string {
  89. return df.fullFilePath
  90. }
  91. func (df *DiskFile) Sync() error {
  92. if df.File == nil {
  93. return os.ErrClosed
  94. }
  95. if isMac {
  96. return nil
  97. }
  98. return df.File.Sync()
  99. }