Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cse550
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Winston Jodjana
cse550
Commits
9eba4ee0
Commit
9eba4ee0
authored
2 years ago
by
Dixon Tirtayadi
Browse files
Options
Downloads
Patches
Plain Diff
Added more server stuff
parent
11feb868
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
assignment2/paxos.py
+46
-13
46 additions, 13 deletions
assignment2/paxos.py
with
46 additions
and
13 deletions
assignment2/paxos.py
+
46
−
13
View file @
9eba4ee0
...
...
@@ -12,17 +12,18 @@ class Paxos(socketserver.TCPServer):
# Sets up other variables
self
.
is_leader
=
False
self
.
ballot
=
BallotNumber
(
1
,
self
.
address
)
self
.
proposals
=
map
()
self
.
accepted
=
map
()
# ...
# Default leader during setup
if
self
.
address
==
servers
[
0
]:
self
.
is_leader
=
True
socketserver
.
TCPServer
.
__init__
(
self
,
address
,
PaxosRequestHandler
)
class
PaxosRequestHandler
(
socketserver
.
BaseRequestHandler
):
class
Paxos
Client
RequestHandler
(
socketserver
.
BaseRequestHandler
):
"""
The request handler class for our server.
...
...
@@ -30,26 +31,58 @@ class PaxosRequestHandler(socketserver.BaseRequestHandler):
override the handle() method to implement communication to the
client.
This will receive lock() / unlock() command
This will receive lock() / unlock() command from client
Handler for proposals and leader election will be a different class (I think, probably using different port?)
"""
def
handle
(
self
):
# Temporary random things
# Use self.server.arg to get servers fields, i.e. self.server.isLeader
pass
# # self.request is the TCP socket connected to the client
# self.data = self.request.recv(1024).strip()
# print("{} wrote:".format(self.client_address[0]))
# print(self.data)
# # just send back the same data, but upper-cased
# self.request.sendall(self.data.upper())
if
not
self
.
server
.
isLeader
:
return
;
# Drop if not the leader
# Note that we guarantee communication client to server is exactly once,
# no need to worry about duplicate request and proposing two slot.
data
=
self
.
request
.
recv
(
1024
).
strip
()
# DEBUG LOG
print
(
"
{} wrote:
"
.
format
(
self
.
client_address
[
0
]))
# DEBUG LOG
print
(
data
)
# DEBUG LOG
# TODO: Change data into a format known for lock or unlock
# Propose
prop
=
Proposal
(
BallotNumber
(
self
.
ballot
().
seq_num
,
self
.
address
()),
data
)
proposals
[
slotIn
,
prop
]
accepted
[
slotIn
,
prop
]
# TODO: PaxosServer.java line 236-256
# Create proposal Message
# Send proposal
# Accept our own proposal
# Wait untl hear majority
# Send back result
self
.
request
.
sendall
(
data
.
upper
())
# TESTING CODE
@total_ordering
clas
Proposal
:
def
__init__
(
self
,
ballot
,
value
)
->
None
:
self
.
ballot
=
ballot
self
.
value
=
value
def
__lt__
(
self
,
other
)
->
bool
:
if
not
self
.
_is_valid_operand
(
other
):
return
NotImplemented
return
self
.
ballot
<
other
.
ballot
def
__eq__
(
self
,
other
)
->
bool
:
if
not
self
.
_is_valid_operand
(
other
):
return
NotImplemented
return
self
.
ballot
==
other
.
ballot
@total_ordering
class
BallotNumber
:
def
__init__
(
self
,
seq_num
,
addr
)
->
None
:
self
.
seq_num
=
seq_num
self
.
addr
=
addr
self
.
seq_num
=
seq_num
# Sequence number of the proposal
self
.
addr
=
addr
# Address of the server proposing
def
increaseBallot
(
self
):
self
.
seq_num
+=
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment