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
fd95a217
Commit
fd95a217
authored
Mar 16, 2021
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
undo: code clean-up
undone_data_tid can't be equal to a TTID.
parent
fd87e153
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
25 deletions
+20
-25
neo/storage/database/manager.py
neo/storage/database/manager.py
+12
-17
neo/storage/handlers/client.py
neo/storage/handlers/client.py
+3
-2
neo/tests/storage/testStorageDBTests.py
neo/tests/storage/testStorageDBTests.py
+5
-6
No files found.
neo/storage/database/manager.py
View file @
fd95a217
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +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/>.
import
os
,
errno
,
socket
,
s
truct
,
s
ys
,
threading
,
time
import
os
,
errno
,
socket
,
sys
,
threading
,
time
from
collections
import
defaultdict
from
collections
import
defaultdict
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
from
copy
import
copy
from
copy
import
copy
...
@@ -747,7 +747,7 @@ class DatabaseManager(object):
...
@@ -747,7 +747,7 @@ class DatabaseManager(object):
r
=
self
.
_getObject
(
oid
,
tid
,
before_tid
)
r
=
self
.
_getObject
(
oid
,
tid
,
before_tid
)
return
(
r
[
0
],
r
[
-
1
])
if
r
else
(
None
,
None
)
return
(
r
[
0
],
r
[
-
1
])
if
r
else
(
None
,
None
)
def
findUndoTID
(
self
,
oid
,
tid
,
ltid
,
undone_tid
,
transaction_object
):
def
findUndoTID
(
self
,
oid
,
ltid
,
undone_tid
,
current_tid
):
"""
"""
oid
oid
Object OID
Object OID
...
@@ -758,10 +758,9 @@ class DatabaseManager(object):
...
@@ -758,10 +758,9 @@ class DatabaseManager(object):
the undo.
the undo.
undone_tid
undone_tid
Transaction to undo
Transaction to undo
transaction_object
current_tid
Object data from memory, if it was modified by running
Serial of object data from memory, if it was modified by running
transaction.
transaction. None otherwise.
None if is was not modified by running transaction.
Returns a 3-tuple:
Returns a 3-tuple:
current_tid (p64)
current_tid (p64)
...
@@ -778,11 +777,7 @@ class DatabaseManager(object):
...
@@ -778,11 +777,7 @@ class DatabaseManager(object):
not current), True otherwise.
not current), True otherwise.
"""
"""
u64
=
util
.
u64
u64
=
util
.
u64
p64
=
util
.
p64
oid
=
u64
(
oid
)
oid
=
u64
(
oid
)
tid
=
u64
(
tid
)
if
ltid
:
ltid
=
u64
(
ltid
)
undone_tid
=
u64
(
undone_tid
)
undone_tid
=
u64
(
undone_tid
)
def
getDataTID
(
tid
=
None
,
before_tid
=
None
):
def
getDataTID
(
tid
=
None
,
before_tid
=
None
):
tid
,
data_tid
=
self
.
_getDataTID
(
oid
,
tid
,
before_tid
)
tid
,
data_tid
=
self
.
_getDataTID
(
oid
,
tid
,
before_tid
)
...
@@ -799,22 +794,22 @@ class DatabaseManager(object):
...
@@ -799,22 +794,22 @@ class DatabaseManager(object):
found_undone_tid
,
undone_data_tid
=
getDataTID
(
tid
=
undone_tid
)
found_undone_tid
,
undone_data_tid
=
getDataTID
(
tid
=
undone_tid
)
if
found_undone_tid
is
None
:
if
found_undone_tid
is
None
:
return
return
if
transaction_object
:
if
current_tid
:
transaction_tid
=
transaction_object
[
2
]
current_data_tid
=
u64
(
current_tid
)
current_tid
=
current_data_tid
=
\
tid
if
transaction_tid
is
None
else
u64
(
transaction_tid
)
else
:
else
:
if
ltid
:
ltid
=
u64
(
ltid
)
current_tid
,
current_data_tid
=
getDataTID
(
before_tid
=
ltid
)
current_tid
,
current_data_tid
=
getDataTID
(
before_tid
=
ltid
)
if
current_tid
is
None
:
if
current_tid
is
None
:
return
None
,
None
,
False
return
None
,
None
,
False
is_current
=
undone_data_tid
in
(
current_data_tid
,
tid
)
current_tid
=
util
.
p64
(
current_
tid
)
# Load object data as it was before given transaction.
# Load object data as it was before given transaction.
# It can be None, in which case it means we are undoing object
# It can be None, in which case it means we are undoing object
# creation.
# creation.
_
,
data_tid
=
getDataTID
(
before_tid
=
undone_tid
)
_
,
data_tid
=
getDataTID
(
before_tid
=
undone_tid
)
if
data_tid
is
not
None
:
if
data_tid
is
not
None
:
data_tid
=
p64
(
data_tid
)
data_tid
=
util
.
p64
(
data_tid
)
return
p64
(
current_tid
),
data_tid
,
is_current
return
current_tid
,
data_tid
,
undone_data_tid
==
current_data_tid
@
abstract
@
abstract
def
lockTransaction
(
self
,
tid
,
ttid
):
def
lockTransaction
(
self
,
tid
,
ttid
):
...
...
neo/storage/handlers/client.py
View file @
fd95a217
...
@@ -181,8 +181,9 @@ class ClientOperationHandler(BaseHandler):
...
@@ -181,8 +181,9 @@ class ClientOperationHandler(BaseHandler):
getObjectFromTransaction
=
app
.
tm
.
getObjectFromTransaction
getObjectFromTransaction
=
app
.
tm
.
getObjectFromTransaction
object_tid_dict
=
{}
object_tid_dict
=
{}
for
oid
in
oid_list
:
for
oid
in
oid_list
:
r
=
findUndoTID
(
oid
,
ttid
,
transaction_object
=
getObjectFromTransaction
(
ttid
,
oid
)
ltid
,
undone_tid
,
getObjectFromTransaction
(
ttid
,
oid
))
r
=
findUndoTID
(
oid
,
ltid
,
undone_tid
,
transaction_object
and
(
transaction_object
[
2
]
or
ttid
))
if
r
:
if
r
:
if
not
r
[
0
]:
if
not
r
[
0
]:
p
=
Errors
.
OidNotFound
(
dump
(
oid
))
p
=
Errors
.
OidNotFound
(
dump
(
oid
))
...
...
neo/tests/storage/testStorageDBTests.py
View file @
fd95a217
...
@@ -395,7 +395,7 @@ class StorageDBTests(NeoUnitTestBase):
...
@@ -395,7 +395,7 @@ class StorageDBTests(NeoUnitTestBase):
# Result: current tid is tid1, data_tid is None (undoing object
# Result: current tid is tid1, data_tid is None (undoing object
# creation)
# creation)
self
.
assertEqual
(
self
.
assertEqual
(
db
.
findUndoTID
(
oid1
,
tid
5
,
tid
4
,
tid1
,
None
),
db
.
findUndoTID
(
oid1
,
tid4
,
tid1
,
None
),
(
tid1
,
None
,
True
))
(
tid1
,
None
,
True
))
# Store a new transaction
# Store a new transaction
...
@@ -407,13 +407,13 @@ class StorageDBTests(NeoUnitTestBase):
...
@@ -407,13 +407,13 @@ class StorageDBTests(NeoUnitTestBase):
# Undoing oid1 tid2, OK: tid2 is latest
# Undoing oid1 tid2, OK: tid2 is latest
# Result: current tid is tid2, data_tid is tid1
# Result: current tid is tid2, data_tid is tid1
self
.
assertEqual
(
self
.
assertEqual
(
db
.
findUndoTID
(
oid1
,
tid
5
,
tid
4
,
tid2
,
None
),
db
.
findUndoTID
(
oid1
,
tid4
,
tid2
,
None
),
(
tid2
,
tid1
,
True
))
(
tid2
,
tid1
,
True
))
# Undoing oid1 tid1, Error: tid2 is latest
# Undoing oid1 tid1, Error: tid2 is latest
# Result: current tid is tid2, data_tid is -1
# Result: current tid is tid2, data_tid is -1
self
.
assertEqual
(
self
.
assertEqual
(
db
.
findUndoTID
(
oid1
,
tid
5
,
tid
4
,
tid1
,
None
),
db
.
findUndoTID
(
oid1
,
tid4
,
tid1
,
None
),
(
tid2
,
None
,
False
))
(
tid2
,
None
,
False
))
# Undoing oid1 tid1 with tid2 being undone in same transaction,
# Undoing oid1 tid1 with tid2 being undone in same transaction,
...
@@ -423,8 +423,7 @@ class StorageDBTests(NeoUnitTestBase):
...
@@ -423,8 +423,7 @@ class StorageDBTests(NeoUnitTestBase):
# Explanation of transaction_object: oid1, no data but a data serial
# Explanation of transaction_object: oid1, no data but a data serial
# to tid1
# to tid1
self
.
assertEqual
(
self
.
assertEqual
(
db
.
findUndoTID
(
oid1
,
tid5
,
tid4
,
tid1
,
db
.
findUndoTID
(
oid1
,
tid4
,
tid1
,
tid1
),
(
u64
(
oid1
),
None
,
tid1
)),
(
tid1
,
None
,
True
))
(
tid1
,
None
,
True
))
# Store a new transaction
# Store a new transaction
...
@@ -437,7 +436,7 @@ class StorageDBTests(NeoUnitTestBase):
...
@@ -437,7 +436,7 @@ class StorageDBTests(NeoUnitTestBase):
# Result: current tid is tid2, data_tid is None (undoing object
# Result: current tid is tid2, data_tid is None (undoing object
# creation)
# creation)
self
.
assertEqual
(
self
.
assertEqual
(
db
.
findUndoTID
(
oid1
,
tid
5
,
tid
4
,
tid1
,
None
),
db
.
findUndoTID
(
oid1
,
tid4
,
tid1
,
None
),
(
tid3
,
None
,
True
))
(
tid3
,
None
,
True
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
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