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.

86 lines
1.6 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
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
  1. package backend
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. . "github.com/seaweedfs/seaweedfs/weed/storage/types"
  5. "os"
  6. "time"
  7. )
  8. var (
  9. _ BackendStorageFile = &DiskFile{}
  10. )
  11. type DiskFile struct {
  12. File *os.File
  13. fullFilePath string
  14. fileSize int64
  15. modTime time.Time
  16. }
  17. func NewDiskFile(f *os.File) *DiskFile {
  18. stat, err := f.Stat()
  19. if err != nil {
  20. glog.Fatalf("stat file %s: %v", f.Name(), err)
  21. }
  22. offset := stat.Size()
  23. if offset%NeedlePaddingSize != 0 {
  24. offset = offset + (NeedlePaddingSize - offset%NeedlePaddingSize)
  25. }
  26. return &DiskFile{
  27. fullFilePath: f.Name(),
  28. File: f,
  29. fileSize: offset,
  30. modTime: stat.ModTime(),
  31. }
  32. }
  33. func (df *DiskFile) ReadAt(p []byte, off int64) (n int, err error) {
  34. return df.File.ReadAt(p, off)
  35. }
  36. func (df *DiskFile) WriteAt(p []byte, off int64) (n int, err error) {
  37. n, err = df.File.WriteAt(p, off)
  38. if err == nil {
  39. waterMark := off + int64(n)
  40. if waterMark > df.fileSize {
  41. df.fileSize = waterMark
  42. df.modTime = time.Now()
  43. }
  44. }
  45. return
  46. }
  47. func (df *DiskFile) Write(p []byte) (n int, err error) {
  48. return df.WriteAt(p, df.fileSize)
  49. }
  50. func (df *DiskFile) Truncate(off int64) error {
  51. err := df.File.Truncate(off)
  52. if err == nil {
  53. df.fileSize = off
  54. df.modTime = time.Now()
  55. }
  56. return err
  57. }
  58. func (df *DiskFile) Close() error {
  59. return df.File.Close()
  60. }
  61. func (df *DiskFile) GetStat() (datSize int64, modTime time.Time, err error) {
  62. if df.File == nil {
  63. err = os.ErrInvalid
  64. }
  65. return df.fileSize, df.modTime, err
  66. }
  67. func (df *DiskFile) Name() string {
  68. return df.fullFilePath
  69. }
  70. func (df *DiskFile) Sync() error {
  71. return nil
  72. // return df.File.Sync()
  73. }