access

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

package tablepage

package concurrency package transaction

Index

Constants

View Source
const ErrEmptyTuple = errors.Error("tuple cannot be empty")
View Source
const ErrNoFreeSlot = errors.Error("could not find a free slot")
View Source
const ErrNotEnoughSpace = errors.Error("there is not enough space")

Variables

This section is empty.

Functions

func IsDeleted

func IsDeleted(tuple_size uint32) bool

* @return true if the tuple is deleted or empty

func SetDeletedFlag

func SetDeletedFlag(tuple_size uint32) uint32

* @return tuple size with the deleted flag set

func UnsetDeletedFlag

func UnsetDeletedFlag(tuple_size uint32) uint32

* @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 LockMode

type LockMode int32
const (
	SHARED LockMode = iota
	EXCLUSIVE
)

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

func (t *TableHeap) GetFirstPageId() types.PageID

GetFirstPageId returns firstPageId

func (*TableHeap) GetFirstTuple

func (t *TableHeap) GetFirstTuple(txn *Transaction) *tuple.Tuple

GetFirstTuple reads the first tuple from the table

func (*TableHeap) GetTuple

func (t *TableHeap) GetTuple(rid *page.RID, txn *Transaction) *tuple.Tuple

GetTuple reads a tuple from the table

func (*TableHeap) InsertTuple

func (t *TableHeap) InsertTuple(tuple_ *tuple.Tuple, txn *Transaction) (rid *page.RID, err error)

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

type TablePage struct {
	page.Page
}

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

func CastPageAsTablePage(page *page.Page) *TablePage

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 (tp *TablePage) GetFreeSpacePointer() uint32

func (*TablePage) GetNextPageId

func (tp *TablePage) GetNextPageId() types.PageID

func (*TablePage) GetNextTupleRID

func (tp *TablePage) GetNextTupleRID(curRID *page.RID, isNextPage bool) *page.RID

func (*TablePage) GetTablePageId

func (tp *TablePage) GetTablePageId() types.PageID

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 (tp *TablePage) GetTupleCount() uint32

func (*TablePage) GetTupleFirstRID

func (tp *TablePage) GetTupleFirstRID() *page.RID

func (*TablePage) GetTupleOffsetAtSlot

func (tp *TablePage) GetTupleOffsetAtSlot(slot_num uint32) uint32

func (*TablePage) GetTupleSize

func (tp *TablePage) GetTupleSize(slot_num uint32) uint32

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 (tp *TablePage) SetFreeSpacePointer(freeSpacePointer uint32)

func (*TablePage) SetNextPageId

func (tp *TablePage) SetNextPageId(pageId types.PageID)

func (*TablePage) SetPageId

func (tp *TablePage) SetPageId(pageId types.PageID)

func (*TablePage) SetPrevPageId

func (tp *TablePage) SetPrevPageId(pageId types.PageID)

func (*TablePage) SetTupleCount

func (tp *TablePage) SetTupleCount(tupleCount uint32)

func (*TablePage) SetTupleOffsetAtSlot

func (tp *TablePage) SetTupleOffsetAtSlot(slot_num uint32, offset uint32)

* Set tuple offset at slot slot_num.

func (*TablePage) SetTupleSize

func (tp *TablePage) SetTupleSize(slot_num uint32, size uint32)

* 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 TwoPLMode

type TwoPLMode int32

* Two-Phase Locking mode.

const (
	REGULAR TwoPLMode = iota
	STRICT
)

type WType

type WType int32

*

  • Type of write operation.
const (
	INSERT WType = iota
	DELETE
	UPDATE
)

type WriteRecord

type WriteRecord struct {
	// contains filtered or unexported fields
}

*

  • WriteRecord tracks information related to a write.

func NewWriteRecord

func NewWriteRecord(rid page.RID, wtype WType, tuple *tuple.Tuple, table *TableHeap) *WriteRecord

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL