swap out mapVector for rowsVector in mutex fields

This commit is contained in:
Travis Turner 2018-07-18 11:34:22 -05:00
parent a07ed360ab
commit 06f5d04f1c
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
3 changed files with 29 additions and 2 deletions

View file

@ -2058,3 +2058,30 @@ func (m *mapVector) Set(colID, rowID uint64) {
defer m.mu.Unlock()
m.m[colID] = rowID
}
// rowsVector implements the vector interface by looking
// at row data as needed.
type rowsVector struct {
f *fragment
}
// newRowsVector returns a rowsVector for a given fragment.
func newRowsVector(f *fragment) *rowsVector {
return &rowsVector{
f: f,
}
}
// Get returns the rowID associated to the given colID.
// Additionaly, it returns true if a value was found,
// otherwise it returns false.
func (v *rowsVector) Get(colID uint64) (uint64, bool) {
rows := v.f.rowsForColumn(colID)
if len(rows) == 1 {
return rows[0], true
}
return 0, false
}
// Set is not used for rowsVector.
func (v *rowsVector) Set(colID, rowID uint64) {}

View file

@ -1295,7 +1295,7 @@ func mustOpenFragment(index, field, view string, shard uint64, cacheType string)
// mustOpenMutexFragment returns a new instance of Fragment for a mutex field.
func mustOpenMutexFragment(index, field, view string, shard uint64, cacheType string) *fragment {
frag := mustOpenFragment(index, field, view, shard, cacheType)
frag.mutexVector = newMapVector()
frag.mutexVector = newRowsVector(frag)
return frag
}

View file

@ -255,7 +255,7 @@ func (v *view) newFragment(path string, shard uint64) *fragment {
frag.Logger = v.logger
frag.stats = v.stats.WithTags(fmt.Sprintf("shard:%d", shard))
if v.fieldType == FieldTypeMutex {
frag.mutexVector = newMapVector()
frag.mutexVector = newRowsVector(frag)
}
return frag
}