MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
|
Public 成员函数 | |
ObLsmImpl (const ObLsmOptions &options, const string &path) | |
RC | put (const string_view &key, const string_view &value) override |
Inserts or updates a key-value entry in the LSM-Tree. 更多... | |
RC | get (const string_view &key, string *value) override |
Retrieves the value associated with a specified key. 更多... | |
RC | remove (const string_view &key) override |
Delete a key-value entry in the LSM-Tree. 更多... | |
ObLsmTransaction * | begin_transaction () override |
ObLsmIterator * | new_iterator (ObLsmReadOptions options) override |
Creates a new iterator for traversing the LSM-Tree database. 更多... | |
SSTablesPtr | get_sstables () |
RC | recover () |
RC | batch_put (const std::vector< pair< string, string > > &kvs) override |
void | dump_sstables () override |
Dumps all SSTables for debugging purposes. 更多... | |
![]() | |
ObLsm (const ObLsm &)=delete | |
ObLsm & | operator= (const ObLsm &)=delete |
virtual RC | put (const string_view &key, const string_view &value)=0 |
Inserts or updates a key-value entry in the LSM-Tree. 更多... | |
virtual RC | get (const string_view &key, string *value)=0 |
Retrieves the value associated with a specified key. 更多... | |
virtual RC | remove (const string_view &key)=0 |
Delete a key-value entry in the LSM-Tree. 更多... | |
virtual ObLsmTransaction * | begin_transaction ()=0 |
virtual ObLsmIterator * | new_iterator (ObLsmReadOptions options)=0 |
Creates a new iterator for traversing the LSM-Tree database. 更多... | |
virtual RC | batch_put (const vector< pair< string, string > > &kvs)=0 |
Inserts a batch of key-value entries into the LSM-Tree. 更多... | |
virtual void | dump_sstables ()=0 |
Dumps all SSTables for debugging purposes. 更多... | |
Private 成员函数 | |
RC | recover_from_wal () |
RC | recover_from_manifest_records (const std::vector< ObManifestCompaction > &records) |
RC | load_manifest_snapshot (const ObManifestSnapshot &snapshot) |
RC | load_manifest_sstable (const std::vector< std::vector< uint64_t > > &sstables) |
RC | write_manifest_snapshot () |
RC | try_freeze_memtable () |
Attempts to freeze the current active MemTable. 更多... | |
vector< shared_ptr< ObSSTable > > | do_compaction (ObCompaction *compaction) |
Performs compaction on the SSTables selected by the compaction strategy. 更多... | |
void | try_major_compaction () |
Initiates a major compaction process. 更多... | |
void | background_compaction (std::shared_ptr< ObLsmBgCompactCtx > ctx) |
Handles background compaction tasks. 更多... | |
void | build_sstable (shared_ptr< ObMemTable > imem) |
Builds an SSTable from the given MemTable. 更多... | |
string | get_sstable_path (uint64_t sstable_id) |
Retrieves the file path for a given SSTable. 更多... | |
string | get_wal_path (uint64_t memtable_id) |
Retrieves the file path for a given Memtable id. 更多... | |
Private 属性 | |
ObLsmOptions | options_ |
string | path_ |
mutex | mu_ |
std::shared_ptr< WAL > | wal_ |
std::vector< std::shared_ptr< WAL > > | frozen_wals_ |
shared_ptr< ObMemTable > | mem_table_ |
vector< shared_ptr< ObMemTable > > | imem_tables_ |
SSTablesPtr | sstables_ |
common::ThreadPoolExecutor | executor_ |
ObManifest | manifest_ |
atomic< uint64_t > | seq_ {0} |
atomic< uint64_t > | sstable_id_ {0} |
atomic< uint64_t > | memtable_id_ {0} |
condition_variable | cv_ |
const ObDefaultComparator | default_comparator_ |
const ObInternalKeyComparator | internal_key_comparator_ |
atomic< bool > | compacting_ = false |
std::unique_ptr< ObLRUCache< uint64_t, shared_ptr< ObBlock > > > | block_cache_ |
额外继承的成员函数 | |
![]() | |
static RC | open (const ObLsmOptions &options, const string &path, ObLsm **dbptr) |
Opens an LSM-Tree database at the specified path. 更多... | |
|
private |
Handles background compaction tasks.
ctx | Save the data that will be used during the compaction process. |
|
overridevirtual |
实现了 oceanbase::ObLsm.
|
private |
Builds an SSTable from the given MemTable.
Converts the data in an immutable MemTable (imem
) into a new SSTable and writes it to persistent storage. This step is usually part of the compaction pipeline.
imem | A shared pointer to the immutable MemTable (ObMemTable ) to be converted into an SSTable. |
imem
is immutable and ready for conversion.
|
private |
Performs compaction on the SSTables selected by the compaction strategy.
This function takes a compaction plan (represented by ObCompaction
) and merges the inputs into a new set of SSTables. It creates iterators for the SSTables being compacted, merges their data, and writes the merged data into new SSTable files.
picked | A pointer to the compaction plan that specifies the input SSTables to merge. If picked is nullptr , no compaction is performed and an empty result is returned. |
picked
compaction plan.ObLsmIterator
).ObSSTableBuilder
.options_.table_size
), the builder finalizes the current SSTable and starts a new one.picked
object is properly populated with valid inputs.
|
overridevirtual |
Dumps all SSTables for debugging purposes.
This method outputs the structure and contents of all SSTables in the LSM-Tree for debugging or inspection purposes.
实现了 oceanbase::ObLsm.
|
overridevirtual |
Retrieves the value associated with a specified key.
This method looks up the value corresponding to the given key in the LSM-Tree. If the key exists, the value is stored in the output parameter *value
.
key | The key to look up. |
value | Pointer to a string where the retrieved value will be stored. |
实现了 oceanbase::ObLsm.
|
private |
Retrieves the file path for a given SSTable.
sstable_id | The unique identifier of the SSTable whose path needs to be retrieved. |
|
private |
Retrieves the file path for a given Memtable id.
memtable_id | The unique identifier of the memtable whose path needs to be retrieved. |
|
overridevirtual |
Creates a new iterator for traversing the LSM-Tree database.
This method returns a heap-allocated iterator over the contents of the database. The iterator is initially invalid, and the caller must use one of the seek
/seek_to_first
/seek_to_last
methods on the iterator before accessing any elements.
options | Read options to configure the behavior of the iterator. |
实现了 oceanbase::ObLsm.
|
overridevirtual |
Inserts or updates a key-value entry in the LSM-Tree.
This method adds a new entry
key | The key to insert or update. |
value | The value associated with the key. |
实现了 oceanbase::ObLsm.
|
overridevirtual |
Delete a key-value entry in the LSM-Tree.
This method remove a entry
key | The key to remove. |
实现了 oceanbase::ObLsm.
|
private |
Attempts to freeze the current active MemTable.
This method performs operations to freeze the active MemTable when certain conditions are met, such as size thresholds or timing requirements. A frozen MemTable becomes immutable and is ready for compaction.
|
private |
Initiates a major compaction process.
Major compaction involves merging all levels of SSTables into a single, consolidated SSTable, which reduces storage fragmentation and improves read performance. This process typically runs periodically or when triggered by specific conditions.