Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit cf03c7b

Browse files
Merge branch 'master' into join-reordering
2 parents 29e7529 + bd58ed6 commit cf03c7b

19 files changed

+369
-159
lines changed

Jenkinsfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pipeline {
2222
sh 'cd build && make benchmark -j4'
2323
sh 'cd build && make install'
2424
sh 'cd build && bash ../script/testing/psql/psql_test.sh'
25+
sh 'sudo apt-get -qq update && sudo apt-get -qq -y --no-install-recommends install wget default-jdk default-jre' // prerequisites for jdbc_validator
2526
sh 'cd build && python ../script/validators/jdbc_validator.py'
2627
}
2728
}
@@ -48,6 +49,7 @@ pipeline {
4849
// sh 'cd build && make benchmark -j4'
4950
// sh 'cd build && make install'
5051
// sh 'cd build && bash ../script/testing/psql/psql_test.sh'
52+
// sh 'sudo apt-get -qq update && sudo apt-get -qq -y --no-install-recommends install wget default-jdk default-jre' // prerequisites for jdbc_validator
5153
// sh 'cd build && python ../script/validators/jdbc_validator.py'
5254
}
5355
}
@@ -64,6 +66,7 @@ pipeline {
6466
sh 'cd build && make benchmark -j4'
6567
sh 'cd build && make install'
6668
sh 'cd build && bash ../script/testing/psql/psql_test.sh'
69+
sh 'sudo apt-get -qq update && sudo apt-get -qq -y --no-install-recommends install wget default-jdk default-jre' // prerequisites for jdbc_validator
6770
sh 'cd build && python ../script/validators/jdbc_validator.py'
6871
}
6972
}
@@ -79,6 +82,7 @@ pipeline {
7982
// sh 'cd build && make benchmark -j4'
8083
// sh 'cd build && make install'
8184
// sh 'cd build && bash ../script/testing/psql/psql_test.sh'
85+
// sh 'sudo apt-get -qq update && sudo apt-get -qq -y --no-install-recommends install wget default-jdk default-jre' // prerequisites for jdbc_validator
8286
// sh 'cd build && python ../script/validators/jdbc_validator.py'
8387
// }
8488
// }

script/git-hooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if [ -n "$FILES" ]; then
1919
echo "******* Peloton Pre-Commit Hook *******"
2020
echo "***************************************"
2121
echo "Use \"$FORMATTER_PATH -c -f\" to format all staged files."
22-
echo "Or use \"$FORMATTER_PATH --no-verify\" to temporarily bypass the pre-commit hook."
22+
echo "Or use \"git commit --no-verify\" to temporarily bypass the pre-commit hook."
2323
echo
2424
echo "Be aware that changed files have to be staged again!"
2525
echo "***************************************"

src/executor/create_executor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ bool CreateExecutor::CreateTable(const planner::CreatePlan &node) {
203203

204204
bool CreateExecutor::CreateIndex(const planner::CreatePlan &node) {
205205
auto txn = context_->GetTransaction();
206+
auto database_name = node.GetDatabaseName();
206207
std::string table_name = node.GetTableName();
207208
std::string index_name = node.GetIndexName();
208209
bool unique_flag = node.IsUnique();
@@ -211,7 +212,7 @@ bool CreateExecutor::CreateIndex(const planner::CreatePlan &node) {
211212
auto key_attrs = node.GetKeyAttrs();
212213

213214
ResultType result = catalog::Catalog::GetInstance()->CreateIndex(
214-
DEFAULT_DB_NAME, table_name, key_attrs, index_name, unique_flag,
215+
database_name, table_name, key_attrs, index_name, unique_flag,
215216
index_type, txn);
216217
txn->SetResult(result);
217218

src/executor/plan_executor.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void CompileAndExecutePlan(
6464
}
6565

6666
auto on_query_result =
67-
[&on_complete, &consumer](executor::ExecutionResult result) {
67+
[&on_complete, &consumer, plan](executor::ExecutionResult result) {
6868
std::vector<ResultValue> values;
6969
for (const auto &tuple : consumer.GetOutputTuples()) {
7070
for (uint32_t i = 0; i < tuple.tuple_.size(); i++) {
@@ -74,6 +74,7 @@ static void CompileAndExecutePlan(
7474
values.push_back(std::move(str));
7575
}
7676
}
77+
plan->ClearParameterValues();
7778
on_complete(result, std::move(values));
7879
};
7980

@@ -102,6 +103,7 @@ static void InterpretPlan(
102103
result.m_result = ResultType::FAILURE;
103104
result.m_error_message = "Failed initialization of query execution tree";
104105
CleanExecutorTree(executor_tree.get());
106+
plan->ClearParameterValues();
105107
on_complete(result, std::move(values));
106108
return;
107109
}
@@ -131,6 +133,7 @@ static void InterpretPlan(
131133
result.m_processed = executor_context->num_processed;
132134
result.m_result = ResultType::SUCCESS;
133135
CleanExecutorTree(executor_tree.get());
136+
plan->ClearParameterValues();
134137
on_complete(result, std::move(values));
135138
}
136139

@@ -174,7 +177,7 @@ void PlanExecutor::ExecutePlan(
174177
* @return number of executed tuples and logical_tile_list
175178
*/
176179
int PlanExecutor::ExecutePlan(
177-
const planner::AbstractPlan *plan, const std::vector<type::Value> &params,
180+
planner::AbstractPlan *plan, const std::vector<type::Value> &params,
178181
std::vector<std::unique_ptr<executor::LogicalTile>> &logical_tile_list) {
179182
PL_ASSERT(plan != nullptr);
180183
LOG_TRACE("PlanExecutor Start with transaction");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@0xf3d342883f3f0344;
2+
3+
struct CreateIndexRequest {
4+
databaseName @0 :Text;
5+
tableName @1 :Text;
6+
7+
keyAttrs @2 :List(Int32);
8+
indexName @3 :Text;
9+
uniqueKeys @4 :Bool;
10+
11+
indexKeys @5 :Int32;
12+
}
13+
14+
struct CreateIndexResponse {
15+
16+
}
17+
18+
interface PelotonService {
19+
createIndex @0 (request :CreateIndexRequest) -> (response :CreateIndexResponse);
20+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// dedicated_thread_owner.h
6+
//
7+
// Identification: src/include/common/dedicated_thread_owner.h
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
#include <memory>
15+
#include <thread>
16+
#include "common/dedicated_thread_task.h"
17+
18+
namespace peloton {
19+
/**
20+
* @brief DedicatedThreadOwner is the base class for all components that
21+
* needs to manage long running threads inside the system (e.g. GC, thread pool)
22+
*
23+
* The interface exposes necessary behavior to @see DedicatedThreadRegistry, so
24+
* that the system has a centralized record over all the threads currently
25+
* running, and retains control over those threads for tuning purposes.
26+
*
27+
* TODO(tianyu): also add some statistics of thread utilization for tuning
28+
*/
29+
class DedicatedThreadOwner {
30+
public:
31+
/**
32+
* @return the number of threads owned by this owner
33+
*/
34+
size_t GetThreadCount() { return thread_count_; }
35+
36+
/**
37+
* Notifies the owner that a new thread has been given to it
38+
*/
39+
void NotifyNewThread() { thread_count_++; };
40+
41+
/**
42+
* Notifies the owner that the thread running task will be terminated
43+
* @param task the task to be terminated
44+
*/
45+
void NotifyThreadRemoved(std::shared_ptr<DedicatedThreadTask> task) {
46+
thread_count_--;
47+
OnThreadRemoved(task);
48+
}
49+
50+
protected:
51+
/**
52+
* Custom code to be run when removing a thread by each owner. It is expected
53+
* that this function blocks until the thread can be dropped safely
54+
*
55+
* TODO(tianyu) turn into async if need be
56+
*/
57+
virtual void OnThreadRemoved(std::shared_ptr<DedicatedThreadTask>) {}
58+
59+
private:
60+
size_t thread_count_ = 0;
61+
};
62+
} // namespace peloton
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// dedicated_thread_registry.h
6+
//
7+
// Identification: src/include/common/dedicated_thread_registry.h
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
#include <memory>
15+
#include <unordered_map>
16+
#include <vector>
17+
#include <thread>
18+
#include "common/macros.h"
19+
#include "common/dedicated_thread_task.h"
20+
#include "common/dedicated_thread_owner.h"
21+
22+
namespace peloton {
23+
24+
/**
25+
* Singleton class responsible for maintaining and dispensing long running
26+
* (dedicated) threads to other system components. The class also serves
27+
* as a control panel for the brain component to be able to collect information
28+
* on threads in the system and modify how threads are allocated.
29+
*/
30+
class DedicatedThreadRegistry {
31+
public:
32+
DedicatedThreadRegistry() = default;
33+
34+
~DedicatedThreadRegistry() {
35+
// Note that if registry is shutting down, it doesn't matter whether
36+
// owners are notified as this class should have the same life cycle
37+
// as the entire peloton process.
38+
39+
for (auto &entry : thread_owners_table_) {
40+
for (auto &task : entry.second) {
41+
task->Terminate();
42+
threads_table_[task.get()].join();
43+
}
44+
}
45+
}
46+
47+
// TODO(tianyu): Remove when we remove singletons
48+
static DedicatedThreadRegistry &GetInstance() {
49+
static DedicatedThreadRegistry registry;
50+
return registry;
51+
}
52+
53+
/**
54+
*
55+
* Register a thread under requester to run the given task
56+
*
57+
* @param requester The owner to assign the new thread to
58+
* @param args the arguments to pass to constructor of task
59+
* @return the DedicatedThreadTask running on new thread
60+
*/
61+
template <typename Task>
62+
void RegisterDedicatedThread(DedicatedThreadOwner *requester,
63+
std::shared_ptr<Task> task) {
64+
thread_owners_table_[requester].push_back(task);
65+
requester->NotifyNewThread();
66+
threads_table_.emplace(task.get(), std::thread([=] { task->RunTask(); }));
67+
}
68+
69+
// TODO(tianyu): Add code for thread removal
70+
71+
private:
72+
// Using raw pointer is okay since we never dereference said pointer,
73+
// but only use it as a lookup key
74+
std::unordered_map<DedicatedThreadTask *, std::thread> threads_table_;
75+
// Using raw pointer here is also fine since the owner's life cycle is
76+
// not controlled by the registry
77+
std::unordered_map<DedicatedThreadOwner *,
78+
std::vector<std::shared_ptr<DedicatedThreadTask>>>
79+
thread_owners_table_;
80+
};
81+
82+
} // namespace peloton
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// dedicated_thread_task.h
6+
//
7+
// Identification: src/include/common/dedicated_thread_task.h
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
15+
namespace peloton {
16+
/**
17+
* @brief Interface for a task to be run on a dedicated thread
18+
*
19+
* A dedicated thread is a long running thread that fulfills some system
20+
* function running at all times. An example of this would be threads in
21+
* the worker thread pool or the GC thread.
22+
*/
23+
class DedicatedThreadTask {
24+
public:
25+
/**
26+
* Send a termination signal to the dedicated thread.
27+
*
28+
* The thread must then wrap up and exit from its Run function. The
29+
* termination is guaranteed to be communicated to the owner
30+
*/
31+
virtual void Terminate() = 0;
32+
33+
/**
34+
* Executes the dedicated thread. It is assumed that the thread doesn't exit
35+
* until terminate is explicitly called.
36+
*/
37+
virtual void RunTask() = 0;
38+
};
39+
} // namespace peloton

src/include/executor/plan_executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class PlanExecutor {
7070
*/
7171
// FIXME This should be removed when PelotonService is removed/rewritten
7272
static int ExecutePlan(
73-
const planner::AbstractPlan *plan, const std::vector<type::Value> &params,
73+
planner::AbstractPlan *plan, const std::vector<type::Value> &params,
7474
std::vector<std::unique_ptr<executor::LogicalTile>> &logical_tile_list);
7575
};
7676

0 commit comments

Comments
 (0)