Github user hbdeshmukh commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/93#discussion_r74823182 --- Diff: query_execution/ForemanDistributed.cpp --- @@ -0,0 +1,334 @@ +/** + * 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/ForemanDistributed.hpp" + +#include <cstddef> +#include <cstdio> +#include <cstdlib> +#include <memory> +#include <utility> +#include <vector> + +#include "catalog/Catalog.pb.h" +#include "catalog/CatalogDatabase.hpp" +#include "catalog/CatalogRelation.hpp" +#include "catalog/CatalogTypedefs.hpp" +#include "query_execution/AdmitRequestMessage.hpp" +#include "query_execution/PolicyEnforcerDistributed.hpp" +#include "query_execution/QueryExecutionMessages.pb.h" +#include "query_execution/QueryExecutionTypedefs.hpp" +#include "query_execution/QueryExecutionUtil.hpp" +#include "query_execution/ShiftbossDirectory.hpp" +#include "threading/ThreadUtil.hpp" +#include "utility/EqualsAnyConstant.hpp" + +#include "glog/logging.h" + +#include "tmb/address.h" +#include "tmb/id_typedefs.h" +#include "tmb/message_bus.h" +#include "tmb/message_style.h" +#include "tmb/tagged_message.h" + +using std::move; +using std::size_t; +using std::unique_ptr; +using std::vector; + +using tmb::AnnotatedMessage; +using tmb::MessageBus; +using tmb::TaggedMessage; +using tmb::client_id; + +namespace quickstep { + +namespace S = serialization; + +class QueryHandle; + +ForemanDistributed::ForemanDistributed( + MessageBus *bus, + CatalogDatabaseLite *catalog_database, + const int cpu_id, + const bool profile_individual_workorders) + : ForemanBase(bus, cpu_id), + catalog_database_(DCHECK_NOTNULL(catalog_database)) { + const std::vector<QueryExecutionMessageType> sender_message_types{ + kShiftbossRegistrationResponseMessage, + kQueryInitiateMessage, + kWorkOrderMessage, + kInitiateRebuildMessage, + kQueryTeardownMessage, + kSaveQueryResultMessage, + kQueryExecutionSuccessMessage, + kPoisonMessage}; + + for (const auto message_type : sender_message_types) { + bus_->RegisterClientAsSender(foreman_client_id_, message_type); + } + + const std::vector<QueryExecutionMessageType> receiver_message_types{ + kShiftbossRegistrationMessage, + kAdmitRequestMessage, + kQueryInitiateResponseMessage, + kCatalogRelationNewBlockMessage, + kDataPipelineMessage, + kInitiateRebuildResponseMessage, + kWorkOrderCompleteMessage, + kRebuildWorkOrderCompleteMessage, + kWorkOrderFeedbackMessage, + kSaveQueryResultResponseMessage, + kPoisonMessage}; + + for (const auto message_type : receiver_message_types) { + bus_->RegisterClientAsReceiver(foreman_client_id_, message_type); + } + + policy_enforcer_.reset(new PolicyEnforcerDistributed( + foreman_client_id_, + catalog_database_, + &shiftboss_directory_, + bus_, + profile_individual_workorders)); +} + +void ForemanDistributed::run() { + if (cpu_id_ >= 0) { + // We can pin the foreman thread to a CPU if specified. + ThreadUtil::BindToCPU(cpu_id_); + } + + // Ensure that at least one Shiftboss to register. + if (shiftboss_directory_.empty()) { + const AnnotatedMessage annotated_message = bus_->Receive(foreman_client_id_, 0, true); + const TaggedMessage &tagged_message = annotated_message.tagged_message; + DCHECK_EQ(kShiftbossRegistrationMessage, tagged_message.message_type()); + LOG(INFO) << "ForemanDistributed received typed '" << tagged_message.message_type() + << "' message from client " << annotated_message.sender; + + S::ShiftbossRegistrationMessage proto; + CHECK(proto.ParseFromArray(tagged_message.message(), tagged_message.message_bytes())); + + processShiftbossRegisterationMessage(annotated_message.sender, proto.work_order_capacity()); + DCHECK_EQ(1u, shiftboss_directory_.size()); + } + + // Event loop + for (;;) { + // Receive() causes this thread to sleep until next message is received. + const AnnotatedMessage annotated_message = + bus_->Receive(foreman_client_id_, 0, true); + const TaggedMessage &tagged_message = annotated_message.tagged_message; + const tmb::message_type_id message_type = tagged_message.message_type(); + LOG(INFO) << "ForemanDistributed received typed '" << message_type --- End diff -- Do you want to convert the LOG call to DLOG, considering that there will be a large number of messages received by the ForemanDistributed?
--- 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. ---