首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
data编程代写、C/C++程序设计代做
项目预算:
开发周期:
发布时间:
要求地区:
Lab 1: Raft
Introduction
This is the first in a series of labs in which you’ll build a fault-tolerant key/value storage system. In this lab you’ll implement Raft, a
replicated state machine protocol. In the next lab you’ll build a key/value service on top of Raft.
A replicated service achieves fault tolerance by storing complete copies of its state (i.e., data) on multiple replica servers. Replication
allows the service to continue operating even if some of its servers experience failures (crashes or a broken or flaky network). The
challenge is that failures may cause the replicas to hold differing copies of the data.
Raft manages a service’s state replicas, and in particular, it helps the service sort out what the correct state is after failures. Raft
implements a replicated state machine. It organizes client requests into a sequence, called the log, and ensures that all the replicas
agree on the contents of the log. Each replica executes the client requests in the log in the order they appear in the log, applying those
requests to the replica’s local copy of the service’s state. Since all the live replicas see the same log contents, they all execute the
same requests in the same order, and thus continue to have identical service state. If a server fails but later recovers, Raft takes care
of bringing its log up to date. Raft will continue to operate as long as at least a majority of the servers are alive and can talk to each
other. If there is no such majority, Raft will make no progress, but will pick up where it left off as soon as a majority can communicate
again.
In this lab you’ll implement Raft as a C++ class with associated methods, meant to be used as a module in a larger service. A set of
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
In this lab you ll implement Raft as a C class with associated methods, meant to be used as a module in a larger service. A set of
Raft instances talk to each other with RPC to maintain replicated logs. Your Raft interface will support an indefinite sequence of
numbered commands, also called log entries. The entries are numbered with index numbers. The log entry with a given index will
eventually be committed. At that point, your Raft should send the log entry to the larger service for it to execute.
Your Raft instances are only allowed to interact using RPC. For example, different Raft instances are not allowed to share variables.
Your code should not use files at all.
Objective
In this lab you’ll implement most of the Raft design described in the extended paper. You will not implement: saving persistent state,
cluster membership changes (Section 6), log compaction / snapshotting (Section 7).
Some general tips:
Start early. Although the amount of code isn’t large, getting it to work correctly will be challenging.
Read and understand the Raft paper and the Raft lecture notes before you start. Your implementation should follow the paper’s
description closely, particularly Figure 2, since that’s what the tests expect.
Getting Started
Checking out code
Use the following link to get the assignment from GitHub Classroom.
https://classroom.github.com/a/TkjESYSH
Setup
First, make sure you are working on the right branch. Make sure you use lab-raft-solution as the branch name.
$ git checkout -b lab-raft-solution origin/raft-23fa
$ git submodule update --init
$ git push -u origin lab-raft-solution
We supply you with skeleton code and tests in src/deptran/raft.
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
Before compiling, you need to install all needed software dependencies.
sudo apt-get update
sudo apt-get install -y \
git \
pkg-config \
build-essential \
clang \
libapr1-dev libaprutil1-dev \
libboost-all-dev \
libyaml-cpp-dev \
libjemalloc-dev \
python2 \
python3-dev \
python3-pip \
python3-wheel \
python3-setuptools \
libgoogle-perftools-dev
sudo pip3 install -r requirements.txt
To get up and running, execute the following commands:
$ python3 waf configure build --enable-raft-test # compile
$ build/deptran_server -f config/raft_lab_test.yml # test
TEST 1: Initial election
TEST 1 Failed: waited too long for leader election
TESTS FAILED
ARM Mac users (unsupported by staff):
This lab is tested on x64 version of linux, but you may try ubuntu ARM as well. It looks the Multipass setup on this website installs
aarch64 Ubuntu for ARM Mac computers.
For compilation, please use the following command instead.
$ python3 waf configure build --enable-raft-test --boost-libs=/usr/lib/aarch64-linux-gnu
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
The Code
Most of the Raft implementation will be located in src/deptran/raft/. In this directory, there are 3 .cc files (and respective headers)
that you need to modify:
server.cc and server.h
commo.cc and commo.h
service.cc and service.h
Besides these three files, there is also src/deptran/raft/raft_rpc.rpc, where you will find abstract service Raft containing
sample prototypes for the RequestVote and AppendEntries RPCs. Here, you can modify the arguments and return values for the
RequestVote and AppendEntries RPCs and add any other RPCs as you see fit.
Do not create new files, and do not modify any existing files not mentioned.
RPCs
Class RaftServiceImpl (service.cc) implements receiver-end handlers for the RPCs declared in src/deptran/raft_rpc.rpc. To
register a handler for an RPC in RaftServiceImpl, use the RpcHandler macro.
RpcHandler usage: RpcHandler(RPC_NAME, N_PARAMS, PARAMS...) { DEFAULTLOGIC }
RPC_NAME: should match the name of the RPC declared in raft_rpc.rpc
N_PARAMS: number of RPC arguments + number of RPC return values
PARAMS: the RPC arguments and return values in the same order as in raft_rpc.rpc, with comma separations between the type
and name.
DEFAULTLOGIC: write code to assign default values to the RPC’s return value in these brackets. This code will get invoked when the
server is disconnected from the network to simulate a failed RPC. It is important that your RPC sender code recognizes the default
values and ignores them when they happen.
Class RaftCommo (commo.cc) is meant to handle sending RPC requests. See the example sender functions to understand how to send
RPCs in RaftCommo.
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
RPCs in RaftCommo.
Server logic
Class RaftServer (server.cc) is your starting point for writing most of the server logic.
Some useful member variables (inherited from a parent class of RaftServer):
loc_id_: id of the server.
commo(): function that returns the server’s RaftCommo instance.
mtx_: a std::recursive_mutex you can use for protecting data from concurrent access.
Required Functionality
There are a few specific functionalities in RaftServer you need to implement in order to pass all tests.
bool Start(shared_ptr
&cmd, uint64_t *index, uint64_t *term)
Implement this member function
If server is not the leader, return false
Else, start agreement on cmd in a new log entry, set index and term with the server’s current index and term, and return true
void GetState(bool *is_leader, uint64_t *term)
Implement this member function
Populate is_leader with true if the server thinks it is the leader
Populate term with the server’s current term number
function
app_next_
A member variable of a parent class of RaftServer.
Each server must pass each committed command to app next exactly once, in the correct order, as soon as each command is
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
Each server must pass each committed command to app_next_ exactly once, in the correct order, as soon as each command is
committed on each server.
Your first implementation may not be clean enough that you can easily reason about its correctness. Give yourself enough time to
rewrite your implementation so that you can easily reason about its correctness. Subsequent labs will build on this lab, so it is
important to do a good job on your implementation.
You are recommended to do this lab following these two steps:
Part 1A
Implement leader election and heartbeats (AppendEntries RPCs with no log entries). The goal for Part 1A is for a single leader to be
elected, for the leader to remain the leader if there are no failures, and for a new leader to take over if the old leader fails or if packets
to/from the old leader are lost.
Add any state you need to the RaftServer class (but do not use static member variable to share states between different
RaftServer instances) in server.cc. You’ll also need to define a struct to hold information about each log entry. Your code should
follow Figure 2 in the paper as closely as possible.
In RaftServer, create the function to handle RequestVote. Fill in the RequestVote RPC handler in service.cc, connect the RPC
handler and the RaftServer.
When initializing the RaftServer, create a backgrond coroutine that will kick off leader election periodically by sending out
RequestVote RPCs when it hasn’t heard from another peer for a while. This way a peer will learn who is the leader, if there is
already a leader, or become the leader itself.
To implement heartbeats, implement a separate EmptyAppendEntries RPC (AppendEntry without log entries), and have the leader
send them out periodically. Write an EmptyAppendEntries RPC handler method that resets the election timeout so that other
servers don’t step forward as leaders when one has already been elected.
Make sure the election timeouts in different peers don’t always fire at the same time, or else all peers will vote only for themselves
and no one will become the leader.
The tester requires that the leader send heartbeat RPCs no more than ten times per second.
The tester requires your Raft to elect a new leader within five seconds of the failure of the old leader (if a majority of peers can still
communicate). Remember, however, that leader election may require multiple rounds in case of a split vote (which can happen if
packets are lost or if candidates unluckily choose the same random backoff times) You must pick election timeouts (and thus
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
packets are lost or if candidates unluckily choose the same random backoff times). You must pick election timeouts (and thus
heartbeat intervals) that are short enough that it’s very likely that an election will complete in less than five seconds even if it
requires multiple rounds.
The paper’s Section 5.2 mentions election timeouts in the range of 150 to 300 milliseconds. Such a range only makes sense if the
leader sends heartbeats considerably more often than once per 150 milliseconds. Because the tester limits the RPC count (you are
recommended to set the heartbeat interval to 100ms), you will have to use an election timeout larger than the paper’s 150 to 300
milliseconds, but not too large, because then you may fail to elect a leader within five seconds.
If your code has trouble passing the tests, read the paper’s Figure 2 again; the full logic for leader election is spread over multiple
parts of the figure.
A good way to debug your code is to insert print statements when a peer sends or receives a message, and redirect the output in a
file compile_cmd &> out. Then, by studying the trace of messages in the out file, you can identify where your implementation
deviates from the desired protocol. You might find Log_info and Log_debug in the framework useful to turn printing on and off as
you debug different problems.
Part 1B
We want Raft to keep a consistent, replicated log of operations. A call to Start() at the leader starts the process of adding a new
operation to the log; the leader sends the new operation to the other servers in AppendEntries RPCs.
Implement the leader and follower code to append new log entries. This will involve implementing Start(), completing the
AppendEntries RPC structs, sending them, fleshing out the AppendEntry RPC handler, and advancing the commitIndex at the leader.
You will need to implement the election restriction (section 5.4.1 in the paper).
One way to fail the tests is to hold un-needed elections, that is, an election even though the current leader is alive and can talk to all
peers. This can prevent agreement in situations where the tester believes agreement is possible. Bugs in election timer
management, or not sending out heartbeats immediately after winning an election, can cause un-needed elections.
You may need to write code that waits for certain events to occur. Do not write loops that execute continuously without pausing,
since that will slow your implementation enough that it fails tests.
The tests for upcoming labs may fail your code if it runs too slowly. Try to write efficient code.
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
Be Caution & Hints
1. Try to avoid creating coroutines inside Start() function due to ill-prepared coroutine runtime.
2. Sleep the coroutine/thread when it seems necessary to avoid spinning and burning all CPU resources.
3. If you constantly see multiple elections happen almost at the same time throughout several consecutive tests or elections trigger
frequently, even when servers are all live and stable, you may want to adjust the random number for the timer and heartbeat
frequency. (Think about why?)
4. app_next_ should be called on both leader and followers. (Why?)
5. Be aware of outdated PRC replies. Due to (simulated) network delay, the packet might be delayed. Handling delayed replies is
crucial to ensure all server states remain correct.
6. commo() returns a RaftCommo instance, and it has a field named rpc_par_proxies_, which stores information regarding all peers.
7. When calling "sending" functions from the RaftCommo instance, you can use some heuristic timer to wait for the reply. Reply won't
be immediately available.
8. In the file "src/rrr/reactor/event.h", there are multiple useful event types provided. You can use them as you see fit.
Compile and Test
Compile:
$ python3 waf configure build --enable-raft-test
Test:
$ build/deptran_server -f config/raft_lab_test.yml
TEST 1: Initial election
TEST 1 Passed
TEST 2: Re-election after network failure
TEST 2 Passed
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
TEST 2 Passed
TEST 3: Basic agreement
TEST 3 Passed
TEST 4: Agreement despite follower disconnection
TEST 4 Passed
TEST 5: No agreement if too many followers disconnect
TEST 5 Passed
TEST 6: Rejoin of disconnected leader
TEST 6 Passed
TEST 7: Concurrently started agreements
TEST 7 Passed
TEST 8: Leader backs up quickly over incorrect follower logs
TEST 8 Passed
TEST 9: RPC counts aren't too high
TEST 9 Passed
TEST 10: Unreliable agreement
TEST 10 Passed
TEST 11: Figure 8
TEST 11 Passed
ALL TESTS PASSED
Total RPC count: 6609
The source for the tests is in src/deptran/raft/test.cc and src/deptran/raft/testconf.cc.
Submit
Please refer to Piazza for submission guidelines.
DO NOT
Make sure you do not do any of the following; otherwise you will fail the labs, even if the code may pass the testing scripts.
Change/create files other than the files allowed.
Use shared variables between Raft instances.
Use file/network/IPC interface other than the RPC interface given to you.
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
Acknowledgment
Thank Shuai Mu, Julie Lee for sharing this lab. It was originally inspired by MIT 6.824, and the code is based on the academic prototypes of previous
research works, including Rococo/Janus/Snow/DRP/Rolis/DepFast.
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
DS Fall 2023 Home Schedule Piazza Labs Dev Environment Setup
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!