Documentation
¶
Index ¶
- func IsEnoughSpace(end, len int) bool
- func ParseOperation(payload []byte) byte
- func TLLParser(ttl uint32) time.Time
- type Allocator
- type Key
- type ShardedStore
- type Slab
- type SlabManager
- func (s *SlabManager) ChoseSlab(index int) *Slab
- func (s *SlabManager) DeleteOperationFn(payload Transfer)
- func (s *SlabManager) Dispatch(payload Transfer)
- func (s *SlabManager) FreeSpace(index, slabSize int) ([]byte, string)
- func (s *SlabManager) GetIndex(dataSize int) (int, int)
- func (s *SlabManager) GetLRUIndex(index int) *link_list.DLL
- func (s *SlabManager) GetOperationFn(payload Transfer)
- func (s *SlabManager) GetSlab(payloadSize int, conn net.Conn) ([]byte, int, error)
- func (s *SlabManager) GetSlabIndex(index int) *Slab
- func (s *SlabManager) SetOperationFn(payload Transfer)
- func (s *SlabManager) Worker(jobCh <-chan Transfer)
- type Transfer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEnoughSpace ¶
IsEnoughSpace checks if there is enough space to allocate a block of memory from 'end' position to the given length.
func ParseOperation ¶
Types ¶
type Allocator ¶
Allocator is a memory allocator that manages a slice of bytes and keeps track of the next available index.
func (*Allocator) AllocateBlock ¶
AllocateBlock allocates a block of memory in the allocator. It locks the allocator for thread-safety and returns a slice of bytes or an error if there isn't enough space.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key represents a stored object with its field, TTL (Time-To-Live), and a pointer to its node in the LRU list.
type ShardedStore ¶
type ShardedStore struct {
// contains filtered or unexported fields
}
func NewShardedStore ¶
func NewShardedStore() *ShardedStore
func (*ShardedStore) Delete ¶
func (s *ShardedStore) Delete(key string)
func (*ShardedStore) Store ¶
func (s *ShardedStore) Store(key string, value Key)
type Slab ¶
type Slab struct {
sync.RWMutex // Mutex to protect access to the slab
*Allocator // Memory allocator associated with the slab
// contains filtered or unexported fields
}
Slab represents a memory slab used for allocation.
func (*Slab) AllocateMemory ¶
AllocateMemory allocates memory for the slab, either by reusing a free block or allocating a new page.
func (*Slab) FreeMemory ¶
func (*Slab) GetCurrentPage ¶
GetCurrentPage returns the current page of the slab.
func (*Slab) IsSlabActive ¶
IsSlabActive checks if the slab has an active memory page.
func (*Slab) UpdatePage ¶
type SlabManager ¶
type SlabManager struct {
JobCh []chan Transfer // Channel to receive transfer jobs for processing
// contains filtered or unexported fields
}
SlabManager manages slabs, LRU (Least Recently Used) caches, and memory allocation.
func NewSlabManager ¶
func NewSlabManager(slabs []Slab, numberOfWorker int) *SlabManager
NewSlabManager creates a new SlabManager with the provided slabs and starts worker goroutines.
func (*SlabManager) ChoseSlab ¶
func (s *SlabManager) ChoseSlab(index int) *Slab
ChoseSlab returns the slab at the specified index.
func (*SlabManager) DeleteOperationFn ¶
func (s *SlabManager) DeleteOperationFn(payload Transfer)
func (*SlabManager) Dispatch ¶
func (s *SlabManager) Dispatch(payload Transfer)
func (*SlabManager) FreeSpace ¶
func (s *SlabManager) FreeSpace(index, slabSize int) ([]byte, string)
FreeSpace frees space in the slab's LRU cache by removing the least recently used node.
func (*SlabManager) GetIndex ¶
func (s *SlabManager) GetIndex(dataSize int) (int, int)
GetIndex performs a binary search to find the appropriate slab index based on the data size.
func (*SlabManager) GetLRUIndex ¶
func (s *SlabManager) GetLRUIndex(index int) *link_list.DLL
GetLRUIndex returns the LRU cache at the specified index.
func (*SlabManager) GetOperationFn ¶
func (s *SlabManager) GetOperationFn(payload Transfer)
func (*SlabManager) GetSlab ¶
GetSlab allocates a slab of memory based on the payload size, handles errors, and frees space if necessary.
func (*SlabManager) GetSlabIndex ¶
func (s *SlabManager) GetSlabIndex(index int) *Slab
GetSlabIndex returns the slab at the specified index.
func (*SlabManager) SetOperationFn ¶
func (s *SlabManager) SetOperationFn(payload Transfer)
func (*SlabManager) Worker ¶
func (s *SlabManager) Worker(jobCh <-chan Transfer)