Skip to content

Commit

Permalink
Merge pull request ceph#11388 from ukernel/wip-17177
Browse files Browse the repository at this point in the history
os/ObjectStore: properly clear object map when replaying OP_REMOVE

Reviewed-by: Kefu Chai <[email protected]>
Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
yuriw authored Oct 24, 2016
2 parents b0e2028 + c66e466 commit 73a1b45
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/os/filestore/DBObjectMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -902,10 +902,10 @@ int DBObjectMap::clone(const ghobject_t &oid,
{
Header destination = lookup_map_header(*ltarget, target);
if (destination) {
remove_map_header(*ltarget, target, destination, t);
if (check_spos(target, destination, spos))
return 0;
destination->num_children--;
remove_map_header(*ltarget, target, destination, t);
_clear(destination, t);
}
}
Expand Down
69 changes: 43 additions & 26 deletions src/os/filestore/FileStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,7 @@ int FileStore::lfn_unlink(const coll_t& cid, const ghobject_t& o,
}

if (!force_clear_omap) {
if (hardlink == 0) {
if (!m_disable_wbthrottle) {
wbthrottle.clear_object(o); // should be only non-cache ref
}
fdcache.clear(o);
return 0;
} else if (hardlink == 1) {
if (hardlink == 0 || hardlink == 1) {
force_clear_omap = true;
}
}
Expand All @@ -506,6 +500,12 @@ int FileStore::lfn_unlink(const coll_t& cid, const ghobject_t& o,
if (!backend->can_checkpoint())
object_map->sync(&o, &spos);
}
if (hardlink == 0) {
if (!m_disable_wbthrottle) {
wbthrottle.clear_object(o); // should be only non-cache ref
}
return 0;
}
}
r = index->unlink(o);
if (r < 0) {
Expand Down Expand Up @@ -2344,10 +2344,12 @@ void FileStore::_set_replay_guard(int fd,
// first make sure the previous operation commits
::fsync(fd);

// sync object_map too. even if this object has a header or keys,
// it have had them in the past and then removed them, so always
// sync.
object_map->sync(hoid, &spos);
if (!in_progress) {
// sync object_map too. even if this object has a header or keys,
// it have had them in the past and then removed them, so always
// sync.
object_map->sync(hoid, &spos);
}

_inject_failure();

Expand Down Expand Up @@ -2385,7 +2387,8 @@ void FileStore::_close_replay_guard(const coll_t& cid,
VOID_TEMP_FAILURE_RETRY(::close(fd));
}

void FileStore::_close_replay_guard(int fd, const SequencerPosition& spos)
void FileStore::_close_replay_guard(int fd, const SequencerPosition& spos,
const ghobject_t *hoid)
{
if (backend->can_checkpoint())
return;
Expand All @@ -2394,6 +2397,11 @@ void FileStore::_close_replay_guard(int fd, const SequencerPosition& spos)

_inject_failure();

// sync object_map too. even if this object has a header or keys,
// it have had them in the past and then removed them, so always
// sync.
object_map->sync(hoid, &spos);

// then record that we are done with this operation
bufferlist v(40);
::encode(spos, v);
Expand Down Expand Up @@ -5266,18 +5274,30 @@ int FileStore::_collection_move_rename(const coll_t& oldcid, const ghobject_t& o
} else {
assert(0 == "ERROR: source must exist");
}
return 0;
}
if (dstcmp > 0) { // if dstcmp == 0 the guard already says "in-progress"
_set_replay_guard(**fd, spos, &o, true);
}

r = lfn_link(oldcid, c, oldoid, o);
if (replaying && !backend->can_checkpoint() &&
r == -EEXIST) // crashed between link() and set_replay_guard()
r = 0;
if (!replaying) {
return 0;
}
if (allow_enoent && dstcmp > 0) { // if dstcmp == 0, try_rename was started.
return 0;
}

_inject_failure();
r = 0; // don't know if object_map was cloned
} else {
if (dstcmp > 0) { // if dstcmp == 0 the guard already says "in-progress"
_set_replay_guard(**fd, spos, &o, true);
}

r = lfn_link(oldcid, c, oldoid, o);
if (replaying && !backend->can_checkpoint() &&
r == -EEXIST) // crashed between link() and set_replay_guard()
r = 0;

lfn_close(fd);
fd = FDRef();

_inject_failure();
}

if (r == 0) {
// the name changed; link the omap content
Expand All @@ -5288,9 +5308,6 @@ int FileStore::_collection_move_rename(const coll_t& oldcid, const ghobject_t& o

_inject_failure();

lfn_close(fd);
fd = FDRef();

if (r == 0)
r = lfn_unlink(oldcid, oldoid, spos, true);

Expand All @@ -5299,7 +5316,7 @@ int FileStore::_collection_move_rename(const coll_t& oldcid, const ghobject_t& o

// close guard on object so we don't do this again
if (r == 0) {
_close_replay_guard(**fd, spos);
_close_replay_guard(**fd, spos, &o);
lfn_close(fd);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/os/filestore/FileStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ class FileStore : public JournalingObjectStore,
const SequencerPosition &spos);

/// close a replay guard opened with in_progress=true
void _close_replay_guard(int fd, const SequencerPosition& spos);
void _close_replay_guard(int fd, const SequencerPosition& spos,
const ghobject_t *oid=0);
void _close_replay_guard(const coll_t& cid, const SequencerPosition& spos);

/**
Expand Down

0 comments on commit 73a1b45

Please sign in to comment.