refactor: usefilebuffer on writter
This commit is contained in:
parent
ec7b19808f
commit
88abec1d61
|
@ -123,6 +123,7 @@ func (b *BackBalze) Sync(ctx context.Context) error {
|
||||||
msg, err := copyFile(ctx, bc, src)
|
msg, err := copyFile(ctx, bc, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error copying file %s: %v\n", src, err)
|
log.Printf("error copying file %s: %v\n", src, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
msgsChan <- msg
|
msgsChan <- msg
|
||||||
}
|
}
|
||||||
|
@ -261,28 +262,27 @@ func (b *BackBalze) OldSync() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyFile(ctx context.Context, bucket *b2.Bucket, src string) (UploadMessage, error) {
|
func copyFile(ctx context.Context, bucket *b2.Bucket, src string) error {
|
||||||
f, err := os.Open(src)
|
f, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return UploadMessage{}, err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
fi, err := f.Stat()
|
fi, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return UploadMessage{}, err
|
return err
|
||||||
}
|
}
|
||||||
w := bucket.Object(fi.Name()).NewWriter(ctx)
|
w := bucket.Object(fi.Name()).NewWriter(ctx)
|
||||||
w.ConcurrentUploads = writers
|
w.ConcurrentUploads = writers
|
||||||
msg := UploadMessage{
|
// w.ChunkSize = 1e9 / 2
|
||||||
key: fi.Name(),
|
w.UseFileBuffer = true
|
||||||
startAt: time.Now(),
|
log.Println("start copying", fi.Name())
|
||||||
}
|
|
||||||
if _, err := io.Copy(w, f); err != nil {
|
if _, err := io.Copy(w, f); err != nil {
|
||||||
w.Close()
|
w.Close()
|
||||||
return msg, err
|
return err
|
||||||
}
|
}
|
||||||
msg.endAt = time.Now()
|
log.Println("end copying", fi.Name())
|
||||||
return msg, w.Close()
|
return w.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanBucket(ctx context.Context, bucket *b2.Bucket, files []string) error {
|
func cleanBucket(ctx context.Context, bucket *b2.Bucket, files []string) error {
|
||||||
|
|
Loading…
Reference in New Issue