good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
8c63d0d2
Commit
8c63d0d2
authored
6 years ago
by
Anton Evangelatov
Committed by
Péter Szilágyi
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
swarm/storage: extract isValid. correctly remove invalid chunks from store on migration (#17835)
parent
18950591
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swarm/storage/localstore.go
+21
-21
21 additions, 21 deletions
swarm/storage/localstore.go
with
21 additions
and
21 deletions
swarm/storage/localstore.go
+
21
−
21
View file @
8c63d0d2
...
...
@@ -83,6 +83,22 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
return
localStore
,
nil
}
// isValid returns true if chunk passes any of the LocalStore Validators.
// isValid also returns true if LocalStore has no Validators.
func
(
ls
*
LocalStore
)
isValid
(
chunk
Chunk
)
bool
{
// by default chunks are valid. if we have 0 validators, then all chunks are valid.
valid
:=
true
// ls.Validators contains a list of one validator per chunk type.
// if one validator succeeds, then the chunk is valid
for
_
,
v
:=
range
ls
.
Validators
{
if
valid
=
v
.
Validate
(
chunk
.
Address
(),
chunk
.
Data
());
valid
{
break
}
}
return
valid
}
// Put is responsible for doing validation and storage of the chunk
// by using configured ChunkValidators, MemStore and LDBStore.
// If the chunk is not valid, its GetErrored function will
...
...
@@ -96,15 +112,7 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
// After the LDBStore.Put, it is ensured that the MemStore
// contains the chunk with the same data, but nil ReqC channel.
func
(
ls
*
LocalStore
)
Put
(
ctx
context
.
Context
,
chunk
Chunk
)
error
{
valid
:=
true
// ls.Validators contains a list of one validator per chunk type.
// if one validator succeeds, then the chunk is valid
for
_
,
v
:=
range
ls
.
Validators
{
if
valid
=
v
.
Validate
(
chunk
.
Address
(),
chunk
.
Data
());
valid
{
break
}
}
if
!
valid
{
if
!
ls
.
isValid
(
chunk
)
{
return
ErrChunkInvalid
}
...
...
@@ -200,18 +208,10 @@ func (ls *LocalStore) Migrate() error {
if
schema
==
""
{
log
.
Debug
(
"running migrations for"
,
"schema"
,
schema
,
"runtime-schema"
,
CurrentDbSchema
)
cleanupFunc
:=
func
(
c
*
chunk
)
bool
{
// if one of the ls.Validators passes, it means a chunk is of particular type and it is valid
valid
:=
false
for
_
,
v
:=
range
ls
.
Validators
{
if
valid
=
v
.
Validate
(
c
.
Address
(),
c
.
Data
());
valid
{
break
}
}
return
valid
}
ls
.
DbStore
.
Cleanup
(
cleanupFunc
)
// delete chunks that are not valid, i.e. chunks that do not pass any of the ls.Validators
ls
.
DbStore
.
Cleanup
(
func
(
c
*
chunk
)
bool
{
return
!
ls
.
isValid
(
c
)
})
err
:=
ls
.
DbStore
.
PutSchema
(
DbSchemaPurity
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment