Skip to content

Commit

Permalink
Implement "header hack"
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Oct 4, 2023
1 parent bfd16b4 commit e14dcc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ func (fs *Goofys) FreeSomeCleanBuffers(size int64) (int64, bool) {
if buf.dirtyID == 0 || buf.state == BUF_FLUSHED_FULL {
if buf.ptr != nil && !inode.IsRangeLocked(buf.offset, buf.length, false) &&
// Skip recent buffers when possible
(skipRecent == 0 || buf.recency <= skipRecent) {
(skipRecent == 0 || buf.recency <= skipRecent) &&
// Do not evict modified header
(buf.state != BUF_FLUSHED_FULL || buf.offset >= fs.flags.PartSizes[0].PartSize) {
if fs.flags.CachePath != "" && !buf.onDisk {
if toFs == -1 {
toFs = 0
Expand Down Expand Up @@ -605,6 +607,8 @@ func (fs *Goofys) FreeSomeCleanBuffers(size int64) (int64, bool) {
// A flushed buffer can be removed at a cost of finalizing multipart upload
// to read it back later. However it's likely not a problem if we're uploading
// a large file because we may never need to read it back.
// One exception is that we don't do it with the header because various
// software commonly modifies header after writing the whole large file
prev := del-1
if prev < 0 {
prev = i-1
Expand Down
8 changes: 4 additions & 4 deletions internal/goofys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,10 @@ func (s *GoofysTest) TestWriteLargeTruncateMem20M(t *C) {
err = in.SetAttributes(PUInt64(100*1024*1024), nil, nil, nil, nil)
t.Assert(err, IsNil)

//// Modify the beginning of the file - will work after adding "header hack"
//buf[4095] = 1
//err = fh.WriteFile(0, buf[0:4096], true)
//t.Assert(err, IsNil)
// Modify the beginning of the file - will work after adding "header hack"
buf[4095] = 1
err = fh.WriteFile(0, buf[0:4096], true)
t.Assert(err, IsNil)

// Close
fh.Release()
Expand Down

0 comments on commit e14dcc8

Please sign in to comment.