public class KetchSystem
extends java.lang.Object
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
.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
KetchSystem.DefaultExecutorHolder |
Modifier and Type | Field and 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 and 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.
|
Modifier and Type | Method and 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 the
getClock() 's
ProposedTimestamp 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 committer
PersonIdent for ketch system |
java.lang.String |
newLeaderTag()
Construct a random tag to identify a candidate during leader election.
|
boolean |
requireMonotonicLeaderElections()
Whether elections should require monotonically increasing commit
timestamps
|
private static final java.util.Random RNG
private final java.util.concurrent.ScheduledExecutorService executor
private final MonotonicClock clock
private final java.lang.String txnNamespace
private final java.lang.String txnAccepted
private final java.lang.String txnCommitted
private final java.lang.String txnStage
public KetchSystem()
public KetchSystem(java.util.concurrent.ScheduledExecutorService executor, MonotonicClock clock, java.lang.String txnNamespace)
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/"
.public static java.util.concurrent.ScheduledExecutorService defaultExecutor()
public java.util.concurrent.ScheduledExecutorService getExecutor()
public MonotonicClock getClock()
public java.time.Duration getMaxWaitForMonotonicClock()
getClock()
's
ProposedTimestamp
used in commits proposed to the RefTree graph
(getTxnAccepted()
)getClock()
's
ProposedTimestamp
used in commits proposed to the RefTree
graph (getTxnAccepted()
). Defaults to 5 seconds.public boolean requireMonotonicLeaderElections()
true
if elections should require monotonically increasing
commit timestamps. This requires a very good
MonotonicClock
.public java.lang.String getTxnNamespace()
"refs/txn/"
.public java.lang.String getTxnAccepted()
public java.lang.String getTxnCommitted()
public java.lang.String getTxnStage()
"refs/txn/stage/"
."refs/txn/stage/"
.public PersonIdent newCommitter(ProposedTimestamp time)
PersonIdent
for ketch systemtime
- timestamp for the committer.@Nullable public java.lang.String newLeaderTag()
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.
newCommitter()
is
sufficiently unique to identify the leader.public KetchLeader createLeader(Repository repo) throws java.net.URISyntaxException
repo
- local repository stored by the leader.java.net.URISyntaxException
- a follower configuration contains an unsupported URI.protected java.util.List<KetchReplica> createReplicas(KetchLeader leader, Repository repo) throws java.net.URISyntaxException
The collection of replicas must include the local repository.
leader
- the leader driving these replicas.repo
- repository to get the replicas of.java.net.URISyntaxException
- a configured URI is invalid.private static boolean hasParticipation(Config cfg, java.lang.String name)
private static java.lang.String getLocalName(Config cfg)