Skip to content

Commit

Permalink
Merge branch 'dev/isaac'
Browse files Browse the repository at this point in the history
  • Loading branch information
irbowen committed Apr 16, 2017
2 parents 2af5eae + e169d95 commit 6393459
Show file tree
Hide file tree
Showing 32 changed files with 534 additions and 195 deletions.
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ DEBUG = -g
RELEASE = -O3
VERSION = $(RELEASE)

CXXFLAGS = -std=c++14 $(VERSION) -pedantic
CXXFLAGS = -std=c++14 $(VERSION) -pedantic -pthread

BOTH_LIB := objs/network.o objs/message.o
SERVER_LIB := objs/paxos_main.o objs/replica.o objs/acceptor.o objs/learner.o objs/proposer.o objs/kv_store.o $(BOTH_LIB)
REPLICA_LIB := objs/paxos_main.o objs/replica.o objs/acceptor.o objs/learner.o objs/proposer.o objs/kv_store.o $(BOTH_LIB)
CLIENT_LIB := objs/client_lib.o $(BOTH_LIB)
MASTER_LIB := objs/master_main.o objs/master.o objs/shard.o $(BOTH_LIB)

########################################
default: all
all: paxos_server clients
all: paxos_server kv_master clients

DEPS := $(wildcard headers/*.h)

.PRECIOUS: objs/%.o
objs/%.o: src/%.cc $(DEPS)
$(CXX) $(CXXFLAGS) -o $@ -c $<

paxos_server: $(SERVER_LIB)
paxos_server: $(REPLICA_LIB)
$(CXX) $(CXXFLAGS) -o bin/$@ $^

kv_master: $(MASTER_LIB)
$(CXX) $(CXXFLAGS) -o bin/$@ $^

CLIENT_SRC :=$(wildcard src/kv_client_*.cc)
Expand All @@ -30,9 +34,10 @@ clients: $(CLIENTS)
kv_client_%.out: objs/kv_client_%.o $(CLIENT_LIB)
$(CXX) $(CXXFLAGS) -o bin/$@ $^


########################################
clean:
touch bin/paxos_server
touch bin/paxos_server bin/kv_master
touch log_0.txt
touch objs/dummy.o bin/dummy.out
rm objs/*.o bin/*.out log_*.txt bin/paxos_server
rm objs/*.o bin/*.out log_*.txt bin/kv_master bin/paxos_server
3 changes: 0 additions & 3 deletions configs/config3.txt

This file was deleted.

4 changes: 4 additions & 0 deletions configs/master_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
127.0.0.1 7000
2
configs/shard_0.txt
configs/shard_1.txt
File renamed without changes.
5 changes: 5 additions & 0 deletions configs/shard_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
127.0.0.1 8100 0
127.0.0.1 8101 1
127.0.0.1 8102 2
127.0.0.1 8103 3
127.0.0.1 8104 4
11 changes: 11 additions & 0 deletions configs/shard_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
127.0.0.1 8200 0
127.0.0.1 8201 1
127.0.0.1 8202 2
127.0.0.1 8203 3
127.0.0.1 8204 4
127.0.0.1 8205 5
127.0.0.1 8206 6
127.0.0.1 8207 7
127.0.0.1 8208 8
127.0.0.1 8209 9
127.0.0.1 8210 10
11 changes: 11 additions & 0 deletions configs/shard_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
127.0.0.1 8300 0
127.0.0.1 8301 1
127.0.0.1 8302 2
127.0.0.1 8303 3
127.0.0.1 8304 4
127.0.0.1 8305 5
127.0.0.1 8306 6
127.0.0.1 8307 7
127.0.0.1 8308 8
127.0.0.1 8309 9
127.0.0.1 8310 10
11 changes: 11 additions & 0 deletions configs/shard_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
127.0.0.1 8400 0
127.0.0.1 8401 1
127.0.0.1 8402 2
127.0.0.1 8403 3
127.0.0.1 8404 4
127.0.0.1 8405 5
127.0.0.1 8406 6
127.0.0.1 8407 7
127.0.0.1 8408 8
127.0.0.1 8409 9
127.0.0.1 8410 10
21 changes: 5 additions & 16 deletions headers/client_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,21 @@
#ifndef CLIENT_LIB_H
#define CLIENT_LIB_H

#include <iostream>
#include <string>
#include <fstream>
#include <vector>

#include "message.h"
#include "network.h"

class client_lib {
private:
int port;
std::string host;
std::string current_primary;
std::string find_master();
uint cur_view_num = 0;
int client_seq_num;
network net;
std::vector<node> replicas;
std::vector<node> kv_replicas;
int master_port_, client_port_;
std::string master_host_, client_host_;
network net_;
public:
client_lib(int _port, string _host, string config_filename);
// Blocking until success, may retry multiple times under the hood
// Primary, upon receiving learn msg itself, will reply to client
void add_chat_message(std::string msg);
client_lib(int master_port, std::string master_host, int client_port, std::string client_host);
std::string get(std::string key);
void put(std::string key, std::string value);
void delete_key(std::string key);
};

#endif
35 changes: 35 additions & 0 deletions headers/master.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#ifndef master_h
#define master_h

#include <string>
#include <vector>

#include "message.h"
#include "network.h"
#include "shard.h"

class Master {
private:
int port_;
std::string host_;
std::vector<Shard*> shards_;

int tolerated_failures_;

/* The master uses this to communicate
with the clients */
network net_;

public:
/* Init and shit */
Master(int port, std::string host, std::string master_config_file);

/* Generic network code */
void recv();
void handle_msg(Message* message);

int get_shard_id(Message* message);
};

