return db->submit_transaction(t);
}
-int DBObjectMap::link(const hobject_t &hoid,
- Index index,
- const hobject_t &target,
- Index target_index)
-{
- assert(index->coll() != target_index->coll() ||
- hoid != target);
- KeyValueDB::Transaction t = db->get_transaction();
- {
- Header destination = lookup_map_header(target_index->coll(), target);
- if (destination) {
- remove_map_header(target_index->coll(), target, destination, t);
- destination->num_children--;
- _clear(destination, t);
- }
- }
- Header header = lookup_create_map_header(index->coll(), hoid, t);
-
- assert(header->num_children > 0);
- header->num_children++;
- set_header(header, t);
- _Header ldestination;
- ldestination.parent = header->seq;
- set_map_header(target_index->coll(), target, ldestination, t);
- return db->submit_transaction(t);
-}
-
int DBObjectMap::upgrade()
{
assert(0);
Index target_index
);
- int link(
- const hobject_t &hoid,
- Index index,
- const hobject_t &target,
- Index target_index
- );
-
/// Read initial state from backing store
int init(bool upgrade = false);
if (r < 0)
return -errno;
- r = object_map->link(o, path_old->get_index(),
- o, path_new->get_index());
- if (r < 0 && r != -ENOENT)
- return r;
-
r = index_new->created(o, path_new->path());
if (r < 0)
return r;
r = index->lookup(o, &path, &exist);
if (r < 0)
return r;
- object_map->clear(o, path->get_index());
- if (r < 0 && r != -ENOENT)
- return r;
+
+ struct stat st;
+ r = ::stat(path->path(), &st);
+ if (r < 0) {
+ return -errno;
+ }
+ if (st.st_nlink == 1) {
+ r = object_map->clear(o, path->get_index());
+ if (r < 0 && r != -ENOENT)
+ return r;
+ }
}
return index->unlink(o);
}
Index target_index ///< [in] path to target
) { return 0; }
- /// Efficiently tie <target, target_path> to same key space as <hoid, path>
- virtual int link(
- const hobject_t &hoid, ///< [in] object containing map
- Index index, ///< [in] Path to hoid
- const hobject_t &target, ///< [in] target of link
- Index target_index ///< [in] path to target
- ) { return 0; }
-
/// Ensure all previous writes are durable
virtual int sync() { return 0; }
TEST_F(ObjectMapTest, OddEvenClone) {
hobject_t hoid(sobject_t("foo", CEPH_NOSNAP));
hobject_t hoid2(sobject_t("foo2", CEPH_NOSNAP));
- hobject_t hoid_link(sobject_t("foo_link", CEPH_NOSNAP));
Index path = Index(new HashIndex(coll_t("foo_coll"),
string("/bar").c_str(),
2,
2,
- CollectionIndex::HASH_INDEX_TAG_2));
+ CollectionIndex::HOBJECT_WITH_POOL));
for (unsigned i = 0; i < 1000; ++i) {
set_key(hoid, path, "foo" + num_str(i), "bar" + num_str(i));
}
- db->link(hoid, path, hoid_link, path);
db->clone(hoid, path, hoid2, path);
int r = 0;
ASSERT_EQ(1, r);
ASSERT_EQ("bar" + num_str(i), result);
- r = get_key(hoid2, path, "foo" + num_str(i), &result);
- ASSERT_EQ(1, r);
- ASSERT_EQ("bar" + num_str(i), result);
if (i % 2) {
remove_key(hoid, path, "foo" + num_str(i));
} else {
for (unsigned i = 0; i < 1000; ++i) {
string result;
string result2;
- string result3;
r = get_key(hoid, path, "foo" + num_str(i), &result);
- int r3 = get_key(hoid_link, path, "foo" + num_str(i), &result3);
int r2 = get_key(hoid2, path, "foo" + num_str(i), &result2);
if (i % 2) {
ASSERT_EQ(0, r);
- ASSERT_EQ(0, r3);
ASSERT_EQ(1, r2);
ASSERT_EQ("bar" + num_str(i), result2);
} else {
ASSERT_EQ(0, r2);
ASSERT_EQ(1, r);
- ASSERT_EQ(1, r3);
ASSERT_EQ("bar" + num_str(i), result);
- ASSERT_EQ("bar" + num_str(i), result3);
}
}
- db->clear(hoid_link, path);
-
{
ObjectMap::ObjectMapIterator iter = db->get_iterator(hoid, path);
iter->seek_to_first();