Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FdCache ¶
type FdCache struct {
// contains filtered or unexported fields
}
func NewFdCache ¶
NewFdCache returns an initialised FdCache that will hold at most `capacity` file descriptors.
func (*FdCache) Acquire ¶
Acquire returns a cached *fileEntry for the given path, opening the file in read-only mode if necessary. The entry's reference count is incremented; callers MUST invoke Release when they are done so the underlying descriptor can be closed (and the cache pruned) when no longer needed.
Acquire is race-free against concurrent Release and Remove: if the cached entry has been claimed for closing (refs <= 0), Acquire transparently falls through and opens a fresh descriptor rather than returning a stale FileEntry whose file has been closed.
func (*FdCache) CleanUp ¶
CleanUp removes the entry for `path` from the cache and closes the file. This is primarily used when the file itself has been deleted from disk.
func (*FdCache) GetFileLock ¶
GetFileLock returns an RWMutex for the given path, creating it if it doesn't exist. An RWMutex allows multiple concurrent readers while still giving exclusive access to writers (Write/Delete), which is exactly the behaviour we need for raw files. Deprecated: Use GetFileLockManager().GetFileLock(path) instead.
func (*FdCache) Release ¶
Release decrements the reference count for the given entry. When this is the last holder, Release atomically claims the close via dropRef and invokes closeEntry to finalize cleanup.
func (*FdCache) Remove ¶
Remove forcibly evicts the entry for `path` from the cache (if present). This is primarily used when the file itself has been deleted from disk or when the segment containing it has been compacted away.
Remove never closes a file descriptor that an active holder still owns. The close is always performed by the last Release (which transitions refs 1 → -1 and runs closeEntry). If Remove happens to observe that no holder exists (refs == 0, e.g. a defensive/manual state), it atomically claims the close via CAS(0, refsClosed) and closes the FD itself.
type FileEntry ¶
type FileEntry struct {
// contains filtered or unexported fields
}
type FileLockManager ¶
type FileLockManager struct {
// contains filtered or unexported fields
}
FileLockManager manages file-level locks for concurrent access control. It provides RWMutex locks for files, allowing multiple concurrent readers while giving exclusive access to writers (Write/Delete operations).
Thread-safety: All methods are safe for concurrent use.
Usage pattern:
lock := manager.GetFileLock(path) lock.Lock() // or lock.RLock() for read operations defer lock.Unlock() // or lock.RUnlock() // ... perform file operations ...
Note: RemoveFileLock should only be called after the file has been successfully deleted and the lock has been released.
func GetFileLockManager ¶
func GetFileLockManager() *FileLockManager
GetFileLockManager returns the singleton instance of FileLockManager.
func (*FileLockManager) GetFileLock ¶
func (flm *FileLockManager) GetFileLock(path string) *sync.RWMutex
GetFileLock returns an RWMutex for the given path, creating it if it doesn't exist. An RWMutex allows multiple concurrent readers while still giving exclusive access to writers (Write/Delete), which is exactly the behaviour we need for raw files.
func (*FileLockManager) HasLock ¶
func (flm *FileLockManager) HasLock(path string) bool
HasLock returns true if a lock exists in the manager for the given path. Note: This only indicates whether a lock object exists in the manager, not whether the lock is currently held by any goroutine. This method is primarily intended for testing purposes.
func (*FileLockManager) RemoveFileLock ¶
func (flm *FileLockManager) RemoveFileLock(path string)
RemoveFileLock removes the lock for the given path from the manager. This should be called only after a file has been successfully deleted and its lock has been released. Calling this while a lock is still held may lead to unexpected behavior.