Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
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 @@
# 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
collections
import
defaultdict
from
functools
import
wraps
from
neo.lib
import
logging
,
util
from
neo.lib.protocol
import
ZERO_TID
...
...
@@ -59,15 +60,16 @@ class DatabaseManager(object):
"""
if
reset
:
self
.
erase
()
self
.
_uncommitted_data
=
defaultdict
(
int
)
self
.
_setup
(
app
)
def
_setup
(
self
,
app
):
"""To be overriden by the backend to set up a database
It must recover self._uncommitted_data from temporary object table.
_uncommitted_data is a
dict containing refcounts to data of
write-locked objects, except in case of undo, where the refcount is
increased later, when the object is read-locked.
_uncommitted_data is a
lready instantiated and must be updated with
refcounts to data of write-locked objects, except in case of undo,
where the refcount is
increased later, when the object is read-locked.
Keys are data ids and values are number of references.
"""
raise
NotImplementedError
...
...
@@ -316,20 +318,20 @@ class DatabaseManager(object):
"""
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
checksum must be the result of neo.lib.util.makeChecksum(data)
'compression' indicates if 'data' is compressed.
If 'checksum_or_id' is a checksum, it must be the result of
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
with this checksum.
If called with only an id, it only increment the volatile
reference to the data matching the id.
"""
refcount
=
self
.
_uncommitted_data
if
data
is
not
None
:
checksum_or_id
=
self
.
storeData
(
checksum_or_id
,
data
,
compression
)
refcount
[
checksum_or_id
]
=
1
+
refcount
.
get
(
checksum_or_id
,
0
)
if
args
:
checksum_or_id
=
self
.
storeData
(
checksum_or_id
,
*
args
)
self
.
_uncommitted_data
[
checksum_or_id
]
+=
1
return
checksum_or_id
def
releaseData
(
self
,
data_id_list
,
prune
=
False
):
...
...
neo/storage/database/mysqldb.py
View file @
3e91d269
...
...
@@ -217,8 +217,8 @@ class MySQLDatabaseManager(DatabaseManager):
PRIMARY KEY (tid, oid)
) ENGINE = InnoDB"""
)
self
.
_uncommitted_data
=
dict
(
q
(
"SELECT data_id, count(*)"
" FROM tobj WHERE data_id IS NOT NULL GROUP BY data_id"
)
or
()
)
self
.
_uncommitted_data
.
update
(
q
(
"SELECT data_id, count(*)"
" FROM tobj WHERE data_id IS NOT NULL GROUP BY data_id"
))
def
getConfiguration
(
self
,
key
):
try
:
...
...
neo/storage/database/sqlite.py
View file @
3e91d269
...
...
@@ -182,7 +182,7 @@ class SQLiteDatabaseManager(DatabaseManager):
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"
))
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