Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs425_distributed_system_mp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
hangxie2
cs425_distributed_system_mp
Commits
6502f180
Commit
6502f180
authored
3 years ago
by
Hang
Browse files
Options
Downloads
Patches
Plain Diff
fast push
parent
adf4c8d4
No related branches found
No related tags found
1 merge request
!10
MP3 Log Version Ready
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sample_test/src/constants.py
+1
-0
1 addition, 0 deletions
sample_test/src/constants.py
sample_test/src/server.py
+11
-6
11 additions, 6 deletions
sample_test/src/server.py
with
12 additions
and
6 deletions
sample_test/src/constants.py
+
1
−
0
View file @
6502f180
SERVER_IDENTIFIER
=
0
SERVER_IDENTIFIER
=
0
SERVER_ADDRESS
=
1
SERVER_ADDRESS
=
1
SERVER_PORT
=
2
SERVER_PORT
=
2
ACCEPTING_PEER_PORT
=
3
RECONNECT_TIME
=
1
# 1s
RECONNECT_TIME
=
1
# 1s
...
...
This diff is collapsed.
Click to expand it.
sample_test/src/server.py
+
11
−
6
View file @
6502f180
...
@@ -4,7 +4,8 @@ import sys
...
@@ -4,7 +4,8 @@ import sys
import
time
import
time
import
traceback
import
traceback
from
utils
import
gprint
,
rprint
,
pprint
from
utils
import
gprint
,
rprint
,
pprint
from
constants
import
SERVER_IDENTIFIER
,
SERVER_ADDRESS
,
SERVER_PORT
,
RECONNECT_TIME
,
MSG_LENGTH
,
ENCODING_FORMAT
from
constants
import
SERVER_IDENTIFIER
,
SERVER_ADDRESS
,
SERVER_PORT
,
RECONNECT_TIME
,
MSG_LENGTH
,
ENCODING_FORMAT
,
\
ACCEPTING_PEER_PORT
import
socket
import
socket
import
threading
import
threading
from
classDef
import
WriteEntry
,
Account
from
classDef
import
WriteEntry
,
Account
...
@@ -16,6 +17,7 @@ CURRENT_SERVER_ID = ''
...
@@ -16,6 +17,7 @@ CURRENT_SERVER_ID = ''
CURRENT_SERVER_IP
=
socket
.
gethostbyname
(
socket
.
gethostname
())
CURRENT_SERVER_IP
=
socket
.
gethostbyname
(
socket
.
gethostname
())
SERVERS
=
{}
SERVERS
=
{}
CURRENT_SERVER_PORT
=
-
1
CURRENT_SERVER_PORT
=
-
1
BASE_PORT_NUMBER
=
12000
# !!! TW 要用于顺延候选的时候要进行排序,才行!!! 直接用sorted 对key 进行排序就好
# !!! TW 要用于顺延候选的时候要进行排序,才行!!! 直接用sorted 对key 进行排序就好
# 关于write_commited_timestamp 变成list 的改变,虽然我感觉不用改成list, 因为ta 的例子错了,但是吧改了之后全都加了sort, 效果应该差不多把
# 关于write_commited_timestamp 变成list 的改变,虽然我感觉不用改成list, 因为ta 的例子错了,但是吧改了之后全都加了sort, 效果应该差不多把
accounts_map
=
dict
()
accounts_map
=
dict
()
...
@@ -410,6 +412,7 @@ def abort(self_node: SelfNode, timestamp: str):
...
@@ -410,6 +412,7 @@ def abort(self_node: SelfNode, timestamp: str):
# 链接部分
# 链接部分
def
parse_config
(
config_path
:
str
)
->
dict
:
def
parse_config
(
config_path
:
str
)
->
dict
:
servers
=
{}
servers
=
{}
designated_port_number
=
BASE_PORT_NUMBER
with
open
(
config_path
,
'
r
'
)
as
file
:
with
open
(
config_path
,
'
r
'
)
as
file
:
for
line
in
file
:
for
line
in
file
:
server_info
=
line
.
split
(
"
"
)
server_info
=
line
.
split
(
"
"
)
...
@@ -417,8 +420,10 @@ def parse_config(config_path: str) -> dict:
...
@@ -417,8 +420,10 @@ def parse_config(config_path: str) -> dict:
servers
[
server_info
[
SERVER_IDENTIFIER
]]
=
{
servers
[
server_info
[
SERVER_IDENTIFIER
]]
=
{
SERVER_IDENTIFIER
:
server_info
[
SERVER_IDENTIFIER
],
SERVER_IDENTIFIER
:
server_info
[
SERVER_IDENTIFIER
],
SERVER_ADDRESS
:
server_info
[
SERVER_ADDRESS
],
SERVER_ADDRESS
:
server_info
[
SERVER_ADDRESS
],
SERVER_PORT
:
int
(
server_info
[
SERVER_PORT
].
rstrip
())
SERVER_PORT
:
int
(
server_info
[
SERVER_PORT
].
rstrip
()),
ACCEPTING_PEER_PORT
:
designated_port_number
}
}
designated_port_number
+=
100
return
servers
return
servers
...
@@ -454,12 +459,12 @@ def connect_with_all_servers(servers: dict, current_server_id: str, return_value
...
@@ -454,12 +459,12 @@ def connect_with_all_servers(servers: dict, current_server_id: str, return_value
try
:
try
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
host_ip_address
=
SERVER_ID_TO_IP_MAPPING
[
server
[
SERVER_IDENTIFIER
]]
host_ip_address
=
SERVER_ID_TO_IP_MAPPING
[
server
[
SERVER_IDENTIFIER
]]
server
[
SERVER_PORT
]
=
SERVERS
[
CURRENT_SERVER_ID
][
SERVER_PORT
]
+
1
# todo: to be deleted
#
server[SERVER_PORT] = SERVERS[CURRENT_SERVER_ID][SERVER_PORT]+1 # todo: to be deleted
address
=
(
host_ip_address
,
server
[
SERV
ER_PORT
])
address
=
(
host_ip_address
,
server
[
server_id
][
ACCEPTING_PE
ER_PORT
])
s
.
connect
(
address
)
s
.
connect
(
address
)
connect_info
[
server_id
]
=
s
connect_info
[
server_id
]
=
s
gprint
(
f
"
[Connect] -
"
gprint
(
f
"
[Connect] -
"
f
"
Connecting to
{
server
[
SERVER_IDENTIFIER
]
}
:
{
host_ip_address
}
:
{
server
[
SERV
ER_PORT
]
}
success!
"
)
f
"
Connecting to
{
server
[
SERVER_IDENTIFIER
]
}
:
{
host_ip_address
}
:
{
server
[
server_id
][
ACCEPTING_PE
ER_PORT
]
}
success!
"
)
except
Exception
:
except
Exception
:
rprint
(
f
"
[Connect] - Connection to
"
rprint
(
f
"
[Connect] - Connection to
"
f
"
{
server
[
SERVER_IDENTIFIER
]
}
failed.
"
f
"
{
server
[
SERVER_IDENTIFIER
]
}
failed.
"
...
@@ -719,7 +724,7 @@ def accepting_clients(SELF_NODE):
...
@@ -719,7 +724,7 @@ def accepting_clients(SELF_NODE):
def
accepting_peer_servers
(
SELF_NODE
):
def
accepting_peer_servers
(
SELF_NODE
):
try
:
try
:
server
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
server
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
server
.
bind
((
CURRENT_SERVER_IP
,
SERVERS
[
CURRENT_SERVER_ID
][
SERV
ER_PORT
]
+
1
))
server
.
bind
((
CURRENT_SERVER_IP
,
SERVERS
[
CURRENT_SERVER_ID
][
ACCEPTING_PE
ER_PORT
]))
server
.
listen
()
server
.
listen
()
# print(f"[LISTENING] Server is listening on {ADDR}") # DEBUG
# print(f"[LISTENING] Server is listening on {ADDR}") # DEBUG
while
True
:
while
True
:
...
...
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