Class KetchSystem
- java.lang.Object
-
- org.eclipse.jgit.internal.ketch.KetchSystem
-
public class KetchSystem extends java.lang.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
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
KetchSystem.DefaultExecutorHolder
-
Field Summary
Fields Modifier and Type Field Description private MonotonicClock
clock
private java.util.concurrent.ScheduledExecutorService
executor
private static java.util.Random
RNG
private java.lang.String
txnAccepted
private java.lang.String
txnCommitted
private java.lang.String
txnNamespace
private java.lang.String
txnStage
-
Constructor Summary
Constructors Constructor Description KetchSystem()
Create a default system with a thread pool of 1 thread per CPU.KetchSystem(java.util.concurrent.ScheduledExecutorService executor, MonotonicClock clock, java.lang.String txnNamespace)
Create a Ketch system with the provided executor service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description KetchLeader
createLeader(Repository repo)
Construct the KetchLeader instance of a repository.protected java.util.List<KetchReplica>
createReplicas(KetchLeader leader, Repository repo)
Get the collection of replicas for a repository.static java.util.concurrent.ScheduledExecutorService
defaultExecutor()
Get default executor, one thread per available processor.MonotonicClock
getClock()
Get clock to obtain timestamps from.java.util.concurrent.ScheduledExecutorService
getExecutor()
Get executor to perform background operations.private static java.lang.String
getLocalName(Config cfg)
java.time.Duration
getMaxWaitForMonotonicClock()
Get how long the leader will wait for thegetClock()
'sProposedTimestamp
used in commits proposed to the RefTree graph (getTxnAccepted()
)java.lang.String
getTxnAccepted()
Get name of the accepted RefTree graph.java.lang.String
getTxnCommitted()
Get name of the committed RefTree graph.java.lang.String
getTxnNamespace()
Get the namespace used for the RefTree graph and transaction management.java.lang.String
getTxnStage()
Get prefix for staged objects, e.g.private static boolean
hasParticipation(Config cfg, java.lang.String name)
PersonIdent
newCommitter(ProposedTimestamp time)
Create new committerPersonIdent
for ketch systemjava.lang.String
newLeaderTag()
Construct a random tag to identify a candidate during leader election.boolean
requireMonotonicLeaderElections()
Whether elections should require monotonically increasing commit timestamps
-
-
-
Field Detail
-
RNG
private static final java.util.Random RNG
-
executor
private final java.util.concurrent.ScheduledExecutorService executor
-
clock
private final MonotonicClock clock
-
txnNamespace
private final java.lang.String txnNamespace
-
txnAccepted
private final java.lang.String txnAccepted
-
txnCommitted
private final java.lang.String txnCommitted
-
txnStage
private final java.lang.String txnStage
-
-
Constructor Detail
-
KetchSystem
public KetchSystem()
Create a default system with a thread pool of 1 thread per CPU.
-
KetchSystem
public KetchSystem(java.util.concurrent.ScheduledExecutorService executor, MonotonicClock clock, java.lang.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 java.util.concurrent.ScheduledExecutorService defaultExecutor()
Get default executor, one thread per available processor.- Returns:
- default executor, one thread per available processor.
-
getExecutor
public java.util.concurrent.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 java.time.Duration getMaxWaitForMonotonicClock()
Get how long the leader will wait for thegetClock()
'sProposedTimestamp
used in commits proposed to the RefTree graph (getTxnAccepted()
)- Returns:
- how long the leader will wait for the
getClock()
'sProposedTimestamp
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 goodMonotonicClock
.
-
getTxnNamespace
public java.lang.String getTxnNamespace()
Get the namespace used for the RefTree graph and transaction management.- Returns:
- reference namespace such as
"refs/txn/"
.
-
getTxnAccepted
public java.lang.String getTxnAccepted()
Get name of the accepted RefTree graph.- Returns:
- name of the accepted RefTree graph.
-
getTxnCommitted
public java.lang.String getTxnCommitted()
Get name of the committed RefTree graph.- Returns:
- name of the committed RefTree graph.
-
getTxnStage
public java.lang.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 committerPersonIdent
for ketch system- Parameters:
time
- timestamp for the committer.- Returns:
- identity line for the committer header of a RefTreeGraph.
-
newLeaderTag
@Nullable public java.lang.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 uniquenewCommitter
(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 java.net.URISyntaxException
Construct the KetchLeader instance of a repository.- Parameters:
repo
- local repository stored by the leader.- Returns:
- leader instance.
- Throws:
java.net.URISyntaxException
- a follower configuration contains an unsupported URI.
-
createReplicas
protected java.util.List<KetchReplica> createReplicas(KetchLeader leader, Repository repo) throws java.net.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:
java.net.URISyntaxException
- a configured URI is invalid.
-
hasParticipation
private static boolean hasParticipation(Config cfg, java.lang.String name)
-
getLocalName
private static java.lang.String getLocalName(Config cfg)
-
-