Class TxnMgrImpl

java.lang.Object
org.aksw.commons.txn.impl.TxnMgrImpl
All Implemented Interfaces:
TxnMgr

public class TxnMgrImpl extends Object implements 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: '&gt' store/org/example/data.nt locks/.org-example-data/txn-12345.lock -invalid input: '&gt' txns/txn-12345 txns/txn-12345/
Author:
Claus Stadler
  • Field Details

    • rootPath

      protected Path rootPath
    • lockMgr

      protected LockManager<Path> lockMgr
    • txnBasePath

      protected Path txnBasePath
    • resRepo

      protected ResourceRepository<String> resRepo
    • lockRepo

      protected ResourceRepository<String> lockRepo
    • lockStore

      protected LockStore<String[],String> lockStore
    • symlinkStrategy

      protected SymbolicLinkStrategy symlinkStrategy
      Allows for virtual 'symlinks' that are actually regular files; symlinks typically don't work with webdav
    • txnMgrId

      protected String txnMgrId
      The (globally unique) id of the transaction manager - transactions use this id to declare their owner. The id is assigned at runtime
    • heartbeatDuration

      protected TemporalAmount heartbeatDuration
    • pathMatcher

      protected PathMatcher pathMatcher
  • Constructor Details

  • Method Details

    • createSimple

      public static TxnMgrImpl createSimple(Path repoRoot)
    • getRootPath

      public Path getRootPath()
      Specified by:
      getRootPath in interface TxnMgr
    • getPathMatcher

      public PathMatcher getPathMatcher()
    • getHeartbeatDuration

      public TemporalAmount getHeartbeatDuration()
      Description copied from interface: TxnMgr
      The 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:
      getHeartbeatDuration in interface TxnMgr
    • getTxnMgrId

      public String getTxnMgrId()
      Specified by:
      getTxnMgrId in interface TxnMgr
    • getLockStore

      public LockStore<String[],String> getLockStore()
      Specified by:
      getLockStore in interface TxnMgr
    • buildLockGraph

      public void buildLockGraph()
      Build a bipartite graph between dependencies and locks; i.e. Read the locks of the given transactions
    • getSymlinkStrategy

      public SymbolicLinkStrategy getSymlinkStrategy()
    • getResRepo

      public ResourceRepository<String> getResRepo()
      Specified by:
      getResRepo in interface TxnMgr
    • getTxn

      public Txn getTxn(String txnId)
      Description copied from interface: TxnMgr
      Get an accessor to an existing transaction
      Specified by:
      getTxn in interface TxnMgr
    • newTxn

      public Txn newTxn(String id, boolean useJournal, boolean isWrite) throws IOException
      Description copied from interface: TxnMgr
      Create 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:
      newTxn in interface TxnMgr
      Throws:
      IOException
    • streamTxns

      public Stream<Txn> streamTxns() throws IOException
      Description copied from interface: TxnMgr
      Stream all existing transactions
      Specified by:
      streamTxns in interface TxnMgr
      Throws:
      IOException
    • deleteResources

      public void deleteResources() throws IOException
      Deletes the lock and transaction folders. Does not delete the store and index folders.
      Specified by:
      deleteResources in interface TxnMgr
      Throws:
      IOException