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

Commit fdc076c

Browse files
authored
Merge branch 'master' into scripts
2 parents 7c6a7c1 + e40dfcb commit fdc076c

File tree

14 files changed

+354
-156
lines changed

14 files changed

+354
-156
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ if [ -n "$FILES" ]; then
1818
echo "***************************************"
1919
echo "******* Peloton Pre-Commit Hook *******"
2020
echo "***************************************"
21-
echo "Use \"$FORMATTER_COMMAND -c -f\" to format all staged files."
22-
echo "Or use \"$FORMATTER_COMMAND --no-verify\" to temporarily bypass the pre-commit hook."
21+
echo "Use \"$FORMATTER_PATH -c -f\" to format all staged files."
22+
echo "Or use \"git commit --no-verify\" to temporarily bypass the pre-commit hook."
23+
2324
echo
2425
echo "Be aware that changed files have to be staged again!"
2526
echo "***************************************"
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/network/network_thread.h

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// peloton_rpc_handler_task.h
6+
//
7+
// Identification: src/include/network/peloton_rpc_handler_task.h
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
#include "capnp/ez-rpc.h"
15+
#include "capnp/message.h"
16+
#include "common/dedicated_thread_task.h"
17+
#include "common/logger.h"
18+
#include "kj/debug.h"
19+
#include "peloton/capnp/peloton_service.capnp.h"
20+
21+
namespace peloton {
22+
namespace network {
23+
class PelotonRpcServerImpl final : public PelotonService::Server {
24+
protected:
25+
kj::Promise<void> createIndex(CreateIndexContext) override {
26+
// TODO(tianyu) Write actual index code
27+
LOG_DEBUG("Received rpc to create index");
28+
return kj::READY_NOW;
29+
}
30+
};
31+
32+
33+
class PelotonRpcHandlerTask : public DedicatedThreadTask {
34+
public:
35+
explicit PelotonRpcHandlerTask(const char *address) : address_(address) {}
36+
37+
void Terminate() override {
38+
// TODO(tianyu): Not implemented. See:
39+
// https://groups.google.com/forum/#!topic/capnproto/bgxCdqGD6oE
40+
}
41+
42+
void RunTask() override {
43+
capnp::EzRpcServer server(kj::heap<PelotonRpcServerImpl>(), address_);
44+
LOG_DEBUG("Server listening on %s", address_);
45+
kj::NEVER_DONE.wait(server.getWaitScope());
46+
}
47+
48+
private:
49+
const char *address_;
50+
};
51+
} // namespace network
52+
} // namespace peloton

0 commit comments

Comments
 (0)