Skip to content

Commit

Permalink
Merge "Add config-tracker database inside each client." into R2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jul 10, 2015
2 parents 09345e6 + 7be53ae commit f15a8e7
Show file tree
Hide file tree
Showing 10 changed files with 348 additions and 55 deletions.
44 changes: 44 additions & 0 deletions src/ifmap/ifmap_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "ifmap/ifmap_client.h"

#include "ifmap/ifmap_exporter.h"
#include "base/bitset.h"
#include "ifmap/ifmap_update.h"

IFMapClient::IFMapClient()
: index_(kIndexInvalid), exporter_(NULL), msgs_sent_(0), msgs_blocked_(0),
Expand All @@ -30,3 +32,45 @@ std::vector<std::string> IFMapClient::vm_list() const {
return vm_list;
}

void IFMapClient::ConfigTrackerAdd(IFMapState *state) {
config_tracker_.insert(state);
}

void IFMapClient::ConfigTrackerDelete(IFMapState *state) {
CtSz_t num = config_tracker_.erase(state);
assert(num == 1);
}

bool IFMapClient::ConfigTrackerHasState(IFMapState *state) {
ConfigTracker::iterator iter = config_tracker_.find(state);
return (iter == config_tracker_.end() ? false : true);
}

bool IFMapClient::ConfigTrackerEmpty() {
return config_tracker_.empty();
}

size_t IFMapClient::ConfigTrackerSize() {
return config_tracker_.size();
}

void IFMapClient::ConfigDbCleanup() {
BitSet rm_bs;
rm_bs.set(index_);

for (ConfigTracker::iterator iter = config_tracker_.begin();
iter != config_tracker_.end(); ++iter) {
IFMapState *state = *iter;
state->InterestReset(rm_bs);
state->AdvertisedReset(rm_bs);
}
config_tracker_.clear();
}

void IFMapClient::ResetLinkDeleteClients() {
BitSet rm_bs;
rm_bs.set(index_);

exporter_->ResetLinkDeleteClients(rm_bs);
}

15 changes: 14 additions & 1 deletion src/ifmap/ifmap_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
#include <map>
#include <string>
#include <vector>
#include <boost/unordered_set.hpp>

class IFMapExporter;
class IFMapState;

