Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
add documentation for instance
Browse files Browse the repository at this point in the history
  • Loading branch information
skyzh committed Jul 26, 2019
1 parent 890cadd commit 8540a52
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -28,7 +28,7 @@ script:
- pytest -vs test_control.py
- pytest -vs test_membership.py
- pytest -vs test_sync_log.py
- pytest -vs . ; exit 0
- pytest -vs . ; echo
env:
- BUILD_TYPE=DEBUG
- BUILD_TYPE=RELEASE
Expand Down
75 changes: 75 additions & 0 deletions src/core/Instance.h
Expand Up @@ -54,43 +54,118 @@ class Instance {

bool __debug_offline;

/**
* Constructor
* id is node id, rpc is an instance of RPCClient
* @param id
* @param rpc
*/
Instance(const string &id, shared_ptr<RPCClient> rpc);

/**
* Initialize raft node
*/
void start();

/**
* Run routine tasks
*/
void update();

/**
* Generate election timeout
* @return election timeout between 150 and 300
*/
static TICK generate_timeout();

/**
* Increase term number and begin election
*/
void begin_election();

/**
* Send RPCs to nodes in cluster to synchronize logs
*/
void sync_log();

/**
* Transform to follower
*/
void as_follower();

/**
* Transform to candidate
*/
void as_candidate();

/**
* Transform to leader
*/
void as_leader();

/**
* Get corresponding role string
* @return string of role
*/
string get_role_string();

/**
* Update clusters
* @param clusters
*/
void set_clusters(const vector<Cluster> &clusters);

/**
* Get cluster size
* @return cluster size
*/
unsigned cluster_size();

// TODO: remove from parameter as it is no longer used
/**
* Process RPC message
* @param from (deprecated)
* @param message
*/
void on_rpc(const string &from, shared_ptr<Message> message);

/**
* Get term number in message
* @param message
* @return term number
*/
static Term get_term(shared_ptr<Message> message);

/**
* Get sender in message
* @param message
* @return sender string
*/
static string get_from(shared_ptr<Message> message);

/**
* Append entry to leader
* @param entry
*/
void append_entry(const string &entry);

/**
* Check whether a message is membership change
* @param entry
*/
void try_membership_change(const string &entry);

/**
* After old-new cluster config is committed, commit new cluster config
* (WIP)
*/
void resolve_membership_change();

/**
* Check if a node is in current cluster
* @param c node id
* @return if in cluster, true, else false
*/
bool check_in_cluster(const Cluster &c);
};

Expand Down

0 comments on commit 8540a52

Please sign in to comment.