@@ -41,7 +41,6 @@ import (
41
41
"github.com/samber/lo"
42
42
"github.com/tidwall/gjson"
43
43
"golang.org/x/sync/errgroup"
44
- "golang.org/x/sync/singleflight"
45
44
46
45
"github.com/rudderlabs/rudder-go-kit/bytesize"
47
46
"github.com/rudderlabs/rudder-go-kit/config"
@@ -471,14 +470,13 @@ type Handle struct {
471
470
logger logger.Logger
472
471
stats stats.Stats
473
472
474
- datasetList []dataSetT
475
- datasetRangeList []dataSetRangeT
476
- dsRangeFuncMap map [string ]func () (dsRangeMinMax , error )
477
- distinctValuesCache * distinctValuesCache
478
- distinctParameterSingleFlight * singleflight.Group
479
- dsListLock * lock.Locker
480
- dsMigrationLock * lock.Locker
481
- noResultsCache * cache.NoResultsCache [ParameterFilterT ]
473
+ datasetList []dataSetT
474
+ datasetRangeList []dataSetRangeT
475
+ dsRangeFuncMap map [string ]func () (dsRangeMinMax , error )
476
+ distinctValuesCache * distinctValuesCache
477
+ dsListLock * lock.Locker
478
+ dsMigrationLock * lock.Locker
479
+ noResultsCache * cache.NoResultsCache [ParameterFilterT ]
482
480
483
481
// table count stats
484
482
statTableCount stats.Measurement
@@ -781,7 +779,6 @@ func (jd *Handle) init() {
781
779
jd .logger = logger .NewLogger ().Child ("jobsdb" ).Child (jd .tablePrefix )
782
780
}
783
781
jd .dsRangeFuncMap = make (map [string ]func () (dsRangeMinMax , error ))
784
- jd .distinctParameterSingleFlight = new (singleflight.Group )
785
782
jd .distinctValuesCache = NewDistinctValuesCache ()
786
783
787
784
if jd .config == nil {
@@ -1983,43 +1980,22 @@ func (jd *Handle) getDistinctValuesPerDataset(
1983
1980
}
1984
1981
1985
1982
func (jd * Handle ) GetDistinctParameterValues (ctx context.Context , parameter ParameterName ) ([]string , error ) {
1986
- res , err , shared := jd .distinctParameterSingleFlight .Do (parameter .string (), func () (interface {}, error ) {
1987
- if ! jd .dsMigrationLock .RTryLockWithCtx (ctx ) {
1988
- return nil , fmt .Errorf ("could not acquire a migration read lock: %w" , ctx .Err ())
1989
- }
1990
- defer jd .dsMigrationLock .RUnlock ()
1991
- if ! jd .dsListLock .RTryLockWithCtx (ctx ) {
1992
- return nil , fmt .Errorf ("could not acquire a dslist read lock: %w" , ctx .Err ())
1993
- }
1994
- dsList := jd .getDSList ()
1995
- jd .logger .Info (dsList )
1996
- jd .dsListLock .RUnlock ()
1997
- values , err := jd .distinctValuesCache .GetDistinctValues (
1998
- parameter .string (),
1999
- lo .Map (dsList , func (ds dataSetT , _ int ) string { return ds .JobTable }),
2000
- func (datasets []string ) (map [string ][]string , error ) {
2001
- return jd .getDistinctValuesPerDataset (datasets , parameter )
2002
- },
2003
- )
2004
- if err != nil {
2005
- return nil , err
2006
- }
2007
- return values , nil
2008
- })
2009
- if shared {
2010
- jd .stats .NewTaggedStat ("jobsdb_get_distinct_parameter_values_shared" , stats .CountType , stats.Tags {
2011
- "parameter" : parameter .string (),
2012
- "tablePrefix" : jd .tablePrefix ,
2013
- }).Increment ()
2014
- }
2015
- if err != nil {
2016
- return nil , err
1983
+ if ! jd .dsMigrationLock .RTryLockWithCtx (ctx ) {
1984
+ return nil , fmt .Errorf ("could not acquire a migration read lock: %w" , ctx .Err ())
2017
1985
}
2018
- val , ok := res .([] string )
2019
- if ! ok {
2020
- return nil , fmt .Errorf ("type assertion failed" )
1986
+ defer jd . dsMigrationLock . RUnlock ( )
1987
+ if ! jd . dsListLock . RTryLockWithCtx ( ctx ) {
1988
+ return nil , fmt .Errorf ("could not acquire a dslist read lock: %w" , ctx . Err () )
2021
1989
}
2022
- return val , nil
1990
+ dsList := jd .getDSList ()
1991
+ jd .dsListLock .RUnlock ()
1992
+ return jd .distinctValuesCache .GetDistinctValues (
1993
+ parameter .string (),
1994
+ lo .Map (dsList , func (ds dataSetT , _ int ) string { return ds .JobTable }),
1995
+ func (datasets []string ) (map [string ][]string , error ) {
1996
+ return jd .getDistinctValuesPerDataset (datasets , parameter )
1997
+ },
1998
+ )
2023
1999
}
2024
2000
2025
2001
func (jd * Handle ) doStoreJobsInTx (ctx context.Context , tx * Tx , ds dataSetT , jobList []* JobT ) error {
0 commit comments