From 76e41817404398a22c485abf994be2e601851f7e Mon Sep 17 00:00:00 2001 From: Seebs Date: Fri, 5 Mar 2021 15:56:02 -0600 Subject: [PATCH] don't reuse sync.Mutex between translate readers The functional option and returned closure combine to result in us using the same sync.Mutex object for every TranslateReader on a given server, which means that if one of them isn't producing anything, we eventually end up waiting on that with all the others blocked waiting for the lock. Use separate locks for each, of the same type as the one initially provided as a template. This does mean that multiple readers can be operating at once, but in theory no two readers should ever be writing to the same stores, we think. --- http/translator.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/http/translator.go b/http/translator.go index 0722dcbf9..a5d1e4152 100644 --- a/http/translator.go +++ b/http/translator.go @@ -22,6 +22,7 @@ import ( "io" "io/ioutil" "net/http" + "reflect" "sync" "github.com/pilosa/pilosa/v2" @@ -33,8 +34,12 @@ func GetOpenTranslateReaderFunc(client *http.Client) pilosa.OpenTranslateReaderF } func GetOpenTranslateReaderWithLockerFunc(client *http.Client, locker sync.Locker) pilosa.OpenTranslateReaderFunc { + lockType := reflect.TypeOf(locker) + if lockType.Kind() == reflect.Ptr { + lockType = lockType.Elem() + } return func(ctx context.Context, nodeURL string, offsets pilosa.TranslateOffsetMap) (pilosa.TranslateEntryReader, error) { - return openTranslateReader(ctx, nodeURL, offsets, client, locker) + return openTranslateReader(ctx, nodeURL, offsets, client, reflect.New(lockType).Interface().(sync.Locker)) } }