cmu-db / peloton

The Self-Driving Database Management System
http://pelotondb.io
Apache License 2.0
2.03k stars 624 forks source link

TransactionContext Read-Only Interface #1396

Open apavlo opened 6 years ago

apavlo commented 6 years ago

We need to think about how we want to set the read-only flag for a TransactionContext. There are currently two ways to set this flag:

  1. When the txn is created in TransactionManager::BeginTransaction() https://github.com/cmu-db/peloton/blob/master/src/include/concurrency/transaction_manager.h#L226-L228

  2. After it has started using TransactionContext::SetReadOnly(): https://github.com/cmu-db/peloton/blob/master/src/include/concurrency/transaction_context.h#L273

I first note that TransactionContext::SetReadOnly() does not check whether a txn has already executed a query that modified the database when we set the flag. This could lead to problems if somebody calls this incorrectly. It also doesn't make sense to support this functionality because if the system doesn't know that a txn is read-only when it starts, then it won't know whether it is read-only until commit time.

Things to fix:

  1. Remove the default value for the read_only flag in TransactionManager::BeginTransaction().

  2. Remove the TransactionContext::SetReadOnly() method.

  3. Add a read_only flag to the TransactionContext constructors. https://github.com/cmu-db/peloton/blob/master/src/include/concurrency/transaction_context.h#L47-L51

  4. Modify TimestampOrderingTransactionManager::CommitTransaction() so that it checks whether a txn has not executed any modifying queries. If so, then it can then be treated as read-only and commit right away. This should happen after we check whether the read-only flag is set. https://github.com/cmu-db/peloton/blob/master/src/concurrency/timestamp_ordering_transaction_manager.cpp#L610