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

[15721] Logging and Recovery #1348

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
fc8eda8
serialized and inserted log records for inserts
gvos94 Feb 20, 2018
e318f53
insert logging refactoring
gvos94 Feb 22, 2018
ba219b4
merged logging branch
gvos94 Mar 20, 2018
2c6a4ba
merged insert-logging branch
gvos94 Mar 20, 2018
a214b57
stored single statement txn status in transaction context
gvos94 Mar 21, 2018
943cb23
single statement transaction - pushed commit to worker thread
gvos94 Mar 21, 2018
cacdf54
Basic starter for getting values from codegen
Mar 22, 2018
fb02b98
Updates getting info from codegen
Mar 23, 2018
fa8ed5a
Working updates with codegen
Mar 23, 2018
d681bf7
multi statement transaction - pushed commit to worker thread
gvos94 Mar 25, 2018
0df5f99
added order by clause to query_logger_test
gvos94 Mar 25, 2018
7cf00b6
Inserts and updates working with codegen
Mar 27, 2018
6ed8c3b
updates bug fix
Mar 30, 2018
2cd4caa
deletes and updates working with ItemPointer
Mar 30, 2018
a04e251
Writing the size of the diff buffer into the update log record
Mar 30, 2018
ec9aa9f
added support for tokenized logging
gvos94 Apr 2, 2018
ea33dd0
merge insert-logging and logging commits
Apr 2, 2018
982edc4
Merge branch 'rearchitect_network' of https://github.com/aaron-tian/p…
Apr 3, 2018
2f8b695
Do not assert for commit log records
Apr 4, 2018
72320a1
Adding log changes to old engine to log schema changes
Apr 6, 2018
8b431e9
plugged in callbacks
gvos94 Apr 6, 2018
216a9b5
Merge branch 'update_codegen' of https://github.com/aaron-tian/peloto…
Apr 6, 2018
48ee867
fixing merge mistakes for abort
Apr 6, 2018
c2a60fb
refactored CommitQuery/AbortQuery callbacks
gvos94 Apr 10, 2018
8f53eda
1. added support for logging BEGIN_TXN
gvos94 Apr 10, 2018
8ceff64
fixed logger thread join bug
gvos94 Apr 11, 2018
fe38ae0
Merge branch 'logger-callbacks_v2' of https://github.com/aaron-tian/p…
Apr 11, 2018
27d88f3
Merge branch 'master' into logging
Apr 12, 2018
913d3f4
Fix macro names
Apr 12, 2018
a09bec0
Fix conflicts left
Apr 12, 2018
7e60721
Remove redundant function duplicates
Apr 12, 2018
3014398
Remove outdated head files and test files about logging
Apr 12, 2018
28ab506
added logger switch
gvos94 Apr 12, 2018
a31a820
merged changes
gvos94 Apr 12, 2018
53251bc
Merge branch 'logger-callbacks' into logging
Apr 12, 2018
cf22beb
Fix macro names
Apr 12, 2018
ec7a306
Remove finished TODO
Apr 12, 2018
ae63217
Add missing switch replacement
Apr 12, 2018
087d2fe
Add tests for log buffers
Apr 12, 2018
7553a08
Create logging testing utility files
Apr 12, 2018
6da91ba
Add and fix headers
Apr 12, 2018
9f79d88
fixed the fucking race condition
gvos94 Apr 13, 2018
a6fb853
fixed build issues
gvos94 Apr 13, 2018
7e59cd8
Add tile group for the log_buffer_test
Apr 13, 2018
04081ff
Merge branch 'master' into logging
apavlo Apr 13, 2018
dab6376
Complete insert record tests
Apr 16, 2018
196e60c
Complete update record tests
Apr 16, 2018
66160c6
fix included header files
Apr 17, 2018
8858d19
Complete delete record tests
Apr 17, 2018
65fca27
Add logging tests
Apr 20, 2018
6d3f61c
minor update bug fix
latelatif Apr 22, 2018
f2f5994
minor update bug fix
latelatif Apr 22, 2018
5495383
Change the log file name to avoid conflicts
Apr 26, 2018
e9cd27b
Add the flexibility to choose the directory and file for logs
Apr 27, 2018
d15d522
Fix the race condition
Apr 27, 2018
a3fe33f
Enable the choice of turn on or off the logging when initializing
Apr 27, 2018
6f3d8e5
Merge branch 'logger-callbacks' into logging
Apr 27, 2018
6a0ec6a
Moving buffer sizes to pg_settings
May 4, 2018
4a7ed2d
buffer sizes moved to settings
latelatif May 4, 2018
e6a37e4
moving log directory and file paths to settings
latelatif May 4, 2018
6f97ffd
Merge branch 'temp_branch' of https://github.com/aaron-tian/peloton i…
latelatif May 4, 2018
229fb62
Asserting that only one logger thread runs
latelatif May 4, 2018
f8d4d19
recovery: completed phase 1
gvos94 Apr 29, 2018
baed22f
PL_* to PELOTON_*
gvos94 May 4, 2018
bb875d2
recovery: added support for calculating replay order in phase 1
gvos94 Apr 30, 2018
1332dc9
recovery: removed an extraneous map
gvos94 May 1, 2018
49c9512
recovery: refactored code for two passes
gvos94 May 1, 2018
af1240b
recovery: completed second pass
gvos94 May 1, 2018
789fe4e
recovery: code refactor
gvos94 May 1, 2018
94a4c92
recovery: reset epoch to max_epoch in log
gvos94 May 1, 2018
f174bea
recovery: recovers a database
gvos94 May 1, 2018
dd04cd0
removed stale values from tcop_txn_state_
gvos94 May 2, 2018
12acc77
update pd_database NextOid during recovery
gvos94 May 3, 2018
8ac72f7
1. Fix database recovery bug - registered db with catalog
gvos94 May 4, 2018
629218c
completed index recovery
gvos94 May 4, 2018
46ceb0e
recovery: recovers a tuple inserts
gvos94 May 4, 2018
e00732c
recovery: recovers tuple-deletes from non-catalog tables. (drop table…
gvos94 May 4, 2018
544c6f9
PL_* to PELOTON_*
gvos94 May 5, 2018
07f2e22
Few bug fixes and code cleanup
latelatif May 5, 2018
5e9b17b
code refactoring
gvos94 May 5, 2018
6ec3e76
moved enable_logging flag to settings
gvos94 May 5, 2018
aa2a4d8
merged anirudh's fixes
gvos94 May 5, 2018
d539040
Adapt to new APIs
May 5, 2018
52b46dd
Specify whether to turn on recovery mode at initilization
May 5, 2018
91f7920
Add the recovery switch into settings
May 5, 2018
2b752da
Adjust the log level
May 5, 2018
1ba0f23
Separate the insert log buffer test
May 5, 2018
7e38591
Separate the update log buffer test
May 5, 2018
3f63eb5
Separate the delete log buffer test
May 5, 2018
4627b6a
Add the codebase for recovery tests
May 5, 2018
c6564d9
Change catalog singletons in recovery to instances
May 6, 2018
5a73bcf
Change logging & header files
May 6, 2018
6b152ff
Merge branch 'master' into logging
latelatif May 8, 2018
0b68865
Incorporating schema/namespace changes with logging/recovery
latelatif May 9, 2018
2793bfa
Add logging and recovery tests
Jun 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 41 additions & 35 deletions src/codegen/buffering_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,46 @@ void BufferingConsumer::Prepare(CompilationContext &ctx) {
runtime_state.RegisterState("consumerState", codegen.CharPtrType());
}

void BufferingConsumer::AddToTupleBuffer(Value &val, CodeGen &codegen, llvm::Value *tuple_buffer, size_t &i) {
const auto &sql_type = val.GetType().GetSqlType();

// Check if it's NULL
Value null_val;
lang::If val_is_null{codegen, val.IsNull(codegen)};
{
// If the value is NULL (i.e., has the NULL bit set), produce the NULL
// value for the given type.
null_val = sql_type.GetNullValue(codegen);
}
val_is_null.EndIf();
val = val_is_null.BuildPHI(null_val, val);

// Output the value using the type's output function
auto *output_func = sql_type.GetOutputFunction(codegen, val.GetType());

// Setup the function arguments
std::vector<llvm::Value *> args = {tuple_buffer, codegen.Const32(i),
val.GetValue()};
// If the value is a string, push back the length
if (val.GetLength() != nullptr) {
args.push_back(val.GetLength());
}

// If the value is a boolean, push back the NULL bit. We don't do that for
// the other data types because we have special values for NULL. Booleans
// in codegen are 1-bit types, as opposed to 1-byte types in the rest of the
// system. Since, we cannot have a special value for NULL in a 1-bit boolean
// system, we pass along the NULL bit during output.
if (sql_type.TypeId() == peloton::type::TypeId::BOOLEAN) {
args.push_back(val.IsNull(codegen));
}

// Call the function
codegen.CallFunc(output_func, args);
}



// For each output attribute, we write out the attribute's value into the
// currently active output tuple. When all attributes have been written, we
// call BufferTuple(...) to append the currently active tuple into the output.
Expand All @@ -95,41 +135,7 @@ void BufferingConsumer::ConsumeResult(ConsumerContext &ctx,
Value val = row.DeriveValue(codegen, output_ais_[i]);

PELOTON_ASSERT(output_ais_[i]->type == val.GetType());
const auto &sql_type = val.GetType().GetSqlType();

// Check if it's NULL
Value null_val;
lang::If val_is_null{codegen, val.IsNull(codegen)};
{
// If the value is NULL (i.e., has the NULL bit set), produce the NULL
// value for the given type.
null_val = sql_type.GetNullValue(codegen);
}
val_is_null.EndIf();
val = val_is_null.BuildPHI(null_val, val);

// Output the value using the type's output function
auto *output_func = sql_type.GetOutputFunction(codegen, val.GetType());

// Setup the function arguments
std::vector<llvm::Value *> args = {tuple_buffer_, codegen.Const32(i),
val.GetValue()};
// If the value is a string, push back the length
if (val.GetLength() != nullptr) {
args.push_back(val.GetLength());
}

// If the value is a boolean, push back the NULL bit. We don't do that for
// the other data types because we have special values for NULL. Booleans
// in codegen are 1-bit types, as opposed to 1-byte types in the rest of the
// system. Since, we cannot have a special value for NULL in a 1-bit boolean
// system, we pass along the NULL bit during output.
if (sql_type.TypeId() == peloton::type::TypeId::BOOLEAN) {
args.push_back(val.IsNull(codegen));
}

// Call the function
codegen.CallFunc(output_func, args);
AddToTupleBuffer(val, codegen, tuple_buffer_, i);
}

// Append the tuple to the output buffer (by calling BufferTuple(...))
Expand Down
8 changes: 3 additions & 5 deletions src/codegen/inserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
#include "codegen/transaction_runtime.h"
#include "common/container_tuple.h"
#include "concurrency/transaction_manager_factory.h"
#include "executor/executor_context.h"
#include "executor/logical_tile.h"
#include "executor/logical_tile_factory.h"
#include "storage/data_table.h"
#include "storage/tile_group.h"
#include "storage/tile.h"
#include "threadpool/logger_queue_pool.h"

namespace peloton {
namespace codegen {
Expand Down Expand Up @@ -48,7 +46,7 @@ peloton::type::AbstractPool *Inserter::GetPool() {
return tile_->GetPool();
}

void Inserter::Insert() {
void Inserter::Insert(char *values_buf, uint32_t values_size) {
PELOTON_ASSERT(table_ && executor_context_ && tile_);
auto *txn = executor_context_->GetTransaction();
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
Expand All @@ -61,7 +59,7 @@ void Inserter::Insert() {
txn_manager.SetTransactionResult(txn, ResultType::FAILURE);
return;
}
txn_manager.PerformInsert(txn, location_, index_entry_ptr);
txn_manager.PerformInsert(txn, location_, index_entry_ptr, values_buf, values_size);
executor_context_->num_processed++;
}

Expand Down
28 changes: 25 additions & 3 deletions src/codegen/operator/insert_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
//
//===----------------------------------------------------------------------===//

#include "codegen/buffering_consumer.h"
#include "codegen/proxy/inserter_proxy.h"
#include "codegen/proxy/query_parameters_proxy.h"
#include "codegen/proxy/storage_manager_proxy.h"
#include "codegen/proxy/transaction_runtime_proxy.h"
#include "codegen/proxy/tuple_proxy.h"
#include "codegen/proxy/value_proxy.h"
#include "codegen/proxy/values_runtime_proxy.h"
#include "codegen/operator/insert_translator.h"
#include "planner/insert_plan.h"
#include "storage/data_table.h"
Expand Down Expand Up @@ -79,15 +82,23 @@ void InsertTranslator::Produce() const {

// Transform into the codegen values and store values in the tuple storage
std::vector<codegen::Value> values;
for (uint32_t column_id = 0; column_id < num_columns; column_id++) {
auto *values_buf = codegen.AllocateBuffer(
ValueProxy::GetType(codegen), num_columns,
"values");
values_buf =
codegen->CreatePointerCast(values_buf, codegen.CharPtrType());
llvm::Value *values_size = codegen.Const32((int32_t)num_columns);
for (size_t column_id = 0; column_id < num_columns; column_id++) {
auto value =
parameter_cache.GetValue(column_id + tuple_idx * num_columns);
values.push_back(value);
peloton::codegen::BufferingConsumer::AddToTupleBuffer(value, codegen, values_buf, column_id);
}
table_storage_.StoreValues(codegen, tuple_ptr, values, pool);

std::vector<llvm::Value *> insert_args = {inserter, values_buf, values_size};
// Complete the insertion
codegen.Call(InserterProxy::Insert, {inserter});
codegen.Call(InserterProxy::Insert, insert_args);
}
}
}
Expand All @@ -103,14 +114,25 @@ void InsertTranslator::Consume(ConsumerContext &, RowBatch::Row &row) const {
// Generate/Materialize tuple data from row and attribute information
std::vector<codegen::Value> values;
auto &ais = insert_plan_.GetAttributeInfos();
auto *values_buf = codegen.AllocateBuffer(
ValueProxy::GetType(codegen), static_cast<uint32_t>(ais.size()),
"values");
values_buf =
codegen->CreatePointerCast(values_buf, codegen.CharPtrType());
llvm::Value *values_size = codegen.Const32((int32_t)ais.size());
size_t i = 0;
for (const auto *ai : ais) {
codegen::Value v = row.DeriveValue(codegen, ai);
values.push_back(v);
peloton::codegen::BufferingConsumer::AddToTupleBuffer(v, codegen, values_buf, i);
i++;
}
table_storage_.StoreValues(codegen, tuple_ptr, values, pool);

std::vector<llvm::Value *> insert_args = {inserter, values_buf, values_size};

// Call Inserter to insert the reserved tuple storage area
codegen.Call(InserterProxy::Insert, {inserter});
codegen.Call(InserterProxy::Insert, insert_args);
}

void InsertTranslator::TearDownState() {
Expand Down
40 changes: 36 additions & 4 deletions src/codegen/operator/update_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
//
//===----------------------------------------------------------------------===//

#include "codegen/buffering_consumer.h"
#include "codegen/lang/if.h"
#include "codegen/proxy/storage_manager_proxy.h"
#include "codegen/proxy/target_proxy.h"
#include "codegen/proxy/updater_proxy.h"
#include "codegen/proxy/value_proxy.h"
#include "codegen/proxy/values_runtime_proxy.h"
#include "codegen/operator/update_translator.h"
#include "codegen/table_storage.h"
#include "codegen/type/sql_type.h"
#include "planner/update_plan.h"
#include "storage/data_table.h"

Expand Down Expand Up @@ -92,17 +96,45 @@ void UpdateTranslator::Consume(ConsumerContext &, RowBatch::Row &row) const {
static_cast<uint32_t>(target_list.size() + direct_map_list.size());
auto &ais = update_plan_.GetAttributeInfos();

auto is_primary_key = update_plan_.GetUpdatePrimaryKey();
llvm::Value *diff = nullptr, *diff_size = nullptr;
if (is_primary_key) {
diff_size = codegen.Const32((int32_t)column_num);
diff = codegen.AllocateBuffer(
ValueProxy::GetType(codegen), column_num,
"diff");
} else {
diff_size = codegen.Const32((int32_t)target_list.size());
diff = codegen.AllocateBuffer(
ValueProxy::GetType(codegen), static_cast<uint32_t>(target_list.size()),
"diff");
}


diff =
codegen->CreatePointerCast(diff, codegen.CharPtrType());
// Collect all the column values
std::vector<codegen::Value> values;
for (uint32_t i = 0; i < column_num; i++) {
for (size_t i = 0, target_id = 0; i < column_num; i++) {
codegen::Value val;
uint32_t target_index = GetTargetIndex(target_list, i);
if (target_index != INVALID_OID) {
// Set the value for the update
const auto &derived_attribute = target_list[target_index].second;
val = row.DeriveValue(codegen, *derived_attribute.expr);
size_t offset = 0;
if (is_primary_key) {
offset = i;
} else {
offset = target_id;
}
peloton::codegen::BufferingConsumer::AddToTupleBuffer(val, codegen, diff, offset);
target_id++;
} else {
val = row.DeriveValue(codegen, ais[i]);
if (is_primary_key) {
peloton::codegen::BufferingConsumer::AddToTupleBuffer(val, codegen, diff, i);
}
}
values.push_back(val);
}
Expand All @@ -112,7 +144,7 @@ void UpdateTranslator::Consume(ConsumerContext &, RowBatch::Row &row) const {
llvm::Value *tuple_ptr;
std::vector<llvm::Value *> prep_args = {updater, row.GetTileGroupID(),
row.GetTID(codegen)};
if (update_plan_.GetUpdatePrimaryKey() == false) {
if (is_primary_key == false) {
tuple_ptr = codegen.Call(UpdaterProxy::Prepare, prep_args);
} else {
tuple_ptr = codegen.Call(UpdaterProxy::PreparePK, prep_args);
Expand All @@ -130,8 +162,8 @@ void UpdateTranslator::Consume(ConsumerContext &, RowBatch::Row &row) const {
table_storage_.StoreValues(codegen, tuple_ptr, values, pool_ptr);

// Finally, update with help from the Updater
std::vector<llvm::Value *> update_args = {updater};
if (update_plan_.GetUpdatePrimaryKey() == false) {
std::vector<llvm::Value *> update_args = {updater, diff, diff_size};
if (is_primary_key == false) {
codegen.Call(UpdaterProxy::Update, update_args);
} else {
codegen.Call(UpdaterProxy::UpdatePK, update_args);
Expand Down
22 changes: 15 additions & 7 deletions src/codegen/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Copyright (c) 2015-17, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "codegen/buffering_consumer.h"
#include "codegen/updater.h"
#include "codegen/transaction_runtime.h"
#include "common/container_tuple.h"
Expand All @@ -23,6 +23,13 @@
#include "type/abstract_pool.h"
#include "common/internal_types.h"
#include "type/value.h"
#include "threadpool/mono_queue_pool.h"
#include "logging/log_record.h"
#include "logging/log_buffer.h"
#include "logging/wal_logger.h"
#include "threadpool/logger_queue_pool.h"
#include "../include/type/value.h"
#include "../include/codegen/value.h"

namespace peloton {
namespace codegen {
Expand Down Expand Up @@ -126,7 +133,7 @@ peloton::type::AbstractPool *Updater::GetPool() {
return tile_->GetPool();
}

void Updater::Update() {
void Updater::Update(char *diff_array, uint32_t diff_size) {
PELOTON_ASSERT(table_ != nullptr && executor_context_ != nullptr);
LOG_TRACE("Updating tuple <%u, %u> from table '%s' (db ID: %u, table ID: %u)",
old_location_.block, old_location_.offset,
Expand All @@ -138,7 +145,7 @@ void Updater::Update() {
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
// Either update in-place
if (is_owner_ == true) {
txn_manager.PerformUpdate(txn, old_location_);
txn_manager.PerformUpdate(txn, old_location_, diff_array, diff_size, target_list_);
// we do not need to add any item pointer to statement-level write set
// here, because we do not generate any new version
executor_context_->num_processed++;
Expand All @@ -157,12 +164,13 @@ void Updater::Update() {
old_location_.offset);
return;
}
txn_manager.PerformUpdate(txn, old_location_, new_location_);
AddToStatementWriteSet(new_location_);
txn_manager.PerformUpdate(txn, old_location_, new_location_, diff_array, diff_size, target_list_);

executor_context_->num_processed++;
AddToStatementWriteSet(new_location_);
}

void Updater::UpdatePK() {
void Updater::UpdatePK(char *diff_array, uint32_t diff_size) {
PELOTON_ASSERT(table_ != nullptr && executor_context_ != nullptr);
LOG_TRACE("Updating tuple <%u, %u> from table '%s' (db ID: %u, table ID: %u)",
old_location_.block, old_location_.offset,
Expand All @@ -181,7 +189,7 @@ void Updater::UpdatePK() {
txn_manager.SetTransactionResult(txn, ResultType::FAILURE);
return;
}
txn_manager.PerformInsert(txn, new_location_, index_entry_ptr);
txn_manager.PerformInsert(txn, new_location_, index_entry_ptr, diff_array, diff_size);
AddToStatementWriteSet(new_location_);
executor_context_->num_processed++;
}
Expand Down
16 changes: 16 additions & 0 deletions src/common/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "tuning/index_tuner.h"
#include "tuning/layout_tuner.h"


namespace peloton {

ThreadPool thread_pool;
Expand Down Expand Up @@ -90,6 +91,21 @@ void PelotonInit::Initialize() {

// Initialize the Statement Cache Manager
StatementCacheManager::Init();

bool enable_logging = settings::SettingsManager::GetBool(settings::SettingId::enable_logging);
if(enable_logging){
if(!logging::LogManager::GetInstance().init()){
LOG_ERROR("LogManager Initialization failed");
}
}

bool enable_recovery = settings::SettingsManager::GetBool(settings::SettingId::enable_recovery);
if(enable_recovery){
logging::LogManager::GetInstance().DoRecovery();
}

threadpool::LoggerQueuePool::GetInstance().Startup();

}

void PelotonInit::Shutdown() {
Expand Down
Loading