Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osd: compact osd feature #16045

Merged
merged 3 commits into from Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions qa/workunits/cephtool/test.sh
Expand Up @@ -2332,6 +2332,12 @@ function test_osd_tell_help_command()
expect_false ceph tell osd.100 help
}

function test_osd_compact()
{
ceph tell osd.1 compact
ceph daemon osd.1 compact
}

function test_mds_tell_help_command()
{
local FS_NAME=cephfs
Expand Down Expand Up @@ -2411,6 +2417,7 @@ OSD_TESTS+=" osd_negative_filestore_merge_threshold"
OSD_TESTS+=" tiering_agent"
OSD_TESTS+=" admin_heap_profiler"
OSD_TESTS+=" osd_tell_help_command"
OSD_TESTS+=" osd_compact"

MDS_TESTS+=" mds_tell"
MDS_TESTS+=" mon_mds"
Expand Down
2 changes: 2 additions & 0 deletions src/os/ObjectMap.h
Expand Up @@ -154,6 +154,8 @@ class ObjectMap {

virtual int check(std::ostream &out, bool repair = false) { return 0; }

virtual void compact() {}

typedef KeyValueDB::GenericIteratorImpl ObjectMapIteratorImpl;
typedef ceph::shared_ptr<ObjectMapIteratorImpl> ObjectMapIterator;
virtual ObjectMapIterator get_iterator(const ghobject_t &oid) {
Expand Down
2 changes: 2 additions & 0 deletions src/os/ObjectStore.h
Expand Up @@ -2020,6 +2020,8 @@ class ObjectStore {
// DEBUG
virtual void inject_data_error(const ghobject_t &oid) {}
virtual void inject_mdata_error(const ghobject_t &oid) {}

virtual void compact() {}
};
WRITE_CLASS_ENCODER(ObjectStore::Transaction)
WRITE_CLASS_ENCODER(ObjectStore::Transaction::TransactionData)
Expand Down
5 changes: 5 additions & 0 deletions src/os/bluestore/BlueStore.h
Expand Up @@ -2377,6 +2377,11 @@ class BlueStore : public ObjectStore,
RWLock::WLocker l(debug_read_error_lock);
debug_mdata_error_objects.insert(o);
}
void compact() override {
assert(db);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to see the impact to front end IO's when compaction is progress, from mark's runs we have seen a slowdown in IO's when compaction is in progress. It is better to warn users when issuing the command. We shouldn't be seeing any timeouts because of this invocation.

db->compact();
}

private:
bool _debug_data_eio(const ghobject_t& o) {
if (!cct->_conf->bluestore_debug_inject_read_err) {
Expand Down
5 changes: 5 additions & 0 deletions src/os/filestore/DBObjectMap.h
Expand Up @@ -230,6 +230,11 @@ class DBObjectMap : public ObjectMap {
/// Ensure that all previous operations are durable
int sync(const ghobject_t *oid=0, const SequencerPosition *spos=0) override;

void compact() override {
assert(db);
db->compact();
}

/// Util, get all objects, there must be no other concurrent access
int list_objects(vector<ghobject_t> *objs ///< [out] objects
);
Expand Down
1 change: 1 addition & 0 deletions src/os/filestore/FileStore.cc
Expand Up @@ -4356,6 +4356,7 @@ void FileStore::inject_mdata_error(const ghobject_t &oid) {
dout(10) << __FUNC__ << ": init error on " << oid << dendl;
mdata_error_set.insert(oid);
}

void FileStore::debug_obj_on_delete(const ghobject_t &oid) {
Mutex::Locker l(read_error_lock);
dout(10) << __FUNC__ << ": clear error on " << oid << dendl;
Expand Down
6 changes: 6 additions & 0 deletions src/os/filestore/FileStore.h
Expand Up @@ -640,6 +640,12 @@ class FileStore : public JournalingObjectStore,
set<ghobject_t> mdata_error_set; // getattr(),stat() will return -EIO
void inject_data_error(const ghobject_t &oid) override;
void inject_mdata_error(const ghobject_t &oid) override;

void compact() override {
assert(object_map);
object_map->compact();
}

void debug_obj_on_delete(const ghobject_t &oid);
bool debug_data_eio(const ghobject_t &oid);
bool debug_mdata_eio(const ghobject_t &oid);
Expand Down
5 changes: 5 additions & 0 deletions src/os/kstore/KStore.h
Expand Up @@ -564,6 +564,11 @@ class KStore : public ObjectStore {
TrackedOpRef op = TrackedOpRef(),
ThreadPool::TPHandle *handle = NULL) override;

void compact () override {
assert(db);
db->compact();
}

private:
// --------------------------------------------------------
// write ops
Expand Down
41 changes: 41 additions & 0 deletions src/osd/OSD.cc
Expand Up @@ -42,6 +42,7 @@

#include "common/errno.h"
#include "common/ceph_argparse.h"
#include "common/ceph_time.h"
#include "common/version.h"
#include "common/io_priority.h"

Expand Down Expand Up @@ -159,6 +160,7 @@
#undef dout_prefix
#define dout_prefix _prefix(_dout, whoami, get_osdmap_epoch())


const double OSD::OSD_TICK_INTERVAL = 1.0;

static ostream& _prefix(std::ostream* _dout, int whoami, epoch_t epoch) {
Expand Down Expand Up @@ -2209,6 +2211,18 @@ bool OSD::asok_command(string admin_command, cmdmap_t& cmdmap, string format,
pg->unlock();
}
f->close_section();
} else if (admin_command == "compact") {
dout(1) << "triggering manual compaction" << dendl;
auto start = ceph::coarse_mono_clock::now();
store->compact();
auto end = ceph::coarse_mono_clock::now();
auto time_span = chrono::duration_cast<chrono::duration<double>>(end - start);
dout(1) << "finished manual compaction in "
<< time_span.count()
<< " seconds" << dendl;
f->open_object_section("compact_result");
f->dump_float("elapsed_time", time_span.count());
f->close_section();
} else {
assert(0 == "broken asok registration");
}
Expand Down Expand Up @@ -2746,6 +2760,12 @@ void OSD::final_init()
"show recent state history");
assert(r == 0);

r = admin_socket->register_command("compact", "compact",
asok_hook,
"Commpact object store's omap."
" WARNING: Compaction probably slows your requests");
assert(r == 0);

test_ops_hook = new TestOpsSocketHook(&(this->service), this->store);
// Note: pools are CephString instead of CephPoolname because
// these commands traditionally support both pool names and numbers
Expand Down Expand Up @@ -3211,12 +3231,15 @@ int OSD::shutdown()
cct->get_admin_socket()->unregister_command("dump_watchers");
cct->get_admin_socket()->unregister_command("dump_reservations");
cct->get_admin_socket()->unregister_command("get_latest_osdmap");
cct->get_admin_socket()->unregister_command("heap");
cct->get_admin_socket()->unregister_command("set_heap_property");
cct->get_admin_socket()->unregister_command("get_heap_property");
cct->get_admin_socket()->unregister_command("dump_objectstore_kv_stats");
cct->get_admin_socket()->unregister_command("dump_scrubs");
cct->get_admin_socket()->unregister_command("calc_objectstore_db_histogram");
cct->get_admin_socket()->unregister_command("flush_store_cache");
cct->get_admin_socket()->unregister_command("dump_pgstate_history");
cct->get_admin_socket()->unregister_command("compact");
delete asok_hook;
asok_hook = NULL;

Expand All @@ -3228,6 +3251,8 @@ int OSD::shutdown()
cct->get_admin_socket()->unregister_command("injectdataerr");
cct->get_admin_socket()->unregister_command("injectmdataerr");
cct->get_admin_socket()->unregister_command("set_recovery_delay");
cct->get_admin_socket()->unregister_command("trigger_scrub");
cct->get_admin_socket()->unregister_command("injectfull");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit looks good.

delete test_ops_hook;
test_ops_hook = NULL;

Expand Down Expand Up @@ -6193,6 +6218,10 @@ COMMAND("dump_pg_recovery_stats", "dump pg recovery statistics",
"osd", "r", "cli,rest")
COMMAND("reset_pg_recovery_stats", "reset pg recovery statistics",
"osd", "rw", "cli,rest")
COMMAND("compact",
"compact object store's omap. "
"WARNING: Compaction probably slows your requests",
"osd", "rw", "cli,rest")
};

void OSD::do_command(Connection *con, ceph_tid_t tid, vector<string>& cmd, bufferlist& data)
Expand Down Expand Up @@ -6607,6 +6636,18 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector<string>& cmd, buffe
}
}

else if (prefix == "compact") {
dout(1) << "triggering manual compaction" << dendl;
auto start = ceph::coarse_mono_clock::now();
store->compact();
auto end = ceph::coarse_mono_clock::now();
auto time_span = chrono::duration_cast<chrono::duration<double>>(end - start);
dout(1) << "finished manual compaction in "
<< time_span.count()
<< " seconds" << dendl;
ss << "compacted omap in " << time_span.count() << " seconds";
}

else {
ss << "unrecognized command! " << cmd;
r = -EINVAL;
Expand Down