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
class
TransactionContext.TransactionPhase1
-
Constructor Summary
Constructors Constructor Description TransactionContext(DatabaseInternal database)
-
Method Summary
-
-
-
Constructor Detail
-
TransactionContext
public TransactionContext(DatabaseInternal database)
-
-
Method Detail
-
begin
public void begin()
- 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
-
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 size, boolean isNew) throws IOException
If the page is not already in transaction tx, loads from the database and clone it locally.- 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.
-
commitFromReplica
public void commitFromReplica(WALFile.WALTransaction buffer, Map<String,TreeMap<TransactionIndexContext.ComparableKey,Map<TransactionIndexContext.IndexKey,TransactionIndexContext.IndexKey>>> keysTx) 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)
-
-