-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[db]log mptrie node #3634
[db]log mptrie node #3634
Changes from 2 commits
fd984d8
dc8b725
ee087b0
fc7ddd6
3a91c4c
7cd23c4
0acee52
549a8ec
76e00cf
b54aaca
af14413
6f736e4
12fd4cf
c7bbe1e
c9b5792
23622ed
8166a5d
6521e42
a575201
33ed183
99efe1a
d485731
c501416
715ccb7
070a33c
1b1944d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,7 @@ func newBranchNode( | |
} | ||
} | ||
} | ||
hashVal, _ := bnode.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeBranch, _actionTypeNew, hashVal, bnode); err != nil { | ||
if err := logNode(_nodeTypeBranch, _actionTypeNew, bnode, cli); err != nil { | ||
return nil, err | ||
} | ||
return bnode, nil | ||
|
@@ -73,8 +72,7 @@ func newRootBranchNode(cli client, children map[byte]node, indices *SortedList, | |
} | ||
} | ||
} | ||
hashVal, _ := bnode.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeBranch, _actionTypeNew, hashVal, bnode); err != nil { | ||
if err := logNode(_nodeTypeBranch, _actionTypeNew, bnode, cli); err != nil { | ||
return nil, err | ||
} | ||
return bnode, nil | ||
|
@@ -93,7 +91,7 @@ func newBranchNodeFromProtoPb(pb *triepb.BranchPb, hashVal []byte) *branchNode { | |
} | ||
bnode.indices = NewSortedList(bnode.children) | ||
bnode.cacheNode.serializable = bnode | ||
if err := logNode(_nodeTypeBranch, _actionTypeNew, hashVal, bnode); err != nil { | ||
if err := logNode(_nodeTypeBranch, _actionTypeNew, bnode, nil); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not working here |
||
panic(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
return bnode | ||
|
@@ -112,8 +110,7 @@ func (b *branchNode) Children() []node { | |
} | ||
|
||
func (b *branchNode) Delete(cli client, key keyType, offset uint8) (node, error) { | ||
hashVal, _ := b.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeBranch, _actionTypeDelete, hashVal, b); err != nil { | ||
if err := logNode(_nodeTypeBranch, _actionTypeDelete, b, cli); err != nil { | ||
return nil, err | ||
} | ||
offsetKey := key[offset] | ||
|
@@ -169,8 +166,7 @@ func (b *branchNode) Delete(cli client, key keyType, offset uint8) (node, error) | |
} | ||
|
||
func (b *branchNode) Upsert(cli client, key keyType, offset uint8, value []byte) (node, error) { | ||
hashVal, _ := b.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeBranch, _actionTypeUpsert, hashVal, b); err != nil { | ||
if err := logNode(_nodeTypeBranch, _actionTypeUpsert, b, cli); err != nil { | ||
return nil, err | ||
} | ||
var newChild node | ||
|
@@ -190,8 +186,7 @@ func (b *branchNode) Upsert(cli client, key keyType, offset uint8, value []byte) | |
} | ||
|
||
func (b *branchNode) Search(cli client, key keyType, offset uint8) (node, error) { | ||
hashVal, _ := b.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeBranch, _actionTypeSearch, hashVal, b); err != nil { | ||
if err := logNode(_nodeTypeBranch, _actionTypeSearch, b, cli); err != nil { | ||
return nil, err | ||
} | ||
child, err := b.child(key[offset]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,7 @@ func newExtensionNode( | |
return nil, err | ||
} | ||
} | ||
hashVal, _ := e.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeExtension, _actionTypeNew, hashVal, e); err != nil { | ||
if err := logNode(_nodeTypeExtension, _actionTypeNew, e, cli); err != nil { | ||
return nil, err | ||
} | ||
return e, nil | ||
|
@@ -55,15 +54,14 @@ func newExtensionNodeFromProtoPb(pb *triepb.ExtendPb, hashVal []byte) *extension | |
child: newHashNode(pb.Value), | ||
} | ||
e.cacheNode.serializable = e | ||
if err := logNode(_nodeTypeExtension, _actionTypeNew, hashVal, e); err != nil { | ||
if err := logNode(_nodeTypeExtension, _actionTypeNew, e, nil); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not working here |
||
panic(err) | ||
} | ||
return e | ||
} | ||
|
||
func (e *extensionNode) Delete(cli client, key keyType, offset uint8) (node, error) { | ||
hashVal, _ := e.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeExtension, _actionTypeDelete, hashVal, e); err != nil { | ||
if err := logNode(_nodeTypeExtension, _actionTypeDelete, e, cli); err != nil { | ||
return nil, err | ||
} | ||
matched := e.commonPrefixLength(key[offset:]) | ||
|
@@ -96,8 +94,7 @@ func (e *extensionNode) Delete(cli client, key keyType, offset uint8) (node, err | |
} | ||
|
||
func (e *extensionNode) Upsert(cli client, key keyType, offset uint8, value []byte) (node, error) { | ||
hashVal, _ := e.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeExtension, _actionTypeUpsert, hashVal, e); err != nil { | ||
if err := logNode(_nodeTypeExtension, _actionTypeUpsert, e, cli); err != nil { | ||
return nil, err | ||
} | ||
matched := e.commonPrefixLength(key[offset:]) | ||
|
@@ -135,8 +132,7 @@ func (e *extensionNode) Upsert(cli client, key keyType, offset uint8, value []by | |
} | ||
|
||
func (e *extensionNode) Search(cli client, key keyType, offset uint8) (node, error) { | ||
hashVal, _ := e.cacheNode.Hash(cli) | ||
if err := logNode(_nodeTypeExtension, _actionTypeSearch, hashVal, e); err != nil { | ||
if err := logNode(_nodeTypeExtension, _actionTypeSearch, e, cli); err != nil { | ||
return nil, err | ||
} | ||
matched := e.commonPrefixLength(key[offset:]) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -38,8 +38,7 @@ func newLeafNode( | |||||||||||||||||
return nil, err | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
hashVal, _ := l.cacheNode.Hash(cli) | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeNew, hashVal, l); err != nil { | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeNew, l, cli); err != nil { | ||||||||||||||||||
return nil, err | ||||||||||||||||||
} | ||||||||||||||||||
return l, nil | ||||||||||||||||||
|
@@ -55,7 +54,7 @@ func newLeafNodeFromProtoPb(pb *triepb.LeafPb, hashVal []byte) *leafNode { | |||||||||||||||||
value: pb.Value, | ||||||||||||||||||
} | ||||||||||||||||||
l.cacheNode.serializable = l | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeNew, hashVal, l); err != nil { | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeNew, l, nil); err != nil { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not working here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought so too at first. iotex-core/db/trie/mptrie/cachenode.go Lines 25 to 32 in 715ccb7
|
||||||||||||||||||
panic(err) | ||||||||||||||||||
} | ||||||||||||||||||
return l | ||||||||||||||||||
|
@@ -70,8 +69,7 @@ func (l *leafNode) Value() []byte { | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func (l *leafNode) Delete(cli client, key keyType, offset uint8) (node, error) { | ||||||||||||||||||
hashVal, _ := l.cacheNode.Hash(cli) | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeDelete, hashVal, l); err != nil { | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeDelete, l, cli); err != nil { | ||||||||||||||||||
return nil, err | ||||||||||||||||||
} | ||||||||||||||||||
if !bytes.Equal(l.key[offset:], key[offset:]) { | ||||||||||||||||||
|
@@ -81,8 +79,7 @@ func (l *leafNode) Delete(cli client, key keyType, offset uint8) (node, error) { | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func (l *leafNode) Upsert(cli client, key keyType, offset uint8, value []byte) (node, error) { | ||||||||||||||||||
hashVal, _ := l.cacheNode.Hash(cli) | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeUpsert, hashVal, l); err != nil { | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeUpsert, l, cli); err != nil { | ||||||||||||||||||
return nil, err | ||||||||||||||||||
} | ||||||||||||||||||
matched := commonPrefixLength(l.key[offset:], key[offset:]) | ||||||||||||||||||
|
@@ -122,8 +119,7 @@ func (l *leafNode) Upsert(cli client, key keyType, offset uint8, value []byte) ( | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func (l *leafNode) Search(cli client, key keyType, offset uint8) (node, error) { | ||||||||||||||||||
hashVal, _ := l.cacheNode.Hash(cli) | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeSearch, hashVal, l); err != nil { | ||||||||||||||||||
if err := logNode(_nodeTypeLeaf, _actionTypeSearch, l, cli); err != nil { | ||||||||||||||||||
return nil, err | ||||||||||||||||||
} | ||||||||||||||||||
if !bytes.Equal(l.key[offset:], key[offset:]) { | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,11 +80,11 @@ func CloseLogDB() error { | |
return logFile.Close() | ||
} | ||
|
||
func logNode(nt nodeType, at actionType, hashvalue []byte, n node) error { | ||
func logNode(nt nodeType, at actionType, n node, cli client) error { | ||
if !enabledLogMptrie { | ||
return nil | ||
} | ||
nodeKey, nodePath, nodeChildren, err := parseNode(n) | ||
nodeKey, nodePath, nodeChildren, hashvalue, err := parseNode(n, cli) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -100,23 +100,26 @@ func logNode(nt nodeType, at actionType, hashvalue []byte, n node) error { | |
HashLen: uint8(len(hashvalue)), | ||
HashVal: hashvalue, | ||
} | ||
// write events length | ||
// write event length | ||
if err = logWriter.WriteByte(byte(len(event.Bytes()))); err != nil { | ||
return err | ||
} | ||
// write events body | ||
// write event body | ||
_, err = logWriter.Write(event.Bytes()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How to read the binary data in the db? Do we have the tool or component to print the data? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A byte is used to save the size of the binrary. Binary itself is not readable and needs to be processed by tool. In the lognode_test.go, there is a parseNodeEvent that can parse the binrary. How the tools are provided needs to be discussed (print, database) |
||
return err | ||
} | ||
|
||
func parseNode(n node) (nodeKey []byte, nodePath []byte, nodeChildren []byte, err error) { | ||
func parseNode(n node, cli client) (nodeKey, nodePath, nodeChildren, hashvalue []byte, err error) { | ||
switch n := n.(type) { | ||
case *leafNode: | ||
nodeKey = n.key | ||
hashvalue, err = n.cacheNode.Hash(cli) | ||
case *extensionNode: | ||
nodePath = n.path | ||
hashvalue, err = n.cacheNode.Hash(cli) | ||
case *branchNode: | ||
nodeChildren = n.indices.List() | ||
hashvalue, err = n.cacheNode.Hash(cli) | ||
default: | ||
err = errors.Errorf("unknown node type %T", n) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is
logging
used at the end of function instead of at the head?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait for the
bnode
Initialized