// An XmppPeer that receives IFMap updates from the server component
class IFMapClient {
public:
typedef std::map<std::string, std::string> VmMap;
typedef boost::unordered_set<IFMapState *> ConfigTracker;
typedef ConfigTracker::size_type CtSz_t;
static const int kIndexInvalid = -1;

IFMapClient();
Expand Down Expand Up @@ -62,7 +66,15 @@ class IFMapClient {
return (vm_map_.size() != 0);
}
// return vm_map_ as a list of strings
std::vector<std::string> vm_list() const;
std::vector<std::string> vm_list() const;

void ConfigTrackerAdd(IFMapState *state);
void ConfigTrackerDelete(IFMapState *state);
bool ConfigTrackerHasState(IFMapState *state);
bool ConfigTrackerEmpty();
size_t ConfigTrackerSize();
void ConfigDbCleanup();
void ResetLinkDeleteClients();

private:
int index_;
Expand All @@ -75,6 +87,7 @@ class IFMapClient {
bool send_is_blocked_;
VmMap vm_map_;
std::string name_;
ConfigTracker config_tracker_;
};

#endif
81 changes: 75 additions & 6 deletions src/ifmap/ifmap_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ifmap/ifmap_update.h"
#include "ifmap/ifmap_update_queue.h"
#include "ifmap/ifmap_update_sender.h"
#include "ifmap/ifmap_util.h"

using namespace std;

Expand Down Expand Up @@ -117,11 +118,8 @@ const BitSet *IFMapExporter::MergeClientInterest(
BitSet *merged_set = new BitSet(*set);
merged_set->set(client->index());
ptr->reset(merged_set);
state->SetInterest(*merged_set);
StateInterestSet(state, *merged_set);
return merged_set;
} else if (table->name() == "__ifmap__.virtual_network.0") {
// TODO: merge the bits corresponding to the virtual networks that
// clients have subscribed for.
}

return set;
Expand Down Expand Up @@ -397,9 +395,11 @@ void IFMapExporter::NodeTableExport(DBTablePartBase *partition,
state->ClearValid();
if (!state->HasDependents()) {
// enqueue delete.
StateInterestReset(state, state->interest());
EnqueueDelete(node, state);
if (state->update_list().empty()) {
entry->ClearState(table, tinfo->id());
assert(state->interest().empty());
delete state;
}
}
Expand Down Expand Up @@ -468,9 +468,9 @@ void IFMapExporter::LinkTableExport(DBTablePartBase *partition,

if (IsFeasible(link->left()) && IsFeasible(link->right())) {
// Interest mask is the intersection of left and right nodes.
state->SetInterest(s_left->interest() & s_right->interest());
StateInterestSet(state, (s_left->interest() & s_right->interest()));
} else {
state->SetInterest(BitSet());
StateInterestSet(state, BitSet());
}

// This is an add operation for nodes that are interested and
Expand Down Expand Up @@ -501,6 +501,8 @@ void IFMapExporter::LinkTableExport(DBTablePartBase *partition,
IFMapNodeState *s_right = state->right();
assert((right != NULL) && (s_right != NULL));
BitSet interest = s_left->interest() & s_right->interest();
StateInterestReset(state, state->interest());

IFMAP_DEBUG(LinkOper, "LinkRemove", left->ToString(), right->ToString(),
s_left->interest().ToString(), s_right->interest().ToString());
walker_->LinkRemove(interest);
Expand All @@ -512,6 +514,7 @@ void IFMapExporter::LinkTableExport(DBTablePartBase *partition,
EnqueueDelete(link, state);
if (state->update_list().empty()) {
entry->ClearState(table, tinfo->id());
assert(state->interest().empty());
delete state;
}

Expand Down Expand Up @@ -546,6 +549,7 @@ void IFMapExporter::StateUpdateOnDequeue(IFMapUpdate *update,
state->Remove(update);
if (state->CanDelete()) {
assert(state->advertised().empty());
assert(state->interest().empty());
db_entry->ClearState(table, TableListenerId(table));
delete state;
}
Expand Down Expand Up @@ -602,3 +606,68 @@ bool IFMapExporter::ConfigChanged(IFMapNode *node) {

return changed;
}

void IFMapExporter::UpdateClientConfigTracker(IFMapState *state,
const BitSet& client_bits, bool add) {
IFMapClient *client = NULL;
for (size_t pos = client_bits.find_first(); pos != BitSet::npos;
pos = client_bits.find_next(pos)) {
client = server_->GetClient(pos);
assert(client);
if (add) {
client->ConfigTrackerAdd(state);
} else {
client->ConfigTrackerDelete(state);
}
}
}

void IFMapExporter::StateInterestSet(IFMapState *state,
const BitSet& interest_bits) {
// Add the node to the config-tracker of all clients that just became
// interested in this node.
bool add = true;
BitSet new_clients;
new_clients.BuildComplement(interest_bits, state->interest());
if (!new_clients.empty()) {
UpdateClientConfigTracker(state, new_clients, add);
}

// Remove the node from the config-tracker of all clients that are no longer
// interested in this node.
add = false;
BitSet old_clients;
old_clients.BuildComplement(state->interest(), interest_bits);
if (!old_clients.empty()) {
UpdateClientConfigTracker(state, old_clients, add);
}

state->SetInterest(interest_bits);
}

// Add the node to the config-tracker of all clients that just became interested
// in this node.
void IFMapExporter::StateInterestOr(IFMapState *state,
const BitSet& interest_bits) {
bool add = true;
UpdateClientConfigTracker(state, interest_bits, add);
state->InterestOr(interest_bits);
}

// Remove the node from the config-tracker of all clients that are no longer
// interested in this node.
void IFMapExporter::StateInterestReset(IFMapState *state,
const BitSet& interest_bits) {
bool add = false;
UpdateClientConfigTracker(state, interest_bits, add);
state->InterestReset(interest_bits);
}

const IFMapTypenameWhiteList &IFMapExporter::get_traversal_white_list() const {
return walker_->get_traversal_white_list();
}

void IFMapExporter::ResetLinkDeleteClients(const BitSet &bset) {
walker_->ResetLinkDeleteClients(bset);
}

10 changes: 10 additions & 0 deletions src/ifmap/ifmap_exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class IFMapUpdate;
class IFMapUpdateQueue;
class IFMapUpdateSender;

struct IFMapTypenameWhiteList;

// The IFMapExporter makes sure that the right entries are added to the update
// queue. It uses the GraphWalker to calculate the 'interest' set for each node
// and then ensures that all clients see the necessary information. It also
Expand Down Expand Up @@ -59,6 +61,14 @@ class IFMapExporter {

bool FilterNeighbor(IFMapNode *lnode, IFMapNode *rnode);

void UpdateClientConfigTracker(IFMapState *state, const BitSet& client_bits,
bool add);
void StateInterestSet(IFMapState *state, const BitSet& interest_bits);
void StateInterestOr(IFMapState *state, const BitSet& interest_bits);
void StateInterestReset(IFMapState *state, const BitSet& interest_bits);
const IFMapTypenameWhiteList &get_traversal_white_list() const;
void ResetLinkDeleteClients(const BitSet &bset);

private:
friend class XmppIfmapTest;
class TableInfo;
Expand Down
21 changes: 17 additions & 4 deletions src/ifmap/ifmap_graph_walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void IFMapGraphWalker::JoinVertex(DBGraphVertex *vertex, const BitSet &bset) {
IFMapNodeState *state = exporter_->NodeStateLocate(node);
IFMAP_DEBUG(JoinVertex, vertex->ToString(), state->interest().ToString(),
bset.ToString());
state->InterestOr(bset);
exporter_->StateInterestOr(state, bset);
node->table()->Change(node);
// Mark all dependent links as potentially modified.
for (IFMapNodeState::iterator iter = state->begin(); iter != state->end();
Expand Down Expand Up @@ -119,7 +119,7 @@ void IFMapGraphWalker::LinkAdd(IFMapNode *lnode, const BitSet &lhs,
}

void IFMapGraphWalker::LinkRemove(const BitSet &bset) {
link_delete_clients_.Set(bset); // link_delete_clients_ | bset
OrLinkDeleteClients(bset); // link_delete_clients_ | bset
link_delete_walk_trigger_->Set();
}

Expand Down Expand Up @@ -177,7 +177,7 @@ bool IFMapGraphWalker::LinkDeleteWalk() {
i = link_delete_clients_.find_next(i);
}
// Remove the subset of clients that we have finished processing.
link_delete_clients_.Reset(done_set);
ResetLinkDeleteClients(done_set);
rm_mask_ |= done_set;

LinkDeleteWalkBatchEnd();
Expand All @@ -191,6 +191,14 @@ bool IFMapGraphWalker::LinkDeleteWalk() {
}
}

void IFMapGraphWalker::OrLinkDeleteClients(const BitSet &bset) {
link_delete_clients_.Set(bset); // link_delete_clients_ | bset
}

void IFMapGraphWalker::ResetLinkDeleteClients(const BitSet &bset) {
link_delete_clients_.Reset(bset);
}

void IFMapGraphWalker::CleanupInterest(DBGraphVertex *vertex) {
// interest = interest - rm_mask_ + nmask
IFMapNode *node = static_cast<IFMapNode *>(vertex);
Expand All @@ -212,7 +220,7 @@ void IFMapGraphWalker::CleanupInterest(DBGraphVertex *vertex) {
return;
}

state->SetInterest(ninterest);
exporter_->StateInterestSet(state, ninterest);
node->table()->Change(node);

// Mark all dependent links as potentially modified.
Expand All @@ -235,6 +243,11 @@ void IFMapGraphWalker::LinkDeleteWalkBatchEnd() {
rm_mask_.clear();
}

const IFMapTypenameWhiteList &IFMapGraphWalker::get_traversal_white_list()
const {
return *traversal_white_list_.get();
}

// The nodes listed below and the nodes in
// IFMapGraphTraversalFilterCalculator::CreateNodeBlackList() are mutually
// exclusive
Expand Down
3 changes: 3 additions & 0 deletions src/ifmap/ifmap_graph_walker.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class IFMapGraphWalker {
void LinkRemove(const BitSet &bset);

bool FilterNeighbor(IFMapNode *lnode, IFMapNode *rnode);
const IFMapTypenameWhiteList &get_traversal_white_list() const;
void ResetLinkDeleteClients(const BitSet &bset);

private:
static const int kMaxLinkDeleteWalks = 1;
Expand All @@ -43,6 +45,7 @@ class IFMapGraphWalker {
void AddLinksToWhitelist();
bool LinkDeleteWalk();
void LinkDeleteWalkBatchEnd();
void OrLinkDeleteClients(const BitSet &bset);

DBGraph *graph_;
IFMapExporter *exporter_;
Expand Down

0 comments on commit f15a8e7

Please sign in to comment.