Skip to content

Commit

Permalink
remove default read_only for transactions (cmu-db#1396:1-3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmwnshn committed Jun 11, 2018
1 parent 50411cb commit e506f17
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
12 changes: 7 additions & 5 deletions src/concurrency/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,26 @@ namespace concurrency {
* i : insert
*/

TransactionContext::TransactionContext(const size_t thread_id,
TransactionContext::TransactionContext(bool read_only, const size_t thread_id,
const IsolationLevelType isolation,
const cid_t &read_id) {
Init(thread_id, isolation, read_id);
Init(read_only, thread_id, isolation, read_id);
}

TransactionContext::TransactionContext(const size_t thread_id,
TransactionContext::TransactionContext(bool read_only, const size_t thread_id,
const IsolationLevelType isolation,
const cid_t &read_id,
const cid_t &commit_id) {
Init(thread_id, isolation, read_id, commit_id);
Init(read_only, thread_id, isolation, read_id, commit_id);
}

TransactionContext::~TransactionContext() {}

void TransactionContext::Init(const size_t thread_id,
void TransactionContext::Init(bool read_only, const size_t thread_id,
const IsolationLevelType isolation,
const cid_t &read_id, const cid_t &commit_id) {
read_only_ = read_only;

read_id_ = read_id;

// commit id can be set at a transaction's commit phase.
Expand Down
13 changes: 5 additions & 8 deletions src/concurrency/transaction_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ConflictAvoidanceType TransactionManager::conflict_avoidance_ =
ConflictAvoidanceType::ABORT;

TransactionContext *TransactionManager::BeginTransaction(
const size_t thread_id, const IsolationLevelType type, bool read_only) {
bool read_only, const size_t thread_id, const IsolationLevelType type) {
TransactionContext *txn = nullptr;

if (type == IsolationLevelType::SNAPSHOT) {
Expand All @@ -45,9 +45,10 @@ TransactionContext *TransactionManager::BeginTransaction(
cid_t commit_id = EpochManagerFactory::GetInstance().EnterEpoch(
thread_id, TimestampType::COMMIT);

txn = new TransactionContext(thread_id, type, read_id, commit_id);
txn = new TransactionContext(read_only, thread_id, type, read_id,
commit_id);
} else {
txn = new TransactionContext(thread_id, type, read_id);
txn = new TransactionContext(read_only, thread_id, type, read_id);
}

} else {
Expand All @@ -58,11 +59,7 @@ TransactionContext *TransactionManager::BeginTransaction(
// transaction processing with decentralized epoch manager
cid_t read_id = EpochManagerFactory::GetInstance().EnterEpoch(
thread_id, TimestampType::READ);
txn = new TransactionContext(thread_id, type, read_id);
}

if (read_only) {
txn->SetReadOnly();
txn = new TransactionContext(read_only, thread_id, type, read_id);
}

txn->SetTimestamp(function::DateFunctions::Now());
Expand Down
26 changes: 11 additions & 15 deletions src/include/concurrency/transaction_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,27 @@ class TransactionContext : public Printable {
TransactionContext(TransactionContext const &) = delete;

public:
TransactionContext(const size_t thread_id, const IsolationLevelType isolation,
const cid_t &read_id);
TransactionContext(bool read_only, const size_t thread_id,
const IsolationLevelType isolation, const cid_t &read_id);

TransactionContext(const size_t thread_id, const IsolationLevelType isolation,
const cid_t &read_id, const cid_t &commit_id);
TransactionContext(bool read_only, const size_t thread_id,
const IsolationLevelType isolation, const cid_t &read_id,
const cid_t &commit_id);

/**
* @brief Destroys the object.
*/
~TransactionContext();

private:
void Init(const size_t thread_id, const IsolationLevelType isolation,
const cid_t &read_id) {
Init(thread_id, isolation, read_id, read_id);
void Init(bool read_only, const size_t thread_id,
const IsolationLevelType isolation, const cid_t &read_id) {
Init(read_only, thread_id, isolation, read_id, read_id);
}

void Init(const size_t thread_id, const IsolationLevelType isolation,
const cid_t &read_id, const cid_t &commit_id);
void Init(bool read_only, const size_t thread_id,
const IsolationLevelType isolation, const cid_t &read_id,
const cid_t &commit_id);

public:
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -265,12 +267,6 @@ class TransactionContext : public Printable {
*/
bool IsReadOnly() const { return read_only_; }

/**
* @brief mark this context as read only
*
*/
void SetReadOnly() { read_only_ = true; }

/**
* @brief Gets the isolation level.
*
Expand Down
12 changes: 9 additions & 3 deletions src/include/concurrency/transaction_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,19 @@ class TransactionManager {
current_txn->SetResult(result);
}

TransactionContext *BeginTransaction() { return BeginTransaction(false); }

TransactionContext *BeginTransaction(const size_t thread_id) {
return BeginTransaction(false, thread_id, isolation_level_);
}

TransactionContext *BeginTransaction(const IsolationLevelType type) {
return BeginTransaction(0, type, false);
return BeginTransaction(false, 0, type);
}

TransactionContext *BeginTransaction(
const size_t thread_id = 0,
const IsolationLevelType type = isolation_level_, bool read_only = false);
bool read_only, const size_t thread_id = 0,
const IsolationLevelType type = isolation_level_);

/**
* @brief Ends a transaction.
Expand Down

0 comments on commit e506f17

Please sign in to comment.