Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
neo
Commits
d85b471d
Commit
d85b471d
authored
Jan 04, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: refactor code to connect to master
parent
1e0c5efc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
26 deletions
+23
-26
neo/client/app.py
neo/client/app.py
+20
-26
neo/client/handlers/master.py
neo/client/handlers/master.py
+3
-0
No files found.
neo/client/app.py
View file @
d85b471d
...
...
@@ -254,20 +254,19 @@ class Application(object):
Lookup for the current primary master node
"""
logging
.
debug
(
'connecting to primary master...'
)
ready
=
False
nm
=
self
.
nm
while
not
ready
:
index
=
0
ask
=
self
.
_ask
handler
=
self
.
primary_bootstrap_handler
while
1
:
# Get network connection to primary master
index
=
0
connected
=
False
while
not
connected
:
while
1
:
if
self
.
primary_master_node
is
not
None
:
# If I know a primary master node, pinpoint it.
self
.
trying_master_node
=
self
.
primary_master_node
self
.
primary_master_node
=
None
else
:
# Otherwise, check one by one.
master_list
=
nm
.
getMasterList
()
master_list
=
self
.
nm
.
getMasterList
()
try
:
self
.
trying_master_node
=
master_list
[
index
]
except
IndexError
:
...
...
@@ -288,37 +287,32 @@ class Application(object):
self
.
trying_master_node
)
continue
try
:
self
.
_
ask
(
conn
,
Packets
.
RequestIdentification
(
ask
(
conn
,
Packets
.
RequestIdentification
(
NodeTypes
.
CLIENT
,
self
.
uuid
,
None
,
self
.
name
),
handler
=
self
.
primary_bootstrap_
handler
)
handler
=
handler
)
except
ConnectionClosed
:
continue
# If we reached the primary master node, mark as connected
connected
=
self
.
primary_master_node
is
not
None
and
\
self
.
primary_master_node
is
self
.
trying_master_node
if
self
.
primary_master_node
is
not
None
and
\
self
.
primary_master_node
is
self
.
trying_master_node
:
break
logging
.
info
(
'Connected to %s'
,
self
.
primary_master_node
)
try
:
ready
=
self
.
identifyToPrimaryNode
(
conn
)
# Request identification and required informations to be
# operational. Might raise ConnectionClosed so that the new
# primary can be looked-up again.
logging
.
info
(
'Initializing from master'
)
ask
(
conn
,
Packets
.
AskNodeInformation
(),
handler
=
handler
)
ask
(
conn
,
Packets
.
AskPartitionTable
(),
handler
=
handler
)
ask
(
conn
,
Packets
.
AskLastTransaction
(),
handler
=
handler
)
if
self
.
pt
.
operational
():
break
except
ConnectionClosed
:
logging
.
error
(
'Connection to %s lost'
,
self
.
trying_master_node
)
self
.
primary_master_node
=
None
logging
.
info
(
"Connected and ready"
)
return
conn
def
identifyToPrimaryNode
(
self
,
conn
):
"""
Request identification and required informations to be operational.
Might raise ConnectionClosed so that the new primary can be
looked-up again.
"""
logging
.
info
(
'Initializing from master'
)
ask
=
self
.
_ask
handler
=
self
.
primary_bootstrap_handler
ask
(
conn
,
Packets
.
AskNodeInformation
(),
handler
=
handler
)
ask
(
conn
,
Packets
.
AskPartitionTable
(),
handler
=
handler
)
self
.
lastTransaction
()
return
self
.
pt
.
operational
()
def
registerDB
(
self
,
db
,
limit
):
self
.
_db
=
db
...
...
neo/client/handlers/master.py
View file @
d85b471d
...
...
@@ -89,6 +89,9 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
def
answerNodeInformation
(
self
,
conn
):
pass
def
answerLastTransaction
(
self
,
conn
,
ltid
):
pass
class
PrimaryNotificationsHandler
(
BaseHandler
):
""" Handler that process the notifications from the primary master """
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment