refactor: prepare for snapshotting

This commit is contained in:
Chris Lu
2019-04-16 09:55:37 -07:00
parent af49aea0c6
commit 338e6d60a5
5 changed files with 9 additions and 8 deletions

View File

@@ -114,7 +114,7 @@ func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntr
fullpath := filer2.FullPath(filepath.ToSlash(filepath.Join(req.Directory, req.Entry.Name)))
chunks, garbages := filer2.CompactFileChunks(req.Entry.Chunks)
fs.filer.DeleteChunks(garbages)
fs.filer.DeleteChunks(fullpath, garbages)
if req.Entry.Attributes == nil {
return nil, fmt.Errorf("can not create entry with empty attributes")
@@ -175,8 +175,8 @@ func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntr
}
if err = fs.filer.UpdateEntry(ctx, entry, newEntry); err == nil {
fs.filer.DeleteChunks(unusedChunks)
fs.filer.DeleteChunks(garbages)
fs.filer.DeleteChunks(entry.FullPath, unusedChunks)
fs.filer.DeleteChunks(entry.FullPath, garbages)
}
fs.filer.NotifyUpdateEvent(entry, newEntry, true)

View File

@@ -206,7 +206,7 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
}
// glog.V(4).Infof("saving %s => %+v", path, entry)
if db_err := fs.filer.CreateEntry(ctx, entry); db_err != nil {
fs.filer.DeleteFileByFileId(fileId)
fs.filer.DeleteChunks(entry.FullPath, entry.Chunks)
glog.V(0).Infof("failing to write %s to filer server : %v", path, db_err)
writeJsonError(w, r, http.StatusInternalServerError, db_err)
return

View File

@@ -170,6 +170,7 @@ func (fs *FilerServer) doAutoChunk(ctx context.Context, w http.ResponseWriter, r
Chunks: fileChunks,
}
if db_err := fs.filer.CreateEntry(ctx, entry); db_err != nil {
fs.filer.DeleteChunks(entry.FullPath, entry.Chunks)
replyerr = db_err
filerResult.Error = db_err.Error()
glog.V(0).Infof("failing to write %s to filer server : %v", path, db_err)