-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDataProviderThread.cpp
More file actions
92 lines (83 loc) · 3.23 KB
/
Copy pathDataProviderThread.cpp
File metadata and controls
92 lines (83 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 "storage/DataProviderThread.hpp"
#include <cstddef>
#include <utility>
#include <vector>
#include "catalog/CatalogDatabase.hpp"
#include "catalog/CatalogRelation.hpp"
#include "catalog/CatalogTypedefs.hpp"
#include "cli/DropRelation.hpp"
#include "query_execution/QueryExecutionTypedefs.hpp"
#include "query_execution/QueryExecutionUtil.hpp"
#include "query_optimizer/QueryProcessor.hpp"
#include "storage/BlockWire.pb.h"
#include "storage/StorageBlock.hpp"
#include "storage/StorageBlockInfo.hpp"
#include "storage/StorageManager.hpp"
#include "threading/ThreadUtil.hpp"
#include "glog/logging.h"
#include "tmb/tagged_message.h"
namespace quickstep {
void DataProviderThread::run() {
if (cpu_id_ >= 0) {
ThreadUtil::BindToCPU(cpu_id_);
}
for (;;) {
const AnnotatedMessage annotated_message =
bus_->Receive(dpt_client_id_, 0, true);
const TaggedMessage &tagged_message = annotated_message.tagged_message;
const message_type_id message_type = tagged_message.message_type();
switch (message_type) {
case kPoisonMessage: {
return;
}
case kBlockRequestMessage: {
BlockRequest request_proto;
CHECK(request_proto.ParseFromArray(tagged_message.message(), tagged_message.message_bytes()));
// extract block ID from the message.
BlockResponse proto;
storage_manager_->sendBlockContents(request_proto.block_id(), &proto);
if (proto.is_valid()) {
// send response back to the client.
const int proto_length = proto.ByteSize();
char *proto_bytes = static_cast<char*>(malloc(proto_length));
CHECK(proto.SerializeToArray(proto_bytes, proto_length));
TaggedMessage message(static_cast<const void*>(proto_bytes),
proto_length,
kBlockResponseMessage);
free(proto_bytes);
QueryExecutionUtil::SendTMBMessage(
bus_, dpt_client_id_, annotated_message.sender, std::move(message));
}
break;
}
case kFinishReadingRelationMessage: {
FinishReadingRelationMessage request_proto;
DropRelation::Drop(*database_->getRelationById(request_proto.relation_id()),
database_,
storage_manager_);
// TODO(harshad) - Check if the call below is thread safe?
query_processor_->saveCatalog();
break;
}
}
}
}
} // namespace quickstep