Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial snapshot state machine implementation #659

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -219,27 +219,25 @@ libraft_la_CFLAGS = $(AM_CFLAGS)
libraft_la_LDFLAGS = $(UV_LIBS)

raft_core_unit_test_SOURCES = \
$(libraft_la_SOURCES) \
src/lib/sm.c \
src/tracing.c \
src/raft/byte.c \
src/raft/compress.c \
src/raft/configuration.c \
src/raft/err.c \
src/raft/flags.c \
src/raft/heap.c \
src/raft/log.c \
test/raft/unit/main_core.c \
test/raft/unit/test_byte.c \
test/raft/unit/test_compress.c \
test/raft/unit/test_configuration.c \
test/raft/unit/test_err.c \
test/raft/unit/test_flags.c \
test/raft/unit/test_log.c \
test/raft/unit/test_queue.c
test/raft/unit/test_queue.c \
test/raft/unit/test_snapshot.c

raft_core_unit_test_CFLAGS = $(AM_CFLAGS) -Wno-conversion
raft_core_unit_test_LDADD = libtest.la

raft_core_integration_test_SOURCES = \
src/tracing.c \
src/lib/sm.c \
test/raft/integration/main_core.c \
test/raft/integration/test_apply.c \
test/raft/integration/test_assign.c \
Expand All @@ -264,6 +262,7 @@ raft_core_integration_test_LDFLAGS = -no-install
raft_core_integration_test_LDADD = libtest.la libraft.la

raft_core_fuzzy_test_SOURCES = \
src/lib/sm.c \
src/tracing.c \
test/raft/fuzzy/main_core.c \
test/raft/fuzzy/test_election.c \
Expand Down Expand Up @@ -294,6 +293,7 @@ raft_uv_unit_test_LDADD = libtest.la $(UV_LIBS)
raft_uv_integration_test_SOURCES = \
$(libraft_la_SOURCES) \
src/tracing.c \
src/lib/sm.c \
test/raft/integration/main_uv.c \
test/raft/integration/test_uv_init.c \
test/raft/integration/test_uv_append.c \
Expand Down
103 changes: 102 additions & 1 deletion src/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <uv.h>

#include "lib/sm.h"
#include "lib/queue.h"

#ifndef RAFT_API
Expand Down Expand Up @@ -328,6 +329,26 @@ struct raft_append_entries_result
};
#define RAFT_APPEND_ENTRIES_RESULT_VERSION 1

typedef uint32_t checksum_t;
typedef uint32_t pageno_t;

struct page_checksum {
pageno_t page_no;
checksum_t checksum;
};

/* page range [from, to], with to included */
struct page_from_to {
pageno_t from;
pageno_t to;
};

enum raft_result {
RAFT_RESULT_OK = 0,
RAFT_RESULT_UNEXPECTED = 1,
RAFT_RESULT_DONE = 2,
};

/**
* Hold the arguments of an InstallSnapshot RPC (figure 5.3).
*/
Expand All @@ -340,9 +361,75 @@ struct raft_install_snapshot
struct raft_configuration conf; /* Config as of last_index. */
raft_index conf_index; /* Commit index of conf. */
struct raft_buffer data; /* Raw snapshot data. */
enum raft_result result;
};
#define RAFT_INSTALL_SNAPSHOT_VERSION 0

struct raft_install_snapshot_result {
int version;

enum raft_result result;
};
#define RAFT_INSTALL_SNAPSHOT_RESULT_VERSION 0

struct raft_signature {
int version;

const char *db;
struct page_from_to page_from_to;
pageno_t cs_page_no;
enum raft_result result;
};
#define RAFT_SIGNATURE_VERSION 0

struct raft_signature_result {
int version;

const char *db;
struct page_checksum *cs;
unsigned int cs_nr;
pageno_t cs_page_no;
enum raft_result result;
};
#define RAFT_SIGNATURE_RESULT_VERSION 0

struct raft_install_snapshot_mv {
int version;

const char *db;
struct page_from_to *mv;
unsigned int mv_nr;
enum raft_result result;
};
#define RAFT_INSTALL_SNAPSHOT_MV_VERSION 0

struct raft_install_snapshot_mv_result {
int version;

const char *db;
pageno_t last_known_page_no; /* used for retries and message losses */
enum raft_result result;
};
#define RAFT_INSTALL_SNAPSHOT_MV_RESULT_VERSION 0

struct raft_install_snapshot_cp {
int version;

const char *db;
pageno_t page_no;
struct raft_buffer page_data;
enum raft_result result;
};
#define RAFT_INSTALL_SNAPSHOT_CP_VERSION 0

struct raft_install_snapshot_cp_result {
int version;

pageno_t last_known_page_no; /* used for retries and message losses */
enum raft_result result;
};
#define RAFT_INSTALL_SNAPSHOT_CP_RESULT_VERSION 0

/**
* Hold the arguments of a TimeoutNow RPC.
*
Expand All @@ -367,7 +454,14 @@ enum {
RAFT_IO_REQUEST_VOTE,
RAFT_IO_REQUEST_VOTE_RESULT,
RAFT_IO_INSTALL_SNAPSHOT,
RAFT_IO_TIMEOUT_NOW
RAFT_IO_TIMEOUT_NOW,
RAFT_IO_SIGNATURE,
RAFT_IO_SIGNATURE_RESULT,
RAFT_IO_INSTALL_SNAPSHOT_RESULT,
RAFT_IO_INSTALL_SNAPSHOT_MV,
RAFT_IO_INSTALL_SNAPSHOT_MV_RESULT,
RAFT_IO_INSTALL_SNAPSHOT_CP,
RAFT_IO_INSTALL_SNAPSHOT_CP_RESULT,
};

/**
Expand Down Expand Up @@ -409,6 +503,13 @@ struct raft_message
struct raft_append_entries append_entries;
struct raft_append_entries_result append_entries_result;
struct raft_install_snapshot install_snapshot;
struct raft_install_snapshot_result install_snapshot_result;
struct raft_signature signature;
struct raft_signature_result signature_result;
struct raft_install_snapshot_cp install_snapshot_cp;
struct raft_install_snapshot_cp_result install_snapshot_cp_result;
struct raft_install_snapshot_mv install_snapshot_mv;
struct raft_install_snapshot_mv_result install_snapshot_mv_result;
struct raft_timeout_now timeout_now;
};
};
Expand Down
1 change: 1 addition & 0 deletions src/raft/raft.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../raft.h"

#include <limits.h>
#include <string.h>

#include "../tracing.h"
Expand Down
Loading
Loading