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
8a189752
Commit
8a189752
authored
Jan 29, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test and modify bug
parent
66826aa4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
21 deletions
+32
-21
kvmvccMavl.go
plugin/store/kvmvccMavl/kvmvccMavl.go
+22
-15
kvmvccMavl_test.go
plugin/store/kvmvccMavl/kvmvccMavl_test.go
+0
-0
kvmvccdb.go
plugin/store/kvmvccMavl/kvmvccdb.go
+9
-5
mavl.go
plugin/store/kvmvccMavl/mavl.go
+1
-1
No files found.
plugin/store/kvmvccMavl/kvmvccMavl.go
View file @
8a189752
...
@@ -20,6 +20,10 @@ var (
...
@@ -20,6 +20,10 @@ var (
kvmvccMavlFork
int64
=
200
*
10000
kvmvccMavlFork
int64
=
200
*
10000
)
)
const
(
canceSize
=
2048
//可以缓存2048个roothash, height对
)
// SetLogLevel set log level
// SetLogLevel set log level
func
SetLogLevel
(
level
string
)
{
func
SetLogLevel
(
level
string
)
{
...
@@ -78,26 +82,26 @@ func New(cfg *types.Store, sub []byte) queue.Module {
...
@@ -78,26 +82,26 @@ func New(cfg *types.Store, sub []byte) queue.Module {
subMavlcfg
.
EnableMavlPrune
=
subcfg
.
EnableMavlPrune
subMavlcfg
.
EnableMavlPrune
=
subcfg
.
EnableMavlPrune
subMavlcfg
.
PruneHeight
=
subcfg
.
PruneHeight
subMavlcfg
.
PruneHeight
=
subcfg
.
PruneHeight
}
}
cance
,
err
:=
lru
.
New
(
1024
)
cance
,
err
:=
lru
.
New
(
canceSize
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
"new KVMVCCMavlStore fail"
)
panic
(
"new KVMVCCMavlStore fail"
)
}
}
kvms
=
&
KVMVCCMavlStore
{
bs
,
NewKVMVCC
(
cfg
,
&
subKVMVCCcfg
,
bs
.
GetDB
()),
kvms
=
&
KVMVCCMavlStore
{
bs
,
NewKVMVCC
(
&
subKVMVCCcfg
,
bs
.
GetDB
()),
NewMavl
(
cfg
,
&
subMavlcfg
,
bs
.
GetDB
()),
cance
}
NewMavl
(
&
subMavlcfg
,
bs
.
GetDB
()),
cance
}
bs
.
SetChild
(
kvms
)
bs
.
SetChild
(
kvms
)
return
kvms
return
kvms
}
}
// Close the KVMVCCStore module
// Close the KVMVCC
Mavl
Store module
func
(
kvmMavls
*
KVMVCCMavlStore
)
Close
()
{
func
(
kvmMavls
*
KVMVCCMavlStore
)
Close
()
{
kvmMavls
.
BaseStore
.
Close
()
kvmMavls
.
BaseStore
.
Close
()
kvmMavls
.
KVMVCCStore
.
Close
()
kvmMavls
.
KVMVCCStore
.
Close
()
kvmMavls
.
MavlStore
.
Close
()
kvmMavls
.
MavlStore
.
Close
()
kmlog
.
Info
(
"store kv
db
closed"
)
kmlog
.
Info
(
"store kv
mMavls
closed"
)
}
}
// Set kvs with statehash to KVMVCCStore
// Set kvs with statehash to KVMVCC
Mavl
Store
func
(
kvmMavls
*
KVMVCCMavlStore
)
Set
(
datas
*
types
.
StoreSet
,
sync
bool
)
([]
byte
,
error
)
{
func
(
kvmMavls
*
KVMVCCMavlStore
)
Set
(
datas
*
types
.
StoreSet
,
sync
bool
)
([]
byte
,
error
)
{
// 这里后续需要考虑分叉回退
// 这里后续需要考虑分叉回退
if
datas
.
Height
<
kvmvccMavlFork
{
if
datas
.
Height
<
kvmvccMavlFork
{
...
@@ -105,7 +109,7 @@ func (kvmMavls *KVMVCCMavlStore) Set(datas *types.StoreSet, sync bool) ([]byte,
...
@@ -105,7 +109,7 @@ func (kvmMavls *KVMVCCMavlStore) Set(datas *types.StoreSet, sync bool) ([]byte,
if
err
!=
nil
{
if
err
!=
nil
{
return
hash
,
err
return
hash
,
err
}
}
_
,
err
=
kvmMavls
.
KVMVCCStore
.
Set
(
datas
,
sync
)
_
,
err
=
kvmMavls
.
KVMVCCStore
.
Set
(
datas
,
hash
,
sync
)
if
err
!=
nil
{
if
err
!=
nil
{
return
hash
,
err
return
hash
,
err
}
}
...
@@ -115,14 +119,14 @@ func (kvmMavls *KVMVCCMavlStore) Set(datas *types.StoreSet, sync bool) ([]byte,
...
@@ -115,14 +119,14 @@ func (kvmMavls *KVMVCCMavlStore) Set(datas *types.StoreSet, sync bool) ([]byte,
return
hash
,
err
return
hash
,
err
}
}
// 仅仅做kvmvcc
// 仅仅做kvmvcc
hash
,
err
:=
kvmMavls
.
KVMVCCStore
.
Set
(
datas
,
sync
)
hash
,
err
:=
kvmMavls
.
KVMVCCStore
.
Set
(
datas
,
nil
,
sync
)
if
err
==
nil
{
if
err
==
nil
{
kvmMavls
.
cance
.
Add
(
string
(
hash
),
datas
.
Height
)
kvmMavls
.
cance
.
Add
(
string
(
hash
),
datas
.
Height
)
}
}
return
hash
,
err
return
hash
,
err
}
}
// Get kvs with statehash from KVMVCCStore
// Get kvs with statehash from KVMVCC
Mavl
Store
func
(
kvmMavls
*
KVMVCCMavlStore
)
Get
(
datas
*
types
.
StoreGet
)
[][]
byte
{
func
(
kvmMavls
*
KVMVCCMavlStore
)
Get
(
datas
*
types
.
StoreGet
)
[][]
byte
{
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
datas
.
StateHash
));
ok
{
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
datas
.
StateHash
));
ok
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
...
@@ -133,7 +137,7 @@ func (kvmMavls *KVMVCCMavlStore) Get(datas *types.StoreGet) [][]byte {
...
@@ -133,7 +137,7 @@ func (kvmMavls *KVMVCCMavlStore) Get(datas *types.StoreGet) [][]byte {
return
kvmMavls
.
KVMVCCStore
.
Get
(
datas
)
return
kvmMavls
.
KVMVCCStore
.
Get
(
datas
)
}
}
// MemSet set kvs to the mem of KVMVCCStore module and return the StateHash
// MemSet set kvs to the mem of KVMVCC
Mavl
Store module and return the StateHash
func
(
kvmMavls
*
KVMVCCMavlStore
)
MemSet
(
datas
*
types
.
StoreSet
,
sync
bool
)
([]
byte
,
error
)
{
func
(
kvmMavls
*
KVMVCCMavlStore
)
MemSet
(
datas
*
types
.
StoreSet
,
sync
bool
)
([]
byte
,
error
)
{
// 这里后续需要考虑分叉回退
// 这里后续需要考虑分叉回退
if
datas
.
Height
<
kvmvccMavlFork
{
if
datas
.
Height
<
kvmvccMavlFork
{
...
@@ -141,7 +145,7 @@ func (kvmMavls *KVMVCCMavlStore) MemSet(datas *types.StoreSet, sync bool) ([]byt
...
@@ -141,7 +145,7 @@ func (kvmMavls *KVMVCCMavlStore) MemSet(datas *types.StoreSet, sync bool) ([]byt
if
err
!=
nil
{
if
err
!=
nil
{
return
hash
,
err
return
hash
,
err
}
}
_
,
err
=
kvmMavls
.
KVMVCCStore
.
MemSet
(
datas
,
sync
)
_
,
err
=
kvmMavls
.
KVMVCCStore
.
MemSet
(
datas
,
hash
,
sync
)
if
err
!=
nil
{
if
err
!=
nil
{
return
hash
,
err
return
hash
,
err
}
}
...
@@ -151,17 +155,17 @@ func (kvmMavls *KVMVCCMavlStore) MemSet(datas *types.StoreSet, sync bool) ([]byt
...
@@ -151,17 +155,17 @@ func (kvmMavls *KVMVCCMavlStore) MemSet(datas *types.StoreSet, sync bool) ([]byt
return
hash
,
err
return
hash
,
err
}
}
// 仅仅做kvmvcc
// 仅仅做kvmvcc
hash
,
err
:=
kvmMavls
.
KVMVCCStore
.
MemSet
(
datas
,
sync
)
hash
,
err
:=
kvmMavls
.
KVMVCCStore
.
MemSet
(
datas
,
nil
,
sync
)
if
err
==
nil
{
if
err
==
nil
{
kvmMavls
.
cance
.
Add
(
string
(
hash
),
datas
.
Height
)
kvmMavls
.
cance
.
Add
(
string
(
hash
),
datas
.
Height
)
}
}
return
hash
,
err
return
hash
,
err
}
}
// Commit kvs in the mem of KVMVCCStore module to state db and return the StateHash
// Commit kvs in the mem of KVMVCC
Mavl
Store module to state db and return the StateHash
func
(
kvmMavls
*
KVMVCCMavlStore
)
Commit
(
req
*
types
.
ReqHash
)
([]
byte
,
error
)
{
func
(
kvmMavls
*
KVMVCCMavlStore
)
Commit
(
req
*
types
.
ReqHash
)
([]
byte
,
error
)
{
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
req
.
Hash
));
ok
{
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
req
.
Hash
));
ok
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
hash
,
err
:=
kvmMavls
.
MavlStore
.
Commit
(
req
)
hash
,
err
:=
kvmMavls
.
MavlStore
.
Commit
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
hash
,
err
return
hash
,
err
...
@@ -177,7 +181,7 @@ func (kvmMavls *KVMVCCMavlStore) Commit(req *types.ReqHash) ([]byte, error) {
...
@@ -177,7 +181,7 @@ func (kvmMavls *KVMVCCMavlStore) Commit(req *types.ReqHash) ([]byte, error) {
return
kvmMavls
.
KVMVCCStore
.
Commit
(
req
)
return
kvmMavls
.
KVMVCCStore
.
Commit
(
req
)
}
}
// Rollback kvs in the mem of KVMVCCStore module and return the StateHash
// Rollback kvs in the mem of KVMVCC
Mavl
Store module and return the StateHash
func
(
kvmMavls
*
KVMVCCMavlStore
)
Rollback
(
req
*
types
.
ReqHash
)
([]
byte
,
error
)
{
func
(
kvmMavls
*
KVMVCCMavlStore
)
Rollback
(
req
*
types
.
ReqHash
)
([]
byte
,
error
)
{
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
req
.
Hash
));
ok
{
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
req
.
Hash
));
ok
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
...
@@ -201,10 +205,13 @@ func (kvmMavls *KVMVCCMavlStore) IterateRangeByStateHash(statehash []byte, start
...
@@ -201,10 +205,13 @@ func (kvmMavls *KVMVCCMavlStore) IterateRangeByStateHash(statehash []byte, start
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
statehash
));
ok
{
if
value
,
ok
:=
kvmMavls
.
cance
.
Get
(
string
(
statehash
));
ok
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
if
value
.
(
int64
)
<
kvmvccMavlFork
{
kvmMavls
.
MavlStore
.
IterateRangeByStateHash
(
statehash
,
start
,
end
,
ascending
,
fn
)
kvmMavls
.
MavlStore
.
IterateRangeByStateHash
(
statehash
,
start
,
end
,
ascending
,
fn
)
return
}
}
kvmMavls
.
KVMVCCStore
.
IterateRangeByStateHash
(
statehash
,
start
,
end
,
ascending
,
fn
)
kvmMavls
.
KVMVCCStore
.
IterateRangeByStateHash
(
statehash
,
start
,
end
,
ascending
,
fn
)
return
}
}
kvmMavls
.
KVMVCCStore
.
IterateRangeByStateHash
(
statehash
,
start
,
end
,
ascending
,
fn
)
kvmMavls
.
KVMVCCStore
.
IterateRangeByStateHash
(
statehash
,
start
,
end
,
ascending
,
fn
)
return
}
}
// ProcEvent handles supported events
// ProcEvent handles supported events
...
...
plugin/store/kvmvccMavl/kvmvccMavl_test.go
View file @
8a189752
This diff is collapsed.
Click to expand it.
plugin/store/kvmvccMavl/kvmvccdb.go
View file @
8a189752
...
@@ -26,7 +26,7 @@ type KVMVCCStore struct {
...
@@ -26,7 +26,7 @@ type KVMVCCStore struct {
// NewKVMVCC construct KVMVCCStore module
// NewKVMVCC construct KVMVCCStore module
func
NewKVMVCC
(
cfg
*
types
.
Store
,
sub
*
subKVMVCCConfig
,
db
dbm
.
DB
)
*
KVMVCCStore
{
func
NewKVMVCC
(
sub
*
subKVMVCCConfig
,
db
dbm
.
DB
)
*
KVMVCCStore
{
var
kvs
*
KVMVCCStore
var
kvs
*
KVMVCCStore
enable
:=
false
enable
:=
false
if
sub
!=
nil
{
if
sub
!=
nil
{
...
@@ -46,8 +46,10 @@ func (mvccs *KVMVCCStore) Close() {
...
@@ -46,8 +46,10 @@ func (mvccs *KVMVCCStore) Close() {
}
}
// Set kvs with statehash to KVMVCCStore
// Set kvs with statehash to KVMVCCStore
func
(
mvccs
*
KVMVCCStore
)
Set
(
datas
*
types
.
StoreSet
,
sync
bool
)
([]
byte
,
error
)
{
func
(
mvccs
*
KVMVCCStore
)
Set
(
datas
*
types
.
StoreSet
,
hash
[]
byte
,
sync
bool
)
([]
byte
,
error
)
{
hash
:=
calcHash
(
datas
)
if
hash
==
nil
{
hash
=
calcHash
(
datas
)
}
kvlist
,
err
:=
mvccs
.
mvcc
.
AddMVCC
(
datas
.
KV
,
hash
,
datas
.
StateHash
,
datas
.
Height
)
kvlist
,
err
:=
mvccs
.
mvcc
.
AddMVCC
(
datas
.
KV
,
hash
,
datas
.
StateHash
,
datas
.
Height
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -76,12 +78,14 @@ func (mvccs *KVMVCCStore) Get(datas *types.StoreGet) [][]byte {
...
@@ -76,12 +78,14 @@ func (mvccs *KVMVCCStore) Get(datas *types.StoreGet) [][]byte {
}
}
// MemSet set kvs to the mem of KVMVCCStore module and return the StateHash
// MemSet set kvs to the mem of KVMVCCStore module and return the StateHash
func
(
mvccs
*
KVMVCCStore
)
MemSet
(
datas
*
types
.
StoreSet
,
sync
bool
)
([]
byte
,
error
)
{
func
(
mvccs
*
KVMVCCStore
)
MemSet
(
datas
*
types
.
StoreSet
,
hash
[]
byte
,
sync
bool
)
([]
byte
,
error
)
{
kvset
,
err
:=
mvccs
.
checkVersion
(
datas
.
Height
)
kvset
,
err
:=
mvccs
.
checkVersion
(
datas
.
Height
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
hash
:=
calcHash
(
datas
)
if
hash
==
nil
{
hash
=
calcHash
(
datas
)
}
//kmlog.Debug("KVMVCCStore MemSet AddMVCC", "prestatehash", common.ToHex(datas.StateHash), "hash", common.ToHex(hash), "height", datas.Height)
//kmlog.Debug("KVMVCCStore MemSet AddMVCC", "prestatehash", common.ToHex(datas.StateHash), "hash", common.ToHex(hash), "height", datas.Height)
kvlist
,
err
:=
mvccs
.
mvcc
.
AddMVCC
(
datas
.
KV
,
hash
,
datas
.
StateHash
,
datas
.
Height
)
kvlist
,
err
:=
mvccs
.
mvcc
.
AddMVCC
(
datas
.
KV
,
hash
,
datas
.
StateHash
,
datas
.
Height
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/store/kvmvccMavl/mavl.go
View file @
8a189752
...
@@ -26,7 +26,7 @@ type MavlStore struct {
...
@@ -26,7 +26,7 @@ type MavlStore struct {
}
}
// NewMavl new mavl store module
// NewMavl new mavl store module
func
NewMavl
(
cfg
*
types
.
Store
,
sub
*
subMavlConfig
,
db
dbm
.
DB
)
*
MavlStore
{
func
NewMavl
(
sub
*
subMavlConfig
,
db
dbm
.
DB
)
*
MavlStore
{
var
subcfg
subMavlConfig
var
subcfg
subMavlConfig
if
sub
!=
nil
{
if
sub
!=
nil
{
subcfg
.
EnableMavlPrefix
=
sub
.
EnableMavlPrefix
subcfg
.
EnableMavlPrefix
=
sub
.
EnableMavlPrefix
...
...
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