Documentation
¶
Overview ¶
package tablepage
package concurrency package transaction
Index ¶
- Constants
- func IsDeleted(tuple_size uint32) bool
- func SetDeletedFlag(tuple_size uint32) uint32
- func UnsetDeletedFlag(tuple_size uint32) uint32
- type DeadlockMode
- type LockManager
- func (lock_manager *LockManager) AddEdge(t1 types.TxnID, t2 types.TxnID)
- func (lock_manager *LockManager) ClearLockTablesForDebug()
- func (lock_manager *LockManager) Detection() bool
- func (lock_manager *LockManager) HasCycle(txn_id *types.TxnID) bool
- func (lock_manager *LockManager) LockExclusive(txn *Transaction, rid *page.RID) bool
- func (lock_manager *LockManager) LockShared(txn *Transaction, rid *page.RID) bool
- func (lock_manager *LockManager) LockUpgrade(txn *Transaction, rid *page.RID) bool
- func (lock_manager *LockManager) Prevention() bool
- func (lock_manager *LockManager) PrintLockTables()
- func (lock_manager *LockManager) RemoveEdge(t1 types.TxnID, t2 types.TxnID)
- func (lock_manager *LockManager) RunCycleDetection()
- func (lock_manager *LockManager) Unlock(txn *Transaction, rid_list []page.RID) bool
- type LockMode
- type LockRequest
- type LockRequestQueue
- type TableHeap
- func (t *TableHeap) ApplyDelete(rid *page.RID, txn *Transaction)
- func (t *TableHeap) GetBufferPoolManager() *buffer.BufferPoolManager
- func (t *TableHeap) GetFirstPageId() types.PageID
- func (t *TableHeap) GetFirstTuple(txn *Transaction) *tuple.Tuple
- func (t *TableHeap) GetTuple(rid *page.RID, txn *Transaction) *tuple.Tuple
- func (t *TableHeap) InsertTuple(tuple_ *tuple.Tuple, txn *Transaction) (rid *page.RID, err error)
- func (t *TableHeap) Iterator(txn *Transaction) *TableHeapIterator
- func (t *TableHeap) MarkDelete(rid *page.RID, txn *Transaction) bool
- func (t *TableHeap) RollbackDelete(rid *page.RID, txn *Transaction)
- func (t *TableHeap) UpdateTuple(tuple_ *tuple.Tuple, update_col_idxs []int, schema_ *schema.Schema, ...) (bool, *page.RID)
- type TableHeapIterator
- type TablePage
- func (table_page *TablePage) ApplyDelete(rid *page.RID, txn *Transaction, log_manager *recovery.LogManager)
- func (tp *TablePage) GetFreeSpacePointer() uint32
- func (tp *TablePage) GetNextPageId() types.PageID
- func (tp *TablePage) GetNextTupleRID(curRID *page.RID, isNextPage bool) *page.RID
- func (tp *TablePage) GetTablePageId() types.PageID
- func (tp *TablePage) GetTuple(rid *page.RID, log_manager *recovery.LogManager, lock_manager *LockManager, ...) *tuple.Tuple
- func (tp *TablePage) GetTupleCount() uint32
- func (tp *TablePage) GetTupleFirstRID() *page.RID
- func (tp *TablePage) GetTupleOffsetAtSlot(slot_num uint32) uint32
- func (tp *TablePage) GetTupleSize(slot_num uint32) uint32
- func (tp *TablePage) Init(pageId types.PageID, prevPageId types.PageID, log_manager *recovery.LogManager, ...)
- func (tp *TablePage) InsertTuple(tuple *tuple.Tuple, log_manager *recovery.LogManager, ...) (*page.RID, error)
- func (tp *TablePage) MarkDelete(rid *page.RID, txn *Transaction, lock_manager *LockManager, ...) bool
- func (tp *TablePage) RollbackDelete(rid *page.RID, txn *Transaction, log_manager *recovery.LogManager)
- func (tp *TablePage) SetFreeSpacePointer(freeSpacePointer uint32)
- func (tp *TablePage) SetNextPageId(pageId types.PageID)
- func (tp *TablePage) SetPageId(pageId types.PageID)
- func (tp *TablePage) SetPrevPageId(pageId types.PageID)
- func (tp *TablePage) SetTupleCount(tupleCount uint32)
- func (tp *TablePage) SetTupleOffsetAtSlot(slot_num uint32, offset uint32)
- func (tp *TablePage) SetTupleSize(slot_num uint32, size uint32)
- func (tp *TablePage) UpdateTuple(new_tuple *tuple.Tuple, update_col_idxs []int, schema_ *schema.Schema, ...) (bool, error, *tuple.Tuple)
- type Transaction
- func (txn *Transaction) AddIntoWriteSet(write_record *WriteRecord)
- func (txn *Transaction) GetExclusiveLockSet() []page.RID
- func (txn *Transaction) GetPrevLSN() types.LSN
- func (txn *Transaction) GetSharedLockSet() []page.RID
- func (txn *Transaction) GetState() TransactionState
- func (txn *Transaction) GetTransactionId() types.TxnID
- func (txn *Transaction) GetWriteSet() []*WriteRecord
- func (txn *Transaction) IsExclusiveLocked(rid *page.RID) bool
- func (txn *Transaction) IsSharedLocked(rid *page.RID) bool
- func (txn *Transaction) SetExclusiveLockSet(set []page.RID)
- func (txn *Transaction) SetPrevLSN(prev_lsn types.LSN)
- func (txn *Transaction) SetSharedLockSet(set []page.RID)
- func (txn *Transaction) SetState(state TransactionState)
- func (txn *Transaction) SetWriteSet(write_set []*WriteRecord)
- type TransactionManager
- func (transaction_manager *TransactionManager) Abort(txn *Transaction)
- func (transaction_manager *TransactionManager) Begin(txn *Transaction) *Transaction
- func (transaction_manager *TransactionManager) BlockAllTransactions()
- func (transaction_manager *TransactionManager) Commit(txn *Transaction)
- func (transaction_manager *TransactionManager) ResumeTransactions()
- type TransactionState
- type TwoPLMode
- type WType
- type WriteRecord
Constants ¶
const ErrEmptyTuple = errors.Error("tuple cannot be empty")
const ErrNoFreeSlot = errors.Error("could not find a free slot")
const ErrNotEnoughSpace = errors.Error("there is not enough space")
Variables ¶
This section is empty.
Functions ¶
func SetDeletedFlag ¶
* @return tuple size with the deleted flag set
func UnsetDeletedFlag ¶
* @return tuple size with the deleted flag unset
Types ¶
type DeadlockMode ¶
type DeadlockMode int32
* Deadlock mode.
const ( PREVENTION DeadlockMode = iota DETECTION SS2PL_MODE )
type LockManager ¶
type LockManager struct {
// contains filtered or unexported fields
}
*
- LockManager handles transactions asking for locks on records.
func NewLockManager ¶
func NewLockManager(two_pl_mode TwoPLMode, deadlock_mode DeadlockMode) *LockManager
* * Creates a new lock manager configured for the given type of 2-phase locking and deadlock policy. * @param two_pl_mode 2-phase locking mode * @param deadlock_mode deadlock policy
func (*LockManager) AddEdge ¶
func (lock_manager *LockManager) AddEdge(t1 types.TxnID, t2 types.TxnID)
* Adds an edge from t1 -> t2.
func (*LockManager) ClearLockTablesForDebug ¶
func (lock_manager *LockManager) ClearLockTablesForDebug()
func (*LockManager) Detection ¶
func (lock_manager *LockManager) Detection() bool
func (*LockManager) HasCycle ¶
func (lock_manager *LockManager) HasCycle(txn_id *types.TxnID) bool
* * Checks if the graph has a cycle, returning the newest transaction ID in the cycle if so. * @param[out] txn_id if the graph has a cycle, will contain the newest transaction ID * @return false if the graph has no cycle, otherwise stores the newest transaction ID in the cycle to txn_id
func (*LockManager) LockExclusive ¶
func (lock_manager *LockManager) LockExclusive(txn *Transaction, rid *page.RID) bool
* * Acquire a lock on RID in exclusive mode. See [LOCK_NOTE] in header file. * @param txn the transaction requesting the exclusive lock * @param rid the RID to be locked in exclusive mode * @return true if the lock is granted, false otherwise
func (*LockManager) LockShared ¶
func (lock_manager *LockManager) LockShared(txn *Transaction, rid *page.RID) bool
* * Acquire a lock on RID in shared mode. See [LOCK_NOTE] in header file. * @param txn the transaction requesting the shared lock * @param rid the RID to be locked in shared mode * @return true if the lock is granted, false otherwise
func (*LockManager) LockUpgrade ¶
func (lock_manager *LockManager) LockUpgrade(txn *Transaction, rid *page.RID) bool
* * Upgrade a lock from a shared lock to an exclusive access. * @param txn the transaction requesting the lock upgrade * @param rid the RID that should already be locked in shared mode by the requesting transaction * @return true if the upgrade is successful, false otherwise
func (*LockManager) Prevention ¶
func (lock_manager *LockManager) Prevention() bool
func (*LockManager) PrintLockTables ¶
func (lock_manager *LockManager) PrintLockTables()
func (*LockManager) RemoveEdge ¶
func (lock_manager *LockManager) RemoveEdge(t1 types.TxnID, t2 types.TxnID)
* Removes an edge from t1 -> t2.
func (*LockManager) RunCycleDetection ¶
func (lock_manager *LockManager) RunCycleDetection()
* Runs cycle detection in the background.
func (*LockManager) Unlock ¶
func (lock_manager *LockManager) Unlock(txn *Transaction, rid_list []page.RID) bool
* * Release the lock held by the access. * @param txn the transaction releasing the lock, it should actually hold the lock * @param rid the RID that is locked by the transaction * @return true if the unlock is successful, false otherwise
type LockRequest ¶
type LockRequest struct {
// contains filtered or unexported fields
}
func NewLockRequest ¶
func NewLockRequest(txn_id types.TxnID, lock_mode LockMode) *LockRequest
type LockRequestQueue ¶
type LockRequestQueue struct {
// contains filtered or unexported fields
}
type TableHeap ¶
type TableHeap struct {
// contains filtered or unexported fields
}
TableHeap represents a physical table on disk. It contains the id of the first table page. The table page is a doubly-linked to other table pages.
func InitTableHeap ¶
func InitTableHeap(bpm *buffer.BufferPoolManager, pageId types.PageID, log_manager *recovery.LogManager, lock_manager *LockManager) *TableHeap
InitTableHeap ...
func NewTableHeap ¶
func NewTableHeap(bpm *buffer.BufferPoolManager, log_manager *recovery.LogManager, lock_manager *LockManager, txn *Transaction) *TableHeap
NewTableHeap creates a table heap without a (open table)
func (*TableHeap) ApplyDelete ¶
func (t *TableHeap) ApplyDelete(rid *page.RID, txn *Transaction)
func (*TableHeap) GetBufferPoolManager ¶
func (t *TableHeap) GetBufferPoolManager() *buffer.BufferPoolManager
func (*TableHeap) GetFirstPageId ¶
GetFirstPageId returns firstPageId
func (*TableHeap) GetFirstTuple ¶
func (t *TableHeap) GetFirstTuple(txn *Transaction) *tuple.Tuple
GetFirstTuple reads the first tuple from the table
func (*TableHeap) InsertTuple ¶
InsertTuple inserts a tuple into the table PAY ATTENTION: index entry is not inserted
It fetches the first page and tries to insert the tuple there. If the tuple is too large (>= page_size): 1. It tries to insert in the next page 2. If there is no next page, it creates a new page and insert in it
func (*TableHeap) Iterator ¶
func (t *TableHeap) Iterator(txn *Transaction) *TableHeapIterator
Iterator returns a iterator for this table heap
func (*TableHeap) MarkDelete ¶
func (t *TableHeap) MarkDelete(rid *page.RID, txn *Transaction) bool
func (*TableHeap) RollbackDelete ¶
func (t *TableHeap) RollbackDelete(rid *page.RID, txn *Transaction)
func (*TableHeap) UpdateTuple ¶
func (t *TableHeap) UpdateTuple(tuple_ *tuple.Tuple, update_col_idxs []int, schema_ *schema.Schema, rid page.RID, txn *Transaction) (bool, *page.RID)
if specified nil to update_col_idxs and schema_, all data of existed tuple is replaced one of new_tuple if specified not nil, new_tuple also should have all columns defined in schema. but not update target value can be dummy value
type TableHeapIterator ¶
type TableHeapIterator struct {
// contains filtered or unexported fields
}
TableHeapIterator is the access method for table heaps
It iterates through a table heap when Next is called The tuple that it is being pointed to can be accessed with the method Current
func NewTableHeapIterator ¶
func NewTableHeapIterator(tableHeap *TableHeap, lock_manager *LockManager, txn *Transaction) *TableHeapIterator
NewTableHeapIterator creates a new table heap operator for the given table heap It points to the first tuple of the table heap
func (*TableHeapIterator) Current ¶
func (it *TableHeapIterator) Current() *tuple.Tuple
Current points to the current tuple
func (*TableHeapIterator) End ¶
func (it *TableHeapIterator) End() bool
End checks if the iterator is at the end
func (*TableHeapIterator) Next ¶
func (it *TableHeapIterator) Next() *tuple.Tuple
Next advances the iterator trying to find the next tuple The next tuple can be inside the same page of the current tuple or it can be in the next page
type TablePage ¶
Slotted page format:
---------------------------------------------------------
| HEADER | ... FREE SPACE ... | ... INSERTED TUPLES ... |
---------------------------------------------------------
^
free space pointer
Header format (size in bytes):
----------------------------------------------------------------------------
| PageId (4)| LSN (4)| PrevPageId (4)| NextPageId (4)| FreeSpacePointer(4) |
----------------------------------------------------------------------------
----------------------------------------------------------------
| TupleCount (4) | Tuple_1 offset (4) | Tuple_1 size (4) | ... |
----------------------------------------------------------------
func CastPageAsTablePage ¶
CastPageAsTablePage casts the abstract Page struct into TablePage
func (*TablePage) ApplyDelete ¶
func (table_page *TablePage) ApplyDelete(rid *page.RID, txn *Transaction, log_manager *recovery.LogManager)
func (*TablePage) GetFreeSpacePointer ¶
func (*TablePage) GetNextPageId ¶
func (*TablePage) GetNextTupleRID ¶
func (*TablePage) GetTablePageId ¶
func (*TablePage) GetTuple ¶
func (tp *TablePage) GetTuple(rid *page.RID, log_manager *recovery.LogManager, lock_manager *LockManager, txn *Transaction) *tuple.Tuple
func (*TablePage) GetTupleCount ¶
func (*TablePage) GetTupleFirstRID ¶
func (*TablePage) GetTupleOffsetAtSlot ¶
func (*TablePage) GetTupleSize ¶
func (*TablePage) Init ¶
func (tp *TablePage) Init(pageId types.PageID, prevPageId types.PageID, log_manager *recovery.LogManager, lock_manager *LockManager, txn *Transaction)
Init initializes the table header
func (*TablePage) InsertTuple ¶
func (tp *TablePage) InsertTuple(tuple *tuple.Tuple, log_manager *recovery.LogManager, lock_manager *LockManager, txn *Transaction) (*page.RID, error)
Inserts a tuple into the table
func (*TablePage) MarkDelete ¶
func (tp *TablePage) MarkDelete(rid *page.RID, txn *Transaction, lock_manager *LockManager, log_manager *recovery.LogManager) bool
func (*TablePage) RollbackDelete ¶
func (tp *TablePage) RollbackDelete(rid *page.RID, txn *Transaction, log_manager *recovery.LogManager)
func (*TablePage) SetFreeSpacePointer ¶
func (*TablePage) SetNextPageId ¶
func (*TablePage) SetPrevPageId ¶
func (*TablePage) SetTupleCount ¶
func (*TablePage) SetTupleOffsetAtSlot ¶
* Set tuple offset at slot slot_num.
func (*TablePage) SetTupleSize ¶
* Set tuple size at slot slot_num.
func (*TablePage) UpdateTuple ¶
func (tp *TablePage) UpdateTuple(new_tuple *tuple.Tuple, update_col_idxs []int, schema_ *schema.Schema, old_tuple *tuple.Tuple, rid *page.RID, txn *Transaction, lock_manager *LockManager, log_manager *recovery.LogManager) (bool, error, *tuple.Tuple)
if specified nil to update_col_idxs and schema_, all data of existed tuple is replaced one of new_tuple if specified not nil, new_tuple also should have all columns defined in schema. but not update target value can be dummy value return Tuple pointer when updated tuple need to be moved new page location and it should be inserted after old data deleted, otherwise returned nil
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
*
- Transaction tracks information related to a transaction.
func NewTransaction ¶
func NewTransaction(txn_id types.TxnID) *Transaction
func (*Transaction) AddIntoWriteSet ¶
func (txn *Transaction) AddIntoWriteSet(write_record *WriteRecord)
func (*Transaction) GetExclusiveLockSet ¶
func (txn *Transaction) GetExclusiveLockSet() []page.RID
/** @return the set of resources under an exclusive lock */
func (*Transaction) GetPrevLSN ¶
func (txn *Transaction) GetPrevLSN() types.LSN
* @return the previous LSN
func (*Transaction) GetSharedLockSet ¶
func (txn *Transaction) GetSharedLockSet() []page.RID
/** @return the set of resources under a shared lock */
func (*Transaction) GetState ¶
func (txn *Transaction) GetState() TransactionState
* @return the current state of the transaction
func (*Transaction) GetTransactionId ¶
func (txn *Transaction) GetTransactionId() types.TxnID
* @return the id of this transaction
func (*Transaction) GetWriteSet ¶
func (txn *Transaction) GetWriteSet() []*WriteRecord
* @return the list of of write records of this transaction
func (*Transaction) IsExclusiveLocked ¶
func (txn *Transaction) IsExclusiveLocked(rid *page.RID) bool
* @return true if rid is exclusively locked by this transaction
func (*Transaction) IsSharedLocked ¶
func (txn *Transaction) IsSharedLocked(rid *page.RID) bool
* @return true if rid is shared locked by this transaction
func (*Transaction) SetExclusiveLockSet ¶
func (txn *Transaction) SetExclusiveLockSet(set []page.RID)
func (*Transaction) SetPrevLSN ¶
func (txn *Transaction) SetPrevLSN(prev_lsn types.LSN)
* * Set the previous LSN. * @param prev_lsn new previous lsn
func (*Transaction) SetSharedLockSet ¶
func (txn *Transaction) SetSharedLockSet(set []page.RID)
func (*Transaction) SetState ¶
func (txn *Transaction) SetState(state TransactionState)
* * Set the state of the access. * @param state new state
func (*Transaction) SetWriteSet ¶
func (txn *Transaction) SetWriteSet(write_set []*WriteRecord)
type TransactionManager ¶
type TransactionManager struct {
// contains filtered or unexported fields
}
*
- TransactionManager keeps track of all the transactions running in the system.
func NewTransactionManager ¶
func NewTransactionManager(lock_manager *LockManager, log_manager *recovery.LogManager) *TransactionManager
func (*TransactionManager) Abort ¶
func (transaction_manager *TransactionManager) Abort(txn *Transaction)
func (*TransactionManager) Begin ¶
func (transaction_manager *TransactionManager) Begin(txn *Transaction) *Transaction
func (*TransactionManager) BlockAllTransactions ¶
func (transaction_manager *TransactionManager) BlockAllTransactions()
func (*TransactionManager) Commit ¶
func (transaction_manager *TransactionManager) Commit(txn *Transaction)
func (*TransactionManager) ResumeTransactions ¶
func (transaction_manager *TransactionManager) ResumeTransactions()
type TransactionState ¶
type TransactionState int32
const ( GROWING TransactionState = iota SHRINKING COMMITTED ABORTED )
type WriteRecord ¶
type WriteRecord struct {
// contains filtered or unexported fields
}
*
- WriteRecord tracks information related to a write.