Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Distributed-Systems
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Katharina Willig
Distributed-Systems
Commits
0cc20933
Commit
0cc20933
authored
8 months ago
by
Katharina
Browse files
Options
Downloads
Patches
Plain Diff
leader
parent
d6f49be7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kclient.py
+2
-2
2 additions, 2 deletions
kclient.py
server.py
+8
-7
8 additions, 7 deletions
server.py
with
10 additions
and
9 deletions
kclient.py
+
2
−
2
View file @
0cc20933
...
...
@@ -36,8 +36,8 @@ def listen():
# continue
#ignores broadcast messages with own ip #################please enable it after testing!!!!!!!!!!!!!!!!!!!S
#
if address[0]==MY_IP:
#
continue
if
address
[
0
]
==
MY_IP
:
continue
#####identifyLEADER############
# Erkennen von LEADER-Nachrichten
...
...
This diff is collapsed.
Click to expand it.
server.py
+
8
−
7
View file @
0cc20933
...
...
@@ -28,6 +28,7 @@ def broadcast(message):
# Listener function
def
listen
(
queue
,
shared_data
):
"""
Receives messages and updates shared state.
"""
print
(
f
"
Listener from
{
shared_data
[
'
server_id
'
]
}
is listening on
{
server_socket
}
"
)
global
active_servers
while
True
:
try
:
...
...
@@ -75,7 +76,7 @@ def start_election(queue, shared_data):
print
(
"
Starting election...
"
)
broadcast
(
f
"
START_ELECTION:
{
shared_data
[
'
server_id
'
]
}
"
)
timeout
=
time
.
time
()
+
20
# 20-second timeout
timeout
=
time
.
time
()
+
20
# 20-second timeout
, waiting for other servers
highest_id
=
shared_data
[
'
server_id
'
]
while
time
.
time
()
<
timeout
:
...
...
@@ -100,12 +101,12 @@ def start_election(queue, shared_data):
except
multiprocessing
.
queues
.
Empty
:
continue
if
highest_id
==
shared_data
[
'
server_id
'
]:
shared_data
[
'
current_leader
'
]
=
shared_data
[
'
server_id
'
]
broadcast
(
f
"
LEADER:
{
shared_data
[
'
current_leader
'
]
}
"
)
print
(
f
"
I am the leader:
{
shared_data
[
'
current_leader
'
]
}
"
)
else
:
print
(
f
"
Leader election finished, leader is
{
highest_id
}
"
)
if
highest_id
==
shared_data
[
'
server_id
'
]:
shared_data
[
'
current_leader
'
]
=
shared_data
[
'
server_id
'
]
broadcast
(
f
"
LEADER:
{
shared_data
[
'
current_leader
'
]
}
"
)
print
(
f
"
I am the leader:
{
shared_data
[
'
current_leader
'
]
}
"
)
else
:
print
(
f
"
Leader election finished, leader is
{
highest_id
}
"
)
# Heartbeat function
...
...
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