Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
vicotor
mybee
Commits
a80ab64a
Unverified
Commit
a80ab64a
authored
Nov 19, 2020
by
acud
Committed by
GitHub
Nov 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localstore: dont store chunk if it already exists (#979)
parent
09507fc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
19 deletions
+11
-19
mode_put.go
pkg/localstore/mode_put.go
+10
-18
mode_put_test.go
pkg/localstore/mode_put_test.go
+1
-1
No files found.
pkg/localstore/mode_put.go
View file @
a80ab64a
...
@@ -165,26 +165,18 @@ func (db *DB) put(mode storage.ModePut, chs ...swarm.Chunk) (exist []bool, err e
...
@@ -165,26 +165,18 @@ func (db *DB) put(mode storage.ModePut, chs ...swarm.Chunk) (exist []bool, err e
// The batch can be written to the database.
// The batch can be written to the database.
// Provided batch and binID map are updated.
// Provided batch and binID map are updated.
func
(
db
*
DB
)
putRequest
(
batch
*
leveldb
.
Batch
,
binIDs
map
[
uint8
]
uint64
,
item
shed
.
Item
)
(
exists
bool
,
gcSizeChange
int64
,
err
error
)
{
func
(
db
*
DB
)
putRequest
(
batch
*
leveldb
.
Batch
,
binIDs
map
[
uint8
]
uint64
,
item
shed
.
Item
)
(
exists
bool
,
gcSizeChange
int64
,
err
error
)
{
i
,
err
:=
db
.
retrievalDataIndex
.
Get
(
item
)
has
,
err
:=
db
.
retrievalDataIndex
.
Has
(
item
)
switch
{
if
err
!=
nil
{
case
err
==
nil
:
exists
=
true
item
.
StoreTimestamp
=
i
.
StoreTimestamp
item
.
BinID
=
i
.
BinID
case
errors
.
Is
(
err
,
leveldb
.
ErrNotFound
)
:
// no chunk accesses
exists
=
false
default
:
return
false
,
0
,
err
return
false
,
0
,
err
}
}
if
item
.
StoreTimestamp
==
0
{
if
has
{
item
.
StoreTimestamp
=
now
()
return
true
,
0
,
nil
}
}
if
item
.
BinID
==
0
{
item
.
BinID
,
err
=
db
.
incBinID
(
binIDs
,
db
.
po
(
swarm
.
NewAddress
(
item
.
Address
))
)
item
.
StoreTimestamp
=
now
(
)
if
err
!=
nil
{
item
.
BinID
,
err
=
db
.
incBinID
(
binIDs
,
db
.
po
(
swarm
.
NewAddress
(
item
.
Address
)))
return
false
,
0
,
err
if
err
!=
nil
{
}
return
false
,
0
,
err
}
}
gcSizeChange
,
err
=
db
.
setGC
(
batch
,
item
)
gcSizeChange
,
err
=
db
.
setGC
(
batch
,
item
)
...
@@ -197,7 +189,7 @@ func (db *DB) putRequest(batch *leveldb.Batch, binIDs map[uint8]uint64, item she
...
@@ -197,7 +189,7 @@ func (db *DB) putRequest(batch *leveldb.Batch, binIDs map[uint8]uint64, item she
return
false
,
0
,
err
return
false
,
0
,
err
}
}
return
exists
,
gcSizeChange
,
nil
return
false
,
gcSizeChange
,
nil
}
}
// putUpload adds an Item to the batch by updating required indexes:
// putUpload adds an Item to the batch by updating required indexes:
...
...
pkg/localstore/mode_put_test.go
View file @
a80ab64a
...
@@ -73,7 +73,7 @@ func TestModePutRequest(t *testing.T) {
...
@@ -73,7 +73,7 @@ func TestModePutRequest(t *testing.T) {
}
}
for
_
,
ch
:=
range
chunks
{
for
_
,
ch
:=
range
chunks
{
newRetrieveIndexesTestWithAccess
(
db
,
ch
,
storeTimestamp
,
want
Timestamp
)(
t
)
newRetrieveIndexesTestWithAccess
(
db
,
ch
,
storeTimestamp
,
store
Timestamp
)(
t
)
}
}
newItemsCountTest
(
db
.
gcIndex
,
tc
.
count
)(
t
)
newItemsCountTest
(
db
.
gcIndex
,
tc
.
count
)(
t
)
...
...
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