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.

42 lines
1.0 KiB

  1. package repl_util
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/replication/source"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. )
  8. func CopyFromChunkViews(chunkViews []*filer.ChunkView, filerSource *source.FilerSource, writeFunc func(data []byte) error) error {
  9. for _, chunk := range chunkViews {
  10. fileUrls, err := filerSource.LookupFileId(chunk.FileId)
  11. if err != nil {
  12. return err
  13. }
  14. var writeErr error
  15. var shouldRetry bool
  16. for _, fileUrl := range fileUrls {
  17. shouldRetry, err = util.ReadUrlAsStream(fileUrl+"?readDeleted=true", nil, false, chunk.IsFullChunk(), chunk.Offset, int(chunk.Size), func(data []byte) {
  18. writeErr = writeFunc(data)
  19. })
  20. if err != nil {
  21. glog.V(1).Infof("read from %s: %v", fileUrl, err)
  22. } else if writeErr != nil {
  23. glog.V(1).Infof("copy from %s: %v", fileUrl, writeErr)
  24. } else {
  25. break
  26. }
  27. }
  28. if shouldRetry && err != nil {
  29. return err
  30. }
  31. if writeErr != nil {
  32. return writeErr
  33. }
  34. }
  35. return nil
  36. }