metadata

package
v2.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SizeOfTypeCacheEntry

func SizeOfTypeCacheEntry(key string) uint64

Return the size (rss) of a type-cache entry for a given key-string.

Types

type StatCache

type StatCache interface {
	// Insert an entry for the given object record.
	//
	// In order to help cope with caching of arbitrarily out of date (i.e.
	// inconsistent) object listings, entry will not replace any positive entry
	// with a newer generation number, or with an equivalent generation number
	// but newer metadata generation number. We have no choice, however, but to
	// replace negative entries.
	//
	// The entry will expire after the supplied time.
	Insert(m *gcs.MinObject, expiration time.Time)

	// Set up a negative entry for the given name, indicating that the name
	// doesn't exist. Overwrite any existing entry for the name, positive or
	// negative.
	AddNegativeEntry(name string, expiration time.Time)

	// Erase the entry for the given object name, if any.
	Erase(name string)

	// Return the current entry for the given name, or nil if there is a negative
	// entry. Return hit == false when there is neither a positive nor a negative
	// entry, or the entry has expired according to the supplied current time.
	LookUp(name string, now time.Time) (hit bool, m *gcs.MinObject)
}

A cache mapping from name to most recent known record for the object of that name. External synchronization must be provided.

func NewStatCacheBucketView

func NewStatCacheBucketView(sc *lru.Cache, bn string) StatCache

Create a new bucket-view to the passed shared-cache object. For dynamic-mount (mount for multiple buckets), pass bn as bucket-name. For static-mout (mount for single bucket), pass bn as "".

type Type

type Type int
const (
	UnknownType     Type = 0
	SymlinkType     Type = 1
	RegularFileType Type = 2
	ExplicitDirType Type = 3
	ImplicitDirType Type = 4
	NonexistentType Type = 5
)

type TypeCache

type TypeCache interface {
	// Insert inserts the given entry (name -> type)
	// with the entry-expiration at now+ttl.
	Insert(now time.Time, name string, it Type)
	// Erase removes the entry with the given name.
	Erase(name string)
	// Get returns the entry with given name, and also
	// records this entry as latest accessed in the cache.
	// If now > expiration, then entry is removed from cache, and
	// UnknownType is returned.
	// If entry doesn't exist in the cache, then
	// UnknownType is returned.
	Get(now time.Time, name string) Type
}

TypeCache is a (name -> Type) map. It maintains TTL for each entry for supporting TTL-based expiration. Sample usage:

tc := NewTypeCache(size, ttl)
tc.Insert(time.Now(), "file", RegularFileType)
tc.Insert(time.Now(), "dir", ExplicitDirType)
tc.Get(time.Now(),"file") -> RegularFileType
tc.Get(time.Now(),"dir") -> ExplicitDirType
tc.Get(time.Now()+ttl+1ns, "file") -> internally tc.Erase("file") -> UnknownType
tc.Erase("dir")
tc.Get(time.Now(),"dir") -> UnknownType

func NewTypeCache

func NewTypeCache(maxSizeMB int, ttl time.Duration) TypeCache

NewTypeCache creates an LRU-policy-based cache with given parameters. Any entry whose TTL has expired, is removed from the cache on next access (Get). When insertion of next entry would cause size of cache > maxSizeMB, older entries are evicted according to the LRU-policy. If either of TTL or maxSizeMB is zero, nothing is ever cached.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL