Package com.arcadedb.database
Class TransactionContext
- java.lang.Object
-
- com.arcadedb.database.TransactionContext
-
- All Implemented Interfaces:
Transaction
public class TransactionContext extends Object implements Transaction
Manage the transaction context. When the transaction begins, the modifiedPages map is initialized. This allows to always delegate to the transaction context, even if there is no active transaction by ignoring tx data.
At commit time, the files are locked in order (to avoid deadlocks) and to allow parallel commit on different files.
Format of WAL:
txId:long|pages:int|<segmentSize:int|fileId:int|pageNumber:long|pageModifiedFrom:int|pageModifiedTo:int|<prevContent><newContent>segmentSize:int>MagicNumber:long
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TransactionContext.STATUS
static class
TransactionContext.TransactionPhase1
-
Constructor Summary
Constructors Constructor Description TransactionContext(DatabaseInternal database)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIndexOperation(IndexInternal index, boolean addOperation, Object[] keys, RID rid)
MutablePage
addPage(PageId pageId, int pageSize)
void
addUpdatedRecord(Record record)
void
assureIsActive()
void
begin(Database.TRANSACTION_ISOLATION_LEVEL isolationLevel)
Binary
commit()
TransactionContext.TransactionPhase1
commit1stPhase(boolean isLeader)
Locks the files in order, then checks all the pre-conditions.void
commit2ndPhase(TransactionContext.TransactionPhase1 changes)
void
commitFromReplica(WALFile.WALTransaction buffer, Map<String,TreeMap<TransactionIndexContext.ComparableKey,Map<TransactionIndexContext.IndexKey,TransactionIndexContext.IndexKey>>> keysTx, Map<Integer,Integer> bucketRecordDelta)
Executes 1st phase from a replica.Map<Integer,Integer>
getBucketRecordDelta()
long
getBucketRecordDelta(int bucketId)
Returns the delta of records considering the pending changes in transaction.DatabaseInternal
getDatabase()
long
getFileSize(int fileId)
TransactionIndexContext
getIndexChanges()
int
getModifiedPages()
BasePage
getPage(PageId pageId, int size)
Looks for the page in the TX context first, then delegates to the database.Integer
getPageCounter(int indexFileId)
MutablePage
getPageToModify(BasePage page)
Puts the page in the TX modified pages.MutablePage
getPageToModify(PageId pageId, int pageSize, boolean isNew)
If the page is not already in transaction tx, loads from the database and clone it locally.Record
getRecordFromCache(RID rid)
Map<String,Object>
getStats()
TransactionContext.STATUS
getStatus()
boolean
hasPageForRecord(PageId pageId)
Used to determine if a page has been already loaded.boolean
isActive()
boolean
isAsyncFlush()
void
kill()
Test only API.void
removeImmutableRecordsOfSamePage(RID rid)
void
removePagesOfFile(int fileId)
void
removeRecordFromCache(RID rid)
void
reset()
void
rollback()
void
setAsyncFlush(boolean value)
void
setStatus(TransactionContext.STATUS status)
void
setUseWAL(boolean useWAL)
void
setWALFlush(WALFile.FLUSH_TYPE flush)
void
updateBucketRecordDelta(int bucketId, int delta)
Updates the record counter for buckets.void
updateRecordInCache(Record record)
-
-
-
Constructor Detail
-
TransactionContext
public TransactionContext(DatabaseInternal database)
-
-
Method Detail
-
begin
public void begin(Database.TRANSACTION_ISOLATION_LEVEL isolationLevel)
- Specified by:
begin
in interfaceTransaction
-
commit
public Binary commit()
- Specified by:
commit
in interfaceTransaction
-
updateRecordInCache
public void updateRecordInCache(Record record)
-
removeImmutableRecordsOfSamePage
public void removeImmutableRecordsOfSamePage(RID rid)
-
removeRecordFromCache
public void removeRecordFromCache(RID rid)
-
getDatabase
public DatabaseInternal getDatabase()
-
setUseWAL
public void setUseWAL(boolean useWAL)
- Specified by:
setUseWAL
in interfaceTransaction
-
setWALFlush
public void setWALFlush(WALFile.FLUSH_TYPE flush)
- Specified by:
setWALFlush
in interfaceTransaction
-
rollback
public void rollback()
- Specified by:
rollback
in interfaceTransaction
-
assureIsActive
public void assureIsActive()
-
addUpdatedRecord
public void addUpdatedRecord(Record record) throws IOException
- Throws:
IOException
-
hasPageForRecord
public boolean hasPageForRecord(PageId pageId)
Used to determine if a page has been already loaded. This is important for isolation.
-
getPage
public BasePage getPage(PageId pageId, int size) throws IOException
Looks for the page in the TX context first, then delegates to the database.- Throws:
IOException
-
getPageToModify
public MutablePage getPageToModify(PageId pageId, int pageSize, boolean isNew) throws IOException
If the page is not already in transaction tx, loads from the database and clone it locally.- Throws:
IOException
-
getPageToModify
public MutablePage getPageToModify(BasePage page) throws IOException
Puts the page in the TX modified pages.- Throws:
IOException
-
addPage
public MutablePage addPage(PageId pageId, int pageSize)
-
getFileSize
public long getFileSize(int fileId) throws IOException
- Throws:
IOException
-
getPageCounter
public Integer getPageCounter(int indexFileId)
-
isActive
public boolean isActive()
- Specified by:
isActive
in interfaceTransaction
-
getModifiedPages
public int getModifiedPages()
-
kill
public void kill()
Test only API.
-
getBucketRecordDelta
public long getBucketRecordDelta(int bucketId)
Returns the delta of records considering the pending changes in transaction.
-
updateBucketRecordDelta
public void updateBucketRecordDelta(int bucketId, int delta)
Updates the record counter for buckets. At transaction commit, the delta is updated into the schema.
-
commitFromReplica
public void commitFromReplica(WALFile.WALTransaction buffer, Map<String,TreeMap<TransactionIndexContext.ComparableKey,Map<TransactionIndexContext.IndexKey,TransactionIndexContext.IndexKey>>> keysTx, Map<Integer,Integer> bucketRecordDelta) throws TransactionException
Executes 1st phase from a replica.- Throws:
TransactionException
-
commit1stPhase
public TransactionContext.TransactionPhase1 commit1stPhase(boolean isLeader)
Locks the files in order, then checks all the pre-conditions.
-
commit2ndPhase
public void commit2ndPhase(TransactionContext.TransactionPhase1 changes)
-
addIndexOperation
public void addIndexOperation(IndexInternal index, boolean addOperation, Object[] keys, RID rid)
-
isAsyncFlush
public boolean isAsyncFlush()
- Specified by:
isAsyncFlush
in interfaceTransaction
-
setAsyncFlush
public void setAsyncFlush(boolean value)
- Specified by:
setAsyncFlush
in interfaceTransaction
-
reset
public void reset()
-
removePagesOfFile
public void removePagesOfFile(int fileId)
-
getIndexChanges
public TransactionIndexContext getIndexChanges()
-
getStatus
public TransactionContext.STATUS getStatus()
-
setStatus
public void setStatus(TransactionContext.STATUS status)
-
-