diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 226ade962..db3e7d10e 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -253,12 +253,7 @@ func (fh *FileHandle) doFlush(ctx context.Context, header fuse.Header) error { glog.V(4).Infof("%s chunks %d: %v [%d,%d)", fh.f.fullpath(), i, chunk.GetFileIdString(), chunk.Offset, chunk.Offset+int64(chunk.Size)) } - var nonManifestChunks []*filer_pb.FileChunk - for _, c := range fh.f.entry.Chunks { - if !c.IsChunkManifest { - nonManifestChunks = append(nonManifestChunks, c) - } - } + manifestChunks, nonManifestChunks := filer2.SeparateManifestChunks(fh.f.entry.Chunks) chunks, _ := filer2.CompactFileChunks(filer2.LookupFn(fh.f.wfs), nonManifestChunks) chunks, manifestErr := filer2.MaybeManifestize(fh.f.wfs.saveDataAsChunk(fh.f.dir.FullPath()), chunks) @@ -266,7 +261,7 @@ func (fh *FileHandle) doFlush(ctx context.Context, header fuse.Header) error { // not good, but should be ok glog.V(0).Infof("MaybeManifestize: %v", manifestErr) } - fh.f.entry.Chunks = append(chunks, nonManifestChunks...) + fh.f.entry.Chunks = append(chunks, manifestChunks...) fh.f.entryViewCache = nil if err := filer_pb.CreateEntry(client, request); err != nil { diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.go index 48e9253f0..5d066f9a0 100644 --- a/weed/server/filer_grpc_server.go +++ b/weed/server/filer_grpc_server.go @@ -241,22 +241,20 @@ func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntr } func (fs *FilerServer) cleanupChunks(existingEntry *filer2.Entry, newEntry *filer_pb.Entry) (chunks, garbage []*filer_pb.FileChunk, err error) { - chunks = newEntry.Chunks // remove old chunks if not included in the new ones if existingEntry != nil { garbage, err = filer2.MinusChunks(fs.lookupFileId, existingEntry.Chunks, newEntry.Chunks) if err != nil { - return chunks, nil, fmt.Errorf("MinusChunks: %v", err) + return newEntry.Chunks, nil, fmt.Errorf("MinusChunks: %v", err) } } // files with manifest chunks are usually large and append only, skip calculating covered chunks - var coveredChunks []*filer_pb.FileChunk - if !filer2.HasChunkManifest(newEntry.Chunks) { - chunks, coveredChunks = filer2.CompactFileChunks(fs.lookupFileId, newEntry.Chunks) - garbage = append(garbage, coveredChunks...) - } + manifestChunks, nonManifestChunks := filer2.SeparateManifestChunks(newEntry.Chunks) + + chunks, coveredChunks := filer2.CompactFileChunks(fs.lookupFileId, nonManifestChunks) + garbage = append(garbage, coveredChunks...) chunks, err = filer2.MaybeManifestize(fs.saveAsChunk( newEntry.Attributes.Replication, @@ -268,6 +266,9 @@ func (fs *FilerServer) cleanupChunks(existingEntry *filer2.Entry, newEntry *file // not good, but should be ok glog.V(0).Infof("MaybeManifestize: %v", err) } + + chunks = append(chunks, manifestChunks...) + return }