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
f1b72dfe
Commit
f1b72dfe
authored
Jul 04, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: remake _getPartition lazy, similarly to fallback decorator
parent
e823b93c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
9 deletions
+22
-9
neo/storage/database/manager.py
neo/storage/database/manager.py
+22
-9
No files found.
neo/storage/database/manager.py
View file @
f1b72dfe
...
...
@@ -14,20 +14,28 @@
# 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
functools
import
wraps
from
neo.lib
import
logging
,
util
from
neo.lib.protocol
import
ZERO_TID
def
fallback
(
func
):
def
lazymethod
(
func
):
def
getter
(
self
):
cls
=
self
.
__class__
name
=
func
.
__name__
assert
name
not
in
cls
.
__dict__
setattr
(
cls
,
name
,
func
(
self
))
return
getattr
(
self
,
name
)
return
property
(
getter
,
doc
=
func
.
__doc__
)
def
fallback
(
func
):
def
warn
(
self
):
cls
=
self
.
__class__
name
=
func
.
__name__
logging
.
info
(
"Fallback to generic/slow implementation of %s."
" It should be overridden by backend storage (%s)."
,
name
,
cls
.
__name__
)
setattr
(
cls
,
name
,
func
)
return
getattr
(
self
,
name
)
return
property
(
getter
)
func
.
__name__
,
self
.
__class__
.
__name__
)
return
func
return
lazymethod
(
wraps
(
func
)(
warn
))
class
CreationUndone
(
Exception
):
pass
...
...
@@ -67,10 +75,10 @@ class DatabaseManager(object):
def
commit
(
self
):
pass
def
_getPartition
(
self
,
oid_or_tid
):
@
lazymethod
def
_getPartition
(
self
):
np
=
self
.
getNumPartitions
()
self
.
_getPartition
=
lambda
x
:
x
%
np
return
self
.
_getPartition
(
oid_or_tid
)
return
staticmethod
(
lambda
x
:
x
%
np
)
def
getConfiguration
(
self
,
key
):
"""
...
...
@@ -115,7 +123,12 @@ class DatabaseManager(object):
Store the number of partitions into a database.
"""
self
.
setConfiguration
(
'partitions'
,
num_partitions
)
self
.
__class__
.
_getPartition
(
self
,
0
)
cls
=
self
.
__class__
assert
cls
is
not
DatabaseManager
try
:
del
cls
.
_getPartition
except
AttributeError
:
pass
def
getNumReplicas
(
self
):
"""
...
...
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