-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shard fields map and remove locks for concurrency.
- Loading branch information
Showing
2 changed files
with
64 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package builder | ||
|
||
type shardedFieldsMap struct { | ||
data []*fieldsMap | ||
} | ||
|
||
func newShardedFieldsMap( | ||
numShards int, | ||
shardInitialCapacity int, | ||
) *shardedFieldsMap { | ||
data := make([]*fieldsMap, 0, numShards) | ||
for i := 0; i < numShards; i++ { | ||
data = append(data, newFieldsMap(fieldsMapOptions{ | ||
InitialSize: shardInitialCapacity, | ||
})) | ||
} | ||
return &shardedFieldsMap{ | ||
data: data, | ||
} | ||
} | ||
|
||
func (s *shardedFieldsMap) Get(k []byte) (*terms, bool) { | ||
for _, fieldMap := range s.data { | ||
t, found := fieldMap.Get(k) | ||
if found { | ||
return t, found | ||
} | ||
} | ||
return nil, false | ||
} | ||
|
||
func (s *shardedFieldsMap) ShardedGet( | ||
shard int, | ||
k []byte, | ||
) (*terms, bool) { | ||
return s.data[shard].Get(k) | ||
} | ||
|
||
func (s *shardedFieldsMap) ShardedSetUnsafe( | ||
shard int, | ||
k []byte, | ||
v *terms, | ||
opts fieldsMapSetUnsafeOptions, | ||
) { | ||
s.data[shard].SetUnsafe(k, v, opts) | ||
} | ||
|
||
// ResetTerms keeps fields around but resets the terms set for each one. | ||
func (s *shardedFieldsMap) ResetTermsSets() { | ||
for _, fieldMap := range s.data { | ||
for _, entry := range fieldMap.Iter() { | ||
entry.Value().reset() | ||
} | ||
} | ||
} |