mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 08:10:50 +00:00
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.
This commit is contained in:
parent
6832b842b4
commit
7811d016b7
1 changed files with 6 additions and 1 deletions
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue