return buf;
}
-void PG::read_state(ObjectStore *store, bufferlist &bl)
+int PG::read_info(ObjectStore *store, const coll_t coll, bufferlist &bl,
+ pg_info_t &info, map<epoch_t,pg_interval_t> &past_intervals,
+ hobject_t &biginfo_oid, interval_set<snapid_t> &snap_collections)
{
bufferlist::iterator p = bl.begin();
__u8 struct_v;
::decode(struct_v, p);
} else {
bl.clear();
- store->read(coll_t::META_COLL, biginfo_oid, 0, 0, bl);
+ int r = store->read(coll_t::META_COLL, biginfo_oid, 0, 0, bl);
+ if (r < 0)
+ return r;
p = bl.begin();
::decode(past_intervals, p);
}
if (struct_v >= 4)
::decode(info, p);
}
+ return 0;
+}
+
+void PG::read_state(ObjectStore *store, bufferlist &bl)
+{
+ int r = read_info(store, coll, bl, info, past_intervals, biginfo_oid,
+ snap_collections);
+ assert(r >= 0);
try {
- read_log(store);
+ ostringstream oss;
+ read_log(store, coll, log_oid, info, ondisklog, log, missing, oss, this);
+ osd->clog.error() << oss;
}
catch (const buffer::error &e) {
string cr_log_coll_name(get_corrupt_pg_log_name());
return oss;
}
-void PG::read_log(ObjectStore *store)
+/*---------------------------------------------------*/
+// Handle staitc function so it can use dout()
+#undef dout_prefix
+#define dout_prefix if (passedpg) _prefix(_dout, passedpg)
+
+void PG::read_log(ObjectStore *store, coll_t coll, hobject_t log_oid,
+ const pg_info_t &info, OndiskLog &ondisklog, IndexedLog &log,
+ pg_missing_t &missing, ostringstream &oss, const PG *passedpg)
{
// load bounds
ondisklog.tail = ondisklog.head = 0;
// [repair] in order?
if (e.version < last) {
dout(0) << "read_log " << pos << " out of order entry " << e << " follows " << last << dendl;
- osd->clog.error() << info.pgid << " log has out of order entry "
+ oss << info.pgid << " log has out of order entry "
<< e << " following " << last << "\n";
reorder = true;
}
if (last.version == e.version.version) {
dout(0) << "read_log got dup " << e.version << " (last was " << last << ", dropping that one)" << dendl;
log.log.pop_back();
- osd->clog.error() << info.pgid << " read_log got dup "
+ oss << info.pgid << " read_log got dup "
<< e.version << " after " << last << "\n";
}
// [repair] at end of log?
if (!p.end() && e.version == info.last_update) {
- osd->clog.error() << info.pgid << " log has extra data at "
+ oss << info.pgid << " log has extra data at "
<< endpos << "~" << (ondisklog.head-endpos) << " after "
<< info.last_update << "\n";
if (i->is_delete()) continue;
bufferlist bv;
- int r = osd->store->getattr(coll, i->soid, OI_ATTR, bv);
+ int r = store->getattr(coll, i->soid, OI_ATTR, bv);
if (r >= 0) {
object_info_t oi(bv);
if (oi.version < i->version) {
if (did.count(i->second)) continue;
did.insert(i->second);
bufferlist bv;
- int r = osd->store->getattr(coll, i->second, OI_ATTR, bv);
+ int r = store->getattr(coll, i->second, OI_ATTR, bv);
if (r >= 0) {
object_info_t oi(bv);
/**
void add_log_entry(pg_log_entry_t& e, bufferlist& log_bl);
void append_log(vector<pg_log_entry_t>& logv, eversion_t trim_to, ObjectStore::Transaction &t);
- void read_log(ObjectStore *store);
+ static void read_log(ObjectStore *store, coll_t coll, hobject_t log_oid,
+ const pg_info_t &info, OndiskLog &ondisklog, IndexedLog &log,
+ pg_missing_t &missing, ostringstream &oss, const PG *passedpg = NULL);
bool check_log_for_corruption(ObjectStore *store);
void trim(ObjectStore::Transaction& t, eversion_t v);
void trim_ondisklog(ObjectStore::Transaction& t);
void trim_peers();
std::string get_corrupt_pg_log_name() const;
+ static int read_info(ObjectStore *store, const coll_t coll,
+ bufferlist &bl, pg_info_t &info, map<epoch_t,pg_interval_t> &past_intervals,
+ hobject_t &biginfo_oid, interval_set<snapid_t> &snap_collections);
void read_state(ObjectStore *store, bufferlist &bl);
static epoch_t peek_map_epoch(ObjectStore *store,
coll_t coll, bufferlist *bl);
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2013 Inktank
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include <boost/scoped_ptr.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/program_options/option.hpp>
+#include <boost/program_options/options_description.hpp>
+#include <boost/program_options/variables_map.hpp>
+#include <boost/program_options/cmdline.hpp>
+#include <boost/program_options/parsers.hpp>
+#include <iostream>
+#include <set>
+#include <sstream>
+#include <stdlib.h>
+#include <fstream>
+#include <iostream>
+
+#include "common/Formatter.h"
+
+#include "global/global_init.h"
+#include "os/ObjectStore.h"
+#include "os/FileStore.h"
+#include "common/perf_counters.h"
+#include "common/errno.h"
+#include "osd/PG.h"
+#include "osd/OSD.h"
+
+namespace po = boost::program_options;
+using namespace std;
+
+static void invalid_path(string &path)
+{
+ cout << "Invalid path to osd store specified: " << path << "\n";
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ string fspath, jpath, pgid, type;
+ Formatter *formatter = new JSONFormatter(true);
+
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "produce help message")
+ ("filestore-path", po::value<string>(&fspath)->required(),
+ "path to filestore directory, mandatory")
+ ("journal-path", po::value<string>(&jpath)->required(),
+ "path to journal, mandatory")
+ ("pgid", po::value<string>(&pgid)->required(),
+ "PG id, mandatory")
+ ("type", po::value<string>(&type)->required(),
+ "Type which is 'info' or 'log'")
+ ("debug", "Enable diagnostic output to stderr")
+ ;
+
+ po::variables_map vm;
+ po::parsed_options parsed =
+ po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
+ po::store( parsed, vm);
+ try {
+ po::notify(vm);
+ }
+ catch(...) {
+ cout << desc << "\n";
+ exit(1);
+ }
+
+ //Never get here with required() options
+ if (vm.count("help")) {
+ cout << desc << "\n";
+ exit(1);
+ }
+
+ vector<const char *> ceph_options, def_args;
+ vector<string> ceph_option_strings = po::collect_unrecognized(
+ parsed.options, po::include_positional);
+ ceph_options.reserve(ceph_option_strings.size());
+ for (vector<string>::iterator i = ceph_option_strings.begin();
+ i != ceph_option_strings.end();
+ ++i) {
+ ceph_options.push_back(i->c_str());
+ }
+
+ //Suppress derr() output to stderr by default
+ if (!vm.count("debug")) {
+ close(2);
+ (void)open("/dev/null", O_WRONLY);
+ }
+
+ global_init(
+ &def_args, ceph_options, CEPH_ENTITY_TYPE_OSD,
+ CODE_ENVIRONMENT_UTILITY, 0);
+ //CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
+ common_init_finish(g_ceph_context);
+ g_ceph_context->_conf->apply_changes(NULL);
+ g_conf = g_ceph_context->_conf;
+
+ if (!vm.count("filestore-path") || !vm.count("journal-path")) {
+ cout << "Must provide filestore-path and journal-path" << std::endl
+ << desc << std::endl;
+ return 1;
+ }
+
+ if (vm.count("help")) {
+ cout << desc << std::endl;
+ return 1;
+ }
+
+ if (fspath.length() == 0 || jpath.length() == 0 || pgid.length() == 0 ||
+ (type != "info" && type != "log")) {
+ cerr << "Invalid params" << std::endl;
+ exit(1);
+ }
+
+ //Verify that fspath really is an osd store
+ struct stat st;
+ if (::stat(fspath.c_str(), &st) == -1) {
+ perror("fspath");
+ invalid_path(fspath);
+ }
+ if (!S_ISDIR(st.st_mode)) {
+ invalid_path(fspath);
+ }
+ string check = fspath + "/whoami";
+ if (::stat(check.c_str(), &st) == -1) {
+ perror("whoami");
+ invalid_path(fspath);
+ }
+ if (!S_ISREG(st.st_mode)) {
+ invalid_path(fspath);
+ }
+ check = fspath + "/current";
+ if (::stat(check.c_str(), &st) == -1) {
+ perror("current");
+ invalid_path(fspath);
+ }
+ if (!S_ISDIR(st.st_mode)) {
+ invalid_path(fspath);
+ }
+
+ pg_t arg_pgid;
+ if (!arg_pgid.parse(pgid.c_str())) {
+ cerr << "Invalid pgid '" << pgid << "' specified" << std::endl;
+ exit(1);
+ }
+
+ int ret = 0;
+
+ ObjectStore *fs = new FileStore(fspath, jpath);
+
+ if (fs->mount() < 0) {
+ cout << "mount failed" << std::endl;
+ return 1;
+ }
+
+ bool found = false;
+ vector<coll_t> ls;
+ int r = fs->list_collections(ls);
+ if (r < 0) {
+ cerr << "failed to list pgs: " << cpp_strerror(-r) << std::endl;
+ exit(1);
+ }
+
+ for (vector<coll_t>::iterator it = ls.begin();
+ it != ls.end();
+ it++) {
+ coll_t coll = *it;
+ pg_t pgid;
+ snapid_t snap;
+ if (!it->is_pg(pgid, snap)) {
+ continue;
+ }
+
+ if (pgid != arg_pgid) {
+ continue;
+ }
+ if (snap != CEPH_NOSNAP) {
+ cout << "load_pgs skipping snapped dir " << coll
+ << " (pg " << pgid << " snap " << snap << ")" << std::endl;
+ continue;
+ }
+
+ bufferlist bl;
+ epoch_t map_epoch = PG::peek_map_epoch(fs, coll, &bl);
+ (void)map_epoch;
+
+ found = true;
+
+ pg_info_t info;
+ map<epoch_t,pg_interval_t> past_intervals;
+ hobject_t biginfo_oid = OSD::make_pg_biginfo_oid(pgid);
+ interval_set<snapid_t> snap_collections;
+
+ int r = PG::read_info(fs, coll, bl, info, past_intervals, biginfo_oid,
+ snap_collections);
+ if (r < 0) {
+ cerr << "read_info error " << cpp_strerror(-r) << std::endl;
+ ret = 1;
+ continue;
+ }
+
+ if (type == "info") {
+ formatter->open_object_section("info");
+ info.dump(formatter);
+ formatter->close_section();
+ formatter->flush(cout);
+ cout << std::endl;
+ break;
+ } else if (type == "log") {
+ PG::OndiskLog ondisklog;
+ PG::IndexedLog log;
+ pg_missing_t missing;
+ hobject_t logoid = OSD::make_pg_log_oid(pgid);
+ try {
+ ostringstream oss;
+ PG::read_log(fs, coll, logoid, info, ondisklog, log, missing, oss);
+ if (vm.count("debug"))
+ cerr << oss;
+ }
+ catch (const buffer::error &e) {
+ cerr << "read_log threw exception error", e.what();
+ ret = 1;
+ break;
+ }
+
+ formatter->open_object_section("log");
+ log.dump(formatter);
+ formatter->close_section();
+ formatter->flush(cout);
+ cout << std::endl;
+ formatter->open_object_section("missing");
+ missing.dump(formatter);
+ formatter->close_section();
+ formatter->flush(cout);
+ cout << std::endl;
+
+ }
+ }
+
+ if (!found) {
+ cerr << "PG '" << arg_pgid << "' not found" << std::endl;
+ ret = 1;
+ }
+
+ if (fs->umount() < 0) {
+ cerr << "umount failed" << std::endl;
+ return 1;
+ }
+
+ return ret;
+}
+