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

Checkpointing #1310

Open
wants to merge 118 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
eb73c4e
implement checkpointing
ksaito7 Mar 6, 2018
84f4bb3
add database count for checkpointing catalog
ksaito7 Mar 6, 2018
a050273
add checkpointing test
ksaito7 Mar 6, 2018
6e3fdcf
modify checkpointing catalog data
ksaito7 Mar 6, 2018
d0cfa6e
change to use oid for checkpoint file name
ksaito7 Mar 6, 2018
094da29
modify oid_t serialization from long to int
ksaito7 Mar 6, 2018
cfc25b3
clean up checkpointing catalog
ksaito7 Mar 6, 2018
88197c1
implement catalog recovery
ksaito7 Mar 9, 2018
203f0e0
implement checkpoint recovery
ksaito7 Mar 20, 2018
9bb3aef
cleaning some checkpoint stuffs
ksaito7 Mar 20, 2018
58f8adb
cleaning some checkpoint stuffs
ksaito7 Mar 20, 2018
8df22b7
Merge branch 'master' into checkpoint
ksaito7 Mar 20, 2018
f75bbf6
Merge branch 'master' into checkpoint
ksaito7 Mar 21, 2018
2a74961
merge latest version
ksaito7 Mar 21, 2018
21100fd
implement checkpoints keeping tile group structure
ksaito7 Mar 26, 2018
a4ac0a9
Merge branch 'master' into checkpoint
ksaito7 Mar 27, 2018
246ac2c
modify and add for checkpoints
ksaito7 Mar 28, 2018
2fb7e8f
modify and add for checkpoints
ksaito7 Mar 28, 2018
a71329d
modify and add for checkpoints
ksaito7 Mar 29, 2018
7680d8d
implement catalog checkpointing & recovery
ksaito7 Apr 2, 2018
101d822
add low level test for checkpoint recovery
ksaito7 Apr 3, 2018
9daa33e
fix debug log level
ksaito7 Apr 3, 2018
e50223f
fix the function ResultTypeToString
ksaito7 Apr 10, 2018
b856af3
add functions for checkpoints
ksaito7 Apr 10, 2018
2522216
implement checkpoints for foreign key and trigger
ksaito7 Apr 10, 2018
02e73ed
add low level test and constraint test
ksaito7 Apr 10, 2018
ff4163e
disable foreign key checkpoint recovery
ksaito7 Apr 11, 2018
ab8d53c
implement catalog recovery and foreign key recovery
ksaito7 Apr 18, 2018
0a1c0d0
merge the master
ksaito7 Apr 18, 2018
83f348c
modify bugs by merge
ksaito7 Apr 18, 2018
56202b1
change log level from debug to trace
ksaito7 Apr 18, 2018
3150584
fix bugs and format
ksaito7 Apr 19, 2018
4ad205a
change %lu to PRIu64 in LOG print
ksaito7 Apr 20, 2018
55ce729
fix checkpoint type test
ksaito7 Apr 20, 2018
0d858a2
fix checkpoint config value
ksaito7 Apr 20, 2018
c2225b2
for checking Jenkins error
ksaito7 Apr 23, 2018
80ee7d3
modify where the stack over flow might be occurred
ksaito7 Apr 23, 2018
a6c9ab5
fix the order of Columns in Schema
ksaito7 Apr 24, 2018
277d01b
fix where the stack over flow might be occurred
ksaito7 Apr 24, 2018
6d30720
fix where the stack over flow might be occurred
ksaito7 Apr 25, 2018
298fa95
fix where the stack over flow might be occurred
ksaito7 Apr 24, 2018
6ee48b1
Merge remote-tracking branch 'origin/checkpoint' into checkpoint
ksaito7 Apr 25, 2018
175636c
add output logs for debug
ksaito7 Apr 26, 2018
e7472ec
Add debug info
ksaito7 Apr 26, 2018
36c951b
Merge branch 'master' into checkpoint
ksaito7 Apr 26, 2018
39246bd
Add debug info
ksaito7 Apr 26, 2018
b4de859
Delete array data
ksaito7 Apr 26, 2018
c6927f7
Fix memory leaks
ksaito7 Apr 27, 2018
44bc5b9
Modify scandir to readdir
ksaito7 Apr 27, 2018
c441c2c
Add debug info
ksaito7 Apr 27, 2018
fcbdb48
Add debug info
ksaito7 Apr 27, 2018
76d4c83
Modify debug info
ksaito7 Apr 27, 2018
090fba7
Merge branch 'master' into checkpoint
Apr 29, 2018
ca5f2f6
Merge branch 'master' into checkpoint
May 3, 2018
3f6a1b1
add checkpointing test stuff
ksaito7 May 7, 2018
0a84921
Merge branch 'master' into checkpoint
ksaito7 May 7, 2018
2a0471b
follow up to catalog refactoring
ksaito7 May 8, 2018
7e22b88
fix related to review comments
ksaito7 May 9, 2018
bf6bce7
merge with remote branch
ksaito7 May 9, 2018
d32c9e4
clean up
ksaito7 May 9, 2018
5d4c7da
modify test for divided tile groups
ksaito7 May 9, 2018
d3f0125
change beginning transaction place
ksaito7 May 9, 2018
93b6907
check the primary key error
ksaito7 May 10, 2018
678890d
for debug in tile_group.h
ksaito7 May 10, 2018
81aaf65
Fix bugs in recreating database
ksaito7 May 11, 2018
b2ea9f5
Add commit into each constraint test & clean debug output
ksaito7 May 11, 2018
1f8aeaa
Add clearing active_tile_groups_ in DropTileGroup
ksaito7 May 11, 2018
2756302
Fix active tile group stuff
ksaito7 May 11, 2018
f9a7372
Rollback settings for debug
ksaito7 May 11, 2018
be6d111
change vector access method from [] to at
ksaito7 May 12, 2018
a61f470
Formmatting
ksaito7 May 12, 2018
f72d6be
Check where the travis error occurs
ksaito7 May 12, 2018
e110bc8
Check where the travis error occurs
ksaito7 May 12, 2018
4d9d9b6
Check where the travis error occurs
ksaito7 May 12, 2018
f827335
Check where the travis error occurs
ksaito7 May 12, 2018
1eba948
Check where the travis error occurs
ksaito7 May 13, 2018
4c49698
Check where the travis error occurs
ksaito7 May 13, 2018
a068a97
Check where the travis error occurs
ksaito7 May 13, 2018
e602de9
Check where the travis error occurs
ksaito7 May 14, 2018
c6984d8
Check where the travis error occurs
ksaito7 May 14, 2018
05a464e
Merge branch 'master' into checkpoint
ksaito7 May 15, 2018
40259ac
Update tile_group.h
ksaito7 May 15, 2018
59ee7ed
Add layout catalog support
ksaito7 May 16, 2018
437e01c
Remove same name variables
ksaito7 May 17, 2018
c13f179
Simplify column insert
ksaito7 May 18, 2018
bf202c6
Add check of array access
ksaito7 May 18, 2018
e08ad76
Delete unnecessary debug info
ksaito7 May 20, 2018
91636c8
Change variable name
ksaito7 May 21, 2018
46c04a2
Rollback to commit 437e01c
ksaito7 May 21, 2018
3493632
Check where the travis error occurs
ksaito7 May 21, 2018
727d2d6
Check where the travis error occurs
ksaito7 May 21, 2018
f4409bc
Check where the travis error occurs
ksaito7 May 21, 2018
ef93c4b
Modify variable declarations for reference return
ksaito7 May 21, 2018
7abbe07
Modify variable declarations for reference return
ksaito7 May 22, 2018
735d33f
Merge branch 'master' into checkpoint
ksaito7 May 22, 2018
0037a25
Check where the travis error occurs
ksaito7 May 22, 2018
1d335d8
Check where the travis error occurs
ksaito7 May 22, 2018
714e193
Check where the travis error occurs
ksaito7 May 22, 2018
b6ef41f
Check where the travis error occurs
ksaito7 May 22, 2018
839a6c4
Check where the travis error occurs
ksaito7 May 22, 2018
bf77d5a
Merge branch 'master' into checkpoint
ksaito7 Jun 19, 2018
b4adf09
Replace tab with spaces
ksaito7 Jun 19, 2018
d6c93fc
Remove column length from metadata file
ksaito7 Jun 20, 2018
c6c84ea
Update oid recovery logic
ksaito7 Jun 20, 2018
8e32619
Merge transaction beginning point
ksaito7 Jun 20, 2018
3ddfbc8
Add layout recovery from catalog
ksaito7 Jun 20, 2018
0446bc7
Modify recovering layout in tile group
ksaito7 Jun 20, 2018
916833a
Clean up unnecessary functions
ksaito7 Jun 20, 2018
4870ada
Fix a bug in LOG_TRACE
ksaito7 Jun 21, 2018
ff167d8
Add SettingCatalog recovery
ksaito7 Jun 22, 2018
b5e0383
Merge branch 'master' into checkpoint
tli2 Jun 26, 2018
ae826cf
Merge branch 'master' into checkpoint
ksaito7 Jun 29, 2018
5902ee8
Merge branch 'checkpoint' of https://github.com/aaron-tian/peloton in…
ksaito7 Jun 29, 2018
5ae9fd8
Merge branch 'master' into checkpoint
ksaito7 Jul 2, 2018
2ad4c0b
Merge branch 'master' into checkpoint
ksaito7 Jul 4, 2018
c4b3611
Modify checkpoint recovery to create all storage objects from catalog
ksaito7 Jul 5, 2018
b2a881e
Change function names
ksaito7 Jul 5, 2018
af92a66
Add comments and fix unused variables
ksaito7 Jul 5, 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
171 changes: 129 additions & 42 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "catalog/column_catalog.h"
#include "catalog/database_catalog.h"
#include "catalog/database_metrics_catalog.h"
#include "catalog/foreign_key.h"
#include "catalog/index_catalog.h"
#include "catalog/index_metrics_catalog.h"
#include "catalog/language_catalog.h"
Expand Down Expand Up @@ -148,12 +149,12 @@ void Catalog::Bootstrap() {
DatabaseMetricsCatalog::GetInstance(txn);
TableMetricsCatalog::GetInstance(txn);
IndexMetricsCatalog::GetInstance(txn);
QueryMetricsCatalog::GetInstance(txn);
QueryMetricsCatalog::GetInstance(txn);
SettingsCatalog::GetInstance(txn);
TriggerCatalog::GetInstance(txn);
LanguageCatalog::GetInstance(txn);
ProcCatalog::GetInstance(txn);

if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
QueryHistoryCatalog::GetInstance(txn);
}
Expand Down Expand Up @@ -614,18 +615,18 @@ ResultType Catalog::DropIndex(oid_t index_oid,

ResultType Catalog::DropIndex(const std::string &index_name,
concurrency::TransactionContext *txn) {
if(txn == nullptr) {
throw CatalogException("Do not have transaction to drop index " +
index_name);
}
auto index_object = catalog::IndexCatalog::GetInstance()->GetIndexObject(
index_name, txn);
if(index_object == nullptr) {
throw CatalogException("Index name " + index_name + " cannot be found");
}
ResultType result = DropIndex(index_object->GetIndexOid(), txn);
if (txn == nullptr) {
throw CatalogException("Do not have transaction to drop index " +
index_name);
}
auto index_object =
catalog::IndexCatalog::GetInstance()->GetIndexObject(index_name, txn);
if (index_object == nullptr) {
throw CatalogException("Index name " + index_name + " cannot be found");
}
ResultType result = DropIndex(index_object->GetIndexOid(), txn);

return result;
return result;
}

//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -719,6 +720,26 @@ std::shared_ptr<DatabaseCatalogObject> Catalog::GetDatabaseObject(
return database_object;
}

