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.

40 lines
977 B

  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. for _, fileUrl := range fileUrls {
  16. _, err = util.ReadUrlAsStream(fileUrl+"?readDeleted=true", nil, false, chunk.IsFullChunk(), chunk.Offset, int(chunk.Size), func(data []byte) {
  17. writeErr = writeFunc(data)
  18. })
  19. if err != nil {
  20. glog.V(1).Infof("read from %s: %v", fileUrl, err)
  21. } else if writeErr != nil {
  22. glog.V(1).Infof("copy from %s: %v", fileUrl, writeErr)
  23. } else {
  24. break
  25. }
  26. }
  27. if err != nil {
  28. return err
  29. }
  30. }
  31. return nil
  32. }