MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
db.h
1/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and 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//
12// Created by Meiyi & Longda & Wangyunlai on 2021/5/12.
13//
14
15#pragma once
16
17#include <vector>
18#include <string>
19#include <unordered_map>
20#include <memory>
21
22#include "common/rc.h"
23#include "sql/parser/parse_defs.h"
24
25class Table;
26class CLogManager;
27
33class Db
34{
35public:
36 Db() = default;
37 ~Db();
38
46 RC init(const char *name, const char *dbpath);
47
48 RC create_table(const char *table_name, int attribute_count, const AttrInfoSqlNode *attributes);
49
50 Table *find_table(const char *table_name) const;
51 Table *find_table(int32_t table_id) const;
52
53 const char *name() const;
54
55 void all_tables(std::vector<std::string> &table_names) const;
56
57 RC sync();
58
59 RC recover();
60
61 CLogManager *clog_manager();
62
63private:
64 RC open_all_tables();
65
66private:
67 std::string name_;
68 std::string path_;
69 std::unordered_map<std::string, Table *> opened_tables_;
70 std::unique_ptr<CLogManager> clog_manager_;
71
73 int32_t next_table_id_ = 0;
74};
日志管理器
Definition: clog.h:357
一个DB实例负责管理一批表
Definition: db.h:34
RC init(const char *name, const char *dbpath)
初始化一个数据库实例
Definition: db.cpp:38
int32_t next_table_id_
给每个table都分配一个ID,用来记录日志。这里假设所有的DDL都不会并发操作,所以相关的数据都不上锁
Definition: db.h:73
Definition: table.h:37
描述一个属性
Definition: parse_defs.h:149