Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
张蕾
Geth-Modification
Commits
79532a25
Unverified
Commit
79532a25
authored
2 years ago
by
s7v7nislands
Committed by
GitHub
2 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/bloombits: use atomic type (#26993)
parent
881fed03
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
matcher.go
core/bloombits/matcher.go
+3
-3
matcher_test.go
core/bloombits/matcher_test.go
+6
-6
scheduler_test.go
core/bloombits/scheduler_test.go
+3
-3
No files found.
core/bloombits/matcher.go
View file @
79532a25
...
...
@@ -83,7 +83,7 @@ type Matcher struct {
retrievals
chan
chan
*
Retrieval
// Retriever processes waiting for task allocations
deliveries
chan
*
Retrieval
// Retriever processes waiting for task response deliveries
running
uint32
// Atomic flag whether a session is live or not
running
atomic
.
Bool
// Atomic flag whether a session is live or not
}
// NewMatcher creates a new pipeline for retrieving bloom bit streams and doing
...
...
@@ -146,10 +146,10 @@ func (m *Matcher) addScheduler(idx uint) {
// channel is closed.
func
(
m
*
Matcher
)
Start
(
ctx
context
.
Context
,
begin
,
end
uint64
,
results
chan
uint64
)
(
*
MatcherSession
,
error
)
{
// Make sure we're not creating concurrent sessions
if
atomic
.
SwapUint32
(
&
m
.
running
,
1
)
==
1
{
if
m
.
running
.
Swap
(
true
)
{
return
nil
,
errors
.
New
(
"matcher already running"
)
}
defer
atomic
.
StoreUint32
(
&
m
.
running
,
0
)
defer
m
.
running
.
Store
(
false
)
// Initiate a new matching round
session
:=
&
MatcherSession
{
...
...
This diff is collapsed.
Click to expand it.
core/bloombits/matcher_test.go
View file @
79532a25
...
...
@@ -160,7 +160,7 @@ func testMatcher(t *testing.T, filter [][]bloomIndexes, start, blocks uint64, in
}
}
// Track the number of retrieval requests made
var
requested
u
int32
var
requested
atomic
.
U
int32
// Start the matching session for the filter and the retriever goroutines
quit
:=
make
(
chan
struct
{})
...
...
@@ -208,15 +208,15 @@ func testMatcher(t *testing.T, filter [][]bloomIndexes, start, blocks uint64, in
session
.
Close
()
close
(
quit
)
if
retrievals
!=
0
&&
requested
!=
retrievals
{
t
.
Errorf
(
"filter = %v blocks = %v intermittent = %v: request count mismatch, have #%v, want #%v"
,
filter
,
blocks
,
intermittent
,
requested
,
retrievals
)
if
retrievals
!=
0
&&
requested
.
Load
()
!=
retrievals
{
t
.
Errorf
(
"filter = %v blocks = %v intermittent = %v: request count mismatch, have #%v, want #%v"
,
filter
,
blocks
,
intermittent
,
requested
.
Load
()
,
retrievals
)
}
return
requested
return
requested
.
Load
()
}
// startRetrievers starts a batch of goroutines listening for section requests
// and serving them.
func
startRetrievers
(
session
*
MatcherSession
,
quit
chan
struct
{},
retrievals
*
u
int32
,
batch
int
)
{
func
startRetrievers
(
session
*
MatcherSession
,
quit
chan
struct
{},
retrievals
*
atomic
.
U
int32
,
batch
int
)
{
requests
:=
make
(
chan
chan
*
Retrieval
)
for
i
:=
0
;
i
<
10
;
i
++
{
...
...
@@ -238,7 +238,7 @@ func startRetrievers(session *MatcherSession, quit chan struct{}, retrievals *ui
for
i
,
section
:=
range
task
.
Sections
{
if
rand
.
Int
()
%
4
!=
0
{
// Handle occasional missing deliveries
task
.
Bitsets
[
i
]
=
generateBitset
(
task
.
Bit
,
section
)
atomic
.
AddUint32
(
retrievals
,
1
)
retrievals
.
Add
(
1
)
}
}
request
<-
task
...
...
This diff is collapsed.
Click to expand it.
core/bloombits/scheduler_test.go
View file @
79532a25
...
...
@@ -45,13 +45,13 @@ func testScheduler(t *testing.T, clients int, fetchers int, requests int) {
fetch
:=
make
(
chan
*
request
,
16
)
defer
close
(
fetch
)
var
delivered
u
int32
var
delivered
atomic
.
U
int32
for
i
:=
0
;
i
<
fetchers
;
i
++
{
go
func
()
{
defer
fetchPend
.
Done
()
for
req
:=
range
fetch
{
atomic
.
AddUint32
(
&
delivered
,
1
)
delivered
.
Add
(
1
)
f
.
deliver
([]
uint64
{
req
.
section
+
uint64
(
requests
),
// Non-requested data (ensure it doesn't go out of bounds)
...
...
@@ -97,7 +97,7 @@ func testScheduler(t *testing.T, clients int, fetchers int, requests int) {
}
pend
.
Wait
()
if
have
:=
atomic
.
LoadUint32
(
&
delivered
);
int
(
have
)
!=
requests
{
if
have
:=
delivered
.
Load
(
);
int
(
have
)
!=
requests
{
t
.
Errorf
(
"request count mismatch: have %v, want %v"
,
have
,
requests
)
}
}
This diff is collapsed.
Click to expand it.
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