-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.2.0] Event ordering [API-1102] #696
Merged
utku-caglayan
merged 38 commits into
hazelcast:master
from
utku-caglayan:event-ordering
Dec 31, 2021
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
f40f3fe
remove unused field
utku-caglayan 134b168
fix typo
utku-caglayan e604b7e
Initial impl stripe executor impl:
utku-caglayan 33e3d78
handle executor start and stop
utku-caglayan ac232b7
handle partitionID -1
utku-caglayan 2563ce8
fix field alignment issues
utku-caglayan b546c1d
introduce "noSpecificPartition" variable to improve readability
utku-caglayan c4dc047
make queue size and worker count configurable
utku-caglayan 946ba9c
Merge branch 'master' into event-ordering
utku-caglayan eff8e8f
temporary fix for memory leak test
utku-caglayan 22155c9
decrease queue capacity, and document the differences
utku-caglayan 2f91eed
decrease queue capacity, and document the differences
utku-caglayan 16dd0b2
remove event executor configuration
utku-caglayan 7ae872c
address pr reviews for stripe executor
utku-caglayan 158c62e
fix failing "TestMarshalDefaultConfig" test
utku-caglayan 3491021
fix failing test
utku-caglayan c1efb0c
rename "ind" to "i"
utku-caglayan 3e90236
apply review suggestions
utku-caglayan b574499
add map event order test
utku-caglayan e51f5d3
increase TestClientStartShutdownMemoryLeak memory limit
utku-caglayan 9011983
refactor TestClientEventHandlingOrder to group events by partitionID
utku-caglayan f7df88d
refactor int32 to int
utku-caglayan 03fe449
refactor TestClientEventHandlingOrder logic
utku-caglayan 1c7a575
change behavior to not block on "dispatch" if event queue is full
utku-caglayan 2b65d5a
remove unused func
utku-caglayan 3bb2d0f
refactor return of "dispatch"
utku-caglayan ab26f81
undo older bad merge
utku-caglayan 6faa426
fix test to start partitionIDs from 0
utku-caglayan db4dcd6
improve tests
utku-caglayan 99b7971
add dispatch zero&negative key test
utku-caglayan 67d42e5
refactor constructor to raise panic on invalid conf
utku-caglayan 4d0c38c
refactor test for stability
utku-caglayan f8f778f
refactor stripeExecutor to pointer semantics
utku-caglayan 50b5bd5
minor improvement
utku-caglayan feab9ed
fix major bug
utku-caglayan df8e738
implement a blackbox event order test that fails on previous event or…
utku-caglayan 5fadb18
rename a helper func
utku-caglayan 76ee128
refactor struct for padding
utku-caglayan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package invocation | ||
|
||
import ( | ||
"math/rand" | ||
"runtime" | ||
"sync" | ||
) | ||
|
||
var ( | ||
// Default values differ from java impl. Also queue size is calculated differently. | ||
// Java Client: queueSize per worker = defaultEventQueueCapacity / defaultEventWorkerCount | ||
// Go Client: queueSize per worker = defaultEventQueueCapacity | ||
defaultEventQueueCapacity = 10000 | ||
defaultEventWorkerCount = runtime.NumCPU() | ||
) | ||
|
||
// executor represents the function that will run on workers of stripeExecutor. | ||
type executor func(queue chan func(), quit chan struct{}, wg *sync.WaitGroup) | ||
|
||
// stripeExecutor executes given "tasks" preserving the order among the ones that are given with the same key. | ||
type stripeExecutor struct { | ||
quit chan struct{} | ||
execFn executor | ||
taskQueues []chan func() | ||
queueCount int | ||
wg sync.WaitGroup | ||
} | ||
|
||
// newStripeExecutor returns a new stripeExecutor with default configuration. | ||
func newStripeExecutor() *stripeExecutor { | ||
return newStripeExecutorWithConfig(defaultEventWorkerCount, defaultEventQueueCapacity) | ||
} | ||
|
||
// newStripeExecutor returns a new stripeExecutor with configured queueCount and queueSize. If parameters are not greater than zero, it panics. | ||
func newStripeExecutorWithConfig(queueCount, queueSize int) *stripeExecutor { | ||
if queueCount <= 0 { | ||
panic("queueCount must be greater than 0") | ||
} | ||
if queueSize <= 0 { | ||
panic("queueSize must be greater than 0") | ||
} | ||
se := stripeExecutor{ | ||
taskQueues: make([]chan func(), queueCount), | ||
queueCount: queueCount, | ||
} | ||
for i := range se.taskQueues { | ||
se.taskQueues[i] = make(chan func(), queueSize) | ||
} | ||
se.quit = make(chan struct{}) | ||
se.execFn = defaultExecFn | ||
return &se | ||
} | ||
|
||
// start fires up the workers for each queue. | ||
func (se *stripeExecutor) start() { | ||
se.wg.Add(se.queueCount) | ||
for i := range se.taskQueues { | ||
go se.execFn(se.taskQueues[i], se.quit, &se.wg) | ||
} | ||
} | ||
|
||
// dispatch sends the handler "task" to one of the appropriate taskQueues, "tasks" with the same key end up on the same queue. Returns false if queue is full and could not dispatch. | ||
func (se *stripeExecutor) dispatch(key int, task func()) bool { | ||
if key < 0 { | ||
// dispatch random. | ||
key = rand.Intn(se.queueCount) | ||
} | ||
select { | ||
case se.taskQueues[key%se.queueCount] <- task: | ||
default: | ||
// do not block if queue is full. | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// stop blocks until all workers are stopped. | ||
func (se *stripeExecutor) stop() { | ||
close(se.quit) | ||
se.wg.Wait() | ||
} | ||
|
||
func defaultExecFn(queue chan func(), quit chan struct{}, wg *sync.WaitGroup) { | ||
defer wg.Done() | ||
for { | ||
select { | ||
case task := <-queue: | ||
task() | ||
case <-quit: | ||
return | ||
yuce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you refactor this so
m.Put
s run concurrently?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead implemented a blackbox one as we discussed df8e738