Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postings list cache to M3DB index #1370

Merged
merged 5 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/development/m3_stack/m3dbnode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ db:
cache:
series:
policy: lru
postingsList:
richardartoul marked this conversation as resolved.
Show resolved Hide resolved
size: 262144

commitlog:
flushMaxBytes: 524288
Expand Down
56 changes: 56 additions & 0 deletions src/cmd/services/m3dbnode/config/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ package config

import "github.com/m3db/m3/src/dbnode/storage/series"

var (
defaultPostingsListCacheSize = 2 << 17 // 262,144
defaultPostingsListCacheRegexp = true
defaultPostingsListCacheTerms = true
)

// CacheConfigurations is the cache configurations.
type CacheConfigurations struct {
// Series cache policy.
Series *SeriesCacheConfiguration `yaml:"series"`

// PostingsList cache policy.
PostingsList *PostingsListCacheConfiguration `yaml:"postingsList"`
}

// SeriesConfiguration returns the series cache configuration or default
Expand All @@ -38,6 +47,16 @@ func (c CacheConfigurations) SeriesConfiguration() SeriesCacheConfiguration {
return *c.Series
}

// PostingsListConfiguration returns the postings list cache configuration
// or default if none is specified.
func (c CacheConfigurations) PostingsListConfiguration() PostingsListCacheConfiguration {
if c.PostingsList == nil {
return PostingsListCacheConfiguration{}
}

return *c.PostingsList
}

// SeriesCacheConfiguration is the series cache configuration.
type SeriesCacheConfiguration struct {
Policy series.CachePolicy `yaml:"policy"`
Expand All @@ -50,3 +69,40 @@ type LRUSeriesCachePolicyConfiguration struct {
MaxBlocks uint `yaml:"maxBlocks" validate:"nonzero"`
EventsChannelSize uint `yaml:"eventsChannelSize" validate:"nonzero"`
}

// PostingsListCacheConfiguration is the postings list cache configuration.
type PostingsListCacheConfiguration struct {
Size *int `yaml:"size"`
CacheRegexp *bool `yaml:"cacheRegexp"`
CacheTerms *bool `yaml:"cacheTerms"`
}

// SizeOrDefault returns the provided size or the default value is none is
// provided.
func (p *PostingsListCacheConfiguration) SizeOrDefault() int {
if p.Size == nil {
return defaultPostingsListCacheSize
}

return *p.Size
}

// CacheRegexpOrDefault returns the provided cache regexp configuration value
// or the default value is none is provided.
func (p *PostingsListCacheConfiguration) CacheRegexpOrDefault() bool {
if p.CacheRegexp == nil {
return defaultPostingsListCacheRegexp
}

return *p.CacheRegexp
}

// CacheTermsOrDefault returns the provided cache terms configuration value
// or the default value is none is provided.
func (p *PostingsListCacheConfiguration) CacheTermsOrDefault() bool {
if p.CacheTerms == nil {
return defaultPostingsListCacheTerms
}

return *p.CacheTerms
}
10 changes: 10 additions & 0 deletions src/cmd/services/m3dbnode/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ db:
level: info
file: /var/log/m3dbnode.log

cache:
postingsList:
size: 100
cacheRegexp: false
cacheTerms: false

metrics:
prometheus:
handlerPath: /metrics
Expand Down Expand Up @@ -381,6 +387,10 @@ func TestConfiguration(t *testing.T) {
blockRetrieve: null
cache:
series: null
postingsList:
size: 100
cacheRegexp: false
cacheTerms: false
fs:
filePathPrefix: /var/lib/m3db
writeBufferSize: 65536
Expand Down
2 changes: 2 additions & 0 deletions src/dbnode/config/m3dbnode-cluster-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ db:
cache:
series:
policy: lru
postingsList:
size: 262144

commitlog:
flushMaxBytes: 524288
Expand Down
2 changes: 2 additions & 0 deletions src/dbnode/config/m3dbnode-local-etcd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ db:
cache:
series:
policy: lru
postingsList:
size: 262144

commitlog:
flushMaxBytes: 524288
Expand Down
2 changes: 2 additions & 0 deletions src/dbnode/config/m3dbnode-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ db:
cache:
series:
policy: lru
postingsList:
size: 262144

commitlog:
flushMaxBytes: 524288
Expand Down
16 changes: 15 additions & 1 deletion src/dbnode/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,21 @@ func newTestSetup(t *testing.T, opts testOptions, fsOpts fs.Options) (*testSetup
if opts.WriteNewSeriesAsync() {
indexMode = index.InsertAsync
}
storageOpts = storageOpts.SetIndexOptions(storageOpts.IndexOptions().SetInsertMode(indexMode))

plCache, stopReporting, err := index.NewPostingsListCache(10, index.PostingsListCacheOptions{
InstrumentOptions: iOpts,
})
if err != nil {
return nil, fmt.Errorf("unable to create postings list cache: %v", err)
}
// Ok to run immediately since it just closes the background reporting loop. Only ok because
// this is a test setup, in production we would want the metrics.
stopReporting()

indexOpts := storageOpts.IndexOptions().
SetInsertMode(indexMode).
SetPostingsListCache(plCache)
storageOpts = storageOpts.SetIndexOptions(indexOpts)

runtimeOptsMgr := storageOpts.RuntimeOptionsManager()
runtimeOpts := runtimeOptsMgr.Get().
Expand Down
3 changes: 2 additions & 1 deletion src/dbnode/persist/fs/index_read_segments.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func ReadIndexSegments(
return nil, err
}

seg, err := newPersistentSegment(fileset, fsOpts.FSTOptions())
fstOpts := fsOpts.FSTOptions()
seg, err := newPersistentSegment(fileset, fstOpts)
if err != nil {
return nil, err
}
Expand Down
78 changes: 39 additions & 39 deletions src/dbnode/persist/fs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,65 +313,65 @@ type IndexFileSetReader interface {
Validate() error
}

// Options represents the options for filesystem persistence
// Options represents the options for filesystem persistence.
type Options interface {
// Validate will validate the options and return an error if not valid
// Validate will validate the options and return an error if not valid.
Validate() error

// SetClockOptions sets the clock options
// SetClockOptions sets the clock options.
SetClockOptions(value clock.Options) Options

// ClockOptions returns the clock options
// ClockOptions returns the clock options.
ClockOptions() clock.Options

// SetInstrumentOptions sets the instrumentation options
// SetInstrumentOptions sets the instrumentation options.
SetInstrumentOptions(value instrument.Options) Options

// InstrumentOptions returns the instrumentation options
// InstrumentOptions returns the instrumentation options.
InstrumentOptions() instrument.Options

// SetRuntimeOptionsManager sets the runtime options manager
// SetRuntimeOptionsManager sets the runtime options manager.
SetRuntimeOptionsManager(value runtime.OptionsManager) Options

// RuntimeOptionsManager returns the runtime options manager
// RuntimeOptionsManager returns the runtime options manager.
RuntimeOptionsManager() runtime.OptionsManager

// SetDecodingOptions sets the decoding options
// SetDecodingOptions sets the decoding options.
SetDecodingOptions(value msgpack.DecodingOptions) Options

// DecodingOptions returns the decoding options
// DecodingOptions returns the decoding options.
DecodingOptions() msgpack.DecodingOptions

// SetFilePathPrefix sets the file path prefix for sharded TSDB files
// SetFilePathPrefix sets the file path prefix for sharded TSDB files.
SetFilePathPrefix(value string) Options

// FilePathPrefix returns the file path prefix for sharded TSDB files
// FilePathPrefix returns the file path prefix for sharded TSDB files.
FilePathPrefix() string

// SetNewFileMode sets the new file mode
// SetNewFileMode sets the new file mode.
SetNewFileMode(value os.FileMode) Options

// NewFileMode returns the new file mode
// NewFileMode returns the new file mode.
NewFileMode() os.FileMode

// SetNewDirectoryMode sets the new directory mode
// SetNewDirectoryMode sets the new directory mode.
SetNewDirectoryMode(value os.FileMode) Options

// NewDirectoryMode returns the new directory mode
// NewDirectoryMode returns the new directory mode.
NewDirectoryMode() os.FileMode

// SetIndexSummariesPercent size sets the percent of index summaries to write
// SetIndexSummariesPercent size sets the percent of index summaries to write.
SetIndexSummariesPercent(value float64) Options

// IndexSummariesPercent size returns the percent of index summaries to write
// IndexSummariesPercent size returns the percent of index summaries to write.
IndexSummariesPercent() float64

// SetIndexBloomFilterFalsePositivePercent size sets the percent of false positive
// rate to use for the index bloom filter size and k hashes estimation
SetIndexBloomFilterFalsePositivePercent(value float64) Options

// IndexBloomFilterFalsePositivePercent size returns the percent of false positive
// rate to use for the index bloom filter size and k hashes estimation
// rate to use for the index bloom filter size and k hashes estimation.
IndexBloomFilterFalsePositivePercent() float64

// SetForceIndexSummariesMmapMemory sets whether the summaries files will be mmap'd
Expand All @@ -382,66 +382,66 @@ type Options interface {
// as an anonymous region, or as a file.
ForceIndexSummariesMmapMemory() bool

// SetForceBloomFilterMmapMemory sets whether the bloom filters will be mmap'd
// SetForceBloomFilterMmapMemory sets whether the bloom filters will be mmap'd.
// as an anonymous region, or as a file.
SetForceBloomFilterMmapMemory(value bool) Options

// ForceBloomFilterMmapMemory returns whether the bloom filters will be mmap'd
// ForceBloomFilterMmapMemory returns whether the bloom filters will be mmap'd.
// as an anonymous region, or as a file.
ForceBloomFilterMmapMemory() bool

// SetWriterBufferSize sets the buffer size for writing TSDB files
// SetWriterBufferSize sets the buffer size for writing TSDB files.
SetWriterBufferSize(value int) Options

// WriterBufferSize returns the buffer size for writing TSDB files
// WriterBufferSize returns the buffer size for writing TSDB files.
WriterBufferSize() int

// SetInfoReaderBufferSize sets the buffer size for reading TSDB info, digest and checkpoint files
// SetInfoReaderBufferSize sets the buffer size for reading TSDB info, digest and checkpoint files.
SetInfoReaderBufferSize(value int) Options

// InfoReaderBufferSize returns the buffer size for reading TSDB info, digest and checkpoint files
// InfoReaderBufferSize returns the buffer size for reading TSDB info, digest and checkpoint files.
InfoReaderBufferSize() int

// SetDataReaderBufferSize sets the buffer size for reading TSDB data and index files
// SetDataReaderBufferSize sets the buffer size for reading TSDB data and index files.
SetDataReaderBufferSize(value int) Options

// DataReaderBufferSize returns the buffer size for reading TSDB data and index files
// DataReaderBufferSize returns the buffer size for reading TSDB data and index files.
DataReaderBufferSize() int

// SetSeekReaderBufferSize size sets the buffer size for seeking TSDB files
// SetSeekReaderBufferSize size sets the buffer size for seeking TSDB files.
SetSeekReaderBufferSize(value int) Options

// SeekReaderBufferSize size returns the buffer size for seeking TSDB files
// SeekReaderBufferSize size returns the buffer size for seeking TSDB files.
SeekReaderBufferSize() int

// SetMmapEnableHugeTLB sets whether mmap huge pages are enabled when running on linux
// SetMmapEnableHugeTLB sets whether mmap huge pages are enabled when running on linux.
SetMmapEnableHugeTLB(value bool) Options

// MmapEnableHugeTLB returns whether mmap huge pages are enabled when running on linux
// MmapEnableHugeTLB returns whether mmap huge pages are enabled when running on linux.
MmapEnableHugeTLB() bool

// SetMmapHugeTLBThreshold sets the threshold when to use mmap huge pages for mmap'd files on linux
// SetMmapHugeTLBThreshold sets the threshold when to use mmap huge pages for mmap'd files on linux.
SetMmapHugeTLBThreshold(value int64) Options

// MmapHugeTLBThreshold returns the threshold when to use mmap huge pages for mmap'd files on linux
// MmapHugeTLBThreshold returns the threshold when to use mmap huge pages for mmap'd files on linux.
MmapHugeTLBThreshold() int64

// SetTagEncoderPool sets the tag encoder pool
// SetTagEncoderPool sets the tag encoder pool.
SetTagEncoderPool(value serialize.TagEncoderPool) Options

// TagEncoderPool returns the tag encoder pool
// TagEncoderPool returns the tag encoder pool.
TagEncoderPool() serialize.TagEncoderPool

// SetTagDecoderPool sets the tag decoder pool
// SetTagDecoderPool sets the tag decoder pool.
SetTagDecoderPool(value serialize.TagDecoderPool) Options

// TagDecoderPool returns the tag decoder pool
// TagDecoderPool returns the tag decoder pool.
TagDecoderPool() serialize.TagDecoderPool

// SetFStOptions sets the fst options
// SetFStOptions sets the fst options.
SetFSTOptions(value fst.Options) Options

// FSTOptions returns the fst options
// FSTOptions returns the fst options.
FSTOptions() fst.Options
}

Expand Down
Loading