Class KetchSystem


  • public class KetchSystem
    extends Object
    Ketch system-wide configuration.

    This class provides useful defaults for testing and small proof of concepts. Full scale installations are expected to subclass and override methods to provide consistent configuration across all managed repositories.

    Servers should configure their own ScheduledExecutorService.

    • Constructor Detail

      • KetchSystem

        public KetchSystem()
        Create a default system with a thread pool of 1 thread per CPU.
      • KetchSystem

        public KetchSystem​(ScheduledExecutorService executor,
                           MonotonicClock clock,
                           String txnNamespace)
        Create a Ketch system with the provided executor service.
        Parameters:
        executor - thread pool to run background operations.
        clock - clock to create timestamps.
        txnNamespace - reference namespace for the RefTree graph and associated transaction state. Must begin with "refs/" and end with '/', for example "refs/txn/".
    • Method Detail

      • defaultExecutor

        public static ScheduledExecutorService defaultExecutor()
        Get default executor, one thread per available processor.
        Returns:
        default executor, one thread per available processor.
      • getExecutor

        public ScheduledExecutorService getExecutor()
        Get executor to perform background operations.
        Returns:
        executor to perform background operations.
      • getClock

        public MonotonicClock getClock()
        Get clock to obtain timestamps from.
        Returns:
        clock to obtain timestamps from.
      • getMaxWaitForMonotonicClock

        public Duration getMaxWaitForMonotonicClock()
        Get how long the leader will wait for the getClock()'s ProposedTimestamp used in commits proposed to the RefTree graph (getTxnAccepted())
        Returns:
        how long the leader will wait for the getClock()'s ProposedTimestamp used in commits proposed to the RefTree graph (getTxnAccepted()). Defaults to 5 seconds.
      • requireMonotonicLeaderElections

        public boolean requireMonotonicLeaderElections()
        Whether elections should require monotonically increasing commit timestamps
        Returns:
        true if elections should require monotonically increasing commit timestamps. This requires a very good MonotonicClock.
      • getTxnNamespace

        public String getTxnNamespace()
        Get the namespace used for the RefTree graph and transaction management.
        Returns:
        reference namespace such as "refs/txn/".
      • getTxnAccepted

        public String getTxnAccepted()
        Get name of the accepted RefTree graph.
        Returns:
        name of the accepted RefTree graph.
      • getTxnCommitted

        public String getTxnCommitted()
        Get name of the committed RefTree graph.
        Returns:
        name of the committed RefTree graph.
      • getTxnStage

        public String getTxnStage()
        Get prefix for staged objects, e.g. "refs/txn/stage/".
        Returns:
        prefix for staged objects, e.g. "refs/txn/stage/".
      • newCommitter

        public PersonIdent newCommitter​(ProposedTimestamp time)
        Create new committer PersonIdent for ketch system
        Parameters:
        time - timestamp for the committer.
        Returns:
        identity line for the committer header of a RefTreeGraph.
      • newLeaderTag

        @Nullable
        public String newLeaderTag()
        Construct a random tag to identify a candidate during leader election.

        Multiple processes trying to elect themselves leaders at exactly the same time (rounded to seconds) using the same newCommitter(ProposedTimestamp) identity strings, for the same term, may generate the same ObjectId for the election commit and falsely assume they have both won.

        Candidates add this tag to their election ballot commit to disambiguate the election. The tag only needs to be unique for a given triplet of newCommitter(ProposedTimestamp), system time (rounded to seconds), and term. If every replica in the system uses a unique newCommitter (such as including the host name after the "@" in the email address) the tag could be the empty string.

        The default implementation generates a few bytes of random data.

        Returns:
        unique tag; null or empty string if newCommitter() is sufficiently unique to identify the leader.
      • createLeader

        public KetchLeader createLeader​(Repository repo)
                                 throws URISyntaxException
        Construct the KetchLeader instance of a repository.
        Parameters:
        repo - local repository stored by the leader.
        Returns:
        leader instance.
        Throws:
        URISyntaxException - a follower configuration contains an unsupported URI.
      • createReplicas

        protected List<KetchReplica> createReplicas​(KetchLeader leader,
                                                    Repository repo)
                                             throws URISyntaxException
        Get the collection of replicas for a repository.

        The collection of replicas must include the local repository.

        Parameters:
        leader - the leader driving these replicas.
        repo - repository to get the replicas of.
        Returns:
        collection of replicas for the specified repository.
        Throws:
        URISyntaxException - a configured URI is invalid.