Class KetchReplica
- java.lang.Object
-
- org.eclipse.jgit.internal.ketch.KetchReplica
-
- Direct Known Subclasses:
LocalReplica
,RemoteGitReplica
public abstract class KetchReplica extends Object
A Ketch replica, eitherLocalReplica
orRemoteGitReplica
.Replicas can be either a stock Git replica, or a Ketch-aware replica.
A stock Git replica has no special knowledge of Ketch and simply stores objects and references. Ketch communicates with the stock Git replica using the Git push wire protocol. The
KetchLeader
commits an agreed upon state by pushing all references to the Git replica, for example"refs/heads/master"
is pushed during commit. Stock Git replicas useKetchReplica.CommitMethod.ALL_REFS
to record the final state.Ketch-aware replicas understand the
RefTree
sent during the proposal and during commit are able to update their own reference space to match the state represented by theRefTree
. Ketch-aware replicas typically use aRefTreeDatabase
andKetchReplica.CommitMethod.TXN_COMMITTED
to record the final state.KetchReplica instances are tightly coupled with a single
KetchLeader
. Some state may be accessed by the leader thread and uses the leader's ownKetchLeader.lock
to protect shared data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
KetchReplica.CommitMethod
How this replica wants to receive Ketch commit operations.static class
KetchReplica.CommitSpeed
Delay before committing to a replica.static class
KetchReplica.Participation
Participation of a replica in establishing consensus.static class
KetchReplica.State
Current state of a replica.
-
Constructor Summary
Constructors Modifier Constructor Description protected
KetchReplica(KetchLeader leader, String name, ReplicaConfig cfg)
Configure a replica representation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
blockingFetch(Repository repo, ReplicaFetchRequest req)
Fetch objects from the remote using the calling thread.protected String
describeForLog()
Get description of this replica for error/debug logging purposes.KetchReplica.CommitMethod
getCommitMethod()
Get how Ketch will commit to the repository.KetchReplica.CommitSpeed
getCommitSpeed()
Get when Ketch will commit to the repository.KetchLeader
getLeader()
Get leader instance this replica follows.String
getName()
Get unique-ish name for debugging.KetchReplica.Participation
getParticipation()
Get how the replica participates in this Ketch system.KetchSystem
getSystem()
Get system configuration.protected Collection<ReceiveCommand>
prepareCommit(Repository git, Map<String,Ref> current, ObjectId committed)
Build a list of commands to commitKetchReplica.CommitMethod.ALL_REFS
.protected void
shutdown()
Called by leader to perform graceful shutdown.protected abstract void
startPush(ReplicaPushRequest req)
Begin executing a single push.
-
-
-
Constructor Detail
-
KetchReplica
protected KetchReplica(KetchLeader leader, String name, ReplicaConfig cfg)
Configure a replica representation.- Parameters:
leader
- instance this replica follows.name
- unique-ish name identifying this replica for debugging.cfg
- how Ketch should treat the replica.
-
-
Method Detail
-
getSystem
public KetchSystem getSystem()
Get system configuration.- Returns:
- system configuration.
-
getLeader
public KetchLeader getLeader()
Get leader instance this replica follows.- Returns:
- leader instance this replica follows.
-
getName
public String getName()
Get unique-ish name for debugging.- Returns:
- unique-ish name for debugging.
-
describeForLog
protected String describeForLog()
Get description of this replica for error/debug logging purposes.- Returns:
- description of this replica for error/debug logging purposes.
-
getParticipation
public KetchReplica.Participation getParticipation()
Get how the replica participates in this Ketch system.- Returns:
- how the replica participates in this Ketch system.
-
getCommitMethod
public KetchReplica.CommitMethod getCommitMethod()
Get how Ketch will commit to the repository.- Returns:
- how Ketch will commit to the repository.
-
getCommitSpeed
public KetchReplica.CommitSpeed getCommitSpeed()
Get when Ketch will commit to the repository.- Returns:
- when Ketch will commit to the repository.
-
shutdown
protected void shutdown()
Called by leader to perform graceful shutdown.Default implementation cancels any scheduled retry. Subclasses may add additional logic before or after calling
super.shutdown()
.Called with
KetchLeader.lock
held by caller.
-
startPush
protected abstract void startPush(ReplicaPushRequest req)
Begin executing a single push.This method must move processing onto another thread. Called with
KetchLeader.lock
held by caller.- Parameters:
req
- the request to send to the replica.
-
blockingFetch
protected abstract void blockingFetch(Repository repo, ReplicaFetchRequest req) throws IOException
Fetch objects from the remote using the calling thread.Called without
KetchLeader.lock
.- Parameters:
repo
- local repository to fetch objects into.req
- the request to fetch from a replica.- Throws:
IOException
- communication with the replica was not possible.
-
prepareCommit
protected Collection<ReceiveCommand> prepareCommit(Repository git, Map<String,Ref> current, ObjectId committed) throws IOException
Build a list of commands to commitKetchReplica.CommitMethod.ALL_REFS
.- Parameters:
git
- local leader repository to read committed state from.current
- all known references in the replica's repository. Typically this comes from a push advertisement.committed
- state being pushed torefs/txn/committed
.- Returns:
- commands to update during commit.
- Throws:
IOException
- cannot read the committed state.
-
-