}
const coll_t coll_t::META_COLL("meta");
-const coll_t coll_t::TEMP_COLL("temp");
static CompatSet get_osd_compat_set() {
CompatSet::FeatureSet ceph_osd_feature_compat;
ObjectStore::Transaction t;
t.create_collection(coll_t::META_COLL);
t.write(coll_t::META_COLL, OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl);
- t.create_collection(coll_t::TEMP_COLL);
ret = store->apply_transaction(t);
if (ret) {
derr << "OSD::mkfs: error while writing OSD_SUPERBLOCK_POBJECT: "
bind_epoch = osdmap->get_epoch();
- clear_temp();
-
- // make sure (newish) temp dir exists
- if (!store->collection_exists(coll_t::TEMP_COLL)) {
- dout(10) << "creating temp pg dir" << dendl;
- ObjectStore::Transaction t;
- t.create_collection(coll_t::TEMP_COLL);
- store->apply_transaction(t);
- }
-
// load up pgs (as they previously existed)
load_pgs();
-void OSD::clear_temp()
+void OSD::clear_temp(coll_t tmp)
{
dout(10) << "clear_temp" << dendl;
vector<hobject_t> objects;
- store->collection_list(coll_t::TEMP_COLL, objects);
+ store->collection_list(tmp, objects);
dout(10) << objects.size() << " objects" << dendl;
if (objects.empty())
for (vector<hobject_t>::iterator p = objects.begin();
p != objects.end();
p++)
- t->collection_remove(coll_t::TEMP_COLL, *p);
+ t->collection_remove(tmp, *p);
+ t->remove_collection(tmp);
int r = store->queue_transaction(NULL, t);
assert(r == 0);
store->sync_and_flush();
pg_t pgid;
snapid_t snap;
if (!it->is_pg(pgid, snap)) {
+ if (it->is_temp(pgid))
+ clear_temp(*it);
dout(10) << "load_pgs skipping non-pg " << *it << dendl;
continue;
}
assert(tr == 0);
}
+ if (store->collection_exists(coll_t::make_temp_coll(pg->get_pgid()))) {
+ clear_temp(coll_t::make_temp_coll(pg->get_pgid()));
+ }
// on_removal, which calls remove_watchers_and_notifies, and the erasure from
// the pg_map must be done together without unlocking the pg lock,
friend class C_OSD_GetVersion;
- void clear_temp();
+ void clear_temp(coll_t tmp);
// -- alive --
epoch_t up_thru_wanted;
}
ReplicatedPG::ReplicatedPG(OSD *o, PGPool *_pool, pg_t p, const hobject_t& oid, const hobject_t& ioid) :
- PG(o, _pool, p, oid, ioid), snap_trimmer_machine(this)
+ PG(o, _pool, p, oid, ioid), temp_created(false),
+ temp_coll(coll_t::make_temp_coll(p)), snap_trimmer_machine(this)
{
snap_trimmer_machine.initiate();
}
}
}
+coll_t ReplicatedPG::get_temp_coll(ObjectStore::Transaction *t)
+{
+ if (temp_created)
+ return temp_coll;
+ if (!osd->store->collection_exists(temp_coll))
+ t->create_collection(temp_coll);
+ temp_created = true;
+ return temp_coll;
+}
int ReplicatedPG::prepare_transaction(OpContext *ctx)
{
ObjectStore::Transaction *t)
{
if (first) {
- t->remove(coll_t::TEMP_COLL, recovery_info.soid);
- t->touch(coll_t::TEMP_COLL, recovery_info.soid);
- t->omap_setheader(coll_t::TEMP_COLL, recovery_info.soid, omap_header);
+ t->remove(get_temp_coll(t), recovery_info.soid);
+ t->touch(get_temp_coll(t), recovery_info.soid);
+ t->omap_setheader(get_temp_coll(t), recovery_info.soid, omap_header);
}
uint64_t off = 0;
for (interval_set<uint64_t>::const_iterator p = intervals_included.begin();
++p) {
bufferlist bit;
bit.substr_of(data_included, off, p.get_len());
- t->write(coll_t::TEMP_COLL, recovery_info.soid,
+ t->write(get_temp_coll(t), recovery_info.soid,
p.get_start(), p.get_len(), bit);
off += p.get_len();
}
- t->omap_setkeys(coll_t::TEMP_COLL, recovery_info.soid,
+ t->omap_setkeys(get_temp_coll(t), recovery_info.soid,
omap_entries);
- t->setattrs(coll_t::TEMP_COLL, recovery_info.soid,
+ t->setattrs(get_temp_coll(t), recovery_info.soid,
attrs);
}
ObjectStore::Transaction *t)
{
remove_object_with_snap_hardlinks(*t, recovery_info.soid);
- t->collection_move(coll, coll_t::TEMP_COLL, recovery_info.soid);
+ t->collection_move(coll, get_temp_coll(t), recovery_info.soid);
for (map<hobject_t, interval_set<uint64_t> >::const_iterator p =
recovery_info.clone_subset.begin();
p != recovery_info.clone_subset.end();
int do_osd_ops(OpContext *ctx, vector<OSDOp>& ops);
void do_osd_op_effects(OpContext *ctx);
private:
+ bool temp_created;
+ coll_t temp_coll;
+ coll_t get_temp_coll(ObjectStore::Transaction *t);
struct NotTrimming;
struct SnapTrim : boost::statechart::event< SnapTrim > {
SnapTrim() : boost::statechart::event < SnapTrim >() {}
// -- coll_t --
+bool coll_t::is_temp(pg_t& pgid) const
+{
+ const char *cstr(str.c_str());
+ if (!pgid.parse(cstr))
+ return false;
+ const char *tmp_start = strchr(cstr, '_');
+ if (!tmp_start)
+ return false;
+ if (strncmp(tmp_start, "_TEMP", 4) == 0)
+ return true;
+ return false;
+}
+
bool coll_t::is_pg(pg_t& pgid, snapid_t& snap) const
{
const char *cstr(str.c_str());
class coll_t {
public:
const static coll_t META_COLL;
- const static coll_t TEMP_COLL;
coll_t()
: str("meta")
: str(pg_and_snap_to_str(pgid, snap))
{ }
+ static coll_t make_temp_coll(pg_t pgid) {
+ return coll_t(pg_to_tmp_str(pgid));
+ }
+
const std::string& to_str() const {
return str;
}
}
bool is_pg(pg_t& pgid, snapid_t& snap) const;
+ bool is_temp(pg_t& pgid) const;
void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& bl);
inline bool operator==(const coll_t& rhs) const {
oss << p << "_" << s;
return oss.str();
}
+ static std::string pg_to_tmp_str(pg_t p) {
+ std::ostringstream oss;
+ oss << p << "_TEMP";
+ return oss.str();
+ }
std::string str;
};