Skip to content

Commit

Permalink
Refactoring and Test Fixes (#6)
Browse files Browse the repository at this point in the history
* Create format.yml

* Committing clang-format changes'

* Added .clang-format file

* Added .clang-format file

* Committing clang-format changes'

* Fixed typo in format.yml

* Fixing format.yml error

* Fixed typo in format.yml

* Fixing format.yml error

* Update README.md

* Refactored raft log

* Refactored Peer struct

* Refactored log tests

* Added sendAppendEntries and leaderLoop functions

* Refactored log tests

* Updated raft.proto file

* Committing clang-format changes

* Adder server struct

* Rafactored log.go

* Refactored logger package and added options.go file

* Added interface, implementation, and tests for stable storage

* Added options.go file

* Refactored log

* Added state.go file

* Removed unnecessary field in volatile log

* Refactored raft

* Added pkg folder, refactored raft, added server tests

* Fixed bug in peer

* Added functions for replication

* Added additional tests for server

* Fixed bug in raft

* Fixed bug in raft

* Added request/response and rpc for installing snapshot

* Committing clang-format changes

* Added compact function to log

* Added install snapshot RPC skeleton functions

* Added install snapshot RPC skeleton functions

* Added state machine interface and mock with tests

* Added snapshot stroage interface and mock with tests

* Refactored pkg files

* Fixed bug in raft

* Fixed bug in raft and updated test cases

* Updated test cases

* Updated test cases

* Refactored raft

* Added checks for go routine leaks

* Refactored raft and implemented snapshotting

* Refactored log

* Added initial snapshot tests

* Added rpc.go file

* Updated state machine tests

* Added state.go file

* Updated test timeout in workflow

* Fixed bug in raft and added documentation

* Refactored server tests and added additional tests

* Added additional server tests

* Fixed TestSingleSnapshot test case

* Added nil checks to server

* Fixed internal package error

* Refactored tests and fixed bug in peer

* Fixed timing error in tests

* Fixed timing error in tests

* Update go.yml

* Refactored raft

* Refactored raft

* Refactored log and updated log tests

* Fixed bugs in raft and refactored server

* Refactored server tests

* Removed rpc.go and state.go

* Refactored raft

* Updated util random timeout function

* Refactored server tests

* Updated log documentation

* Bug fixing

* Added persistence tests

* Bug fixing

* Added documentation for server tests

* Fixing start and shutdown bugs

* Added additional persistence tests

* Fixed bug in request vote RPC

* Increased default election timeout

* Added partition test

* Added additional partition tests

* Added storage state message to raft.proto

* Committing clang-format changes

* Implemented storage and log encoding interfaces

* Added tests for encoder implementations

* Implemented persistent log

* Added tests for persistent log

* Created peer interface

* Updated storage interface

* Added tests for persistent storage

* Refactored server and server tests

* Refactored raft

* Added encoding documentation

* Updated peer documentation

* Debugging raft livelock

* Refactored encoders

* Fixed bug in log

* Refactored storage

* Fixing raft bugs

* Fixing bug in test cluster

* Updated server test timeouts and documentation

* Rafactoring code and documentation

* Fixed incorrect leader check timeout

* Fixed typos

* Fixed typos

* Updated raft documentation

* Creates separate file for request types and conversion functions

* Refactored test cluster

* Added RaftServer interface and wrote documentation

* Updated documentation

* Updated documentation

* Made simulated failures less frequent. Tests fail on some machines due to no progress being made.

* Updated documentation

* Implemented fast log back up optimization

* Committing clang-format changes

* Fixed bug in peer

* Fixed typo

* Updated protobuf with snapshotting messages

* Added InstallSnapshot requests

* Added InstallSnapshot RPC

* Updated snapshot storage

* Added snapshot encoder and decoder

* Implemented log discard function

* Updated snapshotting options

* Updated mock state machine

* Updated tests to handle snapshots

* Added test for snapshot encoder and decoder

* Updated snapshot options

* Updated server documentation

* Updated server tests with snapshot options

* Refactored raft

* Added Makefile

* Updated workflows

* Committing clang-format changes

* Updated snapshot storage documentation

* Added go fmt to workflow

* Refactored peer

* Updated raft documentation

* Updated snapshot store documentation

* Added additional server test

* Added replay function to log

* Refactored log

* Refactored peer

* Updated log error messages

* Refactored snapshot store and added replay function

* Refactored storage

* Refactored raft

* Refactored peer

* Refactored server tests

* Refactored raft

* Refactored server tests and added additional documentation

* Added linting and dependency verification to go workflow

* Added additional tests and refactored tests

* Updated documentation again

* Added FSM loop to raft and updated snapshotting process

* Updated log entry struct

* Refactored state machine

* Updated server tests to handle new snapshotting process

* Updated Makefile to handle protobuf compilation

* Created testing.go for test utilities

* Decoupled raft state from peer and refactored raft

* Updated log documentation

* Updated storage documentation

* Updated snapshot storage documentation

* Removed state_machine_test.go

* Renamed server

* Moved test cluster to testing.go

* Removed pkg directory

* Fixed server documentation

* Refactored encoders and decoders

* Made peer implementation unexported

* Made log implementation unexported

* Made snapshot storage unexported

* Made storage implementation unexported

* Implemented functions for manual snapshotting

* Added manual snapshot tests

* Updated raft documentation

* Fixed storage and snapshot storage documentation

* Updated README.md

* Updated error documentation and minor refactoring

* Updated snapshot storage documentation

* Updated snapshot storage documentation

* Minor refactoring and documentation updates

* Minor refactoring and documentation updates

* Updated README.md with example

* Updated example code

* Updated README.md

* Updated README.md

* Update README.md

* Update README.md

* Update README.md

* Added doc.go file

* Fixed typos

* Refactored raft

* Added tests for single server cluster

* Made RPC functions exported

* Changed server to accept string addresses

* Updated temporary file names

* Updated temporary file names

* Changed server to accept string addresses

* Updated doc.go

* Update README.md

* Fixed bug with temporary files and updated file permissions

* Fixed snapshotting bug

* Rename go.yml to build.yml

* Update build.yml

* Update README.md

* Updated documentation

* Refactored encoding and decoding functions

* Refactored encoding and decoding functions

* Fixed typos

* Update README.md

* Refactored snapshots

* Updated doc.go

* Added max entries per RPC option

* Updated Makefile

* Fixed snapshot testing bug and documentation

* General refactoring

* Added additional test for log

* Added .idea to .gitignore

* Refactored error handling

* Updated README.md

* Fixed typo in documentation

* Refactored test suite

* Updated build.yml with new make rules

* Refactored test suite

* Refactored test suite

* Fixed documentation typos

* Updated README.md

* Create LICENSE

* Added raft options validity checks (#4)

* Snapshot test fix (#5)

* Fixed testing in build workflow

* Fixed failing snapshot storage test

* Committing go fmt changes
  • Loading branch information
jmsadair authored Jul 22, 2023
1 parent 35d2a7f commit ba9c8e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ jobs:

- name: Test Raft with Snapshotting
run: make test-snapshotting
continue-on-error: true
continue-on-error: false

- name: Test Raft without Snapshotting
run: make test
continue-on-error: true

- name: Check Test Results
run: |
if [ ${{ job.status }} == 'failure' ]; then
echo "Tests failed. Exiting with a non-zero status code."
exit 1
fi
continue-on-error: false
25 changes: 23 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package raft

import (
"github.com/jmsadair/raft/internal/errors"
"time"
)

const (
defaultElectionTimeout = time.Duration(300 * time.Millisecond)
defaultHeartbeat = time.Duration(50 * time.Millisecond)
minElectionTimeout = time.Duration(100 * time.Millisecond)
maxElectionTimeout = time.Duration(2000 * time.Millisecond)
defaultElectionTimeout = time.Duration(300 * time.Millisecond)

minHeartbeat = time.Duration(25 * time.Millisecond)
maxHeartbeat = time.Duration(300 * time.Millisecond)
defaultHeartbeat = time.Duration(50 * time.Millisecond)

minMaxEntriesPerRPC = 50
maxMaxEntriesPerRPC = 500
defaultMaxEntriesPerRPC = 100
)

Expand Down Expand Up @@ -67,6 +76,9 @@ type Option func(options *options) error
// WithElectionTimeout sets the election timeout for the Raft server.
func WithElectionTimeout(time time.Duration) Option {
return func(options *options) error {
if time < minElectionTimeout || time > maxElectionTimeout {
return errors.New("election timeout value is invalid")
}
options.electionTimeout = time
return nil
}
Expand All @@ -75,6 +87,9 @@ func WithElectionTimeout(time time.Duration) Option {
// WithHeartbeatInterval sets the heartbeat interval for the Raft server.
func WithHeartbeatInterval(time time.Duration) Option {
return func(options *options) error {
if time < minHeartbeat || time > maxHeartbeat {
return errors.New("heartbeat interval value is invalid")
}
options.heartbeatInterval = time
return nil
}
Expand All @@ -84,6 +99,9 @@ func WithHeartbeatInterval(time time.Duration) Option {
// transmitted via an AppendEntries RPC.
func WithMaxEntriesPerRPC(maxEntriesPerRPC int) Option {
return func(options *options) error {
if maxEntriesPerRPC < minMaxEntriesPerRPC || maxEntriesPerRPC > maxMaxEntriesPerRPC {
return errors.New("maximum entries per RPC value is invalid")
}
options.maxEntriesPerRPC = maxEntriesPerRPC
return nil
}
Expand All @@ -92,6 +110,9 @@ func WithMaxEntriesPerRPC(maxEntriesPerRPC int) Option {
// WithLogger sets the logger used by the Raft server.
func WithLogger(logger Logger) Option {
return func(options *options) error {
if logger == nil {
return errors.New("logger must not be nil")
}
options.logger = logger
return nil
}
Expand Down
7 changes: 3 additions & 4 deletions snapshot_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ func TestSnapshotStore(t *testing.T) {
validateSnapshot(t, snapshot1, &last1)

snapshot2 := NewSnapshot(2, 2, []byte("test2"))
require.NoError(t, snapshotStore.SaveSnapshot(snapshot1))
require.NoError(t, snapshotStore.SaveSnapshot(snapshot2))

last2, ok := snapshotStore.LastSnapshot()
require.True(t, ok)
validateSnapshot(t, snapshot2, &last2)

snapshots := snapshotStore.ListSnapshots()

require.Len(t, snapshots, 2, "incorrect number of snapshots")
require.Len(t, snapshots, 2)

require.NoError(t, snapshotStore.Close())
require.NoError(t, snapshotStore.Open())
Expand All @@ -42,5 +41,5 @@ func TestSnapshotStore(t *testing.T) {
validateSnapshot(t, snapshot2, &last2)

snapshots = snapshotStore.ListSnapshots()
require.Len(t, snapshots, 2, "incorrect number of snapshots")
require.Len(t, snapshots, 2)
}

0 comments on commit ba9c8e8

Please sign in to comment.