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
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
Show 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, \
...
@@ -27,7 +27,7 @@ from logging import getLogger, Formatter, Logger, LogRecord, StreamHandler, \
DEBUG
,
WARNING
DEBUG
,
WARNING
from
time
import
time
from
time
import
time
from
traceback
import
format_exception
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)
# Stats for storage node of matrix test (py2.7:SQLite)
RECORD_SIZE
=
(
234360832
# extra memory used
RECORD_SIZE
=
(
234360832
# extra memory used
...
@@ -101,15 +101,30 @@ class NEOLogger(Logger):
...
@@ -101,15 +101,30 @@ class NEOLogger(Logger):
if
self
.
_db
is
None
:
if
self
.
_db
is
None
:
return
return
try
:
try
:
self
.
_db
.
execute
(
"BEGIN"
)
for
r
in
self
.
_record_queue
:
for
r
in
self
.
_record_queue
:
self
.
_emit
(
r
)
self
.
_emit
(
r
)
finally
:
finally
:
# Always commit, to not lose any record that we could emit.
# Always commit, to not lose any record that we could emit.
self
.
_db
.
commit
()
self
.
commit
()
self
.
_record_queue
.
clear
()
self
.
_record_queue
.
clear
()
self
.
_record_size
=
0
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
):
def
backlog
(
self
,
max_size
=
1
<<
24
):
with
self
:
with
self
:
self
.
_max_size
=
max_size
self
.
_max_size
=
max_size
...
@@ -133,8 +148,7 @@ class NEOLogger(Logger):
...
@@ -133,8 +148,7 @@ class NEOLogger(Logger):
self
.
_record_size
=
0
self
.
_record_size
=
0
return
return
if
filename
:
if
filename
:
self
.
_db
=
sqlite3
.
connect
(
filename
,
isolation_level
=
None
,
self
.
_db
=
sqlite3
.
connect
(
filename
,
check_same_thread
=
False
)
check_same_thread
=
False
)
q
=
self
.
_db
.
execute
q
=
self
.
_db
.
execute
if
reset
:
if
reset
:
for
t
in
'log'
,
'packet'
:
for
t
in
'log'
,
'packet'
:
...
@@ -169,6 +183,7 @@ class NEOLogger(Logger):
...
@@ -169,6 +183,7 @@ class NEOLogger(Logger):
if
p
==
t
:
if
p
==
t
:
break
break
else
:
else
:
with
self
.
_db
:
q
(
"INSERT INTO protocol VALUES (?,?)"
,
(
time
(),
p
))
q
(
"INSERT INTO protocol VALUES (?,?)"
,
(
time
(),
p
))
__del__
=
setup
__del__
=
setup
...
@@ -193,6 +208,7 @@ class NEOLogger(Logger):
...
@@ -193,6 +208,7 @@ class NEOLogger(Logger):
try
:
try
:
if
self
.
_max_size
is
None
:
if
self
.
_max_size
is
None
:
self
.
_emit
(
record
)
self
.
_emit
(
record
)
self
.
commit
()
else
:
else
:
self
.
_record_size
+=
RECORD_SIZE
+
len
(
record
.
msg
)
self
.
_record_size
+=
RECORD_SIZE
+
len
(
record
.
msg
)
q
=
self
.
_record_queue
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