Skip to content

Commit 77d48cd

Browse files
Merge pull request #1 from theryecatcher/raftimplementation
Merge the Raftimplementation
2 parents 46577bf + 50dcd17 commit 77d48cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2426
-224
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go:
55
- tip # The latest version of Go.
66
env:
77
- GO111MODULE=on
8-
install: true
8+
install: false
99
notifications:
1010
emails: false
1111
script:

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,41 @@
44
Twitter clone for Ditsributed Systems Course
55

66
### Environment
7-
You need to have Go Environment setup on you local machine.
7+
You need to have Go Environment setup on your local machine.
88

99
### Get the code
10-
Just do a git pul on the repo or better you could do a go get any one of the below commands should suffice.
10+
Just do a git pull on the repo or better you could do a go get any one of the below commands should suffice.
1111
```
1212
git clone https://github.com/theryecatcher/chirper/
1313
go get github.com/theryecatcher/chirper
1414
cd chirper/
1515
```
1616

1717
### Have Fun!!!
18-
The code is designed as a in Memory application for the 1st Phase. The Content Database and the User Database run as daemons and aren't part of the main application. You would need to run them seperately to have a functional application. Please follow the below sequence of commands to acheive the same.
18+
The code is designed as an in Memory application with Persistent storage provided by the RAFT Consensus Protocol. The Radt Wrapper, Content Wrapper and the User Wrapper run as daemons and are connected as microservices for the main web server.
1919

20-
You can append & (Run in background) to each of the processes. Or else For Debugging Purposes please run in different Terminals:
20+
The application can be started using the startall.sh bash script as below. The web server doesn't run as a daemon and is a live shell command in the terminal that runs the startall script (Ctrl + C kills it).
21+
```
22+
cd chirper
23+
./startall.sh
24+
```
25+
Note that as the web server uses the HTTP sockets module so you will need to give sudo access to your system which is present in the script just need to provide the sudo password after you start the script.
26+
27+
You can also run them separately to have a functional application. Please follow the below sequence of commands to achieve the same.
28+
29+
You can append & (Run in the background) to each of the processes. Or else For Debugging Purposes please run in different Terminals:
2130
```
2231
cd $GOPATH
2332
src/github.com/theryecatcher/chirper/cmd/backendCntD/backendCntD
2433
src/github.com/theryecatcher/chirper/cmd/backendUsrD/backendUsrD
2534
sudo src/github.com/theryecatcher/chirper/cmd/web/web
2635
```
2736

28-
As seen above the commands start the daemons and also the main wen application. Until this is hosted it is configured to run on localhost.
37+
For killing any of the nodes or daemons just run the commands in kill.txt.
38+
39+
As seen above the commands start the daemons and also the main web application. Until this is hosted it is configured to run on localhost.
2940

30-
You can now browse to "localhost/" to start playing with the application.
41+
You can now browse to "http://localhost/" to start playing with the application.
3142

3243
### Disclaimer!!!
3344
The application is still under active development so kindly let us know if you face any bugs contact details are provided in the About Page.

cmd/backendRaftD/backendRaftD

12.4 MB
Binary file not shown.

cmd/backendRaftD/backendRaftd.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"net"
8+
"os"
9+
10+
"github.com/theryecatcher/chirper/raftd/api/grpc"
11+
"google.golang.org/grpc"
12+
)
13+
14+
// Application parameters
15+
var serverAddr string
16+
var raftAddr string
17+
var joinAddr string
18+
var nodeID string
19+
20+
func init() {
21+
flag.StringVar(&serverAddr, "grpc", "45000", "Set the GRPC bind address")
22+
flag.StringVar(&raftAddr, "node", "46000", "Set Raft bind address")
23+
flag.StringVar(&joinAddr, "leader", "", "Set leader address, if any")
24+
flag.StringVar(&nodeID, "id", "", "Node ID")
25+
flag.Usage = func() {
26+
fmt.Fprintf(os.Stderr, "Usage: %s [options] <raft-local-storage-path> \n", os.Args[0])
27+
flag.PrintDefaults()
28+
}
29+
}
30+
31+
func main() {
32+
flag.Parse()
33+
34+
if flag.NArg() == 0 {
35+
fmt.Fprintf(os.Stderr, "Please run <cmd> -h (help) for usage instructions\n")
36+
os.Exit(1)
37+
}
38+
39+
if nodeID == "" {
40+
fmt.Fprintf(os.Stderr, "Please specify the Node ID/Name\n")
41+
os.Exit(1)
42+
}
43+
44+
// Create Raft Directory for Snapshots.
45+
raftDir := flag.Arg(0)
46+
if raftDir == "" {
47+
fmt.Fprintf(os.Stderr, "Need to have a Raft storage directory\n")
48+
os.Exit(1)
49+
}
50+
os.MkdirAll(raftDir, 0700)
51+
52+
lisraftD, err := net.Listen("tcp", fmt.Sprintf("%v:%v", "localhost", serverAddr))
53+
if err != nil {
54+
log.Fatalf("Error listening %v", err)
55+
}
56+
raftNodeServer := grpc.NewServer()
57+
58+
err = raftdgrpc.RegisterGRPCServer(&raftdgrpc.Config{
59+
RaftLocalDir: raftDir,
60+
RaftNodeAddr: raftAddr,
61+
RaftJoinAddr: joinAddr,
62+
RaftNodeID: nodeID,
63+
}, raftNodeServer)
64+
if err != nil {
65+
log.Fatalf("Failed to start Raft Node: %s", err.Error())
66+
}
67+
raftNodeServer.Serve(lisraftD)
68+
}

contentd/contentd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"github.com/theryecatcher/chirper/contentd/storage"
55
)
66

7+
// Contentd Contentd
78
type Contentd struct {
89
strg contentstorage.Storage
910
}
1011

12+
// New new
1113
func New(cfg *Config) (*Contentd, error) {
1214
return &Contentd{
13-
strg: contentstorage.NewDummyStorage(),
15+
strg: contentstorage.NewContentStore(),
1416
}, nil
1517
}

contentd/contentdpb/service.pb.go

Lines changed: 19 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contentd/contentdpb/service.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "contentd.proto";
44

55
service Contentd {
66
rpc NewTweet (NewTweetRequest) returns (NewTweetResponse);
7-
rpc GetTweet (GetTweetRequest) returns (GetTweetResponse);
7+
// rpc GetTweet (GetTweetRequest) returns (GetTweetResponse);
88
rpc GetTweetsByUser (GetTweetsByUserRequest) returns (GetTweetsByUserResponse);
99
}
1010

contentd/getTweet.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

contentd/getTweet_test.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

contentd/getTweetsByUser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package contentd
22

33
import (
44
"context"
5-
"log"
65

76
"github.com/theryecatcher/chirper/contentd/contentdpb"
87
)
98

109
func (cnt *Contentd) GetTweetsByUser(ctx context.Context, req *contentdpb.GetTweetsByUserRequest) (*contentdpb.GetTweetsByUserResponse, error) {
11-
log.Println("Contentd: get tweets by user")
10+
cnt.strg.GetLoggerHandle().Println("Contentd: get tweets by user")
1211
t, err := cnt.strg.GetTweetsByUser(ctx, req.UID)
1312

1413
return &contentdpb.GetTweetsByUserResponse{

0 commit comments

Comments
 (0)