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
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
Levin Zimmermann
neoppod
Commits
3d0fab20
Commit
3d0fab20
authored
Jul 20, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logger: retry instead of raise if the log is locked by another process
parent
0e3c2712
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
neo/lib/logger.py
neo/lib/logger.py
+22
-6
No files found.
neo/lib/logger.py
View file @
3d0fab20
...
...
@@ -27,7 +27,7 @@ from logging import getLogger, Formatter, Logger, LogRecord, StreamHandler, \
DEBUG
,
WARNING
from
time
import
time
from
traceback
import
format_exception
import
bz2
,
inspect
,
neo
,
os
,
signal
,
sqlite3
,
threading
import
bz2
,
inspect
,
neo
,
os
,
signal
,
sqlite3
,
sys
,
threading
# Stats for storage node of matrix test (py2.7:SQLite)
RECORD_SIZE
=
(
234360832
# extra memory used
...
...
@@ -101,15 +101,30 @@ class NEOLogger(Logger):
if
self
.
_db
is
None
:
return
try
:
self
.
_db
.
execute
(
"BEGIN"
)
for
r
in
self
.
_record_queue
:
self
.
_emit
(
r
)
finally
:
# Always commit, to not lose any record that we could emit.
self
.
_db
.
commit
()
self
.
commit
()
self
.
_record_queue
.
clear
()
self
.
_record_size
=
0
def
commit
(
self
):
try
:
self
.
_db
.
commit
()
except
sqlite3
.
OperationalError
,
e
:
x
=
e
.
args
[
0
]
if
x
==
'database is locked'
:
sys
.
stderr
.
write
(
'%s: retrying to emit log...'
%
x
)
while
e
.
args
[
0
]
==
x
:
try
:
self
.
_db
.
commit
()
except
sqlite3
.
OperationalError
,
e
:
continue
sys
.
stderr
.
write
(
' ok
\
n
'
)
return
raise
def
backlog
(
self
,
max_size
=
1
<<
24
):
with
self
:
self
.
_max_size
=
max_size
...
...
@@ -133,8 +148,7 @@ class NEOLogger(Logger):
self
.
_record_size
=
0
return
if
filename
:
self
.
_db
=
sqlite3
.
connect
(
filename
,
isolation_level
=
None
,
check_same_thread
=
False
)
self
.
_db
=
sqlite3
.
connect
(
filename
,
check_same_thread
=
False
)
q
=
self
.
_db
.
execute
if
reset
:
for
t
in
'log'
,
'packet'
:
...
...
@@ -169,7 +183,8 @@ class NEOLogger(Logger):
if
p
==
t
:
break
else
:
q
(
"INSERT INTO protocol VALUES (?,?)"
,
(
time
(),
p
))
with
self
.
_db
:
q
(
"INSERT INTO protocol VALUES (?,?)"
,
(
time
(),
p
))
__del__
=
setup
def
isEnabledFor
(
self
,
level
):
...
...
@@ -193,6 +208,7 @@ class NEOLogger(Logger):
try
:
if
self
.
_max_size
is
None
:
self
.
_emit
(
record
)
self
.
commit
()
else
:
self
.
_record_size
+=
RECORD_SIZE
+
len
(
record
.
msg
)
q
=
self
.
_record_queue
...
...
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