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
Vincent Pelletier
neoppod
Commits
5923f8f5
Commit
5923f8f5
authored
May 07, 2024
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sqlite: add support for cksumvfs extension
parent
9722d241
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
neo.conf
neo.conf
+1
-0
neo/storage/database/sqlite.py
neo/storage/database/sqlite.py
+28
-0
No files found.
neo.conf
View file @
5923f8f5
...
...
@@ -64,6 +64,7 @@ partitions: 12
# (currently supported: cache_size, journal_mode, synchronous),
# but it can't be used yet to pass open options
# because Python 2.7's sqlite3.connect does not support URIs.
# https://www.sqlite.org/cksumvfs.html can be enabled with cksumvfs=1
# engine: Optional parameter for MySQL.
# Can be InnoDB (default) or RocksDB.
...
...
neo/storage/database/sqlite.py
View file @
5923f8f5
...
...
@@ -19,6 +19,7 @@ import os
import
sqlite3
from
hashlib
import
sha1
import
string
import
subprocess
import
traceback
from
urlparse
import
urlsplit
,
parse_qsl
...
...
@@ -72,12 +73,20 @@ class SQLiteDatabaseManager(DatabaseManager):
VERSION
=
4
cksumvfs
=
None
def
_parse
(
self
,
database
):
pragmas
=
self
.
pragmas
=
{}
if
database
.
startswith
(
'file:'
):
database
=
urlsplit
(
database
)
for
k
,
v
in
parse_qsl
(
database
.
query
,
keep_blank_values
=
True
,
strict_parsing
=
True
):
if
k
==
'cksumvfs'
:
if
self
.
cksumvfs
is
not
None
or
v
not
in
(
'0'
,
'1'
):
raise
DatabaseFailure
(
"invalid or duplicate %s value"
%
k
)
self
.
cksumvfs
=
int
(
v
)
continue
if
k
in
pragmas
:
raise
DatabaseFailure
(
"duplicate pragma: "
+
k
)
if
k
not
in
(
'cache_size'
,
'journal_mode'
,
'synchronous'
):
...
...
@@ -86,6 +95,13 @@ class SQLiteDatabaseManager(DatabaseManager):
self
.
db
=
database
.
path
else
:
self
.
db
=
os
.
path
.
expanduser
(
database
)
if
self
.
cksumvfs
:
db
=
sqlite3
.
connect
(
':memory:'
)
try
:
db
.
enable_load_extension
(
True
)
db
.
load_extension
(
'cksumvfs.so'
)
finally
:
db
.
close
()
if
self
.
UNSAFE
:
pragmas
.
setdefault
(
'synchronous'
,
'OFF'
)
pragmas
.
setdefault
(
'journal_mode'
,
'MEMORY'
)
...
...
@@ -95,10 +111,22 @@ class SQLiteDatabaseManager(DatabaseManager):
def
_connect
(
self
):
logging
.
info
(
'connecting to SQLite database %r'
,
self
.
db
)
if
self
.
cksumvfs
and
not
os
.
path
.
exists
(
self
.
db
):
subprocess
.
check_output
((
'sqlite3'
,
':memory:'
,
'.load cksumvfs.so'
,
'.open "%s"'
%
self
.
db
.
replace
(
'
\
\
'
,
r'\\'
).
replace
(
'"'
,
r'\"'
),
'.filectrl reserve_bytes 8'
,
'vacuum'
))
# PY3: check_call(..., stdout=subprocess.DEVNULL)
os
.
stat
(
self
.
db
)
self
.
conn
=
sqlite3
.
connect
(
self
.
db
,
check_same_thread
=
False
)
self
.
conn
.
text_factory
=
str
self
.
lockFile
(
self
.
db
)
try
:
if
self
.
cksumvfs
:
self
.
cksumvfs
=
0
(
x
,),
=
self
.
query
(
"PRAGMA checksum_verification"
).
fetchall
()
if
not
int
(
x
):
raise
DatabaseFailure
(
"Can't enable cksumvfs."
)
for
pragma
in
map
(
"PRAGMA %s = %s"
.
__mod__
,
self
.
pragmas
.
iteritems
()):
logging
.
info
(
pragma
)
...
...
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