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.

46 lines
1.3 KiB

  1. package meta_cache
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/chrislusf/seaweedfs/weed/filer"
  8. "github.com/chrislusf/seaweedfs/weed/glog"
  9. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. )
  12. func EnsureVisited(mc *MetaCache, client filer_pb.FilerClient, dirPath util.FullPath) error {
  13. return mc.visitedBoundary.EnsureVisited(dirPath, func(path util.FullPath) (childDirectories []string, err error) {
  14. glog.V(4).Infof("ReadDirAllEntries %s ...", path)
  15. for waitTime := time.Second; waitTime < filer.ReadWaitTime; waitTime += waitTime / 2 {
  16. err = filer_pb.ReadDirAllEntries(client, dirPath, "", func(pbEntry *filer_pb.Entry, isLast bool) error {
  17. entry := filer.FromPbEntry(string(dirPath), pbEntry)
  18. if err := mc.doInsertEntry(context.Background(), entry); err != nil {
  19. glog.V(0).Infof("read %s: %v", entry.FullPath, err)
  20. return err
  21. }
  22. if entry.IsDirectory() {
  23. childDirectories = append(childDirectories, entry.Name())
  24. }
  25. return nil
  26. })
  27. if err == nil {
  28. break
  29. }
  30. if strings.Contains(err.Error(), "transport: ") {
  31. glog.V(0).Infof("ReadDirAllEntries %s: %v. Retry in %v", path, err, waitTime)
  32. time.Sleep(waitTime)
  33. continue
  34. }
  35. err = fmt.Errorf("list %s: %v", dirPath, err)
  36. break
  37. }
  38. return
  39. })
  40. }