Skip to content

Commit

Permalink
Merge "Instance manager task queue size 1) To insert the Instnace tas…
Browse files Browse the repository at this point in the history
…k 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." into R2.20
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jun 10, 2015
2 parents 807f384 + 41dfe48 commit 4c660d5
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
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
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 4c660d5

Please sign in to comment.