Skip to content

Commit

Permalink
Merge "Invoke RetryDelete() on unregister of last listener" into R2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jun 22, 2015
2 parents 719c9b1 + 4c3a537 commit 2fa93d0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/db/db_table.cc
Expand Up @@ -114,6 +114,10 @@ DBTableBase::ListenerId DBTableBase::Register(ChangeCallback callback) {

void DBTableBase::Unregister(ListenerId listener) {
info_->Unregister(listener);
// If a table is marked for deletion, then we may trigger the deletion
// process when the last client is removed
if (info_->empty())
RetryDelete();
}

bool DBTableBase::Enqueue(DBRequest *req) {
Expand Down
6 changes: 3 additions & 3 deletions src/db/db_table.h
Expand Up @@ -81,6 +81,9 @@ class DBTableBase {
// Calculate the size across all partitions.
virtual size_t Size() const { return 0; }

// Suspended deletion resume hook for user function
virtual void RetryDelete() { }

DB *database() { return db_; }
const DB *database() const { return db_; }

Expand Down Expand Up @@ -143,9 +146,6 @@ class DBTable : public DBTableBase {
// Delete hook for user function
virtual bool Delete(DBEntry *entry, const DBRequest *req);

// Suspended deletion resume hook for user function
virtual void RetryDelete() { }

void WalkCompleteCallback(DBTableBase *tbl_base);
void NotifyAllEntries();

Expand Down
6 changes: 6 additions & 0 deletions src/db/test/db_base_test.cc
Expand Up @@ -223,7 +223,13 @@ class VlanTable : public DBTableBase {
return table;
}

void RetryDelete() {
retry_delete_count_++;
}

uint32_t retry_delete_count() const { return retry_delete_count_; }
private:
uint32_t retry_delete_count_;
std::vector<VlanTablePart *> partitions_;
DISALLOW_COPY_AND_ASSIGN(VlanTable);
};
Expand Down
12 changes: 10 additions & 2 deletions src/db/test/db_test.cc
Expand Up @@ -79,8 +79,10 @@ class Vlan : public DBEntry {

class VlanTable : public DBTable {
public:
VlanTable(DB *db) : DBTable(db, "__vlan__.0") { };
~VlanTable() { };
VlanTable(DB *db) :
DBTable(db, "__vlan__.0"), retry_delete_count_(0), del_req_count_(0) {
}
~VlanTable() { }

uint32_t del_req_count() const { return del_req_count_; }

Expand Down Expand Up @@ -136,6 +138,12 @@ class VlanTable : public DBTable {
return table;
}

void RetryDelete() {
retry_delete_count_++;
}

uint32_t retry_delete_count() const { return retry_delete_count_; }
uint32_t retry_delete_count_;
uint32_t del_req_count_;
DISALLOW_COPY_AND_ASSIGN(VlanTable);
};
Expand Down
10 changes: 10 additions & 0 deletions src/db/test/db_test_cmn.h
Expand Up @@ -151,12 +151,15 @@ class DBTest : public ::testing::Test {

TEST_F(DBTest, Basic) {
EXPECT_EQ(itbl, db_.FindTable("db.test.vlan.0"));
uint32_t retry_delete_count = itbl->retry_delete_count();

tid_ =
itbl->Register(boost::bind(&DBTest::DBTestListener, this, _1, _2));
EXPECT_EQ(tid_, 0);

itbl->Unregister(tid_);
EXPECT_EQ(itbl->retry_delete_count(), retry_delete_count+1);
retry_delete_count = itbl->retry_delete_count();

for (int i = 0; i < 15; i++) {
tid_ =
Expand All @@ -166,15 +169,22 @@ TEST_F(DBTest, Basic) {
}

itbl->Unregister(7);
// There are pending registers. retry_delete_count is not incremented
EXPECT_EQ(itbl->retry_delete_count(), retry_delete_count);

tid_ =
itbl->Register(boost::bind(&DBTest::DBTestListener, this, _1, _2));
EXPECT_EQ(tid_, 7);


for (int i = 14; i >=0; i--) {
EXPECT_EQ(itbl->retry_delete_count(), retry_delete_count);
itbl->Unregister(i);
}

// All clients are registered. retry_delete_count should be incremented
EXPECT_EQ(itbl->retry_delete_count(), retry_delete_count+1);
retry_delete_count = itbl->retry_delete_count();
}

// To Test:
Expand Down

0 comments on commit 2fa93d0

Please sign in to comment.