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
d4478393
Unverified
Commit
d4478393
authored
Apr 16, 2021
by
acud
Committed by
GitHub
Apr 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localstore: dont acquire batchMu for a single chunk that already exists (#1568)
parent
4d828902
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
mode_put.go
pkg/localstore/mode_put.go
+14
-1
No files found.
pkg/localstore/mode_put.go
View file @
d4478393
...
@@ -44,7 +44,7 @@ func (db *DB) Put(ctx context.Context, mode storage.ModePut, chs ...swarm.Chunk)
...
@@ -44,7 +44,7 @@ func (db *DB) Put(ctx context.Context, mode storage.ModePut, chs ...swarm.Chunk)
return
exist
,
err
return
exist
,
err
}
}
// put stores Chunks to database and updates other indexes. It acquires
lockAddr
// put stores Chunks to database and updates other indexes. It acquires
batchMu
// to protect two calls of this function for the same address in parallel. Item
// to protect two calls of this function for the same address in parallel. Item
// fields Address and Data must not be with their nil values. If chunks with the
// fields Address and Data must not be with their nil values. If chunks with the
// same address are passed in arguments, only the first chunk will be stored,
// same address are passed in arguments, only the first chunk will be stored,
...
@@ -52,6 +52,19 @@ func (db *DB) Put(ctx context.Context, mode storage.ModePut, chs ...swarm.Chunk)
...
@@ -52,6 +52,19 @@ func (db *DB) Put(ctx context.Context, mode storage.ModePut, chs ...swarm.Chunk)
// slice. This is the same behaviour as if the same chunks are passed one by one
// slice. This is the same behaviour as if the same chunks are passed one by one
// in multiple put method calls.
// in multiple put method calls.
func
(
db
*
DB
)
put
(
mode
storage
.
ModePut
,
chs
...
swarm
.
Chunk
)
(
exist
[]
bool
,
err
error
)
{
func
(
db
*
DB
)
put
(
mode
storage
.
ModePut
,
chs
...
swarm
.
Chunk
)
(
exist
[]
bool
,
err
error
)
{
// this is an optimization that tries to optimize on already existing chunks
// not needing to acquire batchMu. This is in order to reduce lock contention
// when chunks are retried across the network for whatever reason.
if
len
(
chs
)
==
1
&&
mode
!=
storage
.
ModePutRequestPin
&&
mode
!=
storage
.
ModePutUploadPin
{
has
,
err
:=
db
.
retrievalDataIndex
.
Has
(
chunkToItem
(
chs
[
0
]))
if
err
!=
nil
{
return
nil
,
err
}
if
has
{
return
[]
bool
{
true
},
nil
}
}
// protect parallel updates
// protect parallel updates
db
.
batchMu
.
Lock
()
db
.
batchMu
.
Lock
()
defer
db
.
batchMu
.
Unlock
()
defer
db
.
batchMu
.
Unlock
()
...
...
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