Skip to content

Commit e67764f

Browse files
authored
perf(selector): shard simple selector's in-memory locker by owner and jitter retries (#1981)
Signed-off-by: hstarorg <jayhu@sign.global>
1 parent 6ce27a4 commit e67764f

11 files changed

Lines changed: 765 additions & 231 deletions

File tree

token/services/selector/benchmark_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
type WalletIDByRawIdentityFunc func(rawIdentity []byte) string
2828

2929
type Locker interface {
30-
Lock(ctx context.Context, id *token2.ID, txID string, reclaim bool) (string, error)
31-
UnlockIDs(ctx context.Context, ids ...*token2.ID) []*token2.ID
30+
Lock(ctx context.Context, owner string, id *token2.ID, txID string, reclaim bool) (string, error)
31+
UnlockIDs(ctx context.Context, owner string, ids ...*token2.ID) []*token2.ID
3232
UnlockByTxID(ctx context.Context, txID string)
3333
IsLocked(id *token2.ID) bool
3434
}
@@ -43,9 +43,9 @@ func (s *extendedSelector) Select(ctx context.Context, ownerFilter token.OwnerFi
4343
}
4444
func (s *extendedSelector) Close() error { return s.Selector.Close() }
4545

46-
func (s *extendedSelector) Unselect(id ...*token2.ID) {
46+
func (s *extendedSelector) Unselect(owner string, id ...*token2.ID) {
4747
if s.Lock != nil {
48-
s.Lock.UnlockIDs(context.Background(), id...)
48+
s.Lock.UnlockIDs(context.Background(), owner, id...)
4949
}
5050
}
5151

@@ -72,7 +72,7 @@ func BenchmarkSelectorSingle(b *testing.B) {
7272
wg.Add(1)
7373
go func(ids []*token2.ID) {
7474
defer wg.Done()
75-
s.selector.Unselect(ids...)
75+
s.selector.Unselect(s.filter.ID(), ids...)
7676
}(ids)
7777
}
7878
})
@@ -110,7 +110,7 @@ func BenchmarkSelectorParallel(b *testing.B) {
110110
wg.Add(1)
111111
go func(ids []*token2.ID) {
112112
defer wg.Done()
113-
s.selector.Unselect(ids...)
113+
s.selector.Unselect(s.filter.ID(), ids...)
114114
}(ids)
115115
}
116116
})
@@ -199,7 +199,7 @@ type LockerProviderFunction func() selector.Locker
199199

200200
type ExtendedSelector interface {
201201
token.Selector
202-
Unselect(id ...*token2.ID)
202+
Unselect(owner string, id ...*token2.ID)
203203
}
204204

205205
type MockTokenIterator struct {

token/services/selector/sherdlock/inmemory/locker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
type Locker interface {
18-
Lock(ctx context.Context, id *token.ID, txID string, reclaim bool) (string, error)
18+
Lock(ctx context.Context, owner string, id *token.ID, txID string, reclaim bool) (string, error)
1919
UnlockByTxID(ctx context.Context, txID string)
2020
}
2121

@@ -32,7 +32,8 @@ func NewLocker(l Locker) *locker {
3232
}
3333

3434
func (l *locker) Lock(ctx context.Context, tokenID *token.ID, consumerTxID transaction.ID) error {
35-
_, err := l.Locker.Lock(ctx, tokenID, consumerTxID, false)
35+
// this adapter has no owner context; the empty owner shares one default shard
36+
_, err := l.Locker.Lock(ctx, "", tokenID, consumerTxID, false)
3637

3738
return err
3839
}

0 commit comments

Comments
 (0)