MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
log_entry.h
1/* Copyright (c) 2021-2022 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 wangyunlai on 2024/01/30
13//
14
15#pragma once
16
17#include "common/sys/rc.h"
18#include "common/types.h"
19#include "storage/clog/log_module.h"
20#include "common/lang/vector.h"
21#include "common/lang/string.h"
22#include "common/lang/memory.h"
23
28struct LogHeader final
29{
30 LSN lsn;
31 int32_t size;
32 int32_t module_id;
33
34 static const int32_t SIZE;
35
36 string to_string() const;
37};
38
44{
45public:
46 LogEntry();
47 ~LogEntry() = default;
48
52 LogEntry(LogEntry &&other);
53
54 LogEntry &operator=(LogEntry &&other);
55
56 LogEntry(const LogEntry &) = delete;
57 LogEntry &operator=(const LogEntry &) = delete;
58
59public:
63 static int32_t max_size() { return 4 * 1024 * 1024; }
67 static int32_t max_payload_size() { return max_size() - LogHeader::SIZE; }
68
69public:
70 RC init(LSN lsn, LogModule::Id module_id, vector<char> &&data);
71 RC init(LSN lsn, LogModule module, vector<char> &&data);
72
73 const LogHeader &header() const { return header_; }
74 const char *data() const { return data_.data(); }
75 int32_t payload_size() const { return header_.size; }
76 int32_t total_size() const { return LogHeader::SIZE + header_.size; }
77
78 void set_lsn(LSN lsn) { header_.lsn = lsn; }
79
80 LSN lsn() const { return header_.lsn; }
81 LogModule module() const { return LogModule(header_.module_id); }
82
83public:
84 string to_string() const;
85
86private:
87 LogHeader header_;
88 vector<char> data_;
89};
描述一条日志
Definition: log_entry.h:44
static int32_t max_size()
一条日志的最大大小
Definition: log_entry.h:63
static int32_t max_payload_size()
一条日志最大payload大小
Definition: log_entry.h:67
vector< char > data_
日志头
Definition: log_entry.h:88
日志模块
Definition: log_module.h:24
Id
Definition: log_module.h:27
描述一条日志头
Definition: log_entry.h:29
string to_string() const
日志头大小
Definition: log_entry.cpp:23
int32_t module_id
日志数据大小,不包含日志头
Definition: log_entry.h:32
int32_t size
日志序列号 log sequence number
Definition: log_entry.h:31
static const int32_t SIZE
日志模块编号
Definition: log_entry.h:34