Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(gcssink): prevent empty object finalization on write failure (#8933)

Chris Lu72eb93919c41
diff --git a/weed/replication/sink/gcssink/gcs_sink.go b/weed/replication/sink/gcssink/gcs_sink.go
index 1c4ae9e9bf..97d9217a25 100644
--- a/weed/replication/sink/gcssink/gcs_sink.go
+++ b/weed/replication/sink/gcssink/gcs_sink.go
@@ -115,23 +115,32 @@ func (g *GcsSink) CreateEntry(key string, entry *filer_pb.Entry, signatures []in
totalSize := filer.FileSize(entry)
chunkViews := filer.ViewFromChunks(context.Background(), g.filerSource.LookupFileId, entry.GetChunks(), 0, int64(totalSize))
- wc := g.client.Bucket(g.bucket).Object(key).NewWriter(context.Background())
- defer wc.Close()
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ wc := g.client.Bucket(g.bucket).Object(key).NewWriter(ctx)
writeFunc := func(data []byte) error {
_, writeErr := wc.Write(data)
return writeErr
}
+ var writeErr error
if len(entry.Content) > 0 {
- return writeFunc(entry.Content)
+ writeErr = writeFunc(entry.Content)
+ } else {
+ writeErr = repl_util.CopyFromChunkViews(chunkViews, g.filerSource, writeFunc)
}
- if err := repl_util.CopyFromChunkViews(chunkViews, g.filerSource, writeFunc); err != nil {
- return err
+ if writeErr != nil {
+ // Cancel the context to abort the GCS upload without touching
+ // any existing object at this key.
+ cancel()
+ wc.Close()
+ return writeErr
}
- return nil
+ return wc.Close()
}