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
3e91d269
Commit
3e91d269
authored
Jul 08, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: use defaultdict to track data of uncommitted objects
parent
a0bd2ae8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
13 deletions
+15
-13
neo/storage/database/manager.py
neo/storage/database/manager.py
+12
-10
neo/storage/database/mysqldb.py
neo/storage/database/mysqldb.py
+2
-2
neo/storage/database/sqlite.py
neo/storage/database/sqlite.py
+1
-1
No files found.
neo/storage/database/manager.py
View file @
3e91d269
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
collections
import
defaultdict
from
functools
import
wraps
from
functools
import
wraps
from
neo.lib
import
logging
,
util
from
neo.lib
import
logging
,
util
from
neo.lib.protocol
import
ZERO_TID
from
neo.lib.protocol
import
ZERO_TID
...
@@ -59,15 +60,16 @@ class DatabaseManager(object):
...
@@ -59,15 +60,16 @@ class DatabaseManager(object):
"""
"""
if
reset
:
if
reset
:
self
.
erase
()
self
.
erase
()
self
.
_uncommitted_data
=
defaultdict
(
int
)
self
.
_setup
(
app
)
self
.
_setup
(
app
)
def
_setup
(
self
,
app
):
def
_setup
(
self
,
app
):
"""To be overriden by the backend to set up a database
"""To be overriden by the backend to set up a database
It must recover self._uncommitted_data from temporary object table.
It must recover self._uncommitted_data from temporary object table.
_uncommitted_data is a
dict containing refcounts to data of
_uncommitted_data is a
lready instantiated and must be updated with
write-locked objects, except in case of undo, where the refcount is
refcounts to data of write-locked objects, except in case of undo,
increased later, when the object is read-locked.
where the refcount is
increased later, when the object is read-locked.
Keys are data ids and values are number of references.
Keys are data ids and values are number of references.
"""
"""
raise
NotImplementedError
raise
NotImplementedError
...
@@ -316,20 +318,20 @@ class DatabaseManager(object):
...
@@ -316,20 +318,20 @@ class DatabaseManager(object):
"""
"""
raise
NotImplementedError
raise
NotImplementedError
def
holdData
(
self
,
checksum_or_id
,
data
=
None
,
compression
=
None
):
def
holdData
(
self
,
checksum_or_id
,
*
args
):
"""Store raw data of temporary object
"""Store raw data of temporary object
checksum must be the result of neo.lib.util.makeChecksum(data)
If 'checksum_or_id' is a checksum, it must be the result of
'compression' indicates if 'data' is compressed.
makeChecksum(data) and extra parameters must be (data, compression)
where 'compression' indicates if 'data' is compressed.
A volatile reference is set to this data until 'releaseData' is called
A volatile reference is set to this data until 'releaseData' is called
with this checksum.
with this checksum.
If called with only an id, it only increment the volatile
If called with only an id, it only increment the volatile
reference to the data matching the id.
reference to the data matching the id.
"""
"""
refcount
=
self
.
_uncommitted_data
if
args
:
if
data
is
not
None
:
checksum_or_id
=
self
.
storeData
(
checksum_or_id
,
*
args
)
checksum_or_id
=
self
.
storeData
(
checksum_or_id
,
data
,
compression
)
self
.
_uncommitted_data
[
checksum_or_id
]
+=
1
refcount
[
checksum_or_id
]
=
1
+
refcount
.
get
(
checksum_or_id
,
0
)
return
checksum_or_id
return
checksum_or_id
def
releaseData
(
self
,
data_id_list
,
prune
=
False
):
def
releaseData
(
self
,
data_id_list
,
prune
=
False
):
...
...
neo/storage/database/mysqldb.py
View file @
3e91d269
...
@@ -217,8 +217,8 @@ class MySQLDatabaseManager(DatabaseManager):
...
@@ -217,8 +217,8 @@ class MySQLDatabaseManager(DatabaseManager):
PRIMARY KEY (tid, oid)
PRIMARY KEY (tid, oid)
) ENGINE = InnoDB"""
)
) ENGINE = InnoDB"""
)
self
.
_uncommitted_data
=
dict
(
q
(
"SELECT data_id, count(*)"
self
.
_uncommitted_data
.
update
(
q
(
"SELECT data_id, count(*)"
" FROM tobj WHERE data_id IS NOT NULL GROUP BY data_id"
)
or
()
)
" FROM tobj WHERE data_id IS NOT NULL GROUP BY data_id"
))
def
getConfiguration
(
self
,
key
):
def
getConfiguration
(
self
,
key
):
try
:
try
:
...
...
neo/storage/database/sqlite.py
View file @
3e91d269
...
@@ -182,7 +182,7 @@ class SQLiteDatabaseManager(DatabaseManager):
...
@@ -182,7 +182,7 @@ class SQLiteDatabaseManager(DatabaseManager):
PRIMARY KEY (tid, oid))
PRIMARY KEY (tid, oid))
"""
)
"""
)
self
.
_uncommitted_data
=
dict
(
q
(
"SELECT data_id, count(*)"
self
.
_uncommitted_data
.
update
(
q
(
"SELECT data_id, count(*)"
" FROM tobj WHERE data_id IS NOT NULL GROUP BY data_id"
))
" FROM tobj WHERE data_id IS NOT NULL GROUP BY data_id"
))
def
getConfiguration
(
self
,
key
):
def
getConfiguration
(
self
,
key
):
...
...
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