From 761140a0fa5408668f72740fb240e0f9d2a3c5a6 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Fri, 25 May 2012 15:06:55 -0700 Subject: [PATCH] FileStore,DBObjectMap: remove ObjectMap link method hobject_t's are now globally unique in filestore. Essentially, there is a 1-to-1 mapping from inodes to hobject_t's. The entry in the DBObjectMap is now tied to the inode/hobject_t. Thus, links needn't be tracked. Rather, we delete the ObjectMap entry when nlink == 0. Signed-off-by: Samuel Just --- src/os/DBObjectMap.cc | 27 --------------------------- src/os/DBObjectMap.h | 7 ------- src/os/FileStore.cc | 19 +++++++++++-------- src/os/ObjectMap.h | 8 -------- src/test/ObjectMap/test_object_map.cc | 14 +------------- 5 files changed, 12 insertions(+), 63 deletions(-) diff --git a/src/os/DBObjectMap.cc b/src/os/DBObjectMap.cc index ecd9d0133e6f3..b116e6bcd9f0a 100644 --- a/src/os/DBObjectMap.cc +++ b/src/os/DBObjectMap.cc @@ -939,33 +939,6 @@ int DBObjectMap::clone(const hobject_t &hoid, 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); diff --git a/src/os/DBObjectMap.h b/src/os/DBObjectMap.h index 6e48bb0e38471..018785afdc82b 100644 --- a/src/os/DBObjectMap.h +++ b/src/os/DBObjectMap.h @@ -168,13 +168,6 @@ public: 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); diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 91978e4af90e1..17ae06d3b4c67 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -360,11 +360,6 @@ int FileStore::lfn_link(coll_t c, coll_t cid, const hobject_t& o) 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; @@ -383,9 +378,17 @@ int FileStore::lfn_unlink(coll_t cid, const hobject_t& o) 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); } diff --git a/src/os/ObjectMap.h b/src/os/ObjectMap.h index 0f3088e641ed5..ea6c78ec9ea61 100644 --- a/src/os/ObjectMap.h +++ b/src/os/ObjectMap.h @@ -131,14 +131,6 @@ public: Index target_index ///< [in] path to target ) { return 0; } - /// Efficiently tie to same key space as - 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; } diff --git a/src/test/ObjectMap/test_object_map.cc b/src/test/ObjectMap/test_object_map.cc index a00a742e93694..c8ac76942c407 100644 --- a/src/test/ObjectMap/test_object_map.cc +++ b/src/test/ObjectMap/test_object_map.cc @@ -656,18 +656,16 @@ TEST_F(ObjectMapTest, CloneOneObject) { 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; @@ -680,9 +678,6 @@ TEST_F(ObjectMapTest, OddEvenClone) { 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 { @@ -693,26 +688,19 @@ TEST_F(ObjectMapTest, OddEvenClone) { 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(); -- 2.39.5