access

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

package tablepage

package concurrency package transaction

Index

Constants

View Source
const ErrEmptyTuple = errors.Error("tuple1 cannot be empty.")
View Source
const ErrGeneral = errors.Error("some error is occured!")
View Source
const ErrNotEnoughSpace = errors.Error("there is not enough space.")
View Source
const ErrPartialUpdate = errors.Error("update with new rid1 is succeeded partially")

delete and insert are needed, but delete is only succeeded case

View Source
const ErrSelfDeletedCase = errors.Error("encont self deleted tuple1.")

Variables

This section is empty.

Functions

func IsDeleted

func IsDeleted(tuple_size uint32) bool

* @return true if the tuple1 is deleted or empty

func SetDeletedFlag

func SetDeletedFlag(tuple_size uint32) uint32

* @return tuple1 size with the deleted flag set

func UnsetDeletedFlag

func UnsetDeletedFlag(tuple_size uint32) uint32

* @return tuple1 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 GetPageId in the cycle if so. * @param[out] txn_id if the graph has a cycle, will contain the newest transaction GetPageId * @return false if the graph has no cycle, otherwise stores the newest transaction GetPageId 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 rid1 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 rid1 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 rid1 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 rid1 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 tuple1 from the table

func (*TableHeap) GetTuple

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

GetTuple reads a tuple1 from the table

func (*TableHeap) InsertTuple

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

InsertTuple inserts a tuple1 into the table PAY ATTENTION: index entry is not inserted

It fetches the first page and tries to insert the tuple1 there. If the tuple1 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, oid uint32, isForUpdate bool, txn *Transaction) bool

when isForUpdate arg is true, write record is not created

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, oid uint32, rid page.RID, txn *Transaction, isRollback bool) (is_success bool, new_rid_ *page.RID, err_ error, update_tuple_ *tuple.Tuple, old_tuple_ *tuple.Tuple)

if specified nil to update_col_idxs and schema_, all data of existed tuple1 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 tuple1 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 tuple1 of the table heap

func (*TableHeapIterator) Current

func (it *TableHeapIterator) Current() *tuple.Tuple

Current points to the current tuple1

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 tuple1 The next tuple1 can be inside the same page of the current tuple1 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 (tp *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) GetTuple

func (tp *TablePage) GetTuple(rid *page.RID, log_manager *recovery.LogManager, lock_manager *LockManager, txn *Transaction) (*tuple.Tuple, error)

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 tuple1 into the table

func (*TablePage) MarkDelete

func (tp *TablePage) MarkDelete(rid *page.RID, txn *Transaction, lock_manager *LockManager, log_manager *recovery.LogManager) (isMarked bool, markedTuple *tuple.Tuple)

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) SetPrevPageId

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

func (*TablePage) SetSerializedPageId added in v0.0.2

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

set value to Page::data memory area. not to Page::id

func (*TablePage) SetTupleCount

func (tp *TablePage) SetTupleCount(tupleCount uint32)

func (*TablePage) SetTupleOffsetAtSlot

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

* Set tuple1 offset at slot slot_num.

func (*TablePage) SetTupleSize

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

* Set tuple1 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 tuple1 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 tuple1 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) GetDebugInfo added in v0.0.2

func (txn *Transaction) GetDebugInfo() string

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) IsAbortable added in v0.0.2

func (txn *Transaction) IsAbortable() bool

func (*Transaction) IsExclusiveLocked

func (txn *Transaction) IsExclusiveLocked(rid *page.RID) bool

* @return true if rid1 is exclusively locked by this transaction

func (*Transaction) IsSharedLocked

func (txn *Transaction) IsSharedLocked(rid *page.RID) bool

* @return true if rid1 is shared locked by this transaction

func (*Transaction) MakeNotAbortable added in v0.0.2

func (txn *Transaction) MakeNotAbortable()

when this txn is set ABORTED, probram panics

func (*Transaction) SetDebugInfo added in v0.0.2

func (txn *Transaction) SetDebugInfo(dbgInfo string)

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(catalog_ catalog_interface.CatalogInterface, 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(catalog_ catalog_interface.CatalogInterface, 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(rid1 *page.RID, rid2 *page.RID, wtype WType, tuple1 *tuple.Tuple, tuple2 *tuple.Tuple, table *TableHeap, oid uint32) *WriteRecord

Jump to

Keyboard shortcuts

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