Documentation ¶
Index ¶
- Constants
- func NewFs(name, rpath string) (fs.Fs, error)
- type ChunkStorage
- type Directory
- type Features
- type Fs
- func (f *Fs) ChunkSize() int64
- func (f *Fs) CleanUp() error
- func (f *Fs) CleanUpCache(ignoreLastTs bool)
- func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error)
- func (f *Fs) DirCacheFlush()
- func (f *Fs) DirMove(src fs.Fs, srcRemote, dstRemote string) error
- func (f *Fs) Features() *fs.Features
- func (f *Fs) Hashes() fs.HashSet
- func (f *Fs) List(dir string) (entries fs.DirEntries, err error)
- func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error)
- func (f *Fs) Mkdir(dir string) error
- func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error)
- func (f *Fs) Name() string
- func (f *Fs) NewObject(remote string) (fs.Object, error)
- func (f *Fs) OpenRateLimited(fn func() (io.ReadCloser, error)) (io.ReadCloser, error)
- func (f *Fs) Purge() error
- func (f *Fs) Put(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)
- func (f *Fs) PutStream(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)
- func (f *Fs) PutUnchecked(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)
- func (f *Fs) Rmdir(dir string) error
- func (f *Fs) Root() string
- func (f *Fs) SetWrapper(wrapper fs.Fs)
- func (f *Fs) Stats() (map[string]map[string]interface{}, error)
- func (f *Fs) String() string
- func (f *Fs) UnWrap() fs.Fs
- func (f *Fs) WrapFs() fs.Fs
- type Handle
- type Memory
- func (m *Memory) AddChunk(fp string, data []byte, offset int64) error
- func (m *Memory) AddChunkAhead(fp string, data []byte, offset int64, t time.Duration) error
- func (m *Memory) CleanChunksByAge(chunkAge time.Duration)
- func (m *Memory) CleanChunksByNeed(offset int64)
- func (m *Memory) CleanChunksBySize(maxSize int64)
- func (m *Memory) Connect(defaultExpiration time.Duration) error
- func (m *Memory) GetChunk(cachedObject *Object, offset int64) ([]byte, error)
- func (m *Memory) HasChunk(cachedObject *Object, offset int64) bool
- type Object
- func (o *Object) Fs() fs.Info
- func (o *Object) Hash(ht fs.HashType) (string, error)
- func (o *Object) MarshalJSON() ([]byte, error)
- func (o *Object) ModTime() time.Time
- func (o *Object) Open(options ...fs.OpenOption) (io.ReadCloser, error)
- func (o *Object) Remote() string
- func (o *Object) Remove() error
- func (o *Object) SetModTime(t time.Time) error
- func (o *Object) Size() int64
- func (o *Object) Storable() bool
- func (o *Object) String() string
- func (o *Object) UnmarshalJSON(b []byte) error
- func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error
- type Persistent
- func (b *Persistent) AddChunk(fp string, data []byte, offset int64) error
- func (b *Persistent) AddDir(cachedDir *Directory) error
- func (b *Persistent) AddObject(cachedObject *Object) error
- func (b *Persistent) CleanChunksByAge(chunkAge time.Duration)
- func (b *Persistent) CleanChunksByNeed(offset int64)
- func (b *Persistent) CleanChunksBySize(maxSize int64)
- func (b *Persistent) CleanEntriesByAge(entryAge time.Duration)
- func (b *Persistent) Close()
- func (b *Persistent) Connect() error
- func (b *Persistent) ExpireDir(fp string) error
- func (b *Persistent) GetChunk(cachedObject *Object, offset int64) ([]byte, error)
- func (b *Persistent) GetChunkTs(path string, offset int64) (time.Time, error)
- func (b *Persistent) GetDirEntries(cachedDir *Directory) (fs.DirEntries, error)
- func (b *Persistent) GetObject(cachedObject *Object) (err error)
- func (b *Persistent) GetRootTs(path string) (time.Time, error)
- func (b *Persistent) HasChunk(cachedObject *Object, offset int64) bool
- func (b *Persistent) HasEntry(remote string) bool
- func (b *Persistent) Purge()
- func (b *Persistent) RemoveDir(fp string) error
- func (b *Persistent) RemoveObject(fp string) error
- func (b *Persistent) Stats() (map[string]map[string]interface{}, error)
- func (b *Persistent) String() string
- type Storage
Constants ¶
const ( // DefCacheChunkSize is the default value for chunk size DefCacheChunkSize = "5M" // DefCacheTotalChunkSize is the default value for the maximum size of stored chunks DefCacheTotalChunkSize = "10G" // DefCacheChunkCleanInterval is the interval at which chunks are cleaned DefCacheChunkCleanInterval = "1m" // DefCacheInfoAge is the default value for object info age DefCacheInfoAge = "6h" // DefCacheReadRetries is the default value for read retries DefCacheReadRetries = 10 // DefCacheTotalWorkers is how many workers run in parallel to download chunks DefCacheTotalWorkers = 4 // DefCacheChunkNoMemory will enable or disable in-memory storage for chunks DefCacheChunkNoMemory = false // DefCacheRps limits the number of requests per second to the source FS DefCacheRps = -1 // DefCacheWrites will cache file data on writes through the cache DefCacheWrites = false )
const ( RootBucket = "root" RootTsBucket = "rootTs" DataTsBucket = "dataTs" )
Constants
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChunkStorage ¶
type ChunkStorage interface { // will check if the chunk is in storage. should be fast and not read the chunk itself if possible HasChunk(cachedObject *Object, offset int64) bool // returns the chunk in storage. return an error if it's not GetChunk(cachedObject *Object, offset int64) ([]byte, error) // add a new chunk AddChunk(fp string, data []byte, offset int64) error // if the storage can cleanup on a cron basis // otherwise it can do a noop operation CleanChunksByAge(chunkAge time.Duration) // if the storage can cleanup chunks after we no longer need them // otherwise it can do a noop operation CleanChunksByNeed(offset int64) // if the storage can cleanup chunks after the total size passes a certain point // otherwise it can do a noop operation CleanChunksBySize(maxSize int64) }
ChunkStorage is a storage type that supports only chunk operations (i.e in RAM)
type Directory ¶
type Directory struct { fs.Directory `json:"-"` CacheFs *Fs `json:"-"` // cache fs Name string `json:"name"` // name of the directory Dir string `json:"dir"` // abs path of the directory CacheModTime int64 `json:"modTime"` // modification or creation time - IsZero for unknown CacheSize int64 `json:"size"` // size of directory and contents or -1 if unknown CacheItems int64 `json:"items"` // number of objects or -1 for unknown CacheType string `json:"cacheType"` // object type }
Directory is a generic dir that stores basic information about it
func DirectoryFromOriginal ¶
DirectoryFromOriginal builds one from a generic fs.Directory
func NewDirectory ¶
NewDirectory builds an empty dir which will be used to unmarshal data in it
type Features ¶
type Features struct {
PurgeDb bool // purge the db before starting
}
Features flags for this storage type
type Fs ¶
Fs represents a wrapped fs.Fs
func (*Fs) CleanUpCache ¶
CleanUpCache will cleanup only the cache data that is expired
func (*Fs) DirMove ¶
DirMove moves src, srcRemote to this remote at dstRemote using server side move operations.
func (*Fs) List ¶
func (f *Fs) List(dir string) (entries fs.DirEntries, err error)
List the objects and directories in dir into entries
func (*Fs) ListR ¶
func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error)
ListR lists the objects and directories of the Fs starting from dir recursively into out.
func (*Fs) OpenRateLimited ¶
func (f *Fs) OpenRateLimited(fn func() (io.ReadCloser, error)) (io.ReadCloser, error)
OpenRateLimited will execute a closure under a rate limiter watch
func (*Fs) Put ¶
func (f *Fs) Put(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)
Put in to the remote path with the modTime given of the given size
func (*Fs) PutStream ¶
func (f *Fs) PutStream(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)
PutStream uploads the object
func (*Fs) PutUnchecked ¶
func (f *Fs) PutUnchecked(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)
PutUnchecked uploads the object
func (*Fs) SetWrapper ¶
SetWrapper sets the Fs that is wrapping this Fs
type Handle ¶
type Handle struct { UseMemory bool // contains filtered or unexported fields }
Handle is managing the read/write/seek operations on an open handle
func NewObjectHandle ¶
NewObjectHandle returns a new Handle for an existing Object
type Memory ¶
type Memory struct { ChunkStorage // contains filtered or unexported fields }
Memory is a wrapper of transient storage for a go-cache store
func NewMemory ¶
NewMemory builds this cache storage defaultExpiration will set the expiry time of chunks in this storage
func (*Memory) AddChunkAhead ¶
AddChunkAhead adds a new chunk of a cached object
func (*Memory) CleanChunksByAge ¶
CleanChunksByAge will cleanup on a cron basis
func (*Memory) CleanChunksByNeed ¶
CleanChunksByNeed will cleanup chunks after the FS passes a specific chunk
func (*Memory) CleanChunksBySize ¶
CleanChunksBySize will cleanup chunks after the total size passes a certain point
type Object ¶
type Object struct { fs.Object `json:"-"` CacheFs *Fs `json:"-"` // cache fs Name string `json:"name"` // name of the directory Dir string `json:"dir"` // abs path of the object CacheModTime int64 `json:"modTime"` // modification or creation time - IsZero for unknown CacheSize int64 `json:"size"` // size of directory and contents or -1 if unknown CacheStorable bool `json:"storable"` // says whether this object can be stored CacheType string `json:"cacheType"` // contains filtered or unexported fields }
Object is a generic file like object that stores basic information about it
func ObjectFromOriginal ¶
ObjectFromOriginal builds one from a generic fs.Object
func (*Object) Hash ¶
Hash requests a hash of the object and stores in the cache since it might or might not be called, this is lazy loaded
func (*Object) MarshalJSON ¶
MarshalJSON is needed to override the hashes map (needed to support older versions of Go)
func (*Object) Open ¶
func (o *Object) Open(options ...fs.OpenOption) (io.ReadCloser, error)
Open is used to request a specific part of the file using fs.RangeOption
func (*Object) SetModTime ¶
SetModTime sets the ModTime of this object
func (*Object) UnmarshalJSON ¶
UnmarshalJSON is needed to override the CacheHashes map (needed to support older versions of Go)
func (*Object) Update ¶
func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error
Update will change the object data
type Persistent ¶
type Persistent struct { Storage // contains filtered or unexported fields }
Persistent is a wrapper of persistent storage for a bolt.DB file
func GetPersistent ¶
func GetPersistent(dbPath string, f *Features) (*Persistent, error)
GetPersistent returns a single instance for the specific store
func (*Persistent) AddChunk ¶
func (b *Persistent) AddChunk(fp string, data []byte, offset int64) error
AddChunk adds a new chunk of a cached object
func (*Persistent) AddDir ¶
func (b *Persistent) AddDir(cachedDir *Directory) error
AddDir will update a CachedDirectory metadata and all its entries
func (*Persistent) AddObject ¶
func (b *Persistent) AddObject(cachedObject *Object) error
AddObject will create a cached object in its parent directory
func (*Persistent) CleanChunksByAge ¶
func (b *Persistent) CleanChunksByAge(chunkAge time.Duration)
CleanChunksByAge will cleanup on a cron basis
func (*Persistent) CleanChunksByNeed ¶
func (b *Persistent) CleanChunksByNeed(offset int64)
CleanChunksByNeed is a noop for this implementation
func (*Persistent) CleanChunksBySize ¶
func (b *Persistent) CleanChunksBySize(maxSize int64)
CleanChunksBySize will cleanup chunks after the total size passes a certain point
func (*Persistent) CleanEntriesByAge ¶
func (b *Persistent) CleanEntriesByAge(entryAge time.Duration)
CleanEntriesByAge will cleanup on a cron basis
func (*Persistent) Close ¶
func (b *Persistent) Close()
Close should be called when the program ends gracefully
func (*Persistent) Connect ¶
func (b *Persistent) Connect() error
Connect creates a connection to the configured file refreshDb will delete the file before to create an empty DB if it's set to true
func (*Persistent) ExpireDir ¶
func (b *Persistent) ExpireDir(fp string) error
ExpireDir will flush a CachedDirectory and all its objects from the objects chunks will remain as they are
func (*Persistent) GetChunk ¶
func (b *Persistent) GetChunk(cachedObject *Object, offset int64) ([]byte, error)
GetChunk will retrieve a single chunk which belongs to a cached object or an error if it doesn't find it
func (*Persistent) GetChunkTs ¶
GetChunkTs retrieves the current timestamp of this chunk
func (*Persistent) GetDirEntries ¶
func (b *Persistent) GetDirEntries(cachedDir *Directory) (fs.DirEntries, error)
GetDirEntries will return a CachedDirectory, its list of dir entries and/or an error if it encountered issues
func (*Persistent) GetObject ¶
func (b *Persistent) GetObject(cachedObject *Object) (err error)
GetObject will return a CachedObject from its parent directory or an error if it doesn't find it
func (*Persistent) GetRootTs ¶
func (b *Persistent) GetRootTs(path string) (time.Time, error)
GetRootTs retrieves the current timestamp of an object or dir
func (*Persistent) HasChunk ¶
func (b *Persistent) HasChunk(cachedObject *Object, offset int64) bool
HasChunk confirms the existence of a single chunk of an object
func (*Persistent) HasEntry ¶
func (b *Persistent) HasEntry(remote string) bool
HasEntry confirms the existence of a single entry (dir or object)
func (*Persistent) RemoveDir ¶
func (b *Persistent) RemoveDir(fp string) error
RemoveDir will delete a CachedDirectory, all its objects and all the chunks stored for it
func (*Persistent) RemoveObject ¶
func (b *Persistent) RemoveObject(fp string) error
RemoveObject will delete a single cached object and all the chunks which belong to it
func (*Persistent) Stats ¶
func (b *Persistent) Stats() (map[string]map[string]interface{}, error)
Stats returns a go map with the stats key values
func (*Persistent) String ¶
func (b *Persistent) String() string
String will return a human friendly string for this DB (currently the dbPath)
type Storage ¶
type Storage interface { ChunkStorage // will update/create a directory or an error if it's not found AddDir(cachedDir *Directory) error // will return a directory with all the entries in it or an error if it's not found GetDirEntries(cachedDir *Directory) (fs.DirEntries, error) // remove a directory and all the objects and chunks in it RemoveDir(fp string) error // remove a directory and all the objects and chunks in it ExpireDir(fp string) error // will return an object (file) or error if it doesn't find it GetObject(cachedObject *Object) (err error) // add a new object to its parent directory // the directory structure (all the parents of this object) is created if its not found AddObject(cachedObject *Object) error // remove an object and all its chunks RemoveObject(fp string) error // Stats returns stats about the cache storage Stats() (map[string]map[string]interface{}, error) // if the storage can cleanup on a cron basis // otherwise it can do a noop operation CleanEntriesByAge(entryAge time.Duration) // Purge will flush the entire cache Purge() // Close should be called when the program ends gracefully Close() }
Storage is a storage type (Bolt) which needs to support both chunk and file based operations