Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/14#discussion_r66689165 --- Diff: query_execution/PolicyEnforcer.cpp --- @@ -0,0 +1,177 @@ +/** + * Copyright 2016, Quickstep Research Group, Computer Sciences Department, + * University of WisconsinâMadison. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +#include "query_execution/PolicyEnforcer.hpp" + +#include <cstddef> +#include <memory> +#include <queue> +#include <utility> +#include <unordered_map> +#include <vector> + +#include "query_execution/QueryExecutionMessages.pb.h" +#include "query_execution/QueryManager.hpp" +#include "query_optimizer/QueryHandle.hpp" +#include "relational_operators/WorkOrder.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +bool PolicyEnforcer::admitQuery(QueryHandle *query_handle) { + if (admitted_queries_.size() < kMaxConcurrentQueries) { + // Ok to admit the query. + const std::size_t query_id = query_handle->query_id(); + if (admitted_queries_.find(query_id) == admitted_queries_.end()) { + admitted_queries_[query_id].reset( + new QueryManager(foreman_client_id_, num_numa_nodes_, query_handle, + catalog_database_, storage_manager_, bus_)); + return true; + } else { + LOG(ERROR) << "Query with the same ID " << query_id << " exists"; + return false; + } + } else { + // This query will have to wait. + waiting_queries_.push(query_handle); + return false; --- End diff -- This is some implementation tricks to save some indentation: ``` if (...) { if (...) { ... return true; } LOG(ERROR) << ...; return false; } waiting_queries_.push(query_handle); return false; ```
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---