MiniOB
1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
src
observer
storage
clog
log_entry.h
1
/* Copyright (c) 2021-2022 OceanBase and/or its affiliates. All rights reserved.
2
miniob is licensed under Mulan PSL v2.
3
You can use this software according to the terms and conditions of the Mulan PSL v2.
4
You may obtain a copy of Mulan PSL v2 at:
5
http://license.coscl.org.cn/MulanPSL2
6
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9
See 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
28
struct
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
43
class
LogEntry
44
{
45
public
:
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
59
public
:
63
static
int32_t
max_size
() {
return
4 * 1024 * 1024; }
67
static
int32_t
max_payload_size
() {
return
max_size
() -
LogHeader::SIZE
; }
68
69
public
:
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
83
public
:
84
string
to_string()
const
;
85
86
private
:
87
LogHeader
header_;
88
vector<char>
data_
;
89
};
LogEntry
描述一条日志
Definition:
log_entry.h:44
LogEntry::max_size
static int32_t max_size()
一条日志的最大大小
Definition:
log_entry.h:63
LogEntry::max_payload_size
static int32_t max_payload_size()
一条日志最大payload大小
Definition:
log_entry.h:67
LogEntry::data_
vector< char > data_
日志头
Definition:
log_entry.h:88
LogModule
日志模块
Definition:
log_module.h:24
LogModule::Id
Id
Definition:
log_module.h:27
LogHeader
描述一条日志头
Definition:
log_entry.h:29
LogHeader::to_string
string to_string() const
日志头大小
Definition:
log_entry.cpp:23
LogHeader::module_id
int32_t module_id
日志数据大小,不包含日志头
Definition:
log_entry.h:32
LogHeader::size
int32_t size
日志序列号 log sequence number
Definition:
log_entry.h:31
LogHeader::SIZE
static const int32_t SIZE
日志模块编号
Definition:
log_entry.h:34
制作者
1.9.5