IConcurrentStateMachine is the interface to be implemented by application's state machine when concurrent access to the state machine is required. For a typical IConcurrentStateMachine type, most of its managed data is expected to be fitted into memory, Dragonboat manages its captured snapshots and
| 43 | // but without concurrent access support. Users are recommended to use the |
| 44 | // IStateMachine interface whenever possible. |
| 45 | type IConcurrentStateMachine interface { |
| 46 | // Update updates the IConcurrentStateMachine instance. The input Entry slice |
| 47 | // is list of continuous proposed and committed commands from clients, they |
| 48 | // are provided together as a batch so the IConcurrentStateMachine |
| 49 | // implementation can choose to batch them and apply together to hide latency. |
| 50 | // |
| 51 | // The Update method must be deterministic, meaning that given the same initial |
| 52 | // state of IConcurrentStateMachine and the same input sequence, it should |
| 53 | // reach to the same updated state and outputs the same returned results. The |
| 54 | // input entry slice should be the only input to this method. Reading from |
| 55 | // the system clock, random number generator or other similar external data |
| 56 | // sources will violate the deterministic requirement of the Update method. |
| 57 | // |
| 58 | // The IConcurrentStateMachine implementation should not keep a reference to |
| 59 | // the input entry slice after return. |
| 60 | // |
| 61 | // Update returns the input entry slice with the Result field of all its |
| 62 | // members set. |
| 63 | // |
| 64 | // Update returns an error when there is unrecoverable error for updating the |
| 65 | // on disk state machine, e.g. disk failure when trying to update the state |
| 66 | // machine. |
| 67 | Update([]Entry) ([]Entry, error) |
| 68 | // Lookup queries the state of the IConcurrentStateMachine instance and |
| 69 | // returns the query result as a byte slice. The input byte slice specifies |
| 70 | // what to query, it is up to the IConcurrentStateMachine implementation to |
| 71 | // interpret the input byte slice. |
| 72 | // |
| 73 | // When an error is returned by the Lookup() method, the error will be passed |
| 74 | // to the caller of NodeHost's ReadLocalNode() or SyncRead() methods to be |
| 75 | // handled. A typical scenario for returning an error is that the state |
| 76 | // machine has already been closed or aborted from a RecoverFromSnapshot |
| 77 | // procedure when Lookup is being handled. |
| 78 | // |
| 79 | // The IConcurrentStateMachine implementation should not keep a reference of |
| 80 | // the input byte slice after return. |
| 81 | // |
| 82 | // The Lookup() method is a read only method, it should never change the state |
| 83 | // of the IConcurrentStateMachine instance. |
| 84 | Lookup(interface{}) (interface{}, error) |
| 85 | // PrepareSnapshot prepares the snapshot to be concurrently captured and saved. |
| 86 | // PrepareSnapshot is invoked before SaveSnapshot is called and it is invoked |
| 87 | // with mutual exclusion protection from the Update method. |
| 88 | // |
| 89 | // PrepareSnapshot in general saves a state identifier of the current state, |
| 90 | // such state identifier is usually a version number, a sequence number, a |
| 91 | // change ID or some other in memory small data structure used for describing |
| 92 | // the point in time state of the state machine. The state identifier is |
| 93 | // returned as an interface{} and it is provided to the SaveSnapshot() method |
| 94 | // so the state machine state at that identified point in time can be saved |
| 95 | // when SaveSnapshot is invoked. |
| 96 | // |
| 97 | // PrepareSnapshot returns an error when there is unrecoverable error for |
| 98 | // preparing the snapshot. |
| 99 | PrepareSnapshot() (interface{}, error) |
| 100 | // SaveSnapshot saves the point in time state of the IConcurrentStateMachine |
| 101 | // identified by the input state identifier to the provided io.Writer backed |
| 102 | // by a file on disk and the provided ISnapshotFileCollection instance. This |
nothing calls this directly
no outgoing calls
no test coverage detected