Skip to content

Commit

Permalink
Flush cached directories every so often during an add
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Apr 29, 2017
1 parent e5529cd commit e0d0618
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var log = logging.Logger("coreunix")
// how many bytes of progress to wait before sending a progress update message
const progressReaderIncrement = 1024 * 256

var liveCacheSize = uint64(256 << 10)

type Link struct {
Name, Hash string
Size uint64
Expand Down Expand Up @@ -104,6 +106,7 @@ type Adder struct {
unlocker bs.Unlocker
tempRoot *cid.Cid
Prefix *cid.Prefix
liveNodes uint64
}

func (adder *Adder) mfsRoot() (*mfs.Root, error) {
Expand Down Expand Up @@ -422,6 +425,18 @@ func (adder *Adder) addFile(file files.File) error {
return err
}

if adder.liveNodes >= liveCacheSize {
// TODO: A smarter cache that uses some sort of lru cache with an eviction handler
mr, err := adder.mfsRoot()
if err != nil {
return err
}
if err := mr.Flush(); err != nil {
return err
}
adder.liveNodes = 0
}

if file.IsDirectory() {
return adder.addDir(file)
}
Expand Down

0 comments on commit e0d0618

Please sign in to comment.