MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
ob_sstable_builder.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11#pragma once
12
13#include "common/lang/memory.h"
14#include "oblsm/table/ob_block_builder.h"
15#include "oblsm/memtable/ob_memtable.h"
16#include "common/lang/string.h"
17#include "oblsm/util/ob_file_writer.h"
18#include "oblsm/table/ob_block.h"
19#include "oblsm/table/ob_sstable.h"
20#include "oblsm/util/ob_lru_cache.h"
21
22namespace oceanbase {
23
28{
29public:
30 ObSSTableBuilder(const ObComparator *comparator, ObLRUCache<uint64_t, shared_ptr<ObBlock>> *block_cache)
31 : comparator_(comparator), block_cache_(block_cache)
32 {}
33 ~ObSSTableBuilder() = default;
34
48 RC build(shared_ptr<ObMemTable> mem_table, const string &file_name, uint32_t sst_id);
49 size_t file_size() const { return file_size_; }
50 shared_ptr<ObSSTable> get_built_table();
51 void reset();
52
53private:
54 void finish_build_block();
55
56 const ObComparator *comparator_ = nullptr;
57 ObBlockBuilder block_builder_;
58 string curr_blk_first_key_;
59 unique_ptr<ObFileWriter> file_writer_;
60 vector<BlockMeta> block_metas_;
61 uint32_t curr_offset_ = 0;
62 uint32_t sst_id_ = 0;
63 size_t file_size_ = 0;
64
65 ObLRUCache<uint64_t, shared_ptr<ObBlock>> *block_cache_ = nullptr;
66};
67} // namespace oceanbase
Build a ObBlock in SSTable
Definition: ob_block_builder.h:24
base class of all comparators
Definition: ob_comparator.h:21
A thread-safe implementation of an LRU (Least Recently Used) cache.
Definition: ob_lru_cache.h:31
Build a SSTable
Definition: ob_sstable_builder.h:28
RC build(shared_ptr< ObMemTable > mem_table, const string &file_name, uint32_t sst_id)
Builds an SSTable from the provided in-memory table and stores it in a file.
Definition: ob_sstable_builder.cpp:17