Class TxnMgrImpl
java.lang.Object
org.aksw.commons.txn.impl.TxnMgrImpl
- All Implemented Interfaces:
TxnMgr
Path-based transaction manager:
Implements a protocol for that uses folders and symlinks to manage locks on paths (files and directories).
The protocol is aimed at allowing multiple processes to run transactions on a common pool of paths
with serializable isolation level (the highest).
Conceptually, three folder structures are involved:
The ./store contains the actual data files.
The ./txns folder holds a subfolder for each active transaction.
Whenever a resource is accessed within a transaction a symlink from the txn folder to the accessed' resource's shadow is created.
The ./shadow is the 'shadow' of the store. For each resource in the store that is involved in a transaction
a folder is created. Upon read or write access lock files are created in the shadow that link to the transaction folder
that owns the lock.
The purpose of the shadow is two fold:
(1) It prevents writing all the management files into the store which causes pollution in case a process
running a transaction exits (or loses connection to the store) without clean up.
(2) While resources in ./store can be arbitrarily nested in subfolders, in ./shadow those entries are 'flattened'
by url encoding their relative path. This makes management somewhat easier because locking resources does not have
to deal with corner cases where one process wants to create a sub folder of an empty folder X and another process wants to
clean up and remove X.
store/org/example/data.nt
locks/.org-example-data/data.nt -invalid input: '>' store/org/example/data.nt
locks/.org-example-data/txn-12345.lock -invalid input: '>' txns/txn-12345
txns/txn-12345/
- Author:
- Claus Stadler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TemporalAmountprotected LockManager<Path> protected ResourceRepository<String> protected PathMatcherprotected ResourceRepository<String> protected Pathprotected SymbolicLinkStrategyAllows for virtual 'symlinks' that are actually regular files; symlinks typically don't work with webdavprotected Pathprotected StringThe (globally unique) id of the transaction manager - transactions use this id to declare their owner. -
Constructor Summary
ConstructorsConstructorDescriptionTxnMgrImpl(String txnMgrId, Path rootPath, PathMatcher pathMatcher, TemporalAmount heartbeatDuration, LockManager<Path> lockMgr, Path txnBasePath, ResourceRepository<String> resRepo, ResourceRepository<String> lockRepo, SymbolicLinkStrategy symlinkStrategy) -
Method Summary
Modifier and TypeMethodDescriptionvoidBuild a bipartite graph between dependencies and locks; i.e.static TxnMgrImplcreateSimple(Path repoRoot) voidDeletes the lock and transaction folders.The time interval between two heartbeats for when transaction metadata in the backend (e.g.Get an accessor to an existing transactionCreate a new transaction.Stream all existing transactions
-
Field Details
-
rootPath
-
lockMgr
-
txnBasePath
-
resRepo
-
lockRepo
-
lockStore
-
symlinkStrategy
Allows for virtual 'symlinks' that are actually regular files; symlinks typically don't work with webdav -
txnMgrId
The (globally unique) id of the transaction manager - transactions use this id to declare their owner. The id is assigned at runtime -
heartbeatDuration
-
pathMatcher
-
-
Constructor Details
-
TxnMgrImpl
public TxnMgrImpl(String txnMgrId, Path rootPath, PathMatcher pathMatcher, TemporalAmount heartbeatDuration, LockManager<Path> lockMgr, Path txnBasePath, ResourceRepository<String> resRepo, ResourceRepository<String> lockRepo, SymbolicLinkStrategy symlinkStrategy)
-
-
Method Details
-
createSimple
-
getRootPath
- Specified by:
getRootPathin interfaceTxnMgr
-
getPathMatcher
-
getHeartbeatDuration
Description copied from interface:TxnMgrThe time interval between two heartbeats for when transaction metadata in the backend (e.g. a file in the filesystem) is updated to indicate that a transaction's process is still running. Conversely, exceeding the heartbeat duration (with a little margin) indicates that the process managing a transaction must have stopped or is terminated and the transaction can be rolled back.- Specified by:
getHeartbeatDurationin interfaceTxnMgr
-
getTxnMgrId
- Specified by:
getTxnMgrIdin interfaceTxnMgr
-
getLockStore
- Specified by:
getLockStorein interfaceTxnMgr
-
buildLockGraph
public void buildLockGraph()Build a bipartite graph between dependencies and locks; i.e. Read the locks of the given transactions -
getSymlinkStrategy
-
getResRepo
- Specified by:
getResRepoin interfaceTxnMgr
-
getTxn
-
newTxn
Description copied from interface:TxnMgrCreate a new transaction. If the id is null then an id will be allocated. If a txn with the given id already exists an exception in raised.- Specified by:
newTxnin interfaceTxnMgr- Throws:
IOException
-
streamTxns
Description copied from interface:TxnMgrStream all existing transactions- Specified by:
streamTxnsin interfaceTxnMgr- Throws:
IOException
-
deleteResources
Deletes the lock and transaction folders. Does not delete the store and index folders.- Specified by:
deleteResourcesin interfaceTxnMgr- Throws:
IOException
-