-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkOrderSelectionPolicy.hpp
141 lines (113 loc) · 3.54 KB
/
WorkOrderSelectionPolicy.hpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* 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.
**/
#ifndef QUICKSTEP_QUERY_EXECUTION_WORK_ORDER_SELECTION_POLICY_HPP_
#define QUICKSTEP_QUERY_EXECUTION_WORK_ORDER_SELECTION_POLICY_HPP_
#include <cstddef>
#include <stack>
#include <queue>
#include "utility/Macros.hpp"
#include "glog/logging.h"
namespace quickstep {
/** \addtogroup QueryExecution
* @{
*/
/**
* @brief Base class for a policy to select work orders for query execution.
**/
class WorkOrderSelectionPolicy {
public:
/**
* @brief Whether there is an available work order for execution.
*
* @return True if a work order is available. Otherwise, false.
**/
virtual bool hasWorkOrder() const = 0;
/**
* @brief Add work order.
*
* @param operator_index The operator index for added work order.
**/
virtual void addWorkOrder(const std::size_t operator_index) = 0;
/**
* @brief Choose the operator index for next workorder execution based on the policy.
*
* @return The operator index chosen for next workorder execution.
**/
virtual std::size_t getOperatorIndexForNextWorkOrder() = 0;
protected:
/**
* @brief Constructor.
**/
WorkOrderSelectionPolicy() {}
private:
DISALLOW_COPY_AND_ASSIGN(WorkOrderSelectionPolicy);
};
/**
* @brief Choose the next work order in a first-in-first-out manner.
**/
class FifoWorkOrderSelectionPolicy final : public WorkOrderSelectionPolicy {
public:
/**
* @brief Constructor.
**/
FifoWorkOrderSelectionPolicy() = default;
bool hasWorkOrder() const override {
return !work_orders_.empty();
}
void addWorkOrder(const std::size_t operator_index) override {
work_orders_.push(operator_index);
}
std::size_t getOperatorIndexForNextWorkOrder() override {
DCHECK(hasWorkOrder());
const std::size_t operator_index = work_orders_.front();
work_orders_.pop();
return operator_index;
}
private:
std::queue<std::size_t> work_orders_;
DISALLOW_COPY_AND_ASSIGN(FifoWorkOrderSelectionPolicy);
};
/**
* @brief Choose the next work order in a last-in-first-out manner.
**/
class LifoWorkOrderSelectionPolicy final : public WorkOrderSelectionPolicy {
public:
/**
* @brief Constructor.
**/
LifoWorkOrderSelectionPolicy() = default;
bool hasWorkOrder() const override {
return !work_orders_.empty();
}
void addWorkOrder(const std::size_t operator_index) override {
work_orders_.push(operator_index);
}
std::size_t getOperatorIndexForNextWorkOrder() override {
DCHECK(hasWorkOrder());
const std::size_t operator_index = work_orders_.top();
work_orders_.pop();
return operator_index;
}
private:
std::stack<std::size_t> work_orders_;
DISALLOW_COPY_AND_ASSIGN(LifoWorkOrderSelectionPolicy);
};
/** @} */
} // namespace quickstep
#endif // QUICKSTEP_QUERY_EXECUTION_WORK_ORDER_SELECTION_POLICY_HPP_