MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / buildSortedSetIdx

Method buildSortedSetIdx

db.go:895–931  ·  view source on GitHub ↗

buildSortedSetIdx builds sorted set index when opening the DB.

(record *core.Record, entry *core.Entry)

Source from the content-addressed store, hash-verified

893
894// buildSortedSetIdx builds sorted set index when opening the DB.
895func (db *DB) buildSortedSetIdx(record *core.Record, entry *core.Entry) error {
896 key, val, meta := entry.Key, entry.Value, entry.Meta
897
898 bucket, err := db.bucketMgr.GetBucketById(entry.Meta.BucketId)
899 if err != nil {
900 return err
901 }
902 bucketId := bucket.Id
903
904 ss := db.Index.SortedSet.GetWithDefault(bucketId)
905
906 switch meta.Flag {
907 case DataZAddFlag:
908 keyAndScore := strings.Split(string(key), SeparatorForZSetKey)
909 if len(keyAndScore) == 2 {
910 key := keyAndScore[0]
911 score, _ := strconv2.StrToFloat64(keyAndScore[1])
912 err = ss.ZAdd(key, SCORE(score), val, record)
913 }
914 case DataZRemFlag:
915 _, err = ss.ZRem(string(key), val)
916 case DataZRemRangeByRankFlag:
917 start, end := splitIntIntStr(string(val), SeparatorForZSetKey)
918 err = ss.ZRemRangeByRank(string(key), start, end)
919 case DataZPopMaxFlag:
920 _, _, err = ss.ZPopMax(string(key))
921 case DataZPopMinFlag:
922 _, _, err = ss.ZPopMin(string(key))
923 }
924
925 // We don't need to panic if sorted set is not found.
926 if err != nil && !errors.Is(err, ErrSortedSetNotFound) {
927 return fmt.Errorf("when build sortedSetIdx err: %s", err)
928 }
929
930 return nil
931}
932
933// buildListIdx builds List index when opening the DB.
934func (db *DB) buildListIdx(record *core.Record, entry *core.Entry) error {

Callers 2

buildIdxesMethod · 0.95
buildIdxesMethod · 0.80

Calls 9

SCORETypeAlias · 0.85
splitIntIntStrFunction · 0.85
GetBucketByIdMethod · 0.80
GetWithDefaultMethod · 0.45
ZAddMethod · 0.45
ZRemMethod · 0.45
ZRemRangeByRankMethod · 0.45
ZPopMaxMethod · 0.45
ZPopMinMethod · 0.45

Tested by

no test coverage detected