Skip to content

Commit

Permalink
Instance manager task queue size
Browse files Browse the repository at this point in the history
1) To insert the Instnace task into task queue, hash of service instance
uuid is used. To identify the numer of task queues avaialble,
.capacity() routine is used on vector, whose value mgiht be more than
the size of the vector. If task is inserted into a vector position
that is more than the size of vector, exception can occur. To avoid
this, .size() routine is invoked.

2) While inserting the task into the map of (service instance, task),
strict error check is made to ensure that we dont insert the same task
again into the map.

3) While starting the task, if there is an error, task is removed from
above map without unregistering the service instance, which might lead
to wrong refcounting. To avaoid this, unregisterserviceinstane() is
invoked which takes care of refcounting.

Change-Id: I1608be4f47d3a981aa1f8b7c9f48e0e80d21fc33
partial-bug: #1462042
  • Loading branch information
divakardhar committed Jun 9, 2015
1 parent 5830525 commit 41dfe48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/vnsw/agent/oper/instance_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void InstanceManager::Enqueue(InstanceTask *task,

InstanceTaskQueue *InstanceManager::GetTaskQueue(const std::string &str) {
boost::hash<std::string> hash;
int index = hash(str) % task_queues_.capacity();
int index = hash(str) % task_queues_.size();
return task_queues_[index];
}

Expand Down Expand Up @@ -438,7 +438,7 @@ bool InstanceManager::StartTask(InstanceTaskQueue *task_queue,
}

task_queue->Pop();
task_svc_instances_.erase(task);
UnregisterSvcInstance(task);
delete task;

return false;
Expand Down Expand Up @@ -488,7 +488,7 @@ void InstanceManager::ScheduleNextTask(InstanceTaskQueue *task_queue) {
}

ServiceInstance *InstanceManager::GetSvcInstance(InstanceTask *task) const {
std::map<InstanceTask *, ServiceInstance*>::const_iterator iter =
TaskSvcMap::const_iterator iter =
task_svc_instances_.find(task);
if (iter != task_svc_instances_.end()) {
return iter->second;
Expand All @@ -498,14 +498,17 @@ ServiceInstance *InstanceManager::GetSvcInstance(InstanceTask *task) const {

void InstanceManager::RegisterSvcInstance(InstanceTask *task,
ServiceInstance *svc_instance) {
task_svc_instances_.insert(std::make_pair(task, svc_instance));
pair<TaskSvcMap::iterator, bool> result =
task_svc_instances_.insert(std::make_pair(task, svc_instance));
assert(result.second);

InstanceState *state = GetState(svc_instance);
assert(state);
state->incr_tasks_running();
}

ServiceInstance *InstanceManager::UnregisterSvcInstance(InstanceTask *task) {
for (std::map<InstanceTask *, ServiceInstance*>::iterator iter =
for (TaskSvcMap::iterator iter =
task_svc_instances_.begin();
iter != task_svc_instances_.end(); ++iter) {
if (task == iter->first) {
Expand All @@ -526,8 +529,7 @@ void InstanceManager::UnregisterSvcInstance(ServiceInstance *svc_instance) {
InstanceState *state = GetState(svc_instance);
assert(state);

std::map<InstanceTask *, ServiceInstance*>::iterator iter =
task_svc_instances_.begin();
TaskSvcMap::iterator iter = task_svc_instances_.begin();
while(iter != task_svc_instances_.end()) {
if (svc_instance == iter->second) {
task_svc_instances_.erase(iter++);
Expand Down
3 changes: 2 additions & 1 deletion src/vnsw/agent/oper/instance_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class InstanceManager {
WorkQueue<InstanceManagerChildEvent> work_queue_;

std::vector<InstanceTaskQueue *> task_queues_;
std::map<InstanceTask *, ServiceInstance *> task_svc_instances_;
typedef std::map<InstanceTask *, ServiceInstance *> TaskSvcMap;
TaskSvcMap task_svc_instances_;
std::map<std::string, int> last_cmd_types_;
std::string loadbalancer_config_path_;
std::string namespace_store_path_;
Expand Down

0 comments on commit 41dfe48

Please sign in to comment.