mirror of
https://github.com/ceph/ceph
synced 2025-01-03 09:32:43 +00:00
test_filestore_idempotent_sequence: add omap
Signed-off-by: Samuel Just <sam.just@inktank.com>
This commit is contained in:
parent
a2eedec5ec
commit
5250e24764
@ -79,6 +79,9 @@ void DeterministicOpSequence::run_one_op(int op, rngen_t& gen)
|
||||
case DSOP_COLL_RENAME:
|
||||
//do_coll_rename(gen);
|
||||
break;
|
||||
case DSOP_SET_ATTRS:
|
||||
do_set_attrs(gen);
|
||||
break;
|
||||
default:
|
||||
assert(0 == "bad op");
|
||||
}
|
||||
@ -166,8 +169,8 @@ void DeterministicOpSequence::do_remove(rngen_t& gen)
|
||||
_do_touch(entry->m_coll, *obj);
|
||||
}
|
||||
|
||||
void DeterministicOpSequence::_gen_random(rngen_t& gen,
|
||||
size_t size, bufferlist& bl) {
|
||||
static void _gen_random(rngen_t& gen,
|
||||
size_t size, bufferlist& bl) {
|
||||
|
||||
static const char alphanum[] = "0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@ -182,6 +185,46 @@ void DeterministicOpSequence::_gen_random(rngen_t& gen,
|
||||
bl.append(bp);
|
||||
}
|
||||
|
||||
static void gen_attrs(rngen_t &gen,
|
||||
map<string, bufferlist> *out) {
|
||||
boost::uniform_int<> num_rng(10, 30);
|
||||
boost::uniform_int<> key_size_rng(5, 10);
|
||||
boost::uniform_int<> val_size_rng(100, 1000);
|
||||
size_t num_attrs = static_cast<size_t>(num_rng(gen));
|
||||
for (size_t i = 0; i < num_attrs; ++i) {
|
||||
size_t key_size = static_cast<size_t>(num_rng(gen));
|
||||
size_t val_size = static_cast<size_t>(num_rng(gen));
|
||||
bufferlist keybl;
|
||||
_gen_random(gen, key_size, keybl);
|
||||
string key(keybl.c_str(), keybl.length());
|
||||
_gen_random(gen, val_size, (*out)[key]);
|
||||
}
|
||||
}
|
||||
|
||||
void DeterministicOpSequence::do_set_attrs(rngen_t& gen) {
|
||||
int coll_id = _gen_coll_id(gen);
|
||||
int obj_id = _gen_obj_id(gen);
|
||||
|
||||
coll_entry_t *entry = get_coll_at(coll_id);
|
||||
if (!entry) {
|
||||
dout(0) << "do_set_attrs coll id " << coll_id << " non-existent" << dendl;
|
||||
return;
|
||||
}
|
||||
|
||||
hobject_t *obj = entry->get_obj(obj_id);
|
||||
if (!obj) {
|
||||
dout(0) << "do_set_attrs " << entry->m_coll.to_str()
|
||||
<< " no object #" << obj_id << dendl;
|
||||
return;
|
||||
}
|
||||
|
||||
map<string, bufferlist> out;
|
||||
gen_attrs(gen, &out);
|
||||
|
||||
dout(0) << "do_set_attrs " << out.size() << " entries" << dendl;
|
||||
return _do_set_attrs(entry->m_coll, *obj, out);
|
||||
}
|
||||
|
||||
void DeterministicOpSequence::do_write(rngen_t& gen)
|
||||
{
|
||||
int coll_id = _gen_coll_id(gen);
|
||||
@ -413,6 +456,16 @@ void DeterministicOpSequence::_do_remove(coll_t coll, hobject_t& obj)
|
||||
m_store->apply_transaction(t);
|
||||
}
|
||||
|
||||
void DeterministicOpSequence::_do_set_attrs(coll_t coll,
|
||||
hobject_t &obj,
|
||||
const map<string, bufferlist> &attrs)
|
||||
{
|
||||
ObjectStore::Transaction t;
|
||||
note_txn(&t);
|
||||
t.omap_setkeys(coll, obj, attrs);
|
||||
m_store->apply_transaction(t);
|
||||
}
|
||||
|
||||
void DeterministicOpSequence::_do_write(coll_t coll, hobject_t& obj,
|
||||
uint64_t off, uint64_t len, const bufferlist& data)
|
||||
{
|
||||
|
@ -42,9 +42,10 @@ class DeterministicOpSequence : public TestFileStoreState {
|
||||
DSOP_COLL_MOVE = 5,
|
||||
DSOP_COLL_RENAME = 6,
|
||||
DSOP_COLL_ADD = 7,
|
||||
DSOP_SET_ATTRS = 8,
|
||||
|
||||
DSOP_FIRST = DSOP_TOUCH,
|
||||
DSOP_LAST = DSOP_COLL_ADD,
|
||||
DSOP_LAST = DSOP_SET_ATTRS,
|
||||
};
|
||||
|
||||
int32_t txn;
|
||||
@ -66,11 +67,15 @@ class DeterministicOpSequence : public TestFileStoreState {
|
||||
void do_coll_move(rngen_t& gen);
|
||||
void do_coll_rename(rngen_t& gen);
|
||||
void do_coll_add(rngen_t& gen);
|
||||
void do_set_attrs(rngen_t& gen);
|
||||
|
||||
virtual void _do_touch(coll_t coll, hobject_t& obj);
|
||||
virtual void _do_remove(coll_t coll, hobject_t& obj);
|
||||
virtual void _do_write(coll_t coll, hobject_t& obj, uint64_t off,
|
||||
uint64_t len, const bufferlist& data);
|
||||
virtual void _do_set_attrs(coll_t coll,
|
||||
hobject_t &obj,
|
||||
const map<string, bufferlist> &attrs);
|
||||
virtual void _do_clone(coll_t coll, hobject_t& orig_obj, hobject_t& new_obj);
|
||||
virtual void _do_clone_range(coll_t coll, hobject_t& orig_obj,
|
||||
hobject_t& new_obj, uint64_t srcoff, uint64_t srclen, uint64_t dstoff);
|
||||
@ -83,7 +88,6 @@ class DeterministicOpSequence : public TestFileStoreState {
|
||||
|
||||
int _gen_coll_id(rngen_t& gen);
|
||||
int _gen_obj_id(rngen_t& gen);
|
||||
void _gen_random(rngen_t& gen, size_t size, bufferlist& bl);
|
||||
void _print_status(int seq, int op);
|
||||
|
||||
private:
|
||||
|
@ -65,6 +65,29 @@ bool FileStoreDiff::diff_attrs(std::map<std::string,bufferptr>& b,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool diff_omap(std::map<std::string,bufferlist>& b,
|
||||
std::map<std::string,bufferlist>& a)
|
||||
{
|
||||
bool ret = false;
|
||||
std::map<std::string, bufferlist>::iterator b_it = b.begin();
|
||||
std::map<std::string, bufferlist>::iterator a_it = a.begin();
|
||||
for (; b_it != b.end(); ++b_it, ++a_it) {
|
||||
if (b_it->first != a_it->first) {
|
||||
dout(0) << "diff_attrs name mismatch (verify: " << b_it->first
|
||||
<< ", store: " << a_it->first << ")" << dendl;
|
||||
ret = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(b_it->second == a_it->second)) {
|
||||
dout(0) << "diff_attrs contents mismatch on attr " << b_it->first << dendl;
|
||||
ret = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool FileStoreDiff::diff_objects_stat(struct stat& a, struct stat& b)
|
||||
{
|
||||
bool ret = false;
|
||||
@ -190,6 +213,39 @@ bool FileStoreDiff::diff_objects(FileStore *a_store, FileStore *b_store, coll_t
|
||||
<< coll << "/" << b_obj << dendl;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
std::map<std::string, bufferlist> a_obj_omap, b_obj_omap;
|
||||
std::set<std::string> a_omap_keys, b_omap_keys;
|
||||
err = a_store->omap_get_keys(coll, a_obj, &a_omap_keys);
|
||||
if (err < 0) {
|
||||
dout(0) << "diff_objects getomap on A object " << coll << "/" << a_obj
|
||||
<< " returns " << err << dendl;
|
||||
ret = true;
|
||||
}
|
||||
err = a_store->omap_get_values(coll, a_obj, a_omap_keys, &a_obj_omap);
|
||||
if (err < 0) {
|
||||
dout(0) << "diff_objects getomap on A object " << coll << "/" << a_obj
|
||||
<< " returns " << err << dendl;
|
||||
ret = true;
|
||||
}
|
||||
err = b_store->omap_get_keys(coll, b_obj, &b_omap_keys);
|
||||
if (err < 0) {
|
||||
dout(0) << "diff_objects getomap on A object " << coll << "/" << b_obj
|
||||
<< " returns " << err << dendl;
|
||||
ret = true;
|
||||
}
|
||||
err = b_store->omap_get_values(coll, b_obj, b_omap_keys, &b_obj_omap);
|
||||
if (err < 0) {
|
||||
dout(0) << "diff_objects getomap on A object " << coll << "/" << b_obj
|
||||
<< " returns " << err << dendl;
|
||||
ret = true;
|
||||
}
|
||||
if (diff_omap(a_obj_omap, b_obj_omap)) {
|
||||
dout(0) << "diff_objects omap mismatch on A object "
|
||||
<< coll << "/" << a_obj << " and B object "
|
||||
<< coll << "/" << b_obj << dendl;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user