Skip to content

Commit

Permalink
Sentinel-08: Sleepy Integ && README.md + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReshiAdavan committed Nov 3, 2023
1 parent 57739ba commit 6541ecb
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Sleepy the Code Reviewer
on:
pull_request:
types:
- opened
- synchronize
permissions: write-all
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Sleepy the Code Reviewer
uses: ReshiAdavan/Sleepy@master
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_MODEL: "gpt-3.5" # Optional: defaults to "gpt-4"
exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@
# Go files
go.work
go.mod

raft/test_test.go
rpc/test_test.go
gobWrapper/test_test.go
kvraft/test_test.go
98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,100 @@

A distributed key-value storage, similar in architecture to Redis, DynamoDB, etc., built in golang and using RAFT consensus.

<!-- # Architecture
### Inspiration

## Solution Architecture
I never understood the idea behind databases like Redis, and DynamoDB. Naive, post "data structure and algorithms" me thought hashmaps are simple data structures that do not need to be scaled to the level that Redis and DynamoDB have.

However, after some curious research and learning, I realized how cool and important KV stores are in the SWE industry. Our key words are software cache, persistency and eventual consistency (CAP Theorem principles).

So, to light the path that I took to explore distributed systems, I started by learning systems design principles, and distributed schemes and their applications in networking and software. Eventually, I wanted to create a distributed systems application, and I gave into creating essentially a clone of Redis, a distributed KV store, aka Sentinel.

### Topics

- Languages: Golang
- Concepts

- Techniques: Multi-threading & Concurrency
- Algorithms: RAFT Consensus Algorithm
- Other: CAP Theorem

### Use It Yourself

Not so fast hotshot. Its quite hard to run... even myself I am struggling as my new computer cannot handle this.

No procedure in place at the moment (Work In Progress)

### Architecture

Unlike NETINfra, the architecture is not split into services, since it is not a microservice project, however, we can treat the architecture almost as if it is, since Sentinel was compartmentalized into separable components as described below.

#### gobWrapper

Wrapper around Go's encoding/gob, that checks and warns about capitalization.

Note: It is not a large implementation, just a wrapper that simplifies and makes calling GOB easier for me.

##### Background

gob manages streams of gobs - binary values exchanged between an Encoder (transmitter) and a Decoder (receiver). A typical use is transporting arguments and results of remote procedure calls (RPCs) such as those provided by net/rpc.

The implementation compiles a custom codec for each data type in the stream and is most efficient when a single Encoder is used to transmit a stream of values, amortizing the cost of compilation.

Refer to the following for more info: https://pkg.go.dev/encoding/gob

#### kvraft

Main business logic around the key value store given RAFT procedure. Methods like retrieving and keys modifying as well as getting values for key value pairs.

There is also configuration for how servers coordinate together given the KV RAFT system and their respective business logic.This includes but does not limit to...

- How they record snapshots of the data, as it changes per node in the system.
- Modifying the logs of all transactions in the system, per node.
- Metrics on testing performance of the KV RAFT system.

...etc

#### Linearizability

Implementation Strategy behind the KV system.

Includes but does not limit to...

- Making nodes
- Inserting Before OR After
- Converting Entries, Linking them Together
- Cache and its associatives
- Hashing keys

#### RAFT

RAFT Consensus Algorithm Implementation.

Includes but does not limit to...

- Configuration of RAFT and its servers
- Shutdown polcies
- Leader election procedures
- Re-election
- Checking stale leaders
- Agreement on terms
- Support for persistent Raft state and kv server snapsho
- Persisted States

...etc

#### RPC

Channel-based RPC that simulates a network that can lose requests, lose replies, delay messages, and entirely disconnect particular hosts. Adapted from Go net/rpc/server.go.

It essentially replicates a subset of the functionality from package go rpc.

Functionalities include...

- Sends gobWrapper-encoded values to ensure that RPCs don't include references to program objects.

##### Background

Package rpc provides access to the exported methods of an object across a network or other I/O connection. A server registers an object, making it visible as a service with the name of the type of the object. After registration, exported methods of the object will be accessible remotely. A server may register multiple objects (services) of different types but it is an error to register multiple objects of the same type.

Refer to the following for more info: https://pkg.go.dev/net/rpc
18 changes: 9 additions & 9 deletions gobWrapper/gobWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ var mu sync.Mutex
var errorCount int // for TestCapital
var checked map[reflect.Type]bool

type LabEncoder struct {
type Encoder struct {
gob *gob.Encoder
}

func NewEncoder(w io.Writer) *LabEncoder {
enc := &LabEncoder{}
func NewEncoder(w io.Writer) *Encoder {
enc := &Encoder{}
enc.gob = gob.NewEncoder(w)
return enc
}

func (enc *LabEncoder) Encode(e interface{}) error {
func (enc *Encoder) Encode(e interface{}) error {
checkValue(e)
return enc.gob.Encode(e)
}

func (enc *LabEncoder) EncodeValue(value reflect.Value) error {
func (enc *Encoder) EncodeValue(value reflect.Value) error {
checkValue(value.Interface())
return enc.gob.EncodeValue(value)
}

type LabDecoder struct {
type Decoder struct {
gob *gob.Decoder
}

func NewDecoder(r io.Reader) *LabDecoder {
dec := &LabDecoder{}
func NewDecoder(r io.Reader) *Decoder {
dec := &Decoder{}
dec.gob = gob.NewDecoder(r)
return dec
}

func (dec *LabDecoder) Decode(e interface{}) error {
func (dec *Decoder) Decode(e interface{}) error {
checkValue(e)
checkDefault(e)
return dec.gob.Decode(e)
Expand Down
2 changes: 1 addition & 1 deletion linearizability/bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ func (b bitset) equals(b2 bitset) bool {
if b[i] != b2[i] {
return false
}
}
}
return true
}

0 comments on commit 6541ecb

Please sign in to comment.