Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DBE-DS-Group1-WS24
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robin Leber
DBE-DS-Group1-WS24
Commits
07245428
Commit
07245428
authored
Jan 30, 2024
by
Robin Leber
Browse files
Options
Downloads
Patches
Plain Diff
fixed leader election
parent
6259c91a
Branches
Branches containing commit
No related tags found
1 merge request
!2
leader election und heartbeat
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.py
+25
-11
25 additions, 11 deletions
server.py
with
25 additions
and
11 deletions
server.py
+
25
−
11
View file @
07245428
...
...
@@ -208,21 +208,33 @@ class Server():
self
.
clients
.
remove
(
client
)
def
basic_lcr
(
self
):
print
(
'
New leader election starts
'
)
print
(
'
++++++++++++++++++++++++++
'
)
print
(
'
server list
'
)
print
(
self
.
serverList
)
print
(
'
New leader election starts
'
)
print
(
'
sending first leader election message to neighbour
'
)
neighbour
=
get_neighbour
(
form_ring
(
self
.
serverList
),
MY_IP
,
'
left
'
)
neighbour_address
=
(
neighbour
,
RING_PORT
)
first_message
=
{
"
mid
"
:
self
.
uuid
,
"
isLeader
"
:
False
}
self
.
participant
=
True
ring_socket
.
sendto
(
json
.
dumps
(
first_message
).
encode
(
'
utf-8
'
),
neighbour_address
)
print
(
'
\n
Waiting to receive election message...
\n
'
)
data
,
address
=
ring_socket
.
recvfrom
(
1024
)
election_message
=
json
.
loads
(
data
.
decode
())
neighbour
=
get_neighbour
(
form_ring
(
self
.
serverList
),
MY_IP
,
'
left
'
)
print
(
'
There is a election message
'
)
print
(
election_message
)
if
election_message
[
'
isLeader
'
]:
if
election_message
.
get
(
'
isLeader
'
):
print
(
'
1: leader info weitergeben
'
)
self
.
leader_uuid
=
election_message
[
'
mid
'
]
# forward received election message to left neighbour
self
.
participant
=
False
ring_socket
.
sendto
(
json
.
dumps
(
election_message
),
neighbour
)
if
election_message
[
'
mid
'
]
<
self
.
uuid
and
not
self
.
participant
:
if
election_message
.
get
(
'
mid
'
)
<
self
.
uuid
and
not
self
.
participant
:
print
(
'
2: mich vorschlagen
'
)
new_election_message
=
{
"
mid
"
:
self
.
uuid
,
"
isLeader
"
:
False
...
...
@@ -230,11 +242,13 @@ class Server():
self
.
participant
=
True
# send received election message to left neighbour
ring_socket
.
sendto
(
json
.
dumps
(
new_election_message
),
neighbour
)
elif
election_message
[
'
mid
'
]
>
self
.
uuid
:
elif
election_message
.
get
(
'
mid
'
)
>
self
.
uuid
:
# send received election message to left neighbour
print
(
'
3: Jemand anderes vorschlagen
'
)
self
.
participant
=
True
ring_socket
.
sendto
(
json
.
dumps
(
election_message
),
neighbour
)
elif
election_message
[
'
mid
'
]
==
self
.
uuid
:
elif
election_message
.
get
(
'
mid
'
)
==
self
.
uuid
:
print
(
'
4: Ich wurde als Leader definiert
'
)
self
.
leader_uid
=
self
.
uuid
self
.
isLeader
=
True
new_election_message
=
{
...
...
@@ -243,7 +257,7 @@ class Server():
}
# send new election message to left neighbour
self
.
participant
=
False
ring_socket
.
sendto
(
json
.
dumps
(
new_election_message
),
neighbour
)
ring_socket
.
sendto
(
json
.
dumps
(
new_election_message
)
.
encode
(
'
utf-8
'
)
,
neighbour
_address
)
# starting all simultaneously working procedures
...
...
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