Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func NewDB ¶
NewDB initializes and returns a new instance of DB with optional configuration provided by variadic Options. It sets up the initial memory tables, SSTable, and recovers data from the Write-Ahead Log (WAL) if present. Returns a pointer to DB and an error if any occurs during setup or recovery.
func (*DB) Del ¶
Del deletes the entry associated with the provided key from the database. It writes a deletion record to the Write-Ahead Log (WAL), if enabled, and marks the entry as deleted in the in-memory table. An error is returned if the database is in the process of shutting down.
func (*DB) Get ¶
Get retrieves the value associated with the specified key from the database. It first checks the memory tables in reverse order and then falls back to the SSTable. If the database is shutting down, it returns an error.
func (*DB) Set ¶
Set stores the given value for the specified key in the database. It writes the data to the Write-Ahead Log (WAL) if enabled and updates the in-memory table. If the in-memory table size exceeds the defined segment size, a flush operation is initiated. Returns an error if the database is shutting down.
func (*DB) Shutdown ¶
func (db *DB) Shutdown()
Shutdown initiates the shutdown process for the database. It prevents new operations by setting the shutdown flag and flushes remaining memory tables to disk. Afterward, it closes the SSTable to finalize the shutdown sequence. This method is idempotent and will return immediately if called again after the shutdown has been initiated.
type Options ¶
type Options func(db *DB)
Options defines a function type that accepts a pointer to DB and modifies its configuration. It is used to customize the behavior of a DB instance during initialization.
func Dir ¶
Dir sets the data directory and write-ahead log (WAL) directory options for the database. This function is intended to be used when configuring a database instance. It takes two string arguments representing the paths for the data directory and WAL directory, respectively. The function returns an Options func that applies these settings to a DB instance.
func SegmentSize ¶
SegmentSize sets the size limit for each data segment in megabytes. The provided value is converted to bytes before being applied to the DB configuration. This function is intended to be used as an option when initializing a database instance.