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
d5e72d01
Commit
d5e72d01
authored
7 months ago
by
Katharina
Browse files
Options
Downloads
Patches
Plain Diff
fix leader pls
parent
7d3e0f1b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.py
+6
-7
6 additions, 7 deletions
server.py
with
6 additions
and
7 deletions
server.py
+
6
−
7
View file @
d5e72d01
...
@@ -82,26 +82,25 @@ def start_election(queue, shared_data):
...
@@ -82,26 +82,25 @@ def start_election(queue, shared_data):
while
time
.
time
()
<
timeout
:
while
time
.
time
()
<
timeout
:
try
:
try
:
message
=
queue
.
get
(
timeout
=
1
)
#waits 1 sec for a message
message
=
queue
.
get
(
timeout
=
1
)
#waits 1 sec for a message
if
"
START_ELECTION
"
in
message
:
if
shared_data
[
'
server_id
'
]
==
sender_uuid
:
continue
elif
"
START_ELECTION
"
in
message
:
sender_uuid
=
message
.
split
(
"
:
"
)[
1
]
sender_uuid
=
message
.
split
(
"
:
"
)[
1
]
active_servers
[
sender_uuid
]
=
time
.
time
()
active_servers
[
sender_uuid
]
=
time
.
time
()
print
(
f
"
Received UUID for election:
{
sender_uuid
}
"
)
print
(
f
"
Received UUID for election:
{
sender_uuid
}
"
)
################dumblogic###onlyworkswith2servers################################
################dumblogic###onlyworkswith2servers################################
if
shared_data
[
'
server_id
'
]
==
sender_uuid
:
if
sender_uuid
>
highest_id
:
continue
else
:
if
sender_uuid
>
highest_id
:
highest_id
=
sender_uuid
highest_id
=
sender_uuid
print
(
f
"
Received higher ID
{
sender_uuid
}
, forwarding...
"
)
print
(
f
"
Received higher ID
{
sender_uuid
}
, forwarding...
"
)
broadcast
(
f
"
START_ELECTION:
{
sender_uuid
}
"
)
broadcast
(
f
"
START_ELECTION:
{
sender_uuid
}
"
)
elif
sender_uuid
==
highest_id
:
elif
sender_uuid
==
highest_id
:
shared_data
[
'
current_leader
'
]
=
sender_uuid
shared_data
[
'
current_leader
'
]
=
sender_uuid
print
(
f
"
(sender) Leader elected:
{
shared_data
[
'
current_leader
'
]
}
"
)
print
(
f
"
(sender) Leader elected:
{
shared_data
[
'
current_leader
'
]
}
"
)
broadcast
(
f
"
LEADER:
{
shared_data
[
'
current_leader
'
]
}
"
)
broadcast
(
f
"
LEADER:
{
shared_data
[
'
current_leader
'
]
}
"
)
else
:
else
:
shared_data
[
'
current_leader
'
]
=
shared_data
[
'
server_id
'
]
shared_data
[
'
current_leader
'
]
=
shared_data
[
'
server_id
'
]
print
(
f
"
(official, its me) Leader elected:
{
shared_data
[
'
current_leader
'
]
}
"
)
print
(
f
"
(official, its me) Leader elected:
{
shared_data
[
'
current_leader
'
]
}
"
)
broadcast
(
f
"
LEADER:
{
shared_data
[
'
current_leader
'
]
}
"
)
broadcast
(
f
"
LEADER:
{
shared_data
[
'
current_leader
'
]
}
"
)
...
...
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