Skip to content
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

Optimization of fetcher with notifiers #733

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions token/services/selector/sherdlock/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"time"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections"
driver3 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/metrics"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
driver2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/tokendb"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
)
Expand Down Expand Up @@ -67,7 +69,7 @@ type fetcherProvider struct {

var fetchers = map[FetcherStrategy]fetchFunc{
Mixed: func(db *tokendb.DB, notifier *tokendb.Notifier, m *Metrics) tokenFetcher {
return newMixedFetcher(db, m)
return newMixedFetcher(db, notifier, m)
},
}

Expand Down Expand Up @@ -107,7 +109,12 @@ type mixedFetcher struct {
m *Metrics
}

func newMixedFetcher(tokenDB TokenDB, m *Metrics) *mixedFetcher {
func newMixedFetcher(tokenDB TokenDB, tokenNotifier driver2.TokenNotifier, m *Metrics) *mixedFetcher {
if err := tokenNotifier.Subscribe(func(operation driver3.Operation, m map[driver3.ColumnKey]string) {
logger.Warnf("New operation %v: [%v]", operation, m)
}); err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not returning an error here, so the code can resort to another strategy?

}
return &mixedFetcher{
lazyFetcher: NewLazyFetcher(tokenDB),
eagerFetcher: newCachedFetcher(tokenDB, freshnessInterval, maxQueries),
Expand Down
6 changes: 5 additions & 1 deletion token/services/selector/sherdlock/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,9 @@ func createManager(pgConnStr string, backoff time.Duration) (testutils.EnhancedM
if err != nil {
return nil, err
}
return testutils.NewEnhancedManager(NewManager(newMixedFetcher(tokenDB, newMetrics(&disabled.Provider{})), lockDB, testutils.TokenQuantityPrecision, backoff, 0), tokenDB), nil
tokenNotifier, err := postgres.NewTokenNotifier(db, opts)
if err != nil {
return nil, err
}
return testutils.NewEnhancedManager(NewManager(newMixedFetcher(tokenDB, tokenNotifier, newMetrics(&disabled.Provider{})), lockDB, testutils.TokenQuantityPrecision, backoff, 0), tokenDB), nil
}
Loading