From 13d6a74eb29bcb8bd1348baecb379ecd408688b3 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 22 Sep 2018 22:11:37 -0700 Subject: [PATCH] consolidate file chunks during create --- weed/server/filer_grpc_server.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.go index 6c3390a26..da506c70a 100644 --- a/weed/server/filer_grpc_server.go +++ b/weed/server/filer_grpc_server.go @@ -125,10 +125,19 @@ func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVol } func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntryRequest) (resp *filer_pb.CreateEntryResponse, err error) { + + fullpath := filer2.FullPath(filepath.Join(req.Directory, req.Entry.Name)) + chunks, garbages := filer2.CompactFileChunks(req.Entry.Chunks) + + for _, garbage := range garbages { + glog.V(0).Infof("deleting %s garbage chunk: %v, [%d, %d)", fullpath, garbage.FileId, garbage.Offset, garbage.Offset+int64(garbage.Size)) + fs.filer.DeleteFileByFileId(garbage.FileId) + } + err = fs.filer.CreateEntry(&filer2.Entry{ - FullPath: filer2.FullPath(filepath.Join(req.Directory, req.Entry.Name)), + FullPath: fullpath, Attr: filer2.PbToEntryAttribute(req.Entry.Attributes), - Chunks: req.Entry.Chunks, + Chunks: chunks, }) if err == nil {