#endif
5 changes: 4 additions & 1 deletion headers/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ enum MessageType {
ACCEPT_VALUE = 8,
PROPOSAL_LEARNT = 9,
PUT = 10,
GET = 11
GET = 11,
DELETE = 12,
ADD_SHARD = 13,
MASTER_ACK = 14
};

class Message {
Expand Down
46 changes: 46 additions & 0 deletions headers/shard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#ifndef shard_h
#define shard_h

#include <condition_variable>
#include <fstream>
#include <mutex>
#include <queue>
#include <string>
#include <thread>
#include <vector>

#include "message.h"
#include "network.h"

class Shard {
private:
/* The port and host that this shard manager will use
to communicate with the shard */
int port_;
std::string host_;
/* The config file which describes the key/value/paxos replicas
in the shard */
std::string config_filename_;
std::vector<node> replicas_;
/* Only incremented on failure, so we can promote a new
leader in the shard */
int cur_view_num_ = 0;
/* Should be incremented on every request to this shard */
int client_seq_num_ = 0;
/* Used to handle and sync communication with the shard */
network net_;
std::queue<Message*> msg_queue_;
std::mutex m;
std::condition_variable cv;
public:
Shard(int port, std::string host, std::string config_filename);
void run();
/* These functions assume that this shard has the key that you want */
void register_msg(Message* message);
Message* handle_get(std::string key, node sender);
Message* handle_put(std::string key, std::string value, node sender);
Message* handle_delete(std::string key, node sender);
};

#endif
25 changes: 25 additions & 0 deletions make_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python3

f = input('How many failures to tolerate per shard? ')
n = input('How many shards? ')
p = input('Starting port (try 8000)? ')

startup = ''
master_config_data = '127.0.0.1 7000\n%s\n' % f
for i in range(0, int(n)):
shard_port = int(p) + 100 * i
shard_config = 'configs/shard_%d.txt' % i
master_config_data += shard_config + '\n'
shard_data = ''
t = 2 * int(f) + 1
for k in range(0, t):
start_str = "./bin/paxos_server --port %d --host 127.0.0.1 --config %s --id %d &\n" % (shard_port + k, shard_config, k)
startup += start_str
shard_data += "127.0.0.1 %d %d\n" % (shard_port + k, k)
f_ = open(shard_config, 'w')
f_.write(shard_data)

f_ = open('scripts/all_start.sh', 'w')
f_.write(startup)
f_ = open('configs/master_config.txt', 'w')
f_.write(master_config_data)
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions scripts/all_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
./bin/paxos_server --port 8000 --host 127.0.0.1 --config configs/shard_0.txt --id 0 &
./bin/paxos_server --port 8001 --host 127.0.0.1 --config configs/shard_0.txt --id 1 &
./bin/paxos_server --port 8002 --host 127.0.0.1 --config configs/shard_0.txt --id 2 &
./bin/paxos_server --port 8003 --host 127.0.0.1 --config configs/shard_0.txt --id 3 &
./bin/paxos_server --port 8004 --host 127.0.0.1 --config configs/shard_0.txt --id 4 &
./bin/paxos_server --port 8100 --host 127.0.0.1 --config configs/shard_1.txt --id 0 &
./bin/paxos_server --port 8101 --host 127.0.0.1 --config configs/shard_1.txt --id 1 &
./bin/paxos_server --port 8102 --host 127.0.0.1 --config configs/shard_1.txt --id 2 &
./bin/paxos_server --port 8103 --host 127.0.0.1 --config configs/shard_1.txt --id 3 &
./bin/paxos_server --port 8104 --host 127.0.0.1 --config configs/shard_1.txt --id 4 &
1 change: 1 addition & 0 deletions tests/kill_all.sh → scripts/kill_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ echo -e "We are killing all the paxos servers and the chat clients\n"
ps aux | grep paxos_server | awk '{print $2}' | xargs kill
ps aux | grep chat_client_ | awk '{print $2}' | xargs kill
ps aux | grep kv_client_ | awk '{print $2}' | xargs kill
ps aux | grep kv_master | awk '{print $2}' | xargs kill
6 changes: 6 additions & 0 deletions scripts/show_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

ps aux | grep paxos_server
ps aux | grep chat_client_
ps aux | grep kv_client_
ps aux | grep kv_master
10 changes: 10 additions & 0 deletions scripts/start_master.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

echo -e "\nStarting up the master..."
./bin/kv_master \
--port 7000 \
--host 127.0.0.1 \
--config configs/master_config.txt &
sleep 1
echo -e "\nMaster is up on port 7000... "

17 changes: 17 additions & 0 deletions scripts/start_one_shard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash


# Start up 2f+1 replicas, where f=1
REPLICAS=(0 1 2)
BASE_PORT=8000
echo -e "\nStart up shard 0 key/value/paxos replicas ..."

for i in {0..2..1}; do
./bin/paxos_server \
--port "$((BASE_PORT + i))" \
--host 127.0.0.1 \
--config configs/shard_0.txt \
--id "$i" \
--holes configs/no_holes.txt &
done

29 changes: 29 additions & 0 deletions scripts/start_two_shards.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash


# Start up 2f+1 replicas, where f=1
REPLICAS=(0 1 2)
BASE_PORT=8000
echo -e "\nStart up shard 0 key/value/paxos replicas ..."

for i in {0..2..1}; do
./bin/paxos_server \
--port "$((BASE_PORT + i))" \
--host 127.0.0.1 \
--config configs/shard_0.txt \
--id "$i" \
--holes configs/no_holes.txt &
done

BASE_PORT=9000
echo -e "\nStart up shard 1 key/value/paxos replicas ..."

for i in {0..2..1}; do
./bin/paxos_server \
--port "$((BASE_PORT + i))" \
--host 127.0.0.1 \
--config configs/shard_1.txt \
--id "$i" \
--holes configs/no_holes.txt &
done

17 changes: 0 additions & 17 deletions src/chat_client_1.cc

This file was deleted.

14 changes: 0 additions & 14 deletions src/chat_client_2.cc

This file was deleted.

21 changes: 0 additions & 21 deletions src/chat_client_3.cc

This file was deleted.

Loading

0 comments on commit 6393459

Please sign in to comment.