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

Commit d895633

Browse files
committed
Refactor original brain files out
1 parent 793f066 commit d895633

26 files changed

+129
-130
lines changed

src/common/dedicated_thread_registry.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "common/dedicated_thread_registry.h"
1414

15+
1516
namespace peloton {
1617

1718
DedicatedThreadRegistry::~DedicatedThreadRegistry() {
@@ -26,16 +27,9 @@ DedicatedThreadRegistry::~DedicatedThreadRegistry() {
2627
}
2728
}
2829
}
30+
2931
DedicatedThreadRegistry &DedicatedThreadRegistry::GetInstance() {
3032
static DedicatedThreadRegistry registry;
3133
return registry;
3234
}
33-
34-
template<typename Task>
35-
void DedicatedThreadRegistry::RegisterDedicatedThread(DedicatedThreadOwner *requester,
36-
std::shared_ptr<Task> task) {
37-
thread_owners_table_[requester].push_back(task);
38-
requester->NotifyNewThread();
39-
threads_table_.emplace(task.get(), std::thread([=] { task->RunTask(); }));
40-
}
4135
}

src/common/init.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <gflags/gflags.h>
1616
#include <google/protobuf/stubs/common.h>
1717

18-
#include "brain/index_tuner.h"
19-
#include "brain/layout_tuner.h"
18+
#include "include/indextuner/index_tuner.h"
19+
#include "include/indextuner/layout_tuner.h"
2020
#include "catalog/catalog.h"
2121
#include "common/statement_cache_manager.h"
2222
#include "common/thread_pool.h"
@@ -43,7 +43,7 @@ void PelotonInit::Initialize() {
4343
// start worker pool
4444
threadpool::MonoQueuePool::GetInstance().Startup();
4545

46-
// start brain thread pool
46+
// start indextuner thread pool
4747
if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
4848
threadpool::MonoQueuePool::GetBrainInstance().Startup();
4949
}
@@ -62,13 +62,13 @@ void PelotonInit::Initialize() {
6262
if (settings::SettingsManager::GetBool(settings::SettingId::index_tuner)) {
6363
// Set the default visibility flag for all indexes to false
6464
index::IndexMetadata::SetDefaultVisibleFlag(false);
65-
auto &index_tuner = brain::IndexTuner::GetInstance();
65+
auto &index_tuner = indextuner::IndexTuner::GetInstance();
6666
index_tuner.Start();
6767
}
6868

6969
// start layout tuner
7070
if (settings::SettingsManager::GetBool(settings::SettingId::layout_tuner)) {
71-
auto &layout_tuner = brain::LayoutTuner::GetInstance();
71+
auto &layout_tuner = indextuner::LayoutTuner::GetInstance();
7272
layout_tuner.Start();
7373
}
7474

@@ -94,13 +94,13 @@ void PelotonInit::Initialize() {
9494
void PelotonInit::Shutdown() {
9595
// shut down index tuner
9696
if (settings::SettingsManager::GetBool(settings::SettingId::index_tuner)) {
97-
auto &index_tuner = brain::IndexTuner::GetInstance();
97+
auto &index_tuner = indextuner::IndexTuner::GetInstance();
9898
index_tuner.Stop();
9999
}
100100

101101
// shut down layout tuner
102102
if (settings::SettingsManager::GetBool(settings::SettingId::layout_tuner)) {
103-
auto &layout_tuner = brain::LayoutTuner::GetInstance();
103+
auto &layout_tuner = indextuner::LayoutTuner::GetInstance();
104104
layout_tuner.Stop();
105105
}
106106

@@ -113,7 +113,7 @@ void PelotonInit::Shutdown() {
113113
// stop worker pool
114114
threadpool::MonoQueuePool::GetInstance().Shutdown();
115115

116-
// stop brain thread pool
116+
// stop indextuner thread pool
117117
if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
118118
threadpool::MonoQueuePool::GetBrainInstance().Shutdown();
119119
}

src/include/common/dedicated_thread_registry.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#include <thread>
1818
#include "common/macros.h"
1919
#include "common/dedicated_thread_task.h"
20+
#include "common/dedicated_thread_owner.h"
2021

2122
namespace peloton {
2223

23-
class DedicatedThreadOwner;
2424
/**
2525
* Singleton class responsible for maintaining and dispensing long running
2626
* (dedicated) threads to other system components. The class also serves
@@ -46,7 +46,11 @@ class DedicatedThreadRegistry {
4646
*/
4747
template <typename Task>
4848
void RegisterDedicatedThread(DedicatedThreadOwner *requester,
49-
std::shared_ptr<Task> task);
49+
std::shared_ptr<Task> task) {
50+
thread_owners_table_[requester].push_back(task);
51+
requester->NotifyNewThread();
52+
threads_table_.emplace(task.get(), std::thread([=] { task->RunTask(); }));
53+
}
5054

5155
// TODO(tianyu): Add code for thread removal
5256

src/include/concurrency/transaction_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class TransactionContext : public Printable {
186186
eid_t epoch_id_;
187187

188188
// vector of strings to log at the end of the transaction
189-
// populated only if the brain is running
189+
// populated only if the indextuner is running
190190
std::vector<std::string> query_strings_;
191191

192192
// timestamp when the transaction began

src/include/brain/brain_util.h renamed to src/include/indextuner/brain_util.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// brain_util.h
66
//
7-
// Identification: /peloton/src/include/brain/brain_util.h
7+
// Identification: /peloton/src/include/indextuner/brain_util.h
88
//
99
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
1010
//
@@ -19,10 +19,10 @@
1919
#include <vector>
2020
#include <algorithm>
2121

22-
#include "brain/sample.h"
22+
#include "sample.h"
2323

2424
namespace peloton {
25-
namespace brain {
25+
namespace indextuner {
2626

2727
/**
2828
* Brain Utility Functions
@@ -34,9 +34,9 @@ class BrainUtil {
3434
* It's a vector because there could be more multiple samples per table.
3535
* TableName -> Sample
3636
*/
37-
static std::unordered_map<std::string, std::vector<brain::Sample>> LoadSamplesFile(
37+
static std::unordered_map<std::string, std::vector<indextuner::Sample>> LoadSamplesFile(
3838
const std::string file_path) {
39-
std::unordered_map<std::string, std::vector<brain::Sample>> samples;
39+
std::unordered_map<std::string, std::vector<indextuner::Sample>> samples;
4040

4141
// Parse the input file line-by-line
4242
std::ifstream infile(file_path);
@@ -60,7 +60,7 @@ class BrainUtil {
6060
}
6161
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
6262

63-
brain::Sample sample(columns, weight, brain::SampleType::ACCESS);
63+
indextuner::Sample sample(columns, weight, indextuner::SampleType::ACCESS);
6464
samples[name].push_back(sample);
6565

6666
} // WHILE

src/include/brain/clusterer.h renamed to src/include/indextuner/clusterer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// clusterer.h
66
//
7-
// Identification: src/include/brain/clusterer.h
7+
// Identification: src/include/indextuner/clusterer.h
88
//
99
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
1010
//
@@ -17,12 +17,12 @@
1717
#include <map>
1818

1919
#include "common/printable.h"
20-
#include "brain/sample.h"
20+
#include "sample.h"
2121
#include "common/printable.h"
2222
#include "common/internal_types.h"
2323

2424
namespace peloton {
25-
namespace brain {
25+
namespace indextuner {
2626

2727
#define NEW_SAMPLE_WEIGHT 0.01
2828

@@ -123,5 +123,5 @@ class Clusterer : public Printable {
123123
oid_t sample_column_count_;
124124
};
125125

126-
} // namespace brain
126+
} // namespace indextuner
127127
} // namespace peloton

src/include/brain/index_tuner.h renamed to src/include/indextuner/index_tuner.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//
33
// Peloton
44
//
5-
// index_tuner.h
5+
// indextuner.h
66
//
7-
// Identification: src/include/brain/index_tuner.h
7+
// Identification: src/include/indextuner/indextuner.h
88
//
99
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
1010
//
@@ -29,7 +29,7 @@ namespace storage {
2929
class DataTable;
3030
}
3131

32-
namespace brain {
32+
namespace indextuner {
3333

3434
/**
3535
* Load statistics for Index Tuner from a file
@@ -224,7 +224,7 @@ class IndexTuner {
224224
*
225225
* @return The workload write ratio.
226226
*/
227-
double ComputeWorkloadWriteRatio(const std::vector<brain::Sample> &samples);
227+
double ComputeWorkloadWriteRatio(const std::vector<indextuner::Sample> &samples);
228228

229229
void DropIndexes(storage::DataTable *table);
230230

@@ -293,5 +293,5 @@ class IndexTuner {
293293
bool visibility_mode_ = false;
294294
};
295295

296-
} // namespace brain
296+
} // namespace indextuner
297297
} // namespace peloton

src/include/brain/layout_tuner.h renamed to src/include/indextuner/layout_tuner.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// layout_tuner.h
66
//
7-
// Identification: src/include/brain/layout_tuner.h
7+
// Identification: src/include/indextuner/layout_tuner.h
88
//
99
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
1010
//
@@ -17,7 +17,7 @@
1717
#include <thread>
1818
#include <vector>
1919

20-
#include "brain/clusterer.h"
20+
#include "clusterer.h"
2121
#include "common/internal_types.h"
2222
#include "common/timer.h"
2323

@@ -27,7 +27,7 @@ namespace storage {
2727
class DataTable;
2828
}
2929

30-
namespace brain {
30+
namespace indextuner {
3131

3232
//===--------------------------------------------------------------------===//
3333
// Layout Tuner
@@ -144,5 +144,5 @@ class LayoutTuner {
144144

145145
};
146146

147-
} // namespace brain
147+
} // namespace indextuner
148148
} // namespace peloton

src/include/brain/sample.h renamed to src/include/indextuner/sample.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// sample.h
66
//
7-
// Identification: src/include/brain/sample.h
7+
// Identification: src/include/indextuner/sample.h
88
//
99
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
1010
//
@@ -19,7 +19,7 @@
1919
#include "common/internal_types.h"
2020

2121
namespace peloton {
22-
namespace brain {
22+
namespace indextuner {
2323

2424
#define DEFAULT_SAMPLE_WEIGHT 1.0
2525
#define DEFAULT_COLUMN_VALUE 0.5
@@ -170,14 +170,14 @@ class Sample : public Printable {
170170

171171
};
172172

173-
} // namespace brain
173+
} // namespace indextuner
174174
} // namespace peloton
175175

176176
namespace std {
177177

178178
template <>
179-
struct hash<peloton::brain::Sample> {
180-
size_t operator()(const peloton::brain::Sample &sample) const {
179+
struct hash<peloton::indextuner::Sample> {
180+
size_t operator()(const peloton::indextuner::Sample &sample) const {
181181
// Compute individual hash values using XOR and bit shifting:
182182
long hash = 31;
183183
auto columns = sample.GetColumnsAccessed();

src/include/storage/data_table.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ extern std::vector<peloton::oid_t> sdbench_column_ids;
3333

3434
namespace peloton {
3535

36-
namespace brain {
36+
namespace indextuner {
3737
class Sample;
38-
} // namespace brain
38+
} // namespace indextuner
3939

4040
namespace catalog {
4141
class ForeignKey;
@@ -241,9 +241,9 @@ class DataTable : public AbstractTable {
241241
// LAYOUT TUNER
242242
//===--------------------------------------------------------------------===//
243243

244-
void RecordLayoutSample(const brain::Sample &sample);
244+
void RecordLayoutSample(const indextuner::Sample &sample);
245245

246-
std::vector<brain::Sample> GetLayoutSamples();
246+
std::vector<indextuner::Sample> GetLayoutSamples();
247247

248248
void ClearLayoutSamples();
249249

@@ -255,9 +255,9 @@ class DataTable : public AbstractTable {
255255
// INDEX TUNER
256256
//===--------------------------------------------------------------------===//
257257

258-
void RecordIndexSample(const brain::Sample &sample);
258+
void RecordIndexSample(const indextuner::Sample &sample);
259259

260-
std::vector<brain::Sample> GetIndexSamples();
260+
std::vector<indextuner::Sample> GetIndexSamples();
261261

262262
void ClearIndexSamples();
263263

@@ -418,13 +418,13 @@ class DataTable : public AbstractTable {
418418
column_map_type default_partition_;
419419

420420
// samples for layout tuning
421-
std::vector<brain::Sample> layout_samples_;
421+
std::vector<indextuner::Sample> layout_samples_;
422422

423423
// layout samples mutex
424424
std::mutex layout_samples_mutex_;
425425

426426
// samples for layout tuning
427-
std::vector<brain::Sample> index_samples_;
427+
std::vector<indextuner::Sample> index_samples_;
428428

429429
// index samples mutex
430430
std::mutex index_samples_mutex_;

0 commit comments

Comments
 (0)