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
971 B

  1. package repl_util
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer"
  4. "github.com/chrislusf/seaweedfs/weed/util/log"
  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. log.Debugf("read from %s: %v", fileUrl, err)
  21. } else if writeErr != nil {
  22. log.Debugf("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. }