raftServer.h 1.5 KB
Newer Older
M
Minghao Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#ifndef TDENGINE_RAFT_SERVER_H
#define TDENGINE_RAFT_SERVER_H

#ifdef __cplusplus
extern "C" {
#endif

#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <string.h>
#include "raft.h"
#include "raft/uv.h"
#include "common.h"


// simulate a db store, just for test
18 19 20 21 22 23 24
#define MAX_KV_LEN 20
#define MAX_RECORD_COUNT 16


//char *keys;
//char *values;
//int writeIndex;
M
Minghao Li 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

void initStore();
void destroyStore();
void putKV(const char *key, const char *value);
char *getKV(const char *key);

typedef struct {
	char dir[DIR_LEN + HOST_LEN * 4];  /* Data dir of UV I/O backend */
	raft_id raftId;                    /* For vote */
	struct raft_fsm *fsm;              /* Sample application FSM */
	struct raft raft;                   /* Raft instance */
	struct raft_io io;                  /* UV I/O backend */

} SInstance;

typedef struct {
	char host[HOST_LEN];
    uint32_t port;
	char address[ADDRESS_LEN];         /* Raft instance address */

	struct uv_loop_s loop;              /* UV loop */
	struct raft_uv_transport transport; /* UV I/O backend transport */

	SInstance instance[MAX_INSTANCE_NUM];
	int32_t instanceCount;

} SRaftServer;

#define MAX_TOKEN_LEN 32
int splitString(const char* str, char* separator, char (*arr)[MAX_TOKEN_LEN], int n_arr);

int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf, struct raft_fsm *pFsm);
int32_t raftServerStart(SRaftServer *pRaftServer);
void raftServerClose(SRaftServer *pRaftServer);


int initFsm(struct raft_fsm *fsm);




#ifdef __cplusplus
}
#endif

#endif // TDENGINE_RAFT_SERVER_H