/* Get database catalog object from cache (cached_only == true),
* or all the way from storage (cached_only == false)
* throw exception and abort txn if not exists/invisible
* */
std::unordered_map<oid_t, std::shared_ptr<DatabaseCatalogObject>>
Catalog::GetDatabaseObjects(concurrency::TransactionContext *txn,
bool cached_only) {
if (txn == nullptr) {
throw CatalogException("Do not have transaction to get database objects");
}

if (!cached_only && !txn->catalog_cache.valid_database_objects) {
// cache miss get from pg_table
return DatabaseCatalog::GetInstance()->GetDatabaseObjects(txn);
}
// make sure to check IsValidTableObjects() before getting table objects
PELOTON_ASSERT(txn->catalog_cache.valid_database_objects);
return txn->catalog_cache.database_objects_cache;
}

/* Check table from pg_table with table_name using txn,
* get it from storage layer using table_oid,
* throw exception and abort txn if not exists/invisible
Expand Down Expand Up @@ -787,6 +808,76 @@ std::shared_ptr<TableCatalogObject> Catalog::GetTableObject(
return table_object;
}

//===--------------------------------------------------------------------===//
// CHECK EXISTENCE WITH NAME - CHECK FROM CATALOG TABLES, USING TRANSACTION
//===--------------------------------------------------------------------===//

// check existence of database with database_name using txn.
bool Catalog::ExistDatabaseByName(const std::string &database_name,
concurrency::TransactionContext *txn) {
if (txn == nullptr)
throw CatalogException("Do not have transaction to check database " +
database_name);

auto database_object =
DatabaseCatalog::GetInstance()->GetDatabaseObject(database_name, txn);
if (database_object == nullptr) {
return false;
} else {
return true;
}
}

// check existence of table with table_name using txn.
bool Catalog::ExistTableByName(const std::string &database_name,
const std::string &table_name,
concurrency::TransactionContext *txn) {
if (txn == nullptr)
throw CatalogException("Do not have transaction to check table " +
table_name);

auto database_object =
DatabaseCatalog::GetInstance()->GetDatabaseObject(database_name, txn);
if (database_object == nullptr) {
return false;
} else {
auto table_object = database_object->GetTableObject(table_name);
if (table_object == nullptr) {
return false;
} else {
return true;
}
}
}

// check existence of index with index_name using txn.
bool Catalog::ExistIndexByName(const std::string &database_name,
const std::string &table_name,
const std::string &index_name,
concurrency::TransactionContext *txn) {
if (txn == nullptr)
throw CatalogException("Do not have transaction to check index " +
index_name);

auto database_object =
DatabaseCatalog::GetInstance()->GetDatabaseObject(database_name, txn);
if (database_object == nullptr) {
return false;
} else {
auto table_object = database_object->GetTableObject(table_name);
if (table_object == nullptr) {
return false;
} else {
auto index_object = table_object->GetIndexObject(index_name);
if (index_object == nullptr) {
return false;
} else {
return true;
}
}
}
}

//===--------------------------------------------------------------------===//
// DEPRECATED
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -1064,11 +1155,11 @@ void Catalog::InitializeFunctions() {
/**
* decimal functions
*/
AddBuiltinFunction(
"abs", {type::TypeId::DECIMAL}, type::TypeId::DECIMAL, internal_lang,
"Abs", function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);
AddBuiltinFunction("abs", {type::TypeId::DECIMAL}, type::TypeId::DECIMAL,
internal_lang, "Abs",
function::BuiltInFuncType{
OperatorId::Abs, function::DecimalFunctions::_Abs},
txn);
AddBuiltinFunction(
"sqrt", {type::TypeId::TINYINT}, type::TypeId::DECIMAL, internal_lang,
"Sqrt", function::BuiltInFuncType{OperatorId::Sqrt,
Expand Down Expand Up @@ -1105,33 +1196,29 @@ void Catalog::InitializeFunctions() {
/**
* integer functions
*/
AddBuiltinFunction(
"abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);
AddBuiltinFunction("abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT,
internal_lang, "Abs",
function::BuiltInFuncType{
OperatorId::Abs, function::DecimalFunctions::_Abs},
txn);

AddBuiltinFunction(
"abs", {type::TypeId::SMALLINT}, type::TypeId::SMALLINT,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);
AddBuiltinFunction("abs", {type::TypeId::SMALLINT},
type::TypeId::SMALLINT, internal_lang, "Abs",
function::BuiltInFuncType{
OperatorId::Abs, function::DecimalFunctions::_Abs},
txn);

AddBuiltinFunction(
"abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);
AddBuiltinFunction("abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER,
internal_lang, "Abs",
function::BuiltInFuncType{
OperatorId::Abs, function::DecimalFunctions::_Abs},
txn);

AddBuiltinFunction(
"abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);
AddBuiltinFunction("abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT,
internal_lang, "Abs",
function::BuiltInFuncType{
OperatorId::Abs, function::DecimalFunctions::_Abs},
txn);

AddBuiltinFunction(
"floor", {type::TypeId::INTEGER}, type::TypeId::DECIMAL,
Expand Down
21 changes: 19 additions & 2 deletions src/catalog/catalog_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "catalog/database_catalog.h"
#include "common/logger.h"
#include "concurrency/transaction_context.h"

namespace peloton {
namespace catalog {
Expand All @@ -33,13 +34,13 @@ bool CatalogCache::InsertDatabaseObject(
// check if already in cache
if (database_objects_cache.find(database_object->GetDatabaseOid()) !=
database_objects_cache.end()) {
LOG_DEBUG("Database %u already exists in cache!",
LOG_TRACE("Database %u already exists in cache!",
database_object->GetDatabaseOid());
return false;
}
if (database_name_cache.find(database_object->GetDatabaseName()) !=
database_name_cache.end()) {
LOG_DEBUG("Database %s already exists in cache!",
LOG_TRACE("Database %s already exists in cache!",
database_object->GetDatabaseName().c_str());
return false;
}
Expand Down Expand Up @@ -111,6 +112,22 @@ std::shared_ptr<DatabaseCatalogObject> CatalogCache::GetDatabaseObject(
return it->second;
}

/* @brief Get database catalog object from cache,
or all the way from storage
* @param txn if nullptr, return nullptr on a cache miss
* @return Shared pointer to the requested database catalog object
*/
std::unordered_map<oid_t, std::shared_ptr<DatabaseCatalogObject>>
CatalogCache::GetDatabaseObjects(concurrency::TransactionContext *txn) {
if (!valid_database_objects && txn != nullptr) {
// cache miss get from pg_database
return DatabaseCatalog::GetInstance()->GetDatabaseObjects(txn);
}
// make sure to check IsValidTableObjects() before getting table objects
PELOTON_ASSERT(valid_database_objects);
return database_objects_cache;
}

/*@brief search table catalog object from all cached database objects
* @param table_oid
* @return table catalog object; if not found return null
Expand Down
42 changes: 42 additions & 0 deletions src/catalog/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,48 @@ void Column::SetInlined() {
}
}

// Serialize this column
void Column::SerializeTo(SerializeOutput &out) {
// Column basic information
out.WriteTextString(column_name);
out.WriteInt((int)column_type);
out.WriteInt(GetLength());
out.WriteInt(column_offset);
out.WriteBool(is_inlined);

// Column constraints
out.WriteLong(constraints.size());
for (auto constraint : constraints) {
constraint.SerializeTo(out);
}
}

// Deserialize this column
Column Column::DeserializeFrom(SerializeInput &in) {
// read basic column information
std::string column_name = in.ReadTextString();
type::TypeId column_type = (type::TypeId)in.ReadInt();
size_t column_length = in.ReadInt();
oid_t column_offset = in.ReadInt();
bool is_inlined = in.ReadBool();

auto column = catalog::Column(column_type, column_length, column_name,
is_inlined, column_offset);

// recover column constraints
size_t column_constraint_count = in.ReadLong();
for (oid_t constraint_idx = 0; constraint_idx < column_constraint_count;
constraint_idx++) {
auto column_constraint = Constraint::DeserializeFrom(in, column_type);
// Foreign key constraint will be stored by DataTable deserializer
if (column_constraint.GetType() != ConstraintType::FOREIGN) {
column.AddConstraint(column_constraint);
}
}

return column;
}

const std::string Column::GetInfo() const {
std::ostringstream os;

Expand Down
46 changes: 46 additions & 0 deletions src/catalog/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,49 @@
namespace peloton {
namespace catalog {

// Serialize this constraint
void Constraint::SerializeTo(SerializeOutput &out) {
out.WriteTextString(constraint_name);
out.WriteInt((int)constraint_type);
out.WriteInt(fk_list_offset);
out.WriteInt(unique_index_list_offset);

if (constraint_type == ConstraintType::DEFAULT) {
default_value->SerializeTo(out);
}

if (constraint_type == ConstraintType::CHECK) {
out.WriteInt((int)exp.first);
exp.second.SerializeTo(out);
}
}

// Deserialize this constraint
Constraint Constraint::DeserializeFrom(SerializeInput &in,
const type::TypeId column_type) {
std::string constraint_name = in.ReadTextString();
ConstraintType constraint_type = (ConstraintType)in.ReadInt();
oid_t foreign_key_list_offset = in.ReadInt();
oid_t unique_index_offset = in.ReadInt();

auto column_constraint = Constraint(constraint_type, constraint_name);
column_constraint.SetForeignKeyListOffset(foreign_key_list_offset);
column_constraint.SetUniqueIndexOffset(unique_index_offset);

if (constraint_type == ConstraintType::DEFAULT) {
type::Value default_value = type::Value::DeserializeFrom(in, column_type);
column_constraint.addDefaultValue(default_value);
}

if (constraint_type == ConstraintType::CHECK) {
auto exp = column_constraint.GetCheckExpression();
ExpressionType exp_type = (ExpressionType)in.ReadInt();
type::Value exp_value = type::Value::DeserializeFrom(in, column_type);
column_constraint.AddCheck(exp_type, exp_value);
}
return column_constraint;
}

const std::string Constraint::GetInfo() const {
std::ostringstream os;
os << "Constraint[" << GetName() << ", "
Expand All @@ -25,6 +68,9 @@ const std::string Constraint::GetInfo() const {
if (GetType() == ConstraintType::CHECK) {
os << ", " << exp.first << " " << exp.second.GetInfo();
}
if (GetType() == ConstraintType::DEFAULT) {
os << ", " << default_value->GetInfo();
}
os << "]";
return os.str();
}
Expand Down
Loading