return db->submit_transaction(t);
}
+int DBObjectMap::clear_keys_header(const ghobject_t &oid,
+ const SequencerPosition *spos)
+{
+ KeyValueDB::Transaction t = db->get_transaction();
+ Header header = lookup_map_header(oid);
+ if (!header)
+ return -ENOENT;
+ if (check_spos(oid, header, spos))
+ return 0;
+
+ // save old attrs
+ KeyValueDB::Iterator iter = db->get_iterator(xattr_prefix(header));
+ if (!iter)
+ return -EINVAL;
+ map<string, bufferlist> attrs;
+ for (iter->seek_to_first(); !iter->status() && iter->valid(); iter->next())
+ attrs.insert(make_pair(iter->key(), iter->value()));
+ if (iter->status())
+ return iter->status();
+
+ // remove current header
+ remove_map_header(oid, header, t);
+ assert(header->num_children > 0);
+ header->num_children--;
+ int r = _clear(header, t);
+ if (r < 0)
+ return r;
+
+ // create new header
+ Header newheader = _generate_new_header(oid, Header());
+ set_map_header(oid, *newheader, t);
+ if (attrs.size())
+ t->set(xattr_prefix(newheader), attrs);
+ return db->submit_transaction(t);
+}
+
int DBObjectMap::get(const ghobject_t &oid,
bufferlist *_header,
map<string, bufferlist> *out)
int r = lfn_find(cid, hoid, &path);
if (r < 0)
return r;
- r = object_map->clear(hoid, &spos);
+ r = object_map->clear_keys_header(hoid, &spos);
if (r < 0 && r != -ENOENT)
return r;
return 0;
const SequencerPosition *spos=0 ///< [in] sequencer position
) = 0;
- /// Clear all map keys and values from oid
+ /// Clear all map keys and values in to_clear from oid
virtual int rm_keys(
const ghobject_t &oid, ///< [in] object containing map
const set<string> &to_clear, ///< [in] Keys to clear
const SequencerPosition *spos=0 ///< [in] sequencer position
) = 0;
+ /// Clear all omap keys and the header
+ virtual int clear_keys_header(
+ const ghobject_t &oid, ///< [in] oid to clear
+ const SequencerPosition *spos=0 ///< [in] sequencer position
+ ) = 0;
+
/// Get all keys and values
virtual int get(
const ghobject_t &oid, ///< [in] object containing map
/// Get all xattrs
virtual int get_all_xattrs(
const ghobject_t &oid, ///< [in] object
- set<string> *out ///< [out] attrs and values
+ set<string> *out ///< [out] attrs and values
) = 0;
/// set xattrs in to_set