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
e5a109f0
Commit
e5a109f0
authored
Mar 05, 2019
by
vipwzw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto ci
parent
afa2401a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
40 deletions
+40
-40
main.go
main.go
+3
-2
kvmvcc_mavl.go
plugin/store/kvmvccmavl/kvmvcc_mavl.go
+3
-3
kvmvccdb.go
plugin/store/kvmvccmavl/kvmvccdb.go
+34
-35
No files found.
main.go
View file @
e5a109f0
...
...
@@ -12,11 +12,12 @@
package
main
import
(
"net/http"
"runtime/debug"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/util/cli"
_
"github.com/33cn/plugin/plugin"
"net/http"
"runtime/debug"
)
func
main
()
{
...
...
plugin/store/kvmvccmavl/kvmvcc_mavl.go
View file @
e5a109f0
...
...
@@ -63,9 +63,9 @@ type KVmMavlStore struct {
}
type
subKVMVCCConfig
struct
{
EnableMVCCIter
bool
`json:"enableMVCCIter"`
EnableMavlPrune
bool
`json:"enableMavlPrune"`
PruneHeight
int32
`json:"pruneHeight"`
EnableMVCCIter
bool
`json:"enableMVCCIter"`
EnableMavlPrune
bool
`json:"enableMavlPrune"`
PruneHeight
int32
`json:"pruneHeight"`
}
type
subMavlConfig
struct
{
...
...
plugin/store/kvmvccmavl/kvmvccdb.go
View file @
e5a109f0
...
...
@@ -5,23 +5,24 @@
package
kvmvccmavl
import
(
"bytes"
"fmt"
"strconv"
"sync/atomic"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/types"
"github.com/golang/protobuf/proto"
"sync/atomic"
"fmt"
"strconv"
"bytes"
)
const
(
pruningStateStart
=
1
pruningStateEnd
=
0
onceScanCount
=
10000
// 单次扫描数目
onceCount
=
1000
// 容器长度
LevelPruningHeight
=
100
*
10000
pruningStateStart
=
1
pruningStateEnd
=
0
onceScanCount
=
10000
// 单次扫描数目
onceCount
=
1000
// 容器长度
LevelPruningHeight
=
100
*
10000
)
var
(
...
...
@@ -29,28 +30,28 @@ var (
// 是否开启裁剪
enablePrune
bool
// 每个10000裁剪一次
pruneHeight
=
10000
pruningState
int32
pruneHeight
=
10000
pruningState
int32
)
var
(
//同common/db中的mvcc相关的定义保持一致
mvccPrefix
=
[]
byte
(
".-mvcc-."
)
mvccMeta
=
append
(
mvccPrefix
,
[]
byte
(
"m."
)
...
)
mvccData
=
append
(
mvccPrefix
,
[]
byte
(
"d."
)
...
)
mvccLast
=
append
(
mvccPrefix
,
[]
byte
(
"l."
)
...
)
mvccMetaVersion
=
append
(
mvccMeta
,
[]
byte
(
"version."
)
...
)
mvccMetaVersionKeyList
=
append
(
mvccMeta
,
[]
byte
(
"versionkl."
)
...
)
mvccPrefix
=
[]
byte
(
".-mvcc-."
)
mvccMeta
=
append
(
mvccPrefix
,
[]
byte
(
"m."
)
...
)
mvccData
=
append
(
mvccPrefix
,
[]
byte
(
"d."
)
...
)
mvccLast
=
append
(
mvccPrefix
,
[]
byte
(
"l."
)
...
)
mvccMetaVersion
=
append
(
mvccMeta
,
[]
byte
(
"version."
)
...
)
mvccMetaVersionKeyList
=
append
(
mvccMeta
,
[]
byte
(
"versionkl."
)
...
)
)
// KVMVCCStore provide kvmvcc store interface implementation
type
KVMVCCStore
struct
{
db
dbm
.
DB
mvcc
dbm
.
MVCC
kvsetmap
map
[
string
][]
*
types
.
KeyValue
enableMVCCIter
bool
enableMavlPrune
bool
pruneHeight
int32
db
dbm
.
DB
mvcc
dbm
.
MVCC
kvsetmap
map
[
string
][]
*
types
.
KeyValue
enableMVCCIter
bool
enableMavlPrune
bool
pruneHeight
int32
}
// NewKVMVCC construct KVMVCCStore module
...
...
@@ -62,10 +63,10 @@ func NewKVMVCC(sub *subKVMVCCConfig, db dbm.DB) *KVMVCCStore {
}
if
enable
{
kvs
=
&
KVMVCCStore
{
db
,
dbm
.
NewMVCCIter
(
db
),
make
(
map
[
string
][]
*
types
.
KeyValue
),
true
,
sub
.
EnableMavlPrune
,
sub
.
PruneHeight
}
true
,
sub
.
EnableMavlPrune
,
sub
.
PruneHeight
}
}
else
{
kvs
=
&
KVMVCCStore
{
db
,
dbm
.
NewMVCC
(
db
),
make
(
map
[
string
][]
*
types
.
KeyValue
),
false
,
sub
.
EnableMavlPrune
,
sub
.
PruneHeight
}
false
,
sub
.
EnableMavlPrune
,
sub
.
PruneHeight
}
}
EnablePrune
(
sub
.
EnableMavlPrune
)
SetPruneHeight
(
int
(
sub
.
PruneHeight
))
...
...
@@ -280,7 +281,6 @@ func calcHash(datas proto.Message) []byte {
return
common
.
Sha256
(
b
)
}
//裁剪-------------------------------------------
// EnablePrune 使能裁剪
func
EnablePrune
(
enable
bool
)
{
...
...
@@ -324,10 +324,10 @@ func pruningFirst(db dbm.DB, curHeight int64) {
continue
}
if
curHeight
<
int64
(
height
)
+
LevelPruningHeight
&&
curHeight
>=
int64
(
height
)
+
int64
(
pruneHeight
)
{
mp
[
string
(
key
)]
=
append
(
mp
[
string
(
key
)],
height
)
count
++
if
curHeight
<
int64
(
height
)
+
LevelPruningHeight
&&
curHeight
>=
int64
(
height
)
+
int64
(
pruneHeight
)
{
mp
[
string
(
key
)]
=
append
(
mp
[
string
(
key
)],
height
)
count
++
}
if
len
(
mp
)
>=
onceCount
-
1
||
count
>
onceScanCount
{
deleteOldKV
(
mp
,
curHeight
,
batch
)
...
...
@@ -344,8 +344,8 @@ func deleteOldKV(mp map[string][]int64, curHeight int64, batch dbm.Batch) {
batch
.
Reset
()
for
key
,
vals
:=
range
mp
{
if
len
(
vals
)
>
1
&&
vals
[
1
]
!=
vals
[
0
]
{
//防止相同高度时候出现的误删除
for
_
,
val
:=
range
vals
[
1
:
]
{
//从第二个开始判断
if
curHeight
>=
val
+
int64
(
pruneHeight
)
{
for
_
,
val
:=
range
vals
[
1
:
]
{
//从第二个开始判断
if
curHeight
>=
val
+
int64
(
pruneHeight
)
{
batch
.
Delete
(
genKeyVersion
([]
byte
(
key
),
val
))
// 删除老版本key
if
batch
.
ValueSize
()
>
batchDataSize
{
batch
.
Write
()
...
...
@@ -368,7 +368,7 @@ func genKeyVersion(key []byte, height int64) []byte {
}
func
getKeyVersion
(
vsnKey
[]
byte
)
([]
byte
,
int64
,
error
)
{
if
len
(
vsnKey
)
<=
len
(
mvccData
)
+
1
+
20
{
if
len
(
vsnKey
)
<=
len
(
mvccData
)
+
1
+
20
{
return
nil
,
0
,
types
.
ErrSize
}
sLen
:=
vsnKey
[
len
(
vsnKey
)
-
20
:
]
...
...
@@ -392,4 +392,4 @@ func isPruning() bool {
func
setPruning
(
state
int32
)
{
atomic
.
StoreInt32
(
&
pruningState
,
state
)
}
\ No newline at end of file
}
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