1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "journal/JournalTrimmer.h"
#include "journal/JournalMetadata.h"
#include "include/stringify.h"
#include "test/journal/RadosTestFixture.h"
#include <limits>
#include <list>
class TestJournalTrimmer : public RadosTestFixture {
public:
void TearDown() override {
for (MetadataList::iterator it = m_metadata_list.begin();
it != m_metadata_list.end(); ++it) {
(*it)->remove_listener(&m_listener);
}
m_metadata_list.clear();
for (std::list<journal::JournalTrimmer*>::iterator it = m_trimmers.begin();
it != m_trimmers.end(); ++it) {
C_SaferCond ctx;
(*it)->shut_down(&ctx);
ASSERT_EQ(0, ctx.wait());
delete *it;
}
RadosTestFixture::TearDown();
}
int append_payload(const ceph::ref_t<journal::JournalMetadata>& metadata,
const std::string &oid, uint64_t object_num,
const std::string &payload, uint64_t *commit_tid) {
int r = append(oid + "." + stringify(object_num), create_payload(payload));
uint64_t tid = metadata->allocate_commit_tid(object_num, 234, 123);
if (commit_tid != NULL) {
*commit_tid = tid;
}
return r;
}
auto create_metadata(const std::string &oid) {
auto metadata = RadosTestFixture::create_metadata(oid);
m_metadata_list.push_back(metadata);
metadata->add_listener(&m_listener);
return metadata;
}
journal::JournalTrimmer *create_trimmer(const std::string &oid,
const ceph::ref_t<journal::JournalMetadata>& metadata) {
journal::JournalTrimmer *trimmer(new journal::JournalTrimmer(
m_ioctx, oid + ".", metadata));
m_trimmers.push_back(trimmer);
return trimmer;
}
int assert_exists(const std::string &oid) {
librados::ObjectWriteOperation op;
op.assert_exists();
return m_ioctx.operate(oid, &op);
}
typedef std::list<ceph::ref_t<journal::JournalMetadata>> MetadataList;
MetadataList m_metadata_list;
std::list<journal::JournalTrimmer*> m_trimmers;
};
TEST_F(TestJournalTrimmer, Committed) {
std::string oid = get_temp_oid();
ASSERT_EQ(0, create(oid, 12, 2));
ASSERT_EQ(0, client_register(oid));
auto metadata = create_metadata(oid);
ASSERT_EQ(0, init_metadata(metadata));
ASSERT_TRUE(wait_for_update(metadata));
ASSERT_EQ(0, metadata->set_active_set(10));
ASSERT_TRUE(wait_for_update(metadata));
uint64_t commit_tid1;
uint64_t commit_tid2;
uint64_t commit_tid3;
uint64_t commit_tid4;
uint64_t commit_tid5;
uint64_t commit_tid6;
ASSERT_EQ(0, append_payload(metadata, oid, 0, "payload", &commit_tid1));
ASSERT_EQ(0, append_payload(metadata, oid, 4, "payload", &commit_tid2));
ASSERT_EQ(0, append_payload(metadata, oid, 5, "payload", &commit_tid3));
ASSERT_EQ(0, append_payload(metadata, oid, 0, "payload", &commit_tid4));
ASSERT_EQ(0, append_payload(metadata, oid, 4, "payload", &commit_tid5));
ASSERT_EQ(0, append_payload(metadata, oid, 5, "payload", &commit_tid6));
journal::JournalTrimmer *trimmer = create_trimmer(oid, metadata);
trimmer->committed(commit_tid4);
trimmer->committed(commit_tid6);
trimmer->committed(commit_tid2);
trimmer->committed(commit_tid5);
trimmer->committed(commit_tid3);
trimmer->committed(commit_tid1);
while (metadata->get_minimum_set() != 2U) {
ASSERT_TRUE(wait_for_update(metadata));
}
ASSERT_EQ(-ENOENT, assert_exists(oid + ".0"));
ASSERT_EQ(-ENOENT, assert_exists(oid + ".2"));
ASSERT_EQ(0, assert_exists(oid + ".5"));
}
TEST_F(TestJournalTrimmer, CommittedWithOtherClient) {
std::string oid = get_temp_oid();
ASSERT_EQ(0, create(oid, 12, 2));
ASSERT_EQ(0, client_register(oid));
ASSERT_EQ(0, client_register(oid, "client2", "slow client"));
auto metadata = create_metadata(oid);
ASSERT_EQ(0, init_metadata(metadata));
ASSERT_TRUE(wait_for_update(metadata));
ASSERT_EQ(0, metadata->set_active_set(10));
ASSERT_TRUE(wait_for_update(metadata));
uint64_t commit_tid1;
uint64_t commit_tid2;
uint64_t commit_tid3;
uint64_t commit_tid4;
ASSERT_EQ(0, append_payload(metadata, oid, 0, "payload", &commit_tid1));
ASSERT_EQ(0, append_payload(metadata, oid, 2, "payload", &commit_tid2));
ASSERT_EQ(0, append_payload(metadata, oid, 3, "payload", &commit_tid3));
ASSERT_EQ(0, append_payload(metadata, oid, 5, "payload", &commit_tid4));
journal::JournalTrimmer *trimmer = create_trimmer(oid, metadata);
trimmer->committed(commit_tid1);
trimmer->committed(commit_tid2);
trimmer->committed(commit_tid3);
trimmer->committed(commit_tid4);
ASSERT_TRUE(wait_for_update(metadata));
ASSERT_EQ(0, assert_exists(oid + ".0"));
ASSERT_EQ(0, assert_exists(oid + ".2"));
ASSERT_EQ(0, assert_exists(oid + ".3"));
ASSERT_EQ(0, assert_exists(oid + ".5"));
}
TEST_F(TestJournalTrimmer, RemoveObjects) {
std::string oid = get_temp_oid();
ASSERT_EQ(0, create(oid, 12, 2));
ASSERT_EQ(0, client_register(oid));
auto metadata = create_metadata(oid);
ASSERT_EQ(0, init_metadata(metadata));
ASSERT_TRUE(wait_for_update(metadata));
ASSERT_EQ(0, metadata->set_active_set(10));
ASSERT_TRUE(wait_for_update(metadata));
ASSERT_EQ(0, append(oid + ".0", create_payload("payload")));
ASSERT_EQ(0, append(oid + ".2", create_payload("payload")));
ASSERT_EQ(0, append(oid + ".3", create_payload("payload")));
ASSERT_EQ(0, append(oid + ".5", create_payload("payload")));
journal::JournalTrimmer *trimmer = create_trimmer(oid, metadata);
C_SaferCond cond;
trimmer->remove_objects(false, &cond);
ASSERT_EQ(0, cond.wait());
ASSERT_TRUE(wait_for_update(metadata));
ASSERT_EQ(-ENOENT, assert_exists(oid + ".0"));
ASSERT_EQ(-ENOENT, assert_exists(oid + ".2"));
ASSERT_EQ(-ENOENT, assert_exists(oid + ".3"));
ASSERT_EQ(-ENOENT, assert_exists(oid + ".5"));
}
TEST_F(TestJournalTrimmer, RemoveObjectsWithOtherClient) {
std::string oid = get_temp_oid();
ASSERT_EQ(0, create(oid, 12, 2));
ASSERT_EQ(0, client_register(oid));
ASSERT_EQ(0, client_register(oid, "client2", "other client"));
auto metadata = create_metadata(oid);
ASSERT_EQ(0, init_metadata(metadata));
ASSERT_TRUE(wait_for_update(metadata));
journal::JournalTrimmer *trimmer = create_trimmer(oid, metadata);
C_SaferCond ctx1;
trimmer->remove_objects(false, &ctx1);
ASSERT_EQ(-EBUSY, ctx1.wait());
C_SaferCond ctx2;
trimmer->remove_objects(true, &ctx2);
ASSERT_EQ(0, ctx2.wait());
}
|