Documentation
¶
Index ¶
- func EncodeManifest(ssts []SSSMeta, key []byte) ([]byte, error)
- func SaveManifest(basePath string, ssts []SSSMeta, key []byte) error
- type ChangeEvent
- type DB
- func (db *DB) Close() error
- func (db *DB) Compact() error
- func (db *DB) Delete(key string) error
- func (db *DB) Flush() error
- func (db *DB) Get(key string) (string, error)
- func (db *DB) Iterator() *Iterator
- func (db *DB) PrefixIterator(prefix string) *Iterator
- func (db *DB) Put(key, value string) error
- func (db *DB) PutBatch(kvs map[string]string) error
- func (db *DB) PutTTL(key, value string, ttl time.Duration) error
- func (db *DB) Subscribe(handler func(ChangeEvent)) int
- func (db *DB) Unsubscribe(id int)
- type Iterator
- type Options
- type SSSMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeManifest ¶
EncodeManifest encodes SSStorage names with binary format, nappy, ptional encryption
Types ¶
type ChangeEvent ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func Open ¶
Open initializes a new database at the specified path. It creates the necessary directories and initializes the WAL. If the path already exists, it will be opened for reading. The options parameter allows for optional encryption key setup. If the encryption key is provided, it must be 32 bytes long for AES-256. If the key is not provided, the database will be unencrypted. The function returns a pointer to the DB instance and an error if any occurs.
func (*DB) Close ¶
Close closes the database and the WAL. It ensures that all data is flushed to the SSS files and the WAL is closed properly. The function returns an error if any occurs during the close operation. It is important to call this function when you are done using the database to ensure data integrity. The function does not delete any SSS files or the WAL file. It only closes the file handles and ensures that all data is written to disk. After calling this function, the database instance should not be used anymore.
func (*DB) Compact ¶
Compact merges multiple SSStorage into a single one. It reads all SSStorages in the base path, merges them into a single map, and writes the merged data into a new SSStorage file. The old SSStorage files are deleted after the merge.
func (*DB) Delete ¶
Delete removes the key-value pair associated with the given key. It first deletes the pair from memory and then writes the delete operation to the WAL. The function returns an error if any occurs during the write operation. If the key does not exist, it will not raise an error. The function does not check the SSS files for the key before deleting it from memory. If the key is found in memory, it will be deleted immediately.
func (*DB) Flush ¶
Flush writes the in-memory data to a new SSS file. It generates a new filename based on the highest existing SSS file number. The new file will be named with the format "sss_00001.qldb". The function returns an error if any occurs during the write operation.
func (*DB) Get ¶
Get retrieves the value associated with the given key. It first checks the in-memory storage and then searches through the SSS files in reverse order. The function returns the value and error whether the key was found. If the key is not found in memory or in any SSS files, it returns an empty string and false. If the key is found, the value is returned in plaintext. If encryption is enabled, the value will be decrypted before returning. The function also handles the case where the key is not found in any SSS files. If the key is found in memory, it will be returned immediately without checking the SSS files.
func (*DB) Iterator ¶
NewIterator creates a new iterator for the database. It retrieves all keys from the in-memory storage, sorts them, and initializes the iterator with the sorted keys and their corresponding values. The iterator starts at index -1, indicating that it is before the first element. The caller can use the Next() method to advance the iterator and access keys and values. The iterator is not thread-safe and should be used by a single goroutine at a time. The caller is responsible for closing the iterator when done. The iterator does not require any additional resources to be closed.
func (*DB) PrefixIterator ¶
NewPrefixIterator creates a new iterator for the database with a specific prefix. It retrieves all keys from the in-memory storage that start with the given prefix, sorts them, and initializes the iterator with the sorted keys and their corresponding values.
func (*DB) Put ¶
Put stores a key-value pair in the database. It first stores the pair in memory and then writes it to the WAL. The function returns an error if any occurs during the write operation. If the key already exists, it will be updated with the new value. The value is stored in plaintext, and if encryption is enabled, it will be encrypted before writing to the WAL.
func (*DB) PutBatch ¶
PutBatch stores multiple key-value pairs in the database. It first stores the pairs in memory and then writes them to the WAL. If the key already exists, it will be updated with the new value.
func (*DB) PutTTL ¶
PutWithTTL stores a key-value pair in the database with a specified time-to-live (TTL). It first stores the pair in memory with the specified TTL and then writes it to the WAL. The function takes a key, a value, and a TTL duration as parameters. The TTL duration specifies how long the key-value pair should be valid. After the TTL expires, the key-value pair will be automatically removed from the in-memory storage. The function returns an error if any occurs during the write operation.
func (*DB) Subscribe ¶
func (db *DB) Subscribe(handler func(ChangeEvent)) int
Subscribe allows you to register a callback function that will be called whenever a change event occurs in the database. The callback function receives a ChangeEvent struct containing the type of change, the key, and the value.
func (*DB) Unsubscribe ¶
Unsubscribe removes a subscriber from the database. The subscriber is identified by its ID, which is returned when the subscriber was added.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
type SSSMeta ¶
func DecodeManifest ¶
DecodeManifest decodes manifest data to extract SSStorage names