Commit c8ab5e03 authored by willem's avatar willem
Browse files

Added raft log

parent caa00deb
......@@ -37,7 +37,7 @@ main_test.c:
fi
sh make-tests.sh "test_*.c" > main_test.c
tests_main: main_test.c raft_server.c raft_candidate.c raft_follower.c raft_leader.c raft_peer.c test_server.c test_server_request_vote.c test_follower.c test_candidate.c test_leader.c test_peer.c mock_send_functions.c CuTest.c $(HASHMAP_DIR)/linked_list_hashmap.c $(LLQUEUE_DIR)/linked_list_queue.c $(AQUEUE_DIR)/arrayqueue.c
tests_main: main_test.c raft_server.c raft_candidate.c raft_follower.c raft_leader.c raft_peer.c test_server.c test_server_request_vote.c test_peer.c mock_send_functions.c CuTest.c $(HASHMAP_DIR)/linked_list_hashmap.c $(LLQUEUE_DIR)/linked_list_queue.c $(AQUEUE_DIR)/arrayqueue.c
$(CC) $(CCFLAGS) -o $@ $^
./tests_main
......
/**
* Copyright (c) 2013, Willem-Hendrik Thiart
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* @file
* @brief ADT for managing Raft log entries (aka commands)
* @author Willem Thiart himself@willemthiart.com
* @version 0.1
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "linked_list_hashmap.h"
#include "arrayqueue.h"
#include "raft.h"
......@@ -16,8 +16,8 @@
#include <assert.h>
#include "linked_list_hashmap.h"
#include "arrayqueue.h"
#include "raft.h"
#include "raft_log.h"
typedef struct {
/* Persistent state: */
......@@ -262,7 +262,7 @@ int raft_recv_appendentries(raft_server_t* me_, const int peer, msg_appendentrie
c->data = malloc(cmd->len);
memcpy(c->data,cmd->data,cmd->len);
if (0 == raft_append_command(me_, c))
if (0 == raft_append_entry(me_, c))
{
/* failure, we couldn't append it for some reason */
r.success = 0;
......@@ -501,7 +501,7 @@ int raft_send_requestvote(raft_server_t* me_, int peer)
* Appends command using the current term.
* Note: we make the assumption that current term is up-to-date
* @return 0 if unsuccessful */
int raft_append_command(raft_server_t* me_, raft_command_t* c)
int raft_append_entry(raft_server_t* me_, raft_command_t* c)
{
raft_server_private_t* me = (void*)me_;
......
#include <stdbool.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "CuTest.h"
#include "raft.h"
#include "mock_send_functions.h"
#include <stdbool.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "CuTest.h"
#include "raft.h"
#include "mock_send_functions.h"
#include <stdbool.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "CuTest.h"
#include "raft.h"
#include "mock_send_functions.h"
......@@ -130,7 +130,7 @@ void TestRaft_server_command_append_increases_logindex(CuTest* tc)
r = raft_new();
CuAssertTrue(tc, 0 == raft_get_current_index(r));
raft_append_command(r,&cmd);
raft_append_entry(r,&cmd);
CuAssertTrue(tc, 1 == raft_get_current_index(r));
}
......@@ -147,7 +147,7 @@ void TestRaft_server_append_command_means_command_gets_current_term(CuTest* tc)
r = raft_new();
CuAssertTrue(tc, 0 == raft_get_current_index(r));
raft_append_command(r,&cmd);
raft_append_entry(r,&cmd);
CuAssertTrue(tc, 1 == raft_get_current_index(r));
}
......@@ -164,13 +164,13 @@ void TestRaft_server_append_command_not_sucessful_if_command_with_id_already_app
r = raft_new();
CuAssertTrue(tc, 0 == raft_get_current_index(r));
raft_append_command(r,&cmd);
raft_append_command(r,&cmd);
raft_append_entry(r,&cmd);
raft_append_entry(r,&cmd);
CuAssertTrue(tc, 1 == raft_get_current_index(r));
/* different ID so we can be successful */
cmd.id = 1;
raft_append_command(r,&cmd);
raft_append_entry(r,&cmd);
CuAssertTrue(tc, 2 == raft_get_current_index(r));
}
......@@ -190,13 +190,13 @@ void TestRaft_server_command_is_retrieveable_using_index(CuTest* tc)
cmd.id = 0;
cmd.data = str;
cmd.len = 3;
raft_append_command(r,&cmd);
raft_append_entry(r,&cmd);
/* different ID so we can be successful */
cmd.id = 1;
cmd.data = str2;
cmd.len = 3;
raft_append_command(r,&cmd);
raft_append_entry(r,&cmd);
//CuAssertTrue(tc, (cmd_appended = raft_get_command_from_index(r,1)));
//CuAssertTrue(tc, !strncmp(cmd_appended->data,str2,3));
......@@ -610,7 +610,7 @@ void TestRaft_follower_recv_appendentries_delete_entries_if_conflict_with_new_en
cmd.len = 3;
cmd.id = 0;
cmd.term = 1;
raft_append_command(r, &cmd);
raft_append_entry(r, &cmd);
CuAssertTrue(tc, 1 == raft_get_log_count(r));
/* pass a appendentry that is newer */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment