Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
d8b23ca4
Commit
d8b23ca4
authored
Jun 22, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify mustwrite batch
parent
08d8d17c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
71 deletions
+29
-71
kvmvccdb.go
plugin/store/kvmvcc/kvmvccdb.go
+1
-6
kvmvcc_mavl.go
plugin/store/kvmvccmavl/kvmvcc_mavl.go
+4
-18
kvmvccdb.go
plugin/store/kvmvccmavl/kvmvccdb.go
+4
-18
db.go
vendor/github.com/33cn/chain33/common/db/db.go
+7
-0
go_level_db.go
vendor/github.com/33cn/chain33/common/db/go_level_db.go
+4
-0
prune.go
vendor/github.com/33cn/chain33/system/store/mavl/db/prune.go
+6
-20
tree.go
vendor/github.com/33cn/chain33/system/store/mavl/db/tree.go
+3
-9
No files found.
plugin/store/kvmvcc/kvmvccdb.go
View file @
d8b23ca4
...
...
@@ -13,7 +13,6 @@ import (
drivers
"github.com/33cn/chain33/system/store"
"github.com/33cn/chain33/types"
"github.com/golang/protobuf/proto"
"fmt"
)
var
klog
=
log
.
New
(
"module"
,
"kvmvccdb"
)
...
...
@@ -230,11 +229,7 @@ func (mvccs *KVMVCCStore) saveKVSets(kvset []*types.KeyValue, sync bool) {
storeBatch
.
Set
(
kvset
[
i
]
.
Key
,
kvset
[
i
]
.
Value
)
}
}
err
:=
storeBatch
.
Write
()
if
err
!=
nil
{
klog
.
Error
(
"store kvmvcc saveKVSets to db failed"
)
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
storeBatch
)
}
func
(
mvccs
*
KVMVCCStore
)
checkVersion
(
height
int64
)
([]
*
types
.
KeyValue
,
error
)
{
...
...
plugin/store/kvmvccmavl/kvmvcc_mavl.go
View file @
d8b23ca4
...
...
@@ -367,7 +367,6 @@ func delMavlData(db dbm.DB) bool {
it
:=
db
.
Iterator
(
nil
,
nil
,
true
)
defer
it
.
Close
()
batch
:=
db
.
NewBatch
(
true
)
var
err
error
for
it
.
Rewind
();
it
.
Valid
();
it
.
Next
()
{
if
quit
{
return
false
...
...
@@ -375,20 +374,14 @@ func delMavlData(db dbm.DB) bool {
if
!
bytes
.
HasPrefix
(
it
.
Key
(),
mvccPrefix
)
{
// 将非mvcc的mavl数据全部删除
batch
.
Delete
(
it
.
Key
())
if
batch
.
ValueSize
()
>
batchDataSize
{
err
=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
batch
.
Reset
()
time
.
Sleep
(
time
.
Millisecond
*
500
)
}
}
}
batch
.
Set
(
genDelMavlKey
(
mvccPrefix
),
[]
byte
(
""
))
err
=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
return
true
}
...
...
@@ -440,7 +433,6 @@ func deletePrunedMavl(db dbm.DB) {
func
deletePrunedMavlData
(
db
dbm
.
DB
,
prefix
string
)
{
it
:=
db
.
Iterator
([]
byte
(
prefix
),
nil
,
true
)
defer
it
.
Close
()
var
err
error
if
it
.
Rewind
()
&&
it
.
Valid
()
{
batch
:=
db
.
NewBatch
(
false
)
for
it
.
Next
();
it
.
Valid
();
it
.
Next
()
{
//第一个不做删除
...
...
@@ -449,17 +441,11 @@ func deletePrunedMavlData(db dbm.DB, prefix string) {
}
batch
.
Delete
(
it
.
Key
())
if
batch
.
ValueSize
()
>
batchDataSize
{
err
=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
batch
.
Reset
()
time
.
Sleep
(
time
.
Millisecond
*
500
)
}
}
err
=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
}
}
plugin/store/kvmvccmavl/kvmvccdb.go
View file @
d8b23ca4
...
...
@@ -184,10 +184,7 @@ func (mvccs *KVMVCCStore) CommitUpgrade(req *types.ReqHash) ([]byte, error) {
batch
.
Set
(
kvset
[
i
]
.
Key
,
kvset
[
i
]
.
Value
)
}
}
err
:=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
delete
(
mvccs
.
kvsetmap
,
string
(
req
.
Hash
))
return
req
.
Hash
,
nil
}
...
...
@@ -266,11 +263,7 @@ func (mvccs *KVMVCCStore) saveKVSets(kvset []*types.KeyValue, sync bool) {
storeBatch
.
Set
(
kvset
[
i
]
.
Key
,
kvset
[
i
]
.
Value
)
}
}
err
:=
storeBatch
.
Write
()
if
err
!=
nil
{
kmlog
.
Info
(
"KVMVCCStore saveKVSets"
,
"Write error"
,
err
)
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
storeBatch
)
}
// GetMaxVersion 获取当前最大高度
...
...
@@ -394,17 +387,13 @@ func deleteOldKV(mp map[string][]int64, curHeight int64, batch dbm.Batch) {
return
}
batch
.
Reset
()
var
err
error
for
key
,
vals
:=
range
mp
{
if
len
(
vals
)
>
1
&&
vals
[
1
]
!=
vals
[
0
]
{
//防止相同高度时候出现的误删除
for
_
,
val
:=
range
vals
[
1
:
]
{
//从第二个开始判断
if
curHeight
>=
val
+
int64
(
pruneHeight
)
{
batch
.
Delete
(
genKeyVersion
([]
byte
(
key
),
val
))
// 删除老版本key
if
batch
.
ValueSize
()
>
batchDataSize
{
err
=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
batch
.
Reset
()
}
}
...
...
@@ -412,10 +401,7 @@ func deleteOldKV(mp map[string][]int64, curHeight int64, batch dbm.Batch) {
}
delete
(
mp
,
key
)
}
err
=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
}
func
genKeyVersion
(
key
[]
byte
,
height
int64
)
[]
byte
{
...
...
vendor/github.com/33cn/chain33/common/db/db.go
View file @
d8b23ca4
...
...
@@ -96,6 +96,13 @@ type Batch interface {
Reset
()
// Reset resets the batch for reuse
}
func
MustWrite
(
batch
Batch
)
{
err
:=
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
}
//IteratorSeeker ...
type
IteratorSeeker
interface
{
Rewind
()
bool
...
...
vendor/github.com/33cn/chain33/common/db/go_level_db.go
View file @
d8b23ca4
...
...
@@ -267,6 +267,10 @@ func (mBatch *goLevelDBBatch) Delete(key []byte) {
}
func
(
mBatch
*
goLevelDBBatch
)
Write
()
error
{
if
mBatch
.
batch
.
Len
()
==
0
{
llog
.
Info
(
"Write"
,
"len"
,
len
)
return
nil
}
err
:=
mBatch
.
db
.
db
.
Write
(
mBatch
.
batch
,
mBatch
.
wop
)
if
err
!=
nil
{
llog
.
Error
(
"Write"
,
"error"
,
err
)
...
...
vendor/github.com/33cn/chain33/system/store/mavl/db/prune.go
View file @
d8b23ca4
...
...
@@ -256,28 +256,22 @@ func pruningFirstLevelNode(db dbm.DB, curHeight int64) {
}
func
addLeafCountKeyToSecondLevel
(
db
dbm
.
DB
,
kvs
[]
*
types
.
KeyValue
,
batch
dbm
.
Batch
)
{
var
err
error
batch
.
Reset
()
for
_
,
kv
:=
range
kvs
{
batch
.
Delete
(
kv
.
Key
)
batch
.
Set
(
genOldLeafCountKeyFromKey
(
kv
.
Key
),
kv
.
Value
)
if
batch
.
ValueSize
()
>
batchDataSize
{
if
err
=
batch
.
Write
();
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
batch
.
Reset
()
}
}
if
err
=
batch
.
Write
();
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
}
func
deleteNode
(
db
dbm
.
DB
,
mp
map
[
string
][]
hashData
,
curHeight
int64
,
batch
dbm
.
Batch
)
{
if
len
(
mp
)
==
0
{
return
}
var
err
error
batch
.
Reset
()
for
key
,
vals
:=
range
mp
{
if
len
(
vals
)
>
1
&&
vals
[
1
]
.
height
!=
vals
[
0
]
.
height
{
//防止相同高度时候出现的误删除
...
...
@@ -297,9 +291,7 @@ func deleteNode(db dbm.DB, mp map[string][]hashData, curHeight int64, batch dbm.
batch
.
Delete
(
leafCountKey
)
// 叶子计数节点
batch
.
Delete
(
val
.
hash
)
// 叶子节点hash值
if
batch
.
ValueSize
()
>
batchDataSize
{
if
err
=
batch
.
Write
();
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
batch
.
Reset
()
}
}
...
...
@@ -307,9 +299,7 @@ func deleteNode(db dbm.DB, mp map[string][]hashData, curHeight int64, batch dbm.
}
delete
(
mp
,
key
)
}
if
err
=
batch
.
Write
();
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
}
func
pruningSecondLevel
(
db
dbm
.
DB
,
curHeight
int64
)
{
...
...
@@ -411,15 +401,11 @@ func deleteOldNode(db dbm.DB, mp map[string][]hashData, curHeight int64, batch d
}
delete
(
mp
,
key
)
if
batch
.
ValueSize
()
>
batchDataSize
{
if
err
=
batch
.
Write
();
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
batch
.
Reset
()
}
}
if
err
=
batch
.
Write
();
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
}
// PruningTreePrintDB pruning tree print db
...
...
vendor/github.com/33cn/chain33/system/store/mavl/db/tree.go
View file @
d8b23ca4
...
...
@@ -404,9 +404,7 @@ func (t *Tree) RemoveLeafCountKey(height int64) {
treelog
.
Debug
(
"RemoveLeafCountKey:"
,
"height"
,
height
,
"key:"
,
string
(
k
),
"hash:"
,
common
.
ToHex
(
hash
))
}
}
if
err
:=
batch
.
Write
();
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
}
dbm
.
MustWrite
(
batch
)
}
// Iterate 依次迭代遍历树的所有键
...
...
@@ -711,15 +709,11 @@ func (ndb *nodeDB) Commit() error {
defer
ndb
.
mtx
.
Unlock
()
// Write saves
err
:=
ndb
.
batch
.
Write
()
if
err
!=
nil
{
panic
(
fmt
.
Sprint
(
"batch write err"
,
err
))
treelog
.
Error
(
"Commit batch.Write err"
,
"err"
,
err
)
}
dbm
.
MustWrite
(
ndb
.
batch
)
ndb
.
batch
=
nil
ndb
.
orphans
=
make
(
map
[
string
]
struct
{})
return
err
return
nil
}
// SetKVPair 设置kv对外接口
...
...
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