mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-12 15:51:01 +00:00
get read lock only where possible in Holder
This commit is contained in:
parent
430b8a6118
commit
ec09582f44
1 changed files with 11 additions and 5 deletions
16
holder.go
16
holder.go
|
|
@ -234,8 +234,8 @@ func (h *Holder) Close() error {
|
|||
// This is used to determine if the rebalancing of data is necessary
|
||||
// when a node joins the cluster.
|
||||
func (h *Holder) HasData() (bool, error) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
if len(h.indexes) > 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
|
@ -385,15 +385,21 @@ func (h *Holder) CreateIndex(name string, opt IndexOptions) (*Index, error) {
|
|||
// CreateIndexIfNotExists returns an index by name.
|
||||
// The index is created if it does not already exist.
|
||||
func (h *Holder) CreateIndexIfNotExists(name string, opt IndexOptions) (*Index, error) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
h.mu.RLock()
|
||||
|
||||
// Find index in cache first.
|
||||
if index := h.indexes[name]; index != nil {
|
||||
h.mu.RUnlock()
|
||||
return index, nil
|
||||
}
|
||||
|
||||
return h.createIndex(name, opt)
|
||||
h.mu.RUnlock()
|
||||
|
||||
index, err := h.CreateIndex(name, opt)
|
||||
if _, ok := err.(ConflictError); err != nil && !ok {
|
||||
return nil, err
|
||||
}
|
||||
return index, nil
|
||||
}
|
||||
|
||||
func (h *Holder) createIndex(name string, opt IndexOptions) (*Index, error) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue