MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
Public 成员函数 | Private 成员函数 | Private 属性 | 所有成员列表
oceanbase::ObLsmImpl类 参考
类 oceanbase::ObLsmImpl 继承关系图:
oceanbase::ObLsm

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. 更多...
 
ObLsmTransactionbegin_transaction () override
 
ObLsmIteratornew_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. 更多...
 
- Public 成员函数 继承自 oceanbase::ObLsm
 ObLsm (const ObLsm &)=delete
 
ObLsmoperator= (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 ObLsmTransactionbegin_transaction ()=0
 
virtual ObLsmIteratornew_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< WALwal_
 
std::vector< std::shared_ptr< WAL > > frozen_wals_
 
shared_ptr< ObMemTablemem_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_
 

额外继承的成员函数

- 静态 Public 成员函数 继承自 oceanbase::ObLsm
static RC open (const ObLsmOptions &options, const string &path, ObLsm **dbptr)
 Opens an LSM-Tree database at the specified path. 更多...
 

成员函数说明

◆ background_compaction()

void oceanbase::ObLsmImpl::background_compaction ( std::shared_ptr< ObLsmBgCompactCtx ctx)
private

Handles background compaction tasks.

参数
ctxSave the data that will be used during the compaction process.

◆ begin_transaction()

ObLsmTransaction * oceanbase::ObLsmImpl::begin_transaction ( )
overridevirtual

实现了 oceanbase::ObLsm.

◆ build_sstable()

void oceanbase::ObLsmImpl::build_sstable ( shared_ptr< ObMemTable imem)
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.

参数
imemA shared pointer to the immutable MemTable (ObMemTable) to be converted into an SSTable.
注解
The caller must ensure that imem is immutable and ready for conversion.

◆ do_compaction()

vector< shared_ptr< ObSSTable > > oceanbase::ObLsmImpl::do_compaction ( ObCompaction compaction)
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.

参数
pickedA 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.
返回
vector<shared_ptr<ObSSTable>> A vector of shared pointers to the newly created SSTables resulting from the compaction process.
  • The function retrieves the inputs (SSTables) from the picked compaction plan.
  • For each SSTable, it creates a new iterator to sequentially scan its data.
  • It merges the iterators using a merging iterator (ObLsmIterator).
  • It writes the merged key-value pairs into new SSTable files using ObSSTableBuilder.
  • If the size of the new SSTable exceeds a predefined size (options_.table_size), the builder finalizes the current SSTable and starts a new one.
警告
Ensure that the picked object is properly populated with valid inputs.

◆ dump_sstables()

void oceanbase::ObLsmImpl::dump_sstables ( )
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.

◆ get()

RC oceanbase::ObLsmImpl::get ( const string_view &  key,
string *  value 
)
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.

参数
keyThe key to look up.
valuePointer to a string where the retrieved value will be stored.
返回
An RC value indicating success or failure of the operation.

实现了 oceanbase::ObLsm.

◆ get_sstable_path()

string oceanbase::ObLsmImpl::get_sstable_path ( uint64_t  sstable_id)
private

Retrieves the file path for a given SSTable.

参数
sstable_idThe unique identifier of the SSTable whose path needs to be retrieved.
返回
A string representing the full file path of the SSTable.

◆ get_wal_path()

string oceanbase::ObLsmImpl::get_wal_path ( uint64_t  memtable_id)
private

Retrieves the file path for a given Memtable id.

参数
memtable_idThe unique identifier of the memtable whose path needs to be retrieved.
返回
A string representing the full file path of the wal.

◆ new_iterator()

ObLsmIterator * oceanbase::ObLsmImpl::new_iterator ( ObLsmReadOptions  options)
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.

参数
optionsRead options to configure the behavior of the iterator.
返回
A pointer to the newly created iterator.
注解
The caller is responsible for deleting the iterator when it is no longer needed.

实现了 oceanbase::ObLsm.

◆ put()

RC oceanbase::ObLsmImpl::put ( const string_view &  key,
const string_view &  value 
)
overridevirtual

Inserts or updates a key-value entry in the LSM-Tree.

This method adds a new entry

参数
keyThe key to insert or update.
valueThe value associated with the key.
返回
An RC value indicating success or failure of the operation.

实现了 oceanbase::ObLsm.

◆ remove()

RC oceanbase::ObLsmImpl::remove ( const string_view &  key)
overridevirtual

Delete a key-value entry in the LSM-Tree.

This method remove a entry

参数
keyThe key to remove.
返回
An RC value indicating success or failure of the operation.

实现了 oceanbase::ObLsm.

◆ try_freeze_memtable()

RC oceanbase::ObLsmImpl::try_freeze_memtable ( )
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.

返回
RC Status code indicating the success or failure of the freeze operation.

◆ try_major_compaction()

void oceanbase::ObLsmImpl::try_major_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.

注解
This function should be called with care, as major compaction is a resource-intensive operation and may affect system performance during execution.

该类的文档由以下文件生成: