Skip to content

Commit

Permalink
Only initialize a single index claims manager instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Nov 10, 2020
1 parent 0a6eb31 commit 5fb09f5
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/dbnode/persist/fs/index_claims_manager.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package fs

import (
Expand All @@ -11,6 +31,11 @@ import (
xtime "github.com/m3db/m3/src/x/time"
)

var (
defaultIndexClaimsManagerOnce sync.Once
defaultIndexClaimsManager *indexClaimsManager
)

type indexClaimsManager struct {
sync.Mutex

Expand All @@ -29,15 +54,18 @@ type volumeIndexClaim struct {

// NewIndexClaimsManager returns an instance of the index claim manager. This manages
// concurrent claims for volume indices per ns and block start.
// NB(bodu): There should be only a single shared index claim manager among all threads
// writing index data filesets.
func NewIndexClaimsManager(opts Options) IndexClaimsManager {
return &indexClaimsManager{
filePathPrefix: opts.FilePathPrefix(),
nowFn: opts.ClockOptions().NowFn(),
volumeIndexClaims: make(map[string]map[xtime.UnixNano]volumeIndexClaim),
nextIndexFileSetVolumeIndexFn: NextIndexFileSetVolumeIndex,
}
// NB(bodu): There should be only a single shared index claim manager among all threads
// writing index data filesets so we only initialize and return a single instance.
defaultIndexClaimsManagerOnce.Do(func() {
defaultIndexClaimsManager = &indexClaimsManager{
filePathPrefix: opts.FilePathPrefix(),
nowFn: opts.ClockOptions().NowFn(),
volumeIndexClaims: make(map[string]map[xtime.UnixNano]volumeIndexClaim),
nextIndexFileSetVolumeIndexFn: NextIndexFileSetVolumeIndex,
}
})
return defaultIndexClaimsManager
}

func (i *indexClaimsManager) ClaimNextIndexFileSetVolumeIndex(
Expand Down

0 comments on commit 5fb09f5

Please sign in to comment.