buildSortedSetIdx builds sorted set index when opening the DB.
(record *core.Record, entry *core.Entry)
| 893 | |
| 894 | // buildSortedSetIdx builds sorted set index when opening the DB. |
| 895 | func (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. |
| 934 | func (db *DB) buildListIdx(record *core.Record, entry *core.Entry) error { |
no test coverage detected