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.

91 lines
2.9 KiB

7 years ago
7 years ago
7 years ago
6 years ago
  1. package filer2
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. )
  8. type FilerStore interface {
  9. // GetName gets the name to locate the configuration in filer.toml file
  10. GetName() string
  11. // Initialize initializes the file store
  12. Initialize(configuration util.Configuration) error
  13. InsertEntry(context.Context, *Entry) error
  14. UpdateEntry(context.Context, *Entry) (err error)
  15. // err == filer2.ErrNotFound if not found
  16. FindEntry(context.Context, FullPath) (entry *Entry, err error)
  17. DeleteEntry(context.Context, FullPath) (err error)
  18. ListDirectoryEntries(ctx context.Context, dirPath FullPath, startFileName string, includeStartFile bool, limit int) ([]*Entry, error)
  19. BeginTransaction(ctx context.Context) (context.Context, error)
  20. CommitTransaction(ctx context.Context) error
  21. RollbackTransaction(ctx context.Context) error
  22. }
  23. var ErrNotFound = errors.New("filer: no entry is found in filer store")
  24. type FilerStoreWrapper struct {
  25. actualStore FilerStore
  26. }
  27. func NewFilerStoreWrapper(store FilerStore) *FilerStoreWrapper {
  28. return &FilerStoreWrapper{
  29. actualStore: store,
  30. }
  31. }
  32. func (fsw *FilerStoreWrapper) GetName() string {
  33. return fsw.actualStore.GetName()
  34. }
  35. func (fsw *FilerStoreWrapper) Initialize(configuration util.Configuration) error {
  36. return fsw.actualStore.Initialize(configuration)
  37. }
  38. func (fsw *FilerStoreWrapper) InsertEntry(ctx context.Context, entry *Entry) error {
  39. filer_pb.BeforeEntrySerialization(entry.Chunks)
  40. return fsw.actualStore.InsertEntry(ctx, entry)
  41. }
  42. func (fsw *FilerStoreWrapper) UpdateEntry(ctx context.Context, entry *Entry) error {
  43. filer_pb.BeforeEntrySerialization(entry.Chunks)
  44. return fsw.actualStore.UpdateEntry(ctx, entry)
  45. }
  46. func (fsw *FilerStoreWrapper) FindEntry(ctx context.Context, fp FullPath) (entry *Entry, err error) {
  47. entry, err = fsw.actualStore.FindEntry(ctx, fp)
  48. if err != nil {
  49. return nil, err
  50. }
  51. filer_pb.AfterEntryDeserialization(entry.Chunks)
  52. return
  53. }
  54. func (fsw *FilerStoreWrapper) DeleteEntry(ctx context.Context, fp FullPath) (err error) {
  55. return fsw.actualStore.DeleteEntry(ctx, fp)
  56. }
  57. func (fsw *FilerStoreWrapper) ListDirectoryEntries(ctx context.Context, dirPath FullPath, startFileName string, includeStartFile bool, limit int) ([]*Entry, error) {
  58. entries, err := fsw.actualStore.ListDirectoryEntries(ctx, dirPath, startFileName, includeStartFile, limit)
  59. if err != nil {
  60. return nil, err
  61. }
  62. for _, entry := range entries {
  63. filer_pb.AfterEntryDeserialization(entry.Chunks)
  64. }
  65. return entries, err
  66. }
  67. func (fsw *FilerStoreWrapper) BeginTransaction(ctx context.Context) (context.Context, error) {
  68. return fsw.actualStore.BeginTransaction(ctx)
  69. }
  70. func (fsw *FilerStoreWrapper) CommitTransaction(ctx context.Context) error {
  71. return fsw.actualStore.CommitTransaction(ctx)
  72. }
  73. func (fsw *FilerStoreWrapper) RollbackTransaction(ctx context.Context) error {
  74. return fsw.actualStore.RollbackTransaction(ctx)
  75. }