Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
abe5efff
Commit
abe5efff
authored
Jan 22, 2025
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Py3 division/except/print/raise-without-traceback
parent
2ee3594a
Changes
33
Hide whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
110 additions
and
108 deletions
+110
-108
neo/admin/app.py
neo/admin/app.py
+1
-1
neo/client/app.py
neo/client/app.py
+1
-1
neo/client/handlers/master.py
neo/client/handlers/master.py
+1
-1
neo/debug.py
neo/debug.py
+4
-3
neo/lib/bootstrap.py
neo/lib/bootstrap.py
+1
-1
neo/lib/connection.py
neo/lib/connection.py
+2
-2
neo/lib/connector.py
neo/lib/connector.py
+9
-9
neo/lib/debug.py
neo/lib/debug.py
+2
-2
neo/lib/event.py
neo/lib/event.py
+5
-5
neo/lib/handler.py
neo/lib/handler.py
+8
-8
neo/lib/node.py
neo/lib/node.py
+1
-1
neo/lib/threaded_app.py
neo/lib/threaded_app.py
+1
-4
neo/lib/util.py
neo/lib/util.py
+2
-2
neo/master/app.py
neo/master/app.py
+6
-6
neo/master/backup_app.py
neo/master/backup_app.py
+2
-2
neo/master/handlers/administration.py
neo/master/handlers/administration.py
+2
-2
neo/master/handlers/master.py
neo/master/handlers/master.py
+2
-2
neo/master/handlers/storage.py
neo/master/handlers/storage.py
+1
-1
neo/master/pt.py
neo/master/pt.py
+0
-2
neo/neoctl/app.py
neo/neoctl/app.py
+1
-1
neo/scripts/neoctl.py
neo/scripts/neoctl.py
+2
-1
neo/scripts/neolog.py
neo/scripts/neolog.py
+8
-7
neo/scripts/runner.py
neo/scripts/runner.py
+6
-5
neo/storage/app.py
neo/storage/app.py
+4
-5
neo/storage/database/manager.py
neo/storage/database/manager.py
+2
-1
neo/storage/database/mysql.py
neo/storage/database/mysql.py
+1
-1
neo/storage/database/sqlite.py
neo/storage/database/sqlite.py
+2
-2
neo/storage/handlers/client.py
neo/storage/handlers/client.py
+5
-5
neo/storage/transactions.py
neo/storage/transactions.py
+2
-2
neo/tests/__init__.py
neo/tests/__init__.py
+9
-8
neo/tests/functional/__init__.py
neo/tests/functional/__init__.py
+13
-12
neo/tests/stat_zodb.py
neo/tests/stat_zodb.py
+2
-1
neo/tests/threaded/test.py
neo/tests/threaded/test.py
+2
-2
No files found.
neo/admin/app.py
View file @
abe5efff
...
...
@@ -210,7 +210,7 @@ class Application(BaseApplication, Monitor):
def
_run
(
self
):
"""Make sure that the status is sane and start a loop."""
if
len
(
self
.
name
)
==
0
:
raise
RuntimeError
,
'cluster name must be non-empty'
raise
RuntimeError
(
'cluster name must be non-empty'
)
# Make a listening port.
handler
=
AdminEventHandler
(
self
)
...
...
neo/client/app.py
View file @
abe5efff
...
...
@@ -364,7 +364,7 @@ class Application(ThreadedApplication):
return
askStorage
(
conn
,
packet
)
except
ConnectionClosed
:
pass
except
NEOStorageReadRetry
,
e
:
except
NEOStorageReadRetry
as
e
:
if
e
.
args
[
0
]:
continue
failed
+=
1
...
...
neo/client/handlers/master.py
View file @
abe5efff
...
...
@@ -36,7 +36,7 @@ class PrimaryNotificationsHandler(MTEventHandler):
def
notPrimaryMaster
(
self
,
*
args
):
try
:
super
(
PrimaryNotificationsHandler
,
self
).
notPrimaryMaster
(
*
args
)
except
PrimaryElected
,
e
:
except
PrimaryElected
as
e
:
self
.
app
.
primary_master_node
,
=
e
.
args
def
answerLastTransaction
(
self
,
conn
,
ltid
):
...
...
neo/debug.py
View file @
abe5efff
...
...
@@ -9,6 +9,7 @@ The prompt is accessible through network in case that the process is daemonized:
<neo.master.app.Application object at 0x1fc9750>
"""
from
__future__
import
print_function
import
sys
def
app_set
():
...
...
@@ -69,7 +70,7 @@ if IF == 'pdb':
s
.
settimeout
(
60
)
s
.
bind
((
'127.0.0.1'
,
0
))
s
.
listen
(
0
)
print
'Listening to %u'
%
s
.
getsockname
()[
1
]
print
(
'Listening to'
,
s
.
getsockname
()[
1
])
sys
.
stdout
.
flush
()
# BBB: On Python 3, print() takes a 'flush' arg.
_socket
=
PdbSocket
(
s
.
accept
()[
0
])
finally
:
...
...
@@ -101,14 +102,14 @@ if IF == 'pdb':
orig
=
getattr
(
orig
,
'__func__'
,
orig
)
self
.
append
((
o
,
name
,
orig
))
setattr
(
o
,
name
,
self
.
_wrap
(
orig
))
print
'BP set on'
,
orig
print
(
'BP set on'
,
orig
)
sys
.
stdout
.
flush
()
self
.
_hold
=
weakref
.
ref
(
pdb
,
self
.
_revert
)
def
_revert
(
self
,
*
_
):
for
x
in
self
:
setattr
(
*
x
)
print
'BP removed on'
,
x
[
2
]
print
(
'BP removed on'
,
x
[
2
])
sys
.
stdout
.
flush
()
del
self
[:]
...
...
neo/lib/bootstrap.py
View file @
abe5efff
...
...
@@ -71,7 +71,7 @@ class BootstrapManager(EventHandler):
if
self
.
current
.
isIdentified
():
return
self
.
current
,
self
.
current
.
getConnection
()
poll
(
1
)
except
PrimaryElected
,
e
:
except
PrimaryElected
as
e
:
if
self
.
current
:
self
.
current
.
getConnection
().
close
()
self
.
current
,
=
e
.
args
...
...
neo/lib/connection.py
View file @
abe5efff
...
...
@@ -497,7 +497,7 @@ class Connection(BaseConnection):
self
.
_queue
.
append
(
packet
)
except
ConnectorException
:
self
.
_closure
()
except
PacketMalformedError
,
e
:
except
PacketMalformedError
as
e
:
logging
.
error
(
'malformed packet from %r: %s'
,
self
,
e
)
self
.
_closure
()
return
empty_queue
and
not
not
self
.
_queue
...
...
@@ -651,7 +651,7 @@ class ClientConnection(Connection):
def
_connect
(
self
):
try
:
connected
=
self
.
connector
.
makeClientConnection
()
except
ConnectorDelayedConnection
,
c
:
except
ConnectorDelayedConnection
as
c
:
connect_limit
,
=
c
.
args
self
.
getTimeout
=
lambda
:
connect_limit
self
.
onTimeout
=
self
.
_delayedConnect
...
...
neo/lib/connector.py
View file @
abe5efff
...
...
@@ -114,7 +114,7 @@ class SocketConnector(object):
self
.
is_server
=
self
.
is_closed
=
False
try
:
self
.
_connect
(
addr
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
if
e
.
errno
==
errno
.
EINPROGRESS
:
return
False
self
.
_error
(
'connect'
,
e
)
...
...
@@ -127,7 +127,7 @@ class SocketConnector(object):
self
.
socket
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
self
.
_bind
(
self
.
addr
)
self
.
socket
.
listen
(
self
.
SOMAXCONN
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
self
.
is_closed
=
True
self
.
socket
.
close
()
self
.
_error
(
'listen'
,
e
)
...
...
@@ -161,13 +161,13 @@ class SocketConnector(object):
s
,
addr
=
self
.
socket
.
accept
()
s
=
self
.
__class__
(
addr
,
s
)
return
s
,
s
.
addr
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
self
.
_error
(
'accept'
,
e
)
def
receive
(
self
,
read_buf
):
try
:
data
=
self
.
socket
.
recv
(
65536
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
self
.
_error
(
'recv'
,
e
)
if
data
:
read_buf
.
feed
(
data
)
...
...
@@ -184,7 +184,7 @@ class SocketConnector(object):
if
msg
:
try
:
n
=
self
.
socket
.
send
(
msg
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
self
.
_error
(
'send'
,
e
)
# Do nothing special if n == 0:
# - it never happens for simple sockets;
...
...
@@ -210,7 +210,7 @@ class SocketConnector(object):
pass
try
:
self
.
socket
.
shutdown
(
socket
.
SHUT_RDWR
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
if
e
.
errno
!=
errno
.
ENOTCONN
:
raise
return
self
.
socket
.
close
...
...
@@ -283,7 +283,7 @@ class _SSL:
read_buf
.
feed
(
data
)
except
ssl
.
SSLWantReadError
:
pass
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
self
.
_error
(
'recv'
,
e
)
@
overlay_connector_class
...
...
@@ -320,7 +320,7 @@ class _SSLHandshake(_SSL):
return
read_buf
is
None
except
ssl
.
SSLWantWriteError
:
return
read_buf
is
not
None
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
# OpenSSL 1.1 may raise socket.error(0)
# where previous versions raised SSLEOFError.
self
.
_error
(
'send'
if
read_buf
is
None
else
'recv'
,
...
...
@@ -346,7 +346,7 @@ class _SSLHandshake(_SSL):
def
receive
(
self
,
read_buf
):
try
:
content_type
=
self
.
socket
.
_sock
.
recv
(
1
,
socket
.
MSG_PEEK
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
self
.
_error
(
'recv'
,
e
)
if
content_type
==
'
\
26
'
:
# handshake
return
self
.
send
(
read_buf
)
...
...
neo/lib/debug.py
View file @
abe5efff
...
...
@@ -125,8 +125,8 @@ class PdbSocket(object):
try
:
self
.
_socket
.
recv
(
0
)
return
True
except
socket
.
error
,
(
err
,
_
)
:
if
e
rr
!=
errno
.
EAGAIN
:
except
socket
.
error
as
e
:
if
e
.
errno
!=
errno
.
EAGAIN
:
raise
self
.
_socket
.
setblocking
(
1
)
return
False
neo/lib/event.py
View file @
abe5efff
...
...
@@ -107,7 +107,7 @@ class EpollEventManager(object):
try
:
return
[
x
for
x
in
self
.
connection_dict
.
itervalues
()
if
not
x
.
isAborted
()]
except
RuntimeError
,
e
:
except
RuntimeError
as
e
:
if
str
(
e
)
!=
dictionary_changed_size_during_iteration
:
raise
logging
.
info
(
"%r"
,
e
)
...
...
@@ -161,7 +161,7 @@ class EpollEventManager(object):
self
.
epoll
.
unregister
(
fd
)
except
KeyError
:
pass
except
IOError
,
e
:
except
IOError
as
e
:
if
e
.
errno
!=
ENOENT
:
raise
else
:
...
...
@@ -214,7 +214,7 @@ class EpollEventManager(object):
timeout
=
t
timeout_object
=
conn
break
except
RuntimeError
,
e
:
except
RuntimeError
as
e
:
if
str
(
e
)
!=
dictionary_changed_size_during_iteration
:
raise
logging
.
info
(
"%r"
,
e
)
...
...
@@ -239,7 +239,7 @@ class EpollEventManager(object):
self
.
_closeAcquire
()
try
:
event_list
=
poll
(
blocking
)
except
IOError
,
exc
:
except
IOError
as
exc
:
if
exc
.
errno
in
(
0
,
EAGAIN
):
logging
.
info
(
'epoll.poll triggered undocumented error %r'
,
exc
.
errno
)
...
...
@@ -306,7 +306,7 @@ class EpollEventManager(object):
self
.
_trigger_list
+=
actions
try
:
os
.
write
(
self
.
_wakeup_wfd
,
'
\
0
'
)
except
OSError
,
e
:
except
OSError
as
e
:
# Ignore if wakeup fd is triggered many times in a row.
if
e
.
errno
!=
EAGAIN
:
raise
...
...
neo/lib/handler.py
View file @
abe5efff
...
...
@@ -72,32 +72,32 @@ class EventHandler(object):
raise
UnexpectedPacketError
(
'no handler found'
)
args
=
packet
.
_args
method
(
conn
,
*
args
,
**
kw
)
except
DelayEvent
,
e
:
except
DelayEvent
as
e
:
assert
not
kw
,
kw
self
.
getEventQueue
().
queueEvent
(
method
,
conn
,
args
,
*
e
.
args
)
except
UnexpectedPacketError
,
e
:
except
UnexpectedPacketError
as
e
:
if
not
conn
.
isClosed
():
self
.
__unexpectedPacket
(
conn
,
packet
,
*
e
.
args
)
except
NotReadyError
,
message
:
except
NotReadyError
as
message
:
if
not
conn
.
isClosed
():
if
not
message
.
args
:
message
=
'Retry Later'
message
=
str
(
message
)
conn
.
answer
(
Errors
.
NotReady
(
message
))
conn
.
abort
()
except
ProtocolError
,
message
:
except
ProtocolError
as
message
:
if
not
conn
.
isClosed
():
message
=
str
(
message
)
conn
.
answer
(
Errors
.
ProtocolError
(
message
))
conn
.
abort
()
except
BackendNotImplemented
,
message
:
m
=
message
[
0
]
except
BackendNotImplemented
as
message
:
m
=
message
.
args
[
0
]
conn
.
answer
(
Errors
.
BackendNotImplemented
(
"%s.%s does not implement %s"
%
(
m
.
im_class
.
__module__
,
m
.
im_class
.
__name__
,
m
.
__name__
)))
except
NonReadableCell
,
e
:
except
NonReadableCell
as
e
:
conn
.
answer
(
Errors
.
NonReadableCell
())
except
AnswerDenied
,
e
:
except
AnswerDenied
as
e
:
conn
.
answer
(
Errors
.
Denied
(
str
(
e
)))
except
AssertionError
:
e
=
sys
.
exc_info
()
...
...
neo/lib/node.py
View file @
abe5efff
...
...
@@ -210,7 +210,7 @@ class MasterDB(object):
try
:
with
open
(
path
)
as
db
:
self
.
_set
=
set
(
map
(
tuple
,
json
.
load
(
db
)))
except
IOError
,
e
:
except
IOError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
self
.
_set
=
set
()
...
...
neo/lib/threaded_app.py
View file @
abe5efff
...
...
@@ -113,15 +113,12 @@ class ThreadedApplication(BaseApplication):
# Guess the handler to use based on the type of node on the
# connection
node
=
self
.
nm
.
getByAddress
(
conn
.
getAddress
())
if
node
is
None
:
raise
ValueError
,
'Expecting an answer from a node '
\
'which type is not known... Is this right ?'
if
node
.
isStorage
():
handler
=
self
.
storage_handler
elif
node
.
isMaster
():
handler
=
self
.
primary_handler
else
:
raise
ValueError
,
'Unknown node type: %r'
%
(
node
.
__class__
,
)
raise
ValueError
(
node
)
with
conn
.
lock
:
handler
.
dispatch
(
conn
,
packet
,
kw
)
...
...
neo/lib/util.py
View file @
abe5efff
...
...
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
division
import
os
,
socket
from
binascii
import
a2b_hex
,
b2a_hex
from
datetime
import
timedelta
,
datetime
...
...
@@ -39,7 +39,7 @@ nextafter()
TID_LOW_OVERFLOW
=
2
**
32
TID_LOW_MAX
=
TID_LOW_OVERFLOW
-
1
SECOND_FROM_UINT32
=
60
.
/
TID_LOW_OVERFLOW
SECOND_FROM_UINT32
=
60
/
TID_LOW_OVERFLOW
MICRO_FROM_UINT32
=
1e6
/
TID_LOW_OVERFLOW
TID_CHUNK_RULES
=
(
(
-
1900
,
0
),
...
...
neo/master/app.py
View file @
abe5efff
...
...
@@ -179,7 +179,7 @@ class Application(BaseApplication):
try
:
with
self
.
em
.
wakeup_fd
():
self
.
_run
()
except
BaseException
,
e
:
except
BaseException
as
e
:
if
not
isinstance
(
e
,
SystemExit
)
or
e
.
code
:
logging
.
exception
(
'Pre-mortem data:'
)
self
.
log
()
...
...
@@ -269,7 +269,7 @@ class Application(BaseApplication):
try
:
while
True
:
poll
(
1
)
except
StateChangedException
,
e
:
except
StateChangedException
as
e
:
if
e
.
args
[
0
]
!=
ClusterStates
.
STARTING_BACKUP
:
raise
self
.
backup_tid
=
tid
=
self
.
getLastTransaction
()
...
...
@@ -325,7 +325,7 @@ class Application(BaseApplication):
sys
.
exit
(
self
.
no_upstream_msg
)
truncate
=
Packets
.
Truncate
(
self
.
backup_app
.
provideService
())
except
StoppedOperation
,
e
:
except
StoppedOperation
as
e
:
logging
.
critical
(
'No longer operational'
)
truncate
=
Packets
.
Truncate
(
*
e
.
args
)
if
e
.
args
else
None
# Automatic restart except if we truncate or retry to.
...
...
@@ -349,10 +349,10 @@ class Application(BaseApplication):
node
.
setPending
()
node_list
.
append
(
node
)
self
.
broadcastNodesInformation
(
node_list
)
except
StateChangedException
,
e
:
except
StateChangedException
as
e
:
assert
e
.
args
[
0
]
==
ClusterStates
.
STOPPING
self
.
shutdown
()
except
PrimaryElected
,
e
:
except
PrimaryElected
as
e
:
self
.
primary_master
,
=
e
.
args
def
playSecondaryRole
(
self
):
...
...
@@ -429,7 +429,7 @@ class Application(BaseApplication):
# All known master nodes are either down or secondary.
# Let's play the primary role again.
break
except
PrimaryElected
,
e
:
except
PrimaryElected
as
e
:
node
=
self
.
primary_master
self
.
primary_master
,
=
e
.
args
assert
node
is
not
self
.
primary_master
,
node
...
...
neo/master/backup_app.py
View file @
abe5efff
...
...
@@ -136,7 +136,7 @@ class BackupApplication(object):
self
.
debug_tid_count
=
0
while
True
:
poll
(
1
)
except
PrimaryFailure
,
msg
:
except
PrimaryFailure
as
msg
:
logging
.
error
(
'upstream master is down: %s'
,
msg
)
finally
:
app
.
backup_tid
=
pt
.
getBackupTid
()
...
...
@@ -150,7 +150,7 @@ class BackupApplication(object):
pass
for
node
in
app
.
nm
.
getClientList
(
True
):
node
.
getConnection
().
close
()
except
StateChangedException
,
e
:
except
StateChangedException
as
e
:
if
e
.
args
[
0
]
!=
ClusterStates
.
STOPPING_BACKUP
:
raise
app
.
changeClusterState
(
*
e
.
args
)
...
...
neo/master/handlers/administration.py
View file @
abe5efff
...
...
@@ -133,7 +133,7 @@ class AdministrationHandler(MasterHandler):
"a running node must be stopped before removal"
)
try
:
cell_list
=
app
.
pt
.
dropNodeList
([
node
],
keep
)
except
PartitionTableException
,
e
:
except
PartitionTableException
as
e
:
raise
AnswerDenied
(
str
(
e
))
node
.
setState
(
state
)
if
node
.
isConnected
():
...
...
@@ -227,7 +227,7 @@ class AdministrationHandler(MasterHandler):
pt
=
app
.
pt
try
:
changed_list
=
pt
.
tweak
(
drop_list
)
except
PartitionTableException
,
e
:
except
PartitionTableException
as
e
:
raise
AnswerDenied
(
str
(
e
))
if
not
dry_run
:
app
.
broadcastPartitionChanges
(
changed_list
)
...
...
neo/master/handlers/master.py
View file @
abe5efff
...
...
@@ -56,7 +56,7 @@ class ElectionHandler(SecondaryHandler):
def
notPrimaryMaster
(
self
,
*
args
):
try
:
super
(
ElectionHandler
,
self
).
notPrimaryMaster
(
*
args
)
except
PrimaryElected
,
e
:
except
PrimaryElected
as
e
:
# We keep playing the primary role when the peer does not
# know yet that we won election against the returned node.
if
not
e
.
args
[
0
].
isIdentified
():
...
...
@@ -80,7 +80,7 @@ class PrimaryHandler(ElectionHandler):
def
notPrimaryMaster
(
self
,
*
args
):
try
:
super
(
ElectionHandler
,
self
).
notPrimaryMaster
(
*
args
)
except
PrimaryElected
,
e
:
except
PrimaryElected
as
e
:
if
e
.
args
[
0
]
is
not
self
.
app
.
primary_master
:
raise
...
...
neo/master/handlers/storage.py
View file @
abe5efff
...
...
@@ -103,7 +103,7 @@ class StorageServiceHandler(BaseServiceHandler):
else
:
try
:
cell_list
=
self
.
app
.
pt
.
setUpToDate
(
node
,
offset
)
except
PartitionTableException
,
e
:
except
PartitionTableException
as
e
:
raise
ProtocolError
(
str
(
e
))
if
not
cell_list
:
logging
.
info
(
"ignored late notification that"
...
...
neo/master/pt.py
View file @
abe5efff
...
...
@@ -51,8 +51,6 @@ class PartitionTable(neo.lib.pt.PartitionTable):
self
.
_id
=
id
def
setNextID
(
self
):
if
self
.
_id
is
None
:
raise
RuntimeError
,
'I do not know the last Partition Table ID'
self
.
_id
+=
1
return
self
.
_id
...
...
neo/neoctl/app.py
View file @
abe5efff
...
...
@@ -353,7 +353,7 @@ class Application(object):
action
=
getattr
(
self
.
neoctl
,
current_action
)
try
:
return
action
(
args
[
level
:])
except
NotReadyException
,
message
:
except
NotReadyException
as
message
:
sys
.
exit
(
'ERROR: %s'
%
message
)
def
_usage
(
self
,
action_dict
,
level
=
0
):
...
...
neo/scripts/neoctl.py
View file @
abe5efff
...
...
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
print_function
from
neo.lib
import
logging
def
main
(
args
=
None
):
...
...
@@ -36,4 +37,4 @@ def main(args=None):
app
=
Application
(
config
[
'address'
],
ssl
=
config
.
get
(
'ssl'
))
r
=
app
.
execute
(
config
[
'cmd'
])
if
r
is
not
None
:
print
r
print
(
r
)
neo/scripts/neolog.py
View file @
abe5efff
...
...
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
print_function
import
argparse
,
bz2
,
gzip
,
errno
,
os
,
signal
,
sqlite3
,
sys
,
time
from
bisect
import
insort
from
itertools
import
chain
...
...
@@ -115,7 +116,7 @@ class Log(object):
self
.
_reload
(
p
[
0
])
except
StopIteration
:
p
=
None
except
sqlite3
.
DatabaseError
,
e
:
except
sqlite3
.
DatabaseError
as
e
:
yield
time
.
time
(),
None
,
'PACKET'
,
self
.
_exc
(
e
)
p
=
None
try
:
...
...
@@ -124,20 +125,20 @@ class Log(object):
yield
self
.
_packet
(
*
p
)
try
:
p
=
next
(
np
,
None
)
except
sqlite3
.
DatabaseError
,
e
:
except
sqlite3
.
DatabaseError
as
e
:
yield
time
.
time
(),
None
,
'PACKET'
,
self
.
_exc
(
e
)
p
=
None
self
.
_log_date
=
date
yield
(
date
,
self
.
_node
(
name
,
cluster
,
nid
),
getLevelName
(
level
),
msg
.
splitlines
())
except
sqlite3
.
DatabaseError
,
e
:
except
sqlite3
.
DatabaseError
as
e
:
yield
time
.
time
(),
None
,
'LOG'
,
self
.
_exc
(
e
)
if
p
:
yield
self
.
_packet
(
*
p
)
try
:
for
p
in
np
:
yield
self
.
_packet
(
*
p
)
except
sqlite3
.
DatabaseError
,
e
:
except
sqlite3
.
DatabaseError
as
e
:
yield
time
.
time
(),
None
,
'PACKET'
,
self
.
_exc
(
e
)
finally
:
self
.
_db
.
rollback
()
...
...
@@ -234,10 +235,10 @@ class Log(object):
if
color
and
levelname
!=
'PACKET'
:
x
=
'
\
x1b
[%sm%s%%s
\
x1b
[39;49;0m'
%
(
color_dict
[
levelname
],
prefix
)
for
msg
in
msg_list
:
print
x
%
msg
print
(
x
%
msg
)
else
:
for
msg
in
msg_list
:
print
prefix
+
msg
print
(
prefix
+
msg
)
def
_packet
(
self
,
date
,
name
,
cluster
,
nid
,
msg_id
,
code
,
peer
,
body
):
self
.
_packet_date
=
date
...
...
@@ -312,7 +313,7 @@ def emit_many(log_list, color=False):
while
event
[
0
]
<=
next_date
:
emit
(
*
event
,
color
=
color
)
event
=
next
()
except
IOError
,
e
:
except
IOError
as
e
:
if
e
.
errno
==
errno
.
EPIPE
:
sys
.
exit
(
1
)
raise
...
...
neo/scripts/runner.py
View file @
abe5efff
...
...
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
division
,
print_function
import
argparse
import
traceback
import
unittest
...
...
@@ -162,7 +163,7 @@ class NeoTestRunner(unittest.TextTestResult):
if not only:
only = '
*
'
else:
print
'
\
n
', name
print
('
\
n
', name)
for test_module in modules:
# load prefix if supplied
if isinstance(test_module, tuple):
...
...
@@ -172,9 +173,9 @@ class NeoTestRunner(unittest.TextTestResult):
continue
try:
test_module = __import__(test_module, fromlist=('
*
',), level=0)
except ImportError
,
err:
except ImportError
as
err:
self.failedImports[test_module] = err
print
"Import of %s failed : %s" % (test_module, err
)
print
("Import of %s failed: %s" % (test_module, err)
)
traceback.print_exc()
continue
suite.addTests(loader.loadTestsFromModule(test_module))
...
...
@@ -213,7 +214,7 @@ class NeoTestRunner(unittest.TextTestResult):
success = self.testsRun - unexpected_count - expected_count
add_status('
Directory
', self.temp_directory)
if self.testsRun:
add_status('
Status
', '
%
.
3
f
%%
' % (success * 100
.0
/ self.testsRun))
add_status('
Status
', '
%
.
3
f
%%
' % (success * 100 / self.testsRun))
for k, v in os.environ.iteritems():
if k.startswith('
NEO_TEST
'):
if k == '
NEO_TESTS_ADAPTER
' and v == '
MySQL
':
...
...
@@ -409,7 +410,7 @@ Environment Variables:
coverage.combine(coverage.neotestrunner)
coverage.save()
if runner.dots:
print
print
()
# build report
if (only or config.stop_on_success) and not config.mail_to:
runner._buildSummary = lambda *args: (
...
...
neo/storage/app.py
View file @
abe5efff
...
...
@@ -202,8 +202,7 @@ class Application(BaseApplication):
def
_run
(
self
):
"""Make sure that the status is sane and start a loop."""
if
len
(
self
.
name
)
==
0
:
raise
RuntimeError
,
'cluster name must be non-empty'
assert
self
.
name
# Make a listening port
handler
=
identification
.
IdentificationHandler
(
self
)
...
...
@@ -226,10 +225,10 @@ class Application(BaseApplication):
try
:
self
.
initialize
()
self
.
doOperation
()
raise
RuntimeError
,
'should not reach here'
except
StoppedOperation
,
msg
:
assert
False
except
StoppedOperation
as
msg
:
logging
.
error
(
'operation stopped: %s'
,
msg
)
except
PrimaryFailure
,
msg
:
except
PrimaryFailure
as
msg
:
logging
.
error
(
'primary master is down: %s'
,
msg
)
finally
:
self
.
operational
=
False
...
...
neo/storage/database/manager.py
View file @
abe5efff
...
...
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
division
import
os
,
errno
,
socket
,
sys
,
thread
,
threading
,
weakref
from
collections
import
defaultdict
from
contextlib
import
contextmanager
...
...
@@ -181,7 +182,7 @@ class BackgroundWorker(object):
dm2
=
copy
(
dm
)
try
:
task
(
weak_app
,
dm
,
dm2
)
except
DatabaseFailure
,
e
:
except
DatabaseFailure
as
e
:
e
.
checkTransientFailure
(
dm2
)
with
dm
:
dm
.
commit
()
...
...
neo/storage/database/mysql.py
View file @
abe5efff
...
...
@@ -210,7 +210,7 @@ class MySQLDatabaseManager(MVCCDatabaseManager):
while
True
:
try
:
return
f
()
except
DatabaseFailure
,
e
:
except
DatabaseFailure
as
e
:
e
.
checkTransientFailure
(
self
)
def
_commit
(
self
):
...
...
neo/storage/database/sqlite.py
View file @
abe5efff
...
...
@@ -39,7 +39,7 @@ def unique_constraint_message(table, *columns):
c
.
execute
(
"CREATE UNIQUE INDEX i ON "
+
x
)
try
:
c
.
executemany
(
insert
,
(
values
,
values
))
except
sqlite3
.
IntegrityError
,
e
:
except
sqlite3
.
IntegrityError
as
e
:
return
e
.
args
[
0
]
assert
False
...
...
@@ -554,7 +554,7 @@ class SQLiteDatabaseManager(DatabaseManager):
try
:
self
.
query
(
"INSERT INTO data VALUES (?,?,?,?)"
,
(
r
,
H
,
compression
,
buffer
(
data
)))
except
sqlite3
.
IntegrityError
,
e
:
except
sqlite3
.
IntegrityError
as
e
:
if
e
.
args
[
0
]
==
_dup
:
(
r
,
d
),
=
self
.
query
(
"SELECT id, value FROM data"
" WHERE hash=? AND compression=?"
,
...
...
neo/storage/handlers/client.py
View file @
abe5efff
...
...
@@ -94,7 +94,7 @@ class ClientOperationHandler(BaseHandler):
try
:
locked
=
self
.
app
.
tm
.
storeObject
(
ttid
,
serial
,
oid
,
compression
,
checksum
,
data
,
data_serial
)
except
ConflictError
,
err
:
except
ConflictError
as
err
:
# resolvable or not
locked
=
err
.
tid
except
NonReadableCell
:
...
...
@@ -132,7 +132,7 @@ class ClientOperationHandler(BaseHandler):
try
:
self
.
_askStoreObject
(
conn
,
oid
,
serial
,
compression
,
checksum
,
data
,
data_serial
,
ttid
,
None
)
except
DelayEvent
,
e
:
except
DelayEvent
as
e
:
# locked by a previous transaction, retry later
self
.
app
.
tm
.
queueEvent
(
self
.
_askStoreObject
,
conn
,
(
oid
,
serial
,
compression
,
checksum
,
data
,
data_serial
,
ttid
,
time
.
time
()),
...
...
@@ -141,7 +141,7 @@ class ClientOperationHandler(BaseHandler):
def
askRelockObject
(
self
,
conn
,
ttid
,
oid
):
try
:
self
.
app
.
tm
.
relockObject
(
ttid
,
oid
,
True
)
except
DelayEvent
,
e
:
except
DelayEvent
as
e
:
# locked by a previous transaction, retry later
self
.
app
.
tm
.
queueEvent
(
self
.
_askRelockObject
,
conn
,
(
ttid
,
oid
,
time
.
time
()),
*
e
.
args
)
...
...
@@ -219,7 +219,7 @@ class ClientOperationHandler(BaseHandler):
self
.
app
.
tm
.
register
(
conn
,
ttid
)
try
:
self
.
_askCheckCurrentSerial
(
conn
,
ttid
,
oid
,
serial
,
None
)
except
DelayEvent
,
e
:
except
DelayEvent
as
e
:
# locked by a previous transaction, retry later
self
.
app
.
tm
.
queueEvent
(
self
.
_askCheckCurrentSerial
,
conn
,
(
ttid
,
oid
,
serial
,
time
.
time
()),
*
e
.
args
)
...
...
@@ -227,7 +227,7 @@ class ClientOperationHandler(BaseHandler):
def
_askCheckCurrentSerial
(
self
,
conn
,
ttid
,
oid
,
serial
,
request_time
):
try
:
locked
=
self
.
app
.
tm
.
checkCurrentSerial
(
ttid
,
oid
,
serial
)
except
ConflictError
,
err
:
except
ConflictError
as
err
:
# resolvable or not
locked
=
err
.
tid
except
NonReadableCell
:
...
...
neo/storage/transactions.py
View file @
abe5efff
...
...
@@ -197,7 +197,7 @@ class TransactionManager(EventQueue):
locked
=
self
.
lockObject
(
ttid
,
txn
.
serial_dict
[
oid
],
oid
)
except
ConflictError
:
self
.
_unstore
(
txn
,
oid
)
except
(
DelayEvent
,
NonReadableCell
)
,
e
:
# pragma: no cover
except
(
DelayEvent
,
NonReadableCell
)
as
e
:
# pragma: no cover
raise
AssertionError
(
e
)
else
:
assert
locked
,
(
oid
,
ttid
,
txn
)
...
...
@@ -468,7 +468,7 @@ class TransactionManager(EventQueue):
# And we'll likely be delayed.
try
:
self
.
lockObject
(
ttid
,
serial
,
oid
)
except
ConflictError
,
e
:
except
ConflictError
as
e
:
# Move the data back to the client for conflict resolution,
# since the client may not have it anymore.
return
serial
,
e
.
tid
,
self
.
_unstore
(
transaction
,
oid
)
...
...
neo/tests/__init__.py
View file @
abe5efff
...
...
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
print_function
import
__builtin__
import
errno
import
functools
...
...
@@ -60,7 +61,7 @@ def expectedFailure(exception=AssertionError):
def
wrapper
(
*
args
,
**
kw
):
try
:
func
(
*
args
,
**
kw
)
except
exception
,
e
:
except
exception
as
e
:
# XXX: passing sys.exc_info() causes deadlocks
raise
_ExpectedFailure
((
type
(
e
),
None
,
None
))
raise
_UnexpectedSuccess
...
...
@@ -135,18 +136,18 @@ def getTempDirectory():
try
:
os
.
makedirs
(
temp_dir
)
break
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
EEXIST
:
raise
last
=
os
.
path
.
join
(
neo_dir
,
"last"
)
try
:
os
.
remove
(
last
)
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
os
.
symlink
(
temp_name
,
last
)
os
.
environ
[
'TEMP'
]
=
temp_dir
print
'Using temp directory %r.'
%
temp_dir
print
(
'Using temp directory'
,
temp_dir
)
return
temp_dir
def
setupMySQL
(
db_list
,
clear_databases
=
True
):
...
...
@@ -165,8 +166,8 @@ def setupMySQL(db_list, clear_databases=True):
if
not
clear_databases
:
continue
conn
.
query
(
'DROP DATABASE `%s`'
%
database
)
except
OperationalError
,
(
code
,
_
)
:
if
code
!=
BAD_DB_ERROR
:
except
OperationalError
as
e
:
if
e
.
args
[
0
]
!=
BAD_DB_ERROR
:
raise
conn
.
query
(
'GRANT ALL ON `%s`.* TO "%s"@"localhost" IDENTIFIED'
' BY "%s"'
%
(
database
,
user
,
password
))
...
...
@@ -207,7 +208,7 @@ class MySQLPool(object):
if
os
.
path
.
exists
(
datadir
):
try
:
os
.
remove
(
sock
)
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
else
:
...
...
@@ -354,7 +355,7 @@ class NeoUnitTestBase(NeoTestBase):
for
i
in
xrange
(
number
):
try
:
os
.
remove
(
self
.
db_template
(
i
))
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
else
:
...
...
neo/tests/functional/__init__.py
View file @
abe5efff
...
...
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
print_function
import
errno
import
os
import
sys
...
...
@@ -112,7 +113,7 @@ class PortAllocator(object):
try
:
s
.
bind
((
local_ip
,
port
))
break
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
if
e
.
errno
!=
errno
.
EADDRINUSE
:
raise
elif
len
(
tried_port_set
)
>=
n
:
...
...
@@ -122,7 +123,7 @@ class PortAllocator(object):
s
.
listen
(
1
)
self
.
socket_list
.
append
(
s
)
return
port
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
if
e
.
errno
!=
errno
.
EADDRINUSE
:
raise
...
...
@@ -210,7 +211,7 @@ class Process(object):
on_fork
()
self
.
run
()
status
=
0
except
SystemExit
,
e
:
except
SystemExit
as
e
:
status
=
e
.
code
if
status
is
None
:
status
=
0
...
...
@@ -226,7 +227,7 @@ class Process(object):
save_coverage
()
os
.
_exit
(
status
)
except
:
print
>>
sys
.
stderr
,
status
print
(
status
,
file
=
sys
.
stderr
)
finally
:
os
.
_exit
(
1
)
logging
.
info
(
'pid %u: %s %s'
,
...
...
@@ -338,7 +339,7 @@ class NEOCluster(object):
self
.
db_list
=
db_list
if
temp_dir
is
None
:
temp_dir
=
tempfile
.
mkdtemp
(
prefix
=
'neo_'
)
print
'Using temp directory '
+
temp_dir
print
(
'Using temp directory'
,
temp_dir
)
if
adapter
==
'MySQL'
:
self
.
db_template
=
setupMySQL
(
db_list
,
clear_databases
)
elif
adapter
==
'SQLite'
:
...
...
@@ -352,7 +353,7 @@ class NEOCluster(object):
db
=
self
.
db_template
(
db
)
try
:
os
.
remove
(
db
)
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
else
:
...
...
@@ -466,7 +467,7 @@ class NEOCluster(object):
def
start
(
last_try
):
try
:
self
.
neoctl
.
startCluster
()
except
(
NotReadyException
,
SystemExit
)
,
e
:
except
(
NotReadyException
,
SystemExit
)
as
e
:
return
False
,
e
return
True
,
None
self
.
expectCondition
(
start
)
...
...
@@ -491,7 +492,7 @@ class NEOCluster(object):
try
:
process
.
kill
(
signal
.
SIGKILL
)
process
.
wait
()
except
NodeProcessError
,
e
:
except
NodeProcessError
as
e
:
error_list
+=
e
.
args
if
clients
:
for
zodb_storage
in
self
.
zodb_storage_list
:
...
...
@@ -626,8 +627,8 @@ class NEOCluster(object):
except
NotReadyException
:
current_try
=
0
if
last_try
is
not
None
and
current_try
<
last_try
:
raise
AssertionError
,
'Regression: %s became %s'
%
\
(
last_try
,
current_try
)
raise
AssertionError
(
'Regression: %s became %s'
%
(
last_try
,
current_try
)
)
return
(
current_try
==
node_count
,
current_try
)
self
.
expectCondition
(
callback
,
*
args
,
**
kw
)
...
...
@@ -663,8 +664,8 @@ class NEOCluster(object):
def
callback
(
last_try
):
current_try
=
self
.
getPrimary
()
if
None
not
in
(
uuid
,
current_try
)
and
uuid
!=
current_try
:
raise
AssertionError
,
'An unexpected primary arose: %r, '
\
'expected %r'
%
(
dump
(
current_try
),
dump
(
uuid
))
raise
AssertionError
(
'Unexpected primary %r, expected %r'
%
(
dump
(
current_try
),
dump
(
uuid
)
))
return
uuid
is
None
or
uuid
==
current_try
,
current_try
self
.
expectCondition
(
callback
,
*
args
,
**
kw
)
...
...
neo/tests/stat_zodb.py
View file @
abe5efff
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
__future__
import
division
,
print_function
import
math
,
random
,
sys
from
cStringIO
import
StringIO
from
ZODB.utils
import
p64
,
u64
...
...
@@ -139,7 +140,7 @@ def stat(*storages):
obj_size_list
.
append
(
size
)
obj_count_list
.
append
(
obj_count
)
tr_size_list
.
append
(
tr_size
)
new_ratio
=
float
(
len
(
oid_set
)
)
/
len
(
obj_size_list
)
new_ratio
=
len
(
oid_set
)
/
len
(
obj_size_list
)
return
(
lognorm_stat
(
obj_size_list
),
lognorm_stat
(
obj_count_list
),
lognorm_stat
(
tr_size_list
),
...
...
neo/tests/threaded/test.py
View file @
abe5efff
...
...
@@ -294,7 +294,7 @@ class Test(NEOThreadedTest):
m2s
.
remove
(
delayUnlockInformation
)
try
:
return
orig
(
tm
,
ttid
,
serial
,
oid
,
*
args
)
except
Exception
,
e
:
except
Exception
as
e
:
except_list
.
append
(
e
.
__class__
)
raise
if
1
:
...
...
@@ -323,7 +323,7 @@ class Test(NEOThreadedTest):
delay
[
0
].
set
()
try
:
return
orig
(
tm
,
ttid
,
serial
,
oid
,
*
args
)
except
Exception
,
e
:
except
Exception
as
e
:
except_list
.
append
(
e
.
__class__
)
raise
def
onAsk
(
orig
,
conn
,
packet
,
*
args
,
**
kw
):
...
...
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