summaryrefslogtreecommitdiffstats
path: root/src/journal
diff options
context:
space:
mode:
authorMykola Golub <mgolub@mirantis.com>2015-09-18 08:23:53 +0200
committerMykola Golub <mgolub@mirantis.com>2015-12-04 12:18:30 +0100
commite8a584ffc1ddd12e0f55a3b0263d8f29322b0ea4 (patch)
treecccbc9ac4097a9e1c4d7a0a8ecd6dacc05fd5b32 /src/journal
parentlibrbd: humanize ImageWatcher and Journal states in debug log (diff)
downloadceph-e8a584ffc1ddd12e0f55a3b0263d8f29322b0ea4.tar.xz
ceph-e8a584ffc1ddd12e0f55a3b0263d8f29322b0ea4.zip
rbd: add new journal rbd commands
Also, extend 'rbd info' to output journal spec if journaling is enabled. Signed-off-by: Mykola Golub <mgolub@mirantis.com>
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/JournalTrimmer.cc19
-rw-r--r--src/journal/JournalTrimmer.h2
-rw-r--r--src/journal/Journaler.cc38
-rw-r--r--src/journal/Journaler.h12
4 files changed, 56 insertions, 15 deletions
diff --git a/src/journal/JournalTrimmer.cc b/src/journal/JournalTrimmer.cc
index 33e3be2c5b0..9e781cebd01 100644
--- a/src/journal/JournalTrimmer.cc
+++ b/src/journal/JournalTrimmer.cc
@@ -29,22 +29,29 @@ JournalTrimmer::~JournalTrimmer() {
m_async_op_tracker.wait_for_ops();
}
-int JournalTrimmer::remove_objects() {
+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);
- JournalMetadata::RegisteredClients registered_clients;
- m_journal_metadata->get_registered_clients(&registered_clients);
- if (registered_clients.size() == 0) {
- return -EINVAL;
- } else if (registered_clients.size() > 1 || m_remove_set_pending) {
+ if (m_remove_set_pending) {
return -EBUSY;
}
+ if (!force) {
+ JournalMetadata::RegisteredClients registered_clients;
+ m_journal_metadata->get_registered_clients(&registered_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;
diff --git a/src/journal/JournalTrimmer.h b/src/journal/JournalTrimmer.h
index 9f557a7671b..46db1c51bab 100644
--- a/src/journal/JournalTrimmer.h
+++ b/src/journal/JournalTrimmer.h
@@ -22,7 +22,7 @@ public:
const JournalMetadataPtr &journal_metadata);
~JournalTrimmer();
- int remove_objects();
+ int remove_objects(bool force);
void committed(uint64_t commit_tid);
private:
diff --git a/src/journal/Journaler.cc b/src/journal/Journaler.cc
index 231cc0400d7..25a50b89bed 100644
--- a/src/journal/Journaler.cc
+++ b/src/journal/Journaler.cc
@@ -42,6 +42,15 @@ struct C_DeleteRecorder : public Context {
using namespace cls::journal;
+std::string Journaler::header_oid(const std::string &journal_id) {
+ return JOURNAL_HEADER_PREFIX + journal_id;
+}
+
+std::string Journaler::object_oid_prefix(int pool_id,
+ const std::string &journal_id) {
+ return JOURNAL_OBJECT_PREFIX + stringify(pool_id) + "." + journal_id + ".";
+}
+
Journaler::Journaler(librados::IoCtx &header_ioctx,
const std::string &journal_id,
const std::string &client_id, double commit_interval)
@@ -51,9 +60,8 @@ Journaler::Journaler(librados::IoCtx &header_ioctx,
m_header_ioctx.dup(header_ioctx);
m_cct = reinterpret_cast<CephContext *>(m_header_ioctx.cct());
- m_header_oid = JOURNAL_HEADER_PREFIX + journal_id;
- m_object_oid_prefix = JOURNAL_OBJECT_PREFIX +
- stringify(m_header_ioctx.get_id()) + "." + journal_id + ".";
+ m_header_oid = header_oid(journal_id);
+ m_object_oid_prefix = object_oid_prefix(m_header_ioctx.get_id(), journal_id);
m_metadata = new JournalMetadata(m_header_ioctx, m_header_oid, m_client_id,
commit_interval);
@@ -108,6 +116,10 @@ int Journaler::init_complete() {
return 0;
}
+void Journaler::shutdown() {
+ m_metadata->shutdown();
+}
+
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;
@@ -127,10 +139,11 @@ int Journaler::create(uint8_t order, uint8_t splay_width, int64_t pool_id) {
return 0;
}
-int Journaler::remove() {
+int Journaler::remove(bool force) {
m_metadata->shutdown();
- int r = m_trimmer->remove_objects();
+ 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;
@@ -165,7 +178,8 @@ void Journaler::start_live_replay(ReplayHandler *replay_handler,
m_player->prefetch_and_watch(interval);
}
-bool Journaler::try_pop_front(ReplayEntry *replay_entry) {
+bool Journaler::try_pop_front(ReplayEntry *replay_entry,
+ std::string* tag) {
assert(m_player != NULL);
Entry entry;
@@ -175,6 +189,9 @@ bool Journaler::try_pop_front(ReplayEntry *replay_entry) {
}
*replay_entry = ReplayEntry(entry.get_data(), commit_tid);
+ if (tag != NULL) {
+ *tag = entry.get_tag();
+ }
return true;
}
@@ -226,6 +243,15 @@ void Journaler::create_player(ReplayHandler *replay_handler) {
replay_handler);
}
+void Journaler::get_metadata(uint8_t *order, uint8_t *splay_width,
+ int64_t *pool_id) {
+ assert(m_metadata != NULL);
+
+ *order = m_metadata->get_order();
+ *splay_width = m_metadata->get_splay_width();
+ *pool_id = m_metadata->get_pool_id();
+}
+
std::ostream &operator<<(std::ostream &os,
const Journaler &journaler) {
os << "[metadata=";
diff --git a/src/journal/Journaler.h b/src/journal/Journaler.h
index 1230e409b2d..48c800d407f 100644
--- a/src/journal/Journaler.h
+++ b/src/journal/Journaler.h
@@ -26,22 +26,28 @@ class ReplayHandler;
class Journaler {
public:
+
+ static std::string header_oid(const std::string &journal_id);
+ static std::string object_oid_prefix(int pool_id,
+ const std::string &journal_id);
+
Journaler(librados::IoCtx &header_ioctx, const std::string &journal_id,
const std::string &client_id, double commit_interval);
~Journaler();
int exists(bool *header_exists) const;
int create(uint8_t order, uint8_t splay_width, int64_t pool_id);
- int remove();
+ int remove(bool force);
void init(Context *on_init);
+ void shutdown();
int register_client(const std::string &description);
int unregister_client();
void start_replay(ReplayHandler *replay_handler);
void start_live_replay(ReplayHandler *replay_handler, double interval);
- bool try_pop_front(ReplayEntry *replay_entry);
+ bool try_pop_front(ReplayEntry *replay_entry, std::string* tag = NULL);
void stop_replay();
void start_append(int flush_interval, uint64_t flush_bytes, double flush_age);
@@ -52,6 +58,8 @@ public:
void committed(const ReplayEntry &replay_entry);
void committed(const Future &future);
+ void get_metadata(uint8_t *order, uint8_t *splay_width, int64_t *pool_id);
+
private:
struct C_InitJournaler : public Context {
Journaler *journaler;