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

Cold flushes #1624

Merged
merged 18 commits into from
Jun 7, 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
35 changes: 33 additions & 2 deletions src/dbnode/generated-source-files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ genny-map-storage-bootstrap-result:
.PHONY: genny-map-storage
genny-map-storage: \
genny-map-storage-database-namespaces \
genny-map-storage-shard
genny-map-storage-shard \
genny-map-storage-dirty-series

# Map generation rule for storage/databaseNamespacesMap
.PHONY: genny-map-storage-database-namespaces
Expand Down Expand Up @@ -129,6 +130,21 @@ genny-map-storage-bootstrap-bootstrapper-commitlog:
mv -f $(m3db_package_path)/src/dbnode/storage/bootstrap/bootstrapper/commitlog/map_gen.go $(m3db_package_path)/src/dbnode/storage/bootstrap/bootstrapper/commitlog/metadata_and_encoders_by_time_map_gen.go
mv -f $(m3db_package_path)/src/dbnode/storage/bootstrap/bootstrapper/commitlog/new_map_gen.go $(m3db_package_path)/src/dbnode/storage/bootstrap/bootstrapper/commitlog/metadata_and_encoders_by_time_new_map_gen.go

# Map generation rule for persist/fs
.PHONY: genny-map-persist-fs
genny-map-persist-fs:
cd $(m3x_package_path) && make idhashmap-gen \
pkg=fs \
value_type=checked.Bytes \
target_package=$(m3db_package)/src/dbnode/persist/fs \
rename_constructor=newCheckedBytesByIDMap \
rename_constructor_options=newCheckedBytesByIDMapOptions \
rename_type_prefix=checkedBytes \
rename_nogen_value=true
# Rename both generated map and constructor files
mv -f $(m3db_package_path)/src/dbnode/persist/fs/map_gen.go $(m3db_package_path)/src/dbnode/persist/fs/checked_bytes_by_id_map_gen.go
mv -f $(m3db_package_path)/src/dbnode/persist/fs/new_map_gen.go $(m3db_package_path)/src/dbnode/persist/fs/checked_bytes_by_id_new_map_gen.go

# Map generation rule for storage/index/ResultsMap
.PHONY: genny-map-storage-index-results
genny-map-storage-index-results:
Expand Down Expand Up @@ -170,7 +186,22 @@ genny-map-storage-index-aggregation-results: genny-map-storage-index-aggregate-v
# This map has a custom constructor; delete the genny generated one
rm -f $(m3db_package_path)/src/dbnode/storage/index/new_map_gen.go

# generation rule for all generated arraypools
# Map generation rule for storage/DirtySeriesMap
.PHONY: genny-map-storage-dirty-series
genny-map-storage-dirty-series:
cd $(m3x_package_path) && make hashmap-gen \
pkg=storage \
key_type=idAndBlockStart \
value_type=*idElement \
value_type_alias=idElement \
target_package=$(m3db_package)/src/dbnode/storage \
rename_type_prefix=dirtySeries
# Rename both generated map and constructor files
mv -f $(m3db_package_path)/src/dbnode/storage/map_gen.go $(m3db_package_path)/src/dbnode/storage/dirty_series_map_gen.go
# This map has a custom constructor; delete the genny generated one
rm -f $(m3db_package_path)/src/dbnode/storage/new_map_gen.go

# Generation rule for all generated arraypools
.PHONY: genny-arraypool-all
genny-arraypool-all: \
genny-arraypool-node-segments \
Expand Down
2 changes: 1 addition & 1 deletion src/dbnode/generated/mocks/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// mockgen rules for generating mocks for exported interfaces (reflection mode)

//go:generate sh -c "mockgen -package=fs $PACKAGE/src/dbnode/persist/fs DataFileSetWriter,DataFileSetReader,DataFileSetSeeker,IndexFileSetWriter,IndexFileSetReader,IndexSegmentFileSetWriter,IndexSegmentFileSet,IndexSegmentFile,SnapshotMetadataFileWriter,DataFileSetSeekerManager,ConcurrentDataFileSetSeeker | genclean -pkg $PACKAGE/src/dbnode/persist/fs -out $GOPATH/src/$PACKAGE/src/dbnode/persist/fs/fs_mock.go"
//go:generate sh -c "mockgen -package=fs $PACKAGE/src/dbnode/persist/fs DataFileSetWriter,DataFileSetReader,DataFileSetSeeker,IndexFileSetWriter,IndexFileSetReader,IndexSegmentFileSetWriter,IndexSegmentFileSet,IndexSegmentFile,SnapshotMetadataFileWriter,DataFileSetSeekerManager,ConcurrentDataFileSetSeeker,MergeWith | genclean -pkg $PACKAGE/src/dbnode/persist/fs -out $GOPATH/src/$PACKAGE/src/dbnode/persist/fs/fs_mock.go"
//go:generate sh -c "mockgen -package=xio $PACKAGE/src/dbnode/x/xio SegmentReader,SegmentReaderPool | genclean -pkg $PACKAGE/src/dbnode/x/xio -out $GOPATH/src/$PACKAGE/src/dbnode/x/xio/io_mock.go"
//go:generate sh -c "mockgen -package=digest -destination=$GOPATH/src/$PACKAGE/src/dbnode/digest/digest_mock.go $PACKAGE/src/dbnode/digest ReaderWithDigest"
//go:generate sh -c "mockgen -package=series $PACKAGE/src/dbnode/storage/series DatabaseSeries,QueryableBlockRetriever | genclean -pkg $PACKAGE/src/dbnode/storage/series -out $GOPATH/src/$PACKAGE/src/dbnode/storage/series/series_mock.go"
Expand Down
300 changes: 300 additions & 0 deletions src/dbnode/persist/fs/checked_bytes_by_id_map_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
// Copyright (c) 2019 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.

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/mauricelam/genny

package fs

import (
"github.com/m3db/m3/src/x/checked"
"github.com/m3db/m3/src/x/ident"
)

// Copyright (c) 2019 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.

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/mauricelam/genny

// Copyright (c) 2018 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.

// checkedBytesMapHash is the hash for a given map entry, this is public to support
// iterating over the map using a native Go for loop.
type checkedBytesMapHash uint64

// checkedBytesMapHashFn is the hash function to execute when hashing a key.
type checkedBytesMapHashFn func(ident.ID) checkedBytesMapHash

// checkedBytesMapEqualsFn is the equals key function to execute when detecting equality of a key.
type checkedBytesMapEqualsFn func(ident.ID, ident.ID) bool

// checkedBytesMapCopyFn is the copy key function to execute when copying the key.
type checkedBytesMapCopyFn func(ident.ID) ident.ID

// checkedBytesMapFinalizeFn is the finalize key function to execute when finished with a key.
type checkedBytesMapFinalizeFn func(ident.ID)

// checkedBytesMap uses the genny package to provide a generic hash map that can be specialized
// by running the following command from this root of the repository:
// ```
// make hashmap-gen pkg=outpkg key_type=Type value_type=Type out_dir=/tmp
// ```
// Or if you would like to use bytes or ident.ID as keys you can use the
// partially specialized maps to generate your own maps as well:
// ```
// make byteshashmap-gen pkg=outpkg value_type=Type out_dir=/tmp
// make idhashmap-gen pkg=outpkg value_type=Type out_dir=/tmp
// ```
// This will output to stdout the generated source file to use for your map.
// It uses linear probing by incrementing the number of the hash created when
// hashing the identifier if there is a collision.
// checkedBytesMap is a value type and not an interface to allow for less painful
// upgrades when adding/removing methods, it is not likely to need mocking so
// an interface would not be super useful either.
type checkedBytesMap struct {
_checkedBytesMapOptions

// lookup uses hash of the identifier for the key and the MapEntry value
// wraps the value type and the key (used to ensure lookup is correct
// when dealing with collisions), we use uint64 for the hash partially
// because lookups of maps with uint64 keys has a fast path for Go.
lookup map[checkedBytesMapHash]checkedBytesMapEntry
}

// _checkedBytesMapOptions is a set of options used when creating an identifier map, it is kept
// private so that implementers of the generated map can specify their own options
// that partially fulfill these options.
type _checkedBytesMapOptions struct {
// hash is the hash function to execute when hashing a key.
hash checkedBytesMapHashFn
// equals is the equals key function to execute when detecting equality.
equals checkedBytesMapEqualsFn
// copy is the copy key function to execute when copying the key.
copy checkedBytesMapCopyFn
// finalize is the finalize key function to execute when finished with a
// key, this is optional to specify.
finalize checkedBytesMapFinalizeFn
// initialSize is the initial size for the map, use zero to use Go's std map
// initial size and consequently is optional to specify.
initialSize int
}

// checkedBytesMapEntry is an entry in the map, this is public to support iterating
// over the map using a native Go for loop.
type checkedBytesMapEntry struct {
// key is used to check equality on lookups to resolve collisions
key _checkedBytesMapKey
// value type stored
value checked.Bytes
}

type _checkedBytesMapKey struct {
key ident.ID
finalize bool
}

// Key returns the map entry key.
func (e checkedBytesMapEntry) Key() ident.ID {
return e.key.key
}

// Value returns the map entry value.
func (e checkedBytesMapEntry) Value() checked.Bytes {
return e.value
}

// _checkedBytesMapAlloc is a non-exported function so that when generating the source code
// for the map you can supply a public constructor that sets the correct
// hash, equals, copy, finalize options without users of the map needing to
// implement them themselves.
func _checkedBytesMapAlloc(opts _checkedBytesMapOptions) *checkedBytesMap {
m := &checkedBytesMap{_checkedBytesMapOptions: opts}
m.Reallocate()
return m
}

func (m *checkedBytesMap) newMapKey(k ident.ID, opts _checkedBytesMapKeyOptions) _checkedBytesMapKey {
key := _checkedBytesMapKey{key: k, finalize: opts.finalizeKey}
if !opts.copyKey {
return key
}

key.key = m.copy(k)
return key
}

func (m *checkedBytesMap) removeMapKey(hash checkedBytesMapHash, key _checkedBytesMapKey) {
delete(m.lookup, hash)
if key.finalize {
m.finalize(key.key)
}
}

// Get returns a value in the map for an identifier if found.
func (m *checkedBytesMap) Get(k ident.ID) (checked.Bytes, bool) {
hash := m.hash(k)
for entry, ok := m.lookup[hash]; ok; entry, ok = m.lookup[hash] {
if m.equals(entry.key.key, k) {
return entry.value, true
}
// Linear probe to "next" to this entry (really a rehash)
hash++
}
var empty checked.Bytes
return empty, false
}

// Set will set the value for an identifier.
func (m *checkedBytesMap) Set(k ident.ID, v checked.Bytes) {
m.set(k, v, _checkedBytesMapKeyOptions{
copyKey: true,
finalizeKey: m.finalize != nil,
})
}

// checkedBytesMapSetUnsafeOptions is a set of options to use when setting a value with
// the SetUnsafe method.
type checkedBytesMapSetUnsafeOptions struct {
NoCopyKey bool
NoFinalizeKey bool
}

// SetUnsafe will set the value for an identifier with unsafe options for how
// the map treats the key.
func (m *checkedBytesMap) SetUnsafe(k ident.ID, v checked.Bytes, opts checkedBytesMapSetUnsafeOptions) {
m.set(k, v, _checkedBytesMapKeyOptions{
copyKey: !opts.NoCopyKey,
finalizeKey: !opts.NoFinalizeKey,
})
}

type _checkedBytesMapKeyOptions struct {
copyKey bool
finalizeKey bool
}

func (m *checkedBytesMap) set(k ident.ID, v checked.Bytes, opts _checkedBytesMapKeyOptions) {
hash := m.hash(k)
for entry, ok := m.lookup[hash]; ok; entry, ok = m.lookup[hash] {
if m.equals(entry.key.key, k) {
m.lookup[hash] = checkedBytesMapEntry{
key: entry.key,
value: v,
}
return
}
// Linear probe to "next" to this entry (really a rehash)
hash++
}

m.lookup[hash] = checkedBytesMapEntry{
key: m.newMapKey(k, opts),
value: v,
}
}

// Iter provides the underlying map to allow for using a native Go for loop
// to iterate the map, however callers should only ever read and not write
// the map.
func (m *checkedBytesMap) Iter() map[checkedBytesMapHash]checkedBytesMapEntry {
return m.lookup
}

// Len returns the number of map entries in the map.
func (m *checkedBytesMap) Len() int {
return len(m.lookup)
}

// Contains returns true if value exists for key, false otherwise, it is
// shorthand for a call to Get that doesn't return the value.
func (m *checkedBytesMap) Contains(k ident.ID) bool {
_, ok := m.Get(k)
return ok
}

// Delete will remove a value set in the map for the specified key.
func (m *checkedBytesMap) Delete(k ident.ID) {
hash := m.hash(k)
for entry, ok := m.lookup[hash]; ok; entry, ok = m.lookup[hash] {
if m.equals(entry.key.key, k) {
m.removeMapKey(hash, entry.key)
return
}
// Linear probe to "next" to this entry (really a rehash)
hash++
}
}

// Reset will reset the map by simply deleting all keys to avoid
// allocating a new map.
func (m *checkedBytesMap) Reset() {
for hash, entry := range m.lookup {
m.removeMapKey(hash, entry.key)
}
}

// Reallocate will avoid deleting all keys and reallocate a new
// map, this is useful if you believe you have a large map and
// will not need to grow back to a similar size.
func (m *checkedBytesMap) Reallocate() {
if m.initialSize > 0 {
m.lookup = make(map[checkedBytesMapHash]checkedBytesMapEntry, m.initialSize)
} else {
m.lookup = make(map[checkedBytesMapHash]checkedBytesMapEntry)
}
}
Loading