m_journal_metadata->flush_commit_position(on_finish);
}
-int JournalTrimmer::remove_objects(bool force) {
- ldout(m_cct, 20) << __func__ << dendl;
- m_async_op_tracker.wait_for_ops();
-
- C_SaferCond ctx;
- {
- Mutex::Locker locker(m_lock);
-
- if (m_remove_set_pending) {
- return -EBUSY;
- }
-
- if (!force) {
- JournalMetadata::RegisteredClients registered_clients;
- m_journal_metadata->get_registered_clients(®istered_clients);
-
- if (registered_clients.size() == 0) {
- return -EINVAL;
- } else if (registered_clients.size() > 1) {
- return -EBUSY;
- }
- }
-
- m_remove_set = std::numeric_limits<uint64_t>::max();
- m_remove_set_pending = true;
- m_remove_set_ctx = &ctx;
-
- remove_set(m_journal_metadata->get_minimum_set());
- }
- return ctx.wait();
-}
-
void JournalTrimmer::remove_objects(bool force, Context *on_finish) {
ldout(m_cct, 20) << __func__ << dendl;
void shut_down(Context *on_finish);
- int remove_objects(bool force);
void remove_objects(bool force, Context *on_finish);
void committed(uint64_t commit_tid);
delete m_threads;
}
-int Journaler::exists(bool *header_exists) const {
- int r = m_header_ioctx.stat(m_header_oid, NULL, NULL);
- if (r < 0 && r != -ENOENT) {
- return r;
- }
-
- *header_exists = (r == 0);
- return 0;
-}
-
void Journaler::exists(Context *on_finish) const {
librados::ObjectReadOperation op;
op.stat(NULL, NULL, NULL);
m_metadata->get_mutable_metadata(minimum_set, active_set, clients, on_finish);
}
-int Journaler::create(uint8_t order, uint8_t splay_width, int64_t pool_id) {
- if (order > 64 || order < 12) {
- lderr(m_cct) << "order must be in the range [12, 64]" << dendl;
- return -EDOM;
- }
- if (splay_width == 0) {
- return -EINVAL;
- }
-
- ldout(m_cct, 5) << "creating new journal: " << m_header_oid << dendl;
- int r = client::create(m_header_ioctx, m_header_oid, order, splay_width,
- pool_id);
- if (r < 0) {
- lderr(m_cct) << "failed to create journal: " << cpp_strerror(r) << dendl;
- return r;
- }
- return 0;
-}
-
void Journaler::create(uint8_t order, uint8_t splay_width,
int64_t pool_id, Context *on_finish) {
if (order > 64 || order < 12) {
comp->release();
}
-int Journaler::remove(bool force) {
- C_SaferCond ctx;
- m_metadata->shut_down(&ctx);
- ctx.wait();
-
- ldout(m_cct, 5) << "removing journal: " << m_header_oid << dendl;
- int r = m_trimmer->remove_objects(force);
- if (r < 0) {
- lderr(m_cct) << "failed to remove journal objects: " << cpp_strerror(r)
- << dendl;
- return r;
- }
-
- r = m_header_ioctx.remove(m_header_oid);
- if (r < 0) {
- lderr(m_cct) << "failed to remove journal header: " << cpp_strerror(r)
- << dendl;
- return r;
- }
- return 0;
-}
-
void Journaler::remove(bool force, Context *on_finish) {
// chain journal removal (reverse order)
on_finish = new FunctionContext([this, on_finish](int r) {
const std::string &client_id, const Settings &settings);
~Journaler();
- int exists(bool *header_exists) const;
void exists(Context *on_finish) const;
- int create(uint8_t order, uint8_t splay_width, int64_t pool_id);
void create(uint8_t order, uint8_t splay_width, int64_t pool_id, Context *ctx);
- int remove(bool force);
void remove(bool force, Context *on_finish);
void init(Context *on_init);
}
}
- r = journaler.remove(true);
+ C_SaferCond ctx1;
+ journaler.remove(true, &ctx1);
+ r = ctx1.wait();
if (r < 0) {
lderr(cct) << __func__ << ": "
<< "failed to reset journal: " << cpp_strerror(r) << dendl;
MockJournaler::get_instance().construct();
}
- int exists(bool *header_exists) const {
- return -EINVAL;
+ void exists(Context *on_finish) const {
+ on_finish->complete(-EINVAL);
}
- int create(uint8_t order, uint8_t splay_width, int64_t pool_id) {
- return -EINVAL;
+ void create(uint8_t order, uint8_t splay_width, int64_t pool_id, Context *on_finish) {
+ on_finish->complete(-EINVAL);
}
- int remove(bool force) {
- return -EINVAL;
+ void remove(bool force, Context *on_finish) {
+ on_finish->complete(-EINVAL);
}
int register_client(const bufferlist &data) {
return -EINVAL;
journal::JournalTrimmer *trimmer = create_trimmer(oid, metadata);
- ASSERT_EQ(0, trimmer->remove_objects(false));
+ 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_TRUE(wait_for_update(metadata));
journal::JournalTrimmer *trimmer = create_trimmer(oid, metadata);
- ASSERT_EQ(-EBUSY, trimmer->remove_objects(false));
- ASSERT_EQ(0, trimmer->remove_objects(true));
+
+ 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());
}
}
int create_journal(uint8_t order, uint8_t splay_width) {
- return m_journaler->create(order, splay_width, -1);
+ C_SaferCond cond;
+ m_journaler->create(order, splay_width, -1, &cond);
+ return cond.wait();
}
int init_journaler() {