Skip to content

Commit

Permalink
os/bluestore: pass strict flag to bluestore_blob_use_tracker_t::equal()
Browse files Browse the repository at this point in the history
And if that flag is true, we'll do a strict equivalence comparison instead.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
  • Loading branch information
xiexingguo committed Jun 29, 2017
1 parent 2b4b718 commit 5070999
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/os/bluestore/bluestore_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ void bluestore_blob_use_tracker_t::split(
}

bool bluestore_blob_use_tracker_t::equal(
const bluestore_blob_use_tracker_t& other) const
const bluestore_blob_use_tracker_t& other,
bool strict) const
{
if (!num_au && !other.num_au) {
return total_bytes == other.total_bytes && au_size == other.au_size;
Expand All @@ -504,6 +505,10 @@ bool bluestore_blob_use_tracker_t::equal(
return true;
}

if (strict) {
return false;
}

uint32_t n = num_au ? num_au : other.num_au;
uint32_t referenced =
num_au ? other.get_referenced_bytes() : get_referenced_bytes();
Expand Down
3 changes: 2 additions & 1 deletion src/os/bluestore/bluestore_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ struct bluestore_blob_use_tracker_t {
bluestore_blob_use_tracker_t* r);

bool equal(
const bluestore_blob_use_tracker_t& other) const;
const bluestore_blob_use_tracker_t& other,
bool strict = true) const;

void bound_encode(size_t& p) const {
denc_varint(au_size, p);
Expand Down
38 changes: 37 additions & 1 deletion src/test/objectstore/test_bluestore_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,43 @@ TEST(GarbageCollector, BasicTest)
em.clear();
old_extents.clear();
}
}
}

TEST(bluestore_blob_use_tracker_t, equal)
{
bluestore_blob_use_tracker_t t1, t2, t3;

ASSERT_TRUE(t1.equal(t2));
ASSERT_TRUE(t1.equal(t2, false));

t1.init(0x8000, 0x1000);
t2.init(0x8000, 0x1000);
ASSERT_TRUE(t1.equal(t2));
ASSERT_TRUE(t1.equal(t2, false));

t1.get(0, 0x1000);
ASSERT_TRUE(!t1.equal(t2));
ASSERT_TRUE(!t1.equal(t2, false));
t2.get(0, 0x1000);
ASSERT_TRUE(t1.equal(t2));
ASSERT_TRUE(t1.equal(t2, false));

t1.get(0x1000, 0x1000);
t2.get(0x2000, 0x1000);
ASSERT_TRUE(!t1.equal(t2));
ASSERT_TRUE(!t1.equal(t2, false));

t3.init(0x8000, 0x8000);
t3.get(0x4000, 0x2000);
ASSERT_TRUE(!t3.equal(t1));
ASSERT_TRUE(t3.equal(t1, false));
ASSERT_TRUE(!t3.equal(t2));
ASSERT_TRUE(t3.equal(t2, false));

t1.clear();
t2.clear();
t3.clear();
}

int main(int argc, char **argv) {
vector<const char*> args;
Expand Down

0 comments on commit 5070999

Please sign in to comment.