]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/journal/test_JournalRecorder.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / test / journal / test_JournalRecorder.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "journal/JournalRecorder.h"
5#include "journal/Entry.h"
6#include "journal/JournalMetadata.h"
7#include "test/journal/RadosTestFixture.h"
8#include <limits>
9#include <list>
9f95a23c 10#include <memory>
7c673cae
FG
11
12class TestJournalRecorder : public RadosTestFixture {
13public:
9f95a23c
TL
14 using JournalRecorderPtr = std::unique_ptr<journal::JournalRecorder,
15 std::function<void(journal::JournalRecorder*)>>;
16 JournalRecorderPtr create_recorder(
17 const std::string &oid, const ceph::ref_t<journal::JournalMetadata>& metadata) {
18 JournalRecorderPtr recorder{
19 new journal::JournalRecorder(m_ioctx, oid + ".", metadata, 0),
20 [](journal::JournalRecorder* recorder) {
21 C_SaferCond cond;
22 recorder->shut_down(&cond);
23 cond.wait();
24 delete recorder;
25 }
26 };
27 recorder->set_append_batch_options(0, std::numeric_limits<uint32_t>::max(), 0);
7c673cae
FG
28 return recorder;
29 }
7c673cae
FG
30};
31
32TEST_F(TestJournalRecorder, Append) {
33 std::string oid = get_temp_oid();
34 ASSERT_EQ(0, create(oid, 12, 2));
35 ASSERT_EQ(0, client_register(oid));
36
9f95a23c 37 auto metadata = create_metadata(oid);
7c673cae
FG
38 ASSERT_EQ(0, init_metadata(metadata));
39
9f95a23c 40 JournalRecorderPtr recorder = create_recorder(oid, metadata);
7c673cae
FG
41
42 journal::Future future1 = recorder->append(123, create_payload("payload"));
43
44 C_SaferCond cond;
45 future1.flush(&cond);
46 ASSERT_EQ(0, cond.wait());
47}
48
49TEST_F(TestJournalRecorder, AppendKnownOverflow) {
50 std::string oid = get_temp_oid();
51 ASSERT_EQ(0, create(oid, 12, 2));
52 ASSERT_EQ(0, client_register(oid));
53
9f95a23c 54 auto metadata = create_metadata(oid);
7c673cae
FG
55 ASSERT_EQ(0, init_metadata(metadata));
56 ASSERT_EQ(0U, metadata->get_active_set());
57
9f95a23c 58 JournalRecorderPtr recorder = create_recorder(oid, metadata);
7c673cae
FG
59
60 recorder->append(123, create_payload(std::string(metadata->get_object_size() -
61 journal::Entry::get_fixed_size(), '1')));
62 journal::Future future2 = recorder->append(123, create_payload(std::string(1, '2')));
63
64 C_SaferCond cond;
65 future2.flush(&cond);
66 ASSERT_EQ(0, cond.wait());
67
68 ASSERT_EQ(1U, metadata->get_active_set());
69}
70
71TEST_F(TestJournalRecorder, AppendDelayedOverflow) {
72 std::string oid = get_temp_oid();
73 ASSERT_EQ(0, create(oid, 12, 2));
74 ASSERT_EQ(0, client_register(oid));
75
9f95a23c 76 auto metadata = create_metadata(oid);
7c673cae
FG
77 ASSERT_EQ(0, init_metadata(metadata));
78 ASSERT_EQ(0U, metadata->get_active_set());
79
9f95a23c
TL
80 JournalRecorderPtr recorder1 = create_recorder(oid, metadata);
81 JournalRecorderPtr recorder2 = create_recorder(oid, metadata);
7c673cae
FG
82
83 recorder1->append(234, create_payload(std::string(1, '1')));
84 recorder2->append(123, create_payload(std::string(metadata->get_object_size() -
85 journal::Entry::get_fixed_size(), '2')));
86
87 journal::Future future = recorder2->append(123, create_payload(std::string(1, '3')));
88
89 C_SaferCond cond;
90 future.flush(&cond);
91 ASSERT_EQ(0, cond.wait());
92
93 ASSERT_EQ(1U, metadata->get_active_set());
94}
95
96TEST_F(TestJournalRecorder, FutureFlush) {
97 std::string oid = get_temp_oid();
98 ASSERT_EQ(0, create(oid, 12, 2));
99 ASSERT_EQ(0, client_register(oid));
100
9f95a23c 101 auto metadata = create_metadata(oid);
7c673cae
FG
102 ASSERT_EQ(0, init_metadata(metadata));
103
9f95a23c 104 JournalRecorderPtr recorder = create_recorder(oid, metadata);
7c673cae
FG
105
106 journal::Future future1 = recorder->append(123, create_payload("payload1"));
107 journal::Future future2 = recorder->append(123, create_payload("payload2"));
108
109 C_SaferCond cond;
110 future2.flush(&cond);
111 ASSERT_EQ(0, cond.wait());
112 ASSERT_TRUE(future1.is_complete());
113 ASSERT_TRUE(future2.is_complete());
114}
115
116TEST_F(TestJournalRecorder, Flush) {
117 std::string oid = get_temp_oid();
118 ASSERT_EQ(0, create(oid, 12, 2));
119 ASSERT_EQ(0, client_register(oid));
120
9f95a23c 121 auto metadata = create_metadata(oid);
7c673cae
FG
122 ASSERT_EQ(0, init_metadata(metadata));
123
9f95a23c 124 JournalRecorderPtr recorder = create_recorder(oid, metadata);
7c673cae
FG
125
126 journal::Future future1 = recorder->append(123, create_payload("payload1"));
127 journal::Future future2 = recorder->append(123, create_payload("payload2"));
128
129 C_SaferCond cond1;
130 recorder->flush(&cond1);
131 ASSERT_EQ(0, cond1.wait());
132
133 C_SaferCond cond2;
134 future2.wait(&cond2);
135 ASSERT_EQ(0, cond2.wait());
136 ASSERT_TRUE(future1.is_complete());
137 ASSERT_TRUE(future2.is_complete());
138}
139
140TEST_F(TestJournalRecorder, OverflowCommitObjectNumber) {
141 std::string oid = get_temp_oid();
142 ASSERT_EQ(0, create(oid, 12, 2));
143 ASSERT_EQ(0, client_register(oid));
144
9f95a23c 145 auto metadata = create_metadata(oid);
7c673cae
FG
146 ASSERT_EQ(0, init_metadata(metadata));
147 ASSERT_EQ(0U, metadata->get_active_set());
148
9f95a23c 149 JournalRecorderPtr recorder = create_recorder(oid, metadata);
7c673cae
FG
150
151 recorder->append(123, create_payload(std::string(metadata->get_object_size() -
152 journal::Entry::get_fixed_size(), '1')));
153 journal::Future future2 = recorder->append(124, create_payload(std::string(1, '2')));
154
155 C_SaferCond cond;
156 future2.flush(&cond);
157 ASSERT_EQ(0, cond.wait());
158
159 ASSERT_EQ(1U, metadata->get_active_set());
160
161 uint64_t object_num;
162 uint64_t tag_tid;
163 uint64_t entry_tid;
164 metadata->get_commit_entry(1, &object_num, &tag_tid, &entry_tid);
165 ASSERT_EQ(0U, object_num);
166 ASSERT_EQ(123U, tag_tid);
167 ASSERT_EQ(0U, entry_tid);
168
169 metadata->get_commit_entry(2, &object_num, &tag_tid, &entry_tid);
170 ASSERT_EQ(2U, object_num);
171 ASSERT_EQ(124U, tag_tid);
172 ASSERT_EQ(0U, entry_tid);
173}
174