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
e5fbcdbe
Commit
e5fbcdbe
authored
Mar 07, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add prune kvmvcc
parent
9a927074
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
18 deletions
+18
-18
round_state.go
plugin/consensus/tendermint/types/round_state.go
+0
-0
certutils.go
...rt/authority/tools/cryptogen/generator/utils/certutils.go
+0
-0
kvmvcc_mavl_test.go
plugin/store/kvmvccmavl/kvmvcc_mavl_test.go
+3
-4
kvmvccdb.go
plugin/store/kvmvccmavl/kvmvccdb.go
+15
-14
No files found.
plugin/consensus/tendermint/types/round_state.go
View file @
e5fbcdbe
plugin/dapp/cert/authority/tools/cryptogen/generator/utils/certutils.go
View file @
e5fbcdbe
plugin/store/kvmvccmavl/kvmvcc_mavl_test.go
View file @
e5fbcdbe
...
...
@@ -13,14 +13,15 @@ import (
"fmt"
"bytes"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
drivers
"github.com/33cn/chain33/system/store"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm
"github.com/33cn/chain33/common/db"
"bytes"
)
const
MaxKeylenth
int
=
64
...
...
@@ -541,7 +542,6 @@ func TestDelMavlData(t *testing.T) {
require
.
NoError
(
t
,
err
)
}
func
TestPruning
(
t
*
testing
.
T
)
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"example"
)
assert
.
Nil
(
t
,
err
)
...
...
@@ -551,7 +551,6 @@ func TestPruning(t *testing.T) {
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
kvmvccStore
:=
NewKVMVCC
(
&
subKVMVCCConfig
{},
store
.
GetDB
())
SetPruneHeight
(
10
)
...
...
plugin/store/kvmvccmavl/kvmvccdb.go
View file @
e5fbcdbe
...
...
@@ -5,15 +5,16 @@
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
(
...
...
@@ -21,7 +22,7 @@ const (
pruningStateEnd
=
0
onceScanCount
=
10000
// 单次扫描数目
onceCount
=
1000
// 容器长度
LevelPruningHeight
=
100
*
10000
levelPruningHeight
=
100
*
10000
)
var
(
...
...
@@ -36,11 +37,11 @@ var (
var
(
//同common/db中的mvcc相关的定义保持一致
mvccPrefix
=
[]
byte
(
".-mvcc-."
)
mvccMeta
=
append
(
mvccPrefix
,
[]
byte
(
"m."
)
...
)
//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."
)
...
)
//mvccLast
= append(mvccPrefix, []byte("l.")...)
//mvccMetaVersion
= append(mvccMeta, []byte("version.")...)
//
mvccMetaVersionKeyList = append(mvccMeta, []byte("versionkl.")...)
)
// KVMVCCStore provide kvmvcc store interface implementation
...
...
@@ -280,8 +281,8 @@ func calcHash(datas proto.Message) []byte {
return
common
.
Sha256
(
b
)
}
/*裁剪-------------------------------------------*/
//裁剪-------------------------------------------
// EnablePrune 使能裁剪
func
EnablePrune
(
enable
bool
)
{
enablePrune
=
enable
...
...
@@ -324,8 +325,8 @@ func pruningFirst(db dbm.DB, curHeight int64) {
continue
}
if
curHeight
<
int64
(
height
)
+
L
evelPruningHeight
&&
curHeight
>=
int64
(
height
)
+
int64
(
pruneHeight
)
{
if
curHeight
<
int64
(
height
)
+
l
evelPruningHeight
&&
curHeight
>=
int64
(
height
)
+
int64
(
pruneHeight
)
{
mp
[
string
(
key
)]
=
append
(
mp
[
string
(
key
)],
height
)
count
++
}
...
...
@@ -350,7 +351,7 @@ func deleteOldKV(mp map[string][]int64, curHeight int64, batch dbm.Batch) {
for
key
,
vals
:=
range
mp
{
if
len
(
vals
)
>
1
&&
vals
[
1
]
!=
vals
[
0
]
{
//防止相同高度时候出现的误删除
for
_
,
val
:=
range
vals
[
1
:
]
{
//从第二个开始判断
if
curHeight
>=
val
+
int64
(
pruneHeight
)
{
if
curHeight
>=
val
+
int64
(
pruneHeight
)
{
batch
.
Delete
(
genKeyVersion
([]
byte
(
key
),
val
))
// 删除老版本key
if
batch
.
ValueSize
()
>
batchDataSize
{
batch
.
Write
()
...
...
@@ -376,7 +377,7 @@ func getKeyVersion(vsnKey []byte) ([]byte, int64, error) {
if
!
bytes
.
Contains
(
vsnKey
,
mvccData
)
{
return
nil
,
0
,
types
.
ErrSize
}
if
len
(
vsnKey
)
<
len
(
mvccData
)
+
1
+
20
{
if
len
(
vsnKey
)
<
len
(
mvccData
)
+
1
+
20
{
return
nil
,
0
,
types
.
ErrSize
}
sLen
:=
vsnKey
[
len
(
vsnKey
)
-
20
:
]
...
...
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