Skip to content

Commit

Permalink
Merge "Add sequence number support for update queue" into R2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 16, 2016
2 parents 5ee38b4 + 50121b4 commit 32da6e6
Show file tree
Hide file tree
Showing 6 changed files with 513 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/ifmap/ifmap_server_show.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ struct UpdateQueueShowEntry {
1: string node_name;
2: string qe_type;
3: string qe_bitset;
4: string queue_insert_ago;
5: u64 sequence;
}

request sandesh IFMapUpdateQueueShowReq {
Expand Down
9 changes: 9 additions & 0 deletions src/ifmap/ifmap_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ifmap/ifmap_update.h"

#include "base/time_util.h"
#include "ifmap/ifmap_node.h"

IFMapObjectPtr::IFMapObjectPtr()
Expand All @@ -21,6 +22,14 @@ IFMapObjectPtr::IFMapObjectPtr(IFMapLink *link)
u.link = link;
}

void IFMapListEntry::set_queue_insert_at_to_now() {
queue_insert_at = UTCTimestampUsec();
}

std::string IFMapListEntry::queue_insert_ago_str() {
return duration_usecs_to_string(UTCTimestampUsec() - queue_insert_at);
}

IFMapUpdate::IFMapUpdate(IFMapNode *node, bool positive)
: IFMapListEntry(positive ? UPDATE : DELETE),
data_(node) {
Expand Down
12 changes: 11 additions & 1 deletion src/ifmap/ifmap_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ struct IFMapListEntry {
DELETE, // delete
MARKER
};
IFMapListEntry(EntryType type) : type(type) { }
IFMapListEntry(EntryType type) :
type(type), queue_insert_at(0), sequence(0) { }

boost::intrusive::list_member_hook<> node;
EntryType type;
uint64_t queue_insert_at;
uint64_t sequence;

bool IsMarker() const { return ((type == MARKER) ? true : false); }
bool IsUpdate() const { return ((type == UPDATE) ? true : false); }
bool IsDelete() const { return ((type == DELETE) ? true : false); }
Expand All @@ -66,6 +71,11 @@ struct IFMapListEntry {
return "Unknown";
}
}
void set_queue_insert_at_to_now();
// Return how much time ago the entry was inserted.
std::string queue_insert_ago_str();
void set_sequence(uint64_t seq) { sequence = seq; }
uint64_t get_sequence() { return sequence; }
};

class IFMapUpdate : public IFMapListEntry {
Expand Down
74 changes: 59 additions & 15 deletions src/ifmap/ifmap_update_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,46 @@
#include "ifmap/ifmap_server.h"
#include "ifmap/ifmap_server_show_types.h"

IFMapUpdateQueue::IFMapUpdateQueue(IFMapServer *server) : server_(server) {
list_.push_back(tail_marker_);
// Convention for SetSequence():
// If we are inserting the item in the middle of the Q, we set its sequence to
// the same value as its successor. If its the last item in the Q, it gets the
// next available sequence number.
void IFMapUpdateQueue::SetSequence(IFMapListEntry *item) {
IFMapListEntry *next = Next(item);
item->set_sequence(next ? next->get_sequence(): ++sequence_);
}

// Insert 'item' at the end of the list.
void IFMapUpdateQueue::PushbackIntoList(IFMapListEntry *item) {
list_.push_back(*item);
SetSequence(item);
item->set_queue_insert_at_to_now();
}

// Insert 'item' before 'ptr'.
void IFMapUpdateQueue::InsertIntoListBefore(IFMapListEntry *ptr,
IFMapListEntry *item) {
list_.insert(list_.iterator_to(*ptr), *item);
SetSequence(item);
item->set_queue_insert_at_to_now();
}

// Insert 'item' after 'ptr'.
void IFMapUpdateQueue::InsertIntoListAfter(IFMapListEntry *ptr,
IFMapListEntry *item) {
list_.insert(++list_.iterator_to(*ptr), *item);
SetSequence(item);
item->set_queue_insert_at_to_now();
}

void IFMapUpdateQueue::EraseFromList(IFMapListEntry *item) {
list_.erase(list_.iterator_to(*item));
item->set_sequence(NULL_SEQUENCE);
}

IFMapUpdateQueue::IFMapUpdateQueue(IFMapServer *server) : server_(server),
sequence_(0) {
PushbackIntoList(&tail_marker_);
}

struct IFMapListEntryDisposer {
Expand All @@ -27,23 +65,27 @@ struct IFMapListEntryDisposer {
}
};

IFMapUpdateQueue::~IFMapUpdateQueue() {
list_.erase(list_.iterator_to(tail_marker_));
void IFMapUpdateQueue::ClearAndDisposeList() {
list_.clear_and_dispose(IFMapListEntryDisposer());
}

IFMapUpdateQueue::~IFMapUpdateQueue() {
EraseFromList(&tail_marker_);
ClearAndDisposeList();
}

bool IFMapUpdateQueue::Enqueue(IFMapUpdate *update) {
assert(!update->advertise().empty());
bool tm_last = false;
if (GetLast() == tail_marker()) {
tm_last = true;
}
list_.push_back(*update);
PushbackIntoList(update);
return tm_last;
}

void IFMapUpdateQueue::Dequeue(IFMapUpdate *update) {
list_.erase(list_.iterator_to(*update));
EraseFromList(update);
}

IFMapMarker *IFMapUpdateQueue::GetMarker(int bit) {
Expand Down Expand Up @@ -89,7 +131,7 @@ void IFMapUpdateQueue::Leave(int bit) {
marker_map_.erase(loc);
marker->mask.reset(bit);
if ((marker != &tail_marker_) && (marker->mask.empty())) {
list_.erase(list_.iterator_to(*marker));
EraseFromList(marker);
delete marker;
}
}
Expand All @@ -112,13 +154,13 @@ void IFMapUpdateQueue::MarkerMerge(IFMapMarker *dst, IFMapMarker *src,
src->mask.Reset(mmove);
if (src->mask.empty()) {
assert(src != &tail_marker_);
list_.erase(list_.iterator_to(*src));
EraseFromList(src);
delete src;
}
}

IFMapMarker* IFMapUpdateQueue::MarkerSplit(IFMapMarker *marker,
IFMapListEntry *current,
IFMapListEntry *current,
const BitSet &msplit, bool before) {
assert(!msplit.empty());
IFMapMarker *new_marker = new IFMapMarker();
Expand All @@ -136,10 +178,10 @@ IFMapMarker* IFMapUpdateQueue::MarkerSplit(IFMapMarker *marker,
}
if (before) {
// Insert new_marker before current
list_.insert(list_.iterator_to(*current), *new_marker);
InsertIntoListBefore(current, new_marker);
} else {
// Insert new_marker after current
list_.insert(++list_.iterator_to(*current), *new_marker);
InsertIntoListAfter(current, new_marker);
}
return new_marker;
}
Expand All @@ -164,17 +206,17 @@ IFMapMarker* IFMapUpdateQueue::MarkerSplitAfter(IFMapMarker *marker,
void IFMapUpdateQueue::MoveMarkerBefore(IFMapMarker *marker,
IFMapListEntry *current) {
if (marker != current) {
list_.erase(list_.iterator_to(*marker));
list_.insert(list_.iterator_to(*current), *marker);
EraseFromList(marker);
InsertIntoListBefore(current, marker);
}
}

// Insert marker after current
void IFMapUpdateQueue::MoveMarkerAfter(IFMapMarker *marker,
IFMapListEntry *current) {
if (marker != current) {
list_.erase(list_.iterator_to(*marker));
list_.insert(++list_.iterator_to(*current), *marker);
EraseFromList(marker);
InsertIntoListAfter(current, marker);
}
}

Expand Down Expand Up @@ -320,6 +362,8 @@ void ShowIFMapUpdateQueue::CopyNode(UpdateQueueShowEntry *dest,
}
dest->qe_bitset = marker->mask.ToNumberedString();
}
dest->queue_insert_ago = src->queue_insert_ago_str();
dest->sequence = src->get_sequence();
}

bool ShowIFMapUpdateQueue::BufferStage(const Sandesh *sr,
Expand Down
10 changes: 9 additions & 1 deletion src/ifmap/ifmap_update_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,19 @@ class IFMapUpdateQueue {

private:
friend class ShowIFMapUpdateQueue;
static const uint64_t NULL_SEQUENCE = 0;
List list_;
MarkerMap marker_map_;
IFMapMarker tail_marker_;
IFMapServer *server_;

uint64_t sequence_;

void SetSequence(IFMapListEntry *item);
void PushbackIntoList(IFMapListEntry *item);
void InsertIntoListBefore(IFMapListEntry *ptr, IFMapListEntry *item);
void InsertIntoListAfter(IFMapListEntry *ptr, IFMapListEntry *item);
void EraseFromList(IFMapListEntry *item);
void ClearAndDisposeList();
IFMapMarker* MarkerSplit(IFMapMarker *marker, IFMapListEntry *current,
const BitSet &msplit, bool before);
};
Expand Down

0 comments on commit 32da6e6

Please sign in to comment.