Skip to content

Commit

Permalink
merge 1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Jan 15, 2025
2 parents cf0d772 + 06a8323 commit 5443662
Show file tree
Hide file tree
Showing 69 changed files with 472 additions and 831 deletions.
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ hot key detect and cache:


## Release-Version
latest version is 1.3.1, have deploy to maven central repository on 2024/12/23
latest version is 1.3.2, have deploy to maven central repository on 2025/01/15
[CHANGE_LOG](/update-en.md)

## SNAPSHOT-version
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Camellia提供了一系列简单易用的服务器组件,包括但不限于:


## RELEASE版本
最新版本是1.3.1,已经发布到maven中央仓库(2024/12/23
最新版本是1.3.2,已经发布到maven中央仓库(2025/01/15
[更新日志](/update-zh.md)

## SNAPSHOT版本
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/
public class CamelliaVersion {

public static final String version = "1.3.1";
public static final String version = "1.3.2";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ _________ .__ .__ .__
\ \____/ __ \| Y Y \ ___/| |_| |_| |/ __ \_
\______ (____ /__|_| /\___ >____/____/__(____ /
\/ \/ \/ \/ \/
:: Camellia-Delay-Queue-Server :: (1.3.1)
:: Camellia-Delay-Queue-Server :: (1.3.2)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ _________ .__ .__ .__
\ \____/ __ \| Y Y \ ___/| |_| |_| |/ __ \_
\______ (____ /__|_| /\___ >____/____/__(____ /
\/ \/ \/ \/ \/
:: Camellia-Hot-Key-Server :: (1.3.1)
:: Camellia-Hot-Key-Server :: (1.3.2)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ _________ .__ .__ .__
\ \____/ __ \| Y Y \ ___/| |_| |_| |/ __ \_
\______ (____ /__|_| /\___ >____/____/__(____ /
\/ \/ \/ \/ \/
:: Camellia-Id-Gen-Segment-Server :: (1.3.1)
:: Camellia-Id-Gen-Segment-Server :: (1.3.2)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ _________ .__ .__ .__
\ \____/ __ \| Y Y \ ___/| |_| |_| |/ __ \_
\______ (____ /__|_| /\___ >____/____/__(____ /
\/ \/ \/ \/ \/
:: Camellia-Id-Gen-Snowflake-Server :: (1.3.1)
:: Camellia-Id-Gen-Snowflake-Server :: (1.3.2)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ _________ .__ .__ .__
\ \____/ __ \| Y Y \ ___/| |_| |_| |/ __ \_
\______ (____ /__|_| /\___ >____/____/__(____ /
\/ \/ \/ \/ \/
:: Camellia-Id-Gen-Strict-Server :: (1.3.1)
:: Camellia-Id-Gen-Strict-Server :: (1.3.2)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ _________ .__ .__ .__
\ \____/ __ \| Y Y \ ___/| |_| |_| |/ __ \_
\______ (____ /__|_| /\___ >____/____/__(____ /
\/ \/ \/ \/ \/
:: Camellia-Redis-Proxy-Server :: (1.3.1)
:: Camellia-Redis-Proxy-Server :: (1.3.2)
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
*/
public class RedisZSet implements EstimateSizeValue {

private static final Comparator<BytesKey> rankComparator = (o1, o2) -> BytesUtils.compare(o1.getKey(), o2.getKey());
private static final Comparator<BytesKey> lexComparator = (o1, o2) -> BytesUtils.compare(o1.getKey(), o2.getKey());
private static final Comparator<ZSetTuple> scoreComparator = (o1, o2) -> {
if (o1.getMember().equals(o2.getMember())) {
return 0;
}
int compare = Double.compare(o1.getScore(), o2.getScore());
if (compare != 0) {
return compare;
}
return BytesUtils.compare(o1.getMember().getKey(), o2.getMember().getKey());
};

private final TreeMap<BytesKey, Double> memberMap = new TreeMap<>(rankComparator);
private final TreeMap<BytesKey, Double> memberMap = new TreeMap<>(lexComparator);
private final TreeSet<ZSetTuple> scoreSet = new TreeSet<>(scoreComparator);

private long estimateSize = 0;
Expand Down Expand Up @@ -55,25 +52,27 @@ public Map<BytesKey, Double> zadd(Map<BytesKey, Double> map) {
estimateSize += 8;
estimateSize += entry.getKey().getKey().length;
}
if (put != null) {
scoreSet.remove(new ZSetTuple(entry.getKey(), put));
}
ZSetTuple zSetTuple = new ZSetTuple(entry.getKey(), entry.getValue());
scoreSet.remove(zSetTuple);
scoreSet.add(zSetTuple);
}
return existsMap;
}

public List<ZSetTuple> zrange(int start, int stop) {
ZSetRank rank = new ZSetRank(start, stop, memberMap.size());
ZSetRank rank = new ZSetRank(start, stop, scoreSet.size());
if (rank.isEmptyRank()) {
return Collections.emptyList();
}
start = rank.getStart();
stop = rank.getStop();
List<ZSetTuple> result = new ArrayList<>();
int count = 0;
for (Map.Entry<BytesKey, Double> entry : memberMap.entrySet()) {
for (ZSetTuple zSetTuple : scoreSet) {
if (count >= start) {
result.add(new ZSetTuple(entry.getKey(), entry.getValue()));
result.add(zSetTuple);
}
if (count >= stop) {
return result;
Expand All @@ -84,17 +83,17 @@ public List<ZSetTuple> zrange(int start, int stop) {
}

public List<ZSetTuple> zrevrange(int start, int stop) {
ZSetRank rank = new ZSetRank(start, stop, memberMap.size());
ZSetRank rank = new ZSetRank(start, stop, scoreSet.size());
if (rank.isEmptyRank()) {
return Collections.emptyList();
}
start = rank.getStart();
stop = rank.getStop();
List<ZSetTuple> result = new ArrayList<>();
int count = 0;
for (Map.Entry<BytesKey, Double> entry : memberMap.descendingMap().entrySet()) {
for (ZSetTuple zSetTuple : scoreSet.descendingSet()) {
if (count >= start) {
result.add(new ZSetTuple(entry.getKey(), entry.getValue()));
result.add(zSetTuple);
}
if (count >= stop) {
return result;
Expand Down Expand Up @@ -225,9 +224,9 @@ public Pair<Integer, ZSetTuple> zrank(BytesKey member) {
return null;
}
int i=0;
for (Map.Entry<BytesKey, Double> entry : memberMap.entrySet()) {
if (entry.getKey().equals(member)) {
return new Pair<>(i, new ZSetTuple(entry.getKey(), entry.getValue()));
for (ZSetTuple zSetTuple : scoreSet) {
if (zSetTuple.getMember().equals(member)) {
return new Pair<>(i, zSetTuple);
}
i ++;
}
Expand All @@ -240,9 +239,9 @@ public Pair<Integer, ZSetTuple> zrevrank(BytesKey member) {
return null;
}
int i=0;
for (Map.Entry<BytesKey, Double> entry : memberMap.descendingMap().entrySet()) {
if (entry.getKey().equals(member)) {
return new Pair<>(i, new ZSetTuple(entry.getKey(), entry.getValue()));
for (ZSetTuple zSetTuple : scoreSet.descendingSet()) {
if (zSetTuple.getMember().equals(member)) {
return new Pair<>(i, zSetTuple);
}
i++;
}
Expand Down Expand Up @@ -280,7 +279,7 @@ public List<Double> zmscore(List<BytesKey> members) {
}

public Map<BytesKey, Double> zremrangeByRank(int start, int stop) {
ZSetRank rank = new ZSetRank(start, stop, memberMap.size());
ZSetRank rank = new ZSetRank(start, stop, scoreSet.size());
if (rank.isEmptyRank()) {
return new HashMap<>();
}
Expand All @@ -289,10 +288,11 @@ public Map<BytesKey, Double> zremrangeByRank(int start, int stop) {
Map<BytesKey, Double> map = new HashMap<>();
List<ZSetTuple> removed = new ArrayList<>();
int count = 0;
for (Map.Entry<BytesKey, Double> entry : memberMap.entrySet()) {

for (ZSetTuple zSetTuple : scoreSet) {
if (count >= start) {
map.put(entry.getKey(), entry.getValue());
removed.add(new ZSetTuple(entry.getKey(), entry.getValue()));
map.put(zSetTuple.getMember(), zSetTuple.getScore());
removed.add(zSetTuple);
}
if (count >= stop) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected final List<ZSetTuple> zrangeByRankVersion0(int slot, KeyMeta keyMeta,
start = zSetRank.getStart();
stop = zSetRank.getStop();

byte[] startKey = keyDesign.zsetMemberSubKey1(keyMeta, key, new byte[0]);
byte[] startKey = keyDesign.zsetMemberSubKey2(keyMeta, key, new byte[0], new byte[0]);
byte[] prefix = startKey;
int targetSize = stop - start + 1;

Expand All @@ -51,9 +51,9 @@ protected final List<ZSetTuple> zrangeByRankVersion0(int slot, KeyMeta keyMeta,
}
startKey = keyValue.getKey();
if (count >= start) {
byte[] member = keyDesign.decodeZSetMemberBySubKey1(keyValue.getKey(), key);
byte[] member = keyDesign.decodeZSetMemberBySubKey2(keyValue.getKey(), key);
if (withScores) {
double score = Utils.bytesToDouble(keyValue.getValue());
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
result.add(new ZSetTuple(new BytesKey(member), score));
} else {
result.add(new ZSetTuple(new BytesKey(member), null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.EncodeVersion;
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.KeyMeta;
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.KeyType;
import com.netease.nim.camellia.redis.proxy.util.Utils;
import com.netease.nim.camellia.tools.utils.BytesKey;
import com.netease.nim.camellia.tools.utils.Pair;

Expand Down Expand Up @@ -163,7 +162,7 @@ protected Reply execute(int slot, Command command) {

private Pair<Integer, ZSetTuple> zrankFromKv(int slot, KeyMeta keyMeta, byte[] key, BytesKey member) {
int scanBatch = kvConfig.scanBatch();
byte[] startKey = keyDesign.zsetMemberSubKey1(keyMeta, key, new byte[0]);
byte[] startKey = keyDesign.zsetMemberSubKey2(keyMeta, key, new byte[0], new byte[0]);
byte[] prefix = startKey;
int index = 0;
while (true) {
Expand All @@ -176,8 +175,9 @@ private Pair<Integer, ZSetTuple> zrankFromKv(int slot, KeyMeta keyMeta, byte[] k
continue;
}
startKey = keyValue.getKey();
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey1(startKey, key), member.getKey())) {
return new Pair<>(index, new ZSetTuple(member, Utils.bytesToDouble(keyValue.getValue())));
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey2(startKey, key), member.getKey())) {
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
return new Pair<>(index, new ZSetTuple(member, score));
}
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private Reply zrevrangeVersion0(int slot, KeyMeta keyMeta, byte[] key, int start
start = rank.getStart();
stop = rank.getStop();

byte[] startKey = keyDesign.zsetMemberSubKey1(keyMeta, key, new byte[0]);
byte[] startKey = keyDesign.zsetMemberSubKey2(keyMeta, key, new byte[0], new byte[0]);
List<ZSetTuple> list = zrevrange0(slot, key, BytesUtils.nextBytes(startKey), startKey, start, stop, withScores);

return ZSetTupleUtils.toReply(list, withScores);
Expand All @@ -221,9 +221,9 @@ private List<ZSetTuple> zrevrange0(int slot, byte[] key, byte[] startKey, byte[]
}
startKey = keyValue.getKey();
if (count >= start) {
byte[] member = keyDesign.decodeZSetMemberBySubKey1(keyValue.getKey(), key);
byte[] member = keyDesign.decodeZSetMemberBySubKey2(keyValue.getKey(), key);
if (withScores) {
double score = Utils.bytesToDouble(keyValue.getValue());
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
list.add(new ZSetTuple(new BytesKey(member), score));
} else {
list.add(new ZSetTuple(new BytesKey(member), null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private Reply zrevrank(int slot, KeyMeta keyMeta, byte[] key, byte[] cacheKey, B

private Pair<Integer, ZSetTuple> zrevrankFromKv(int slot, KeyMeta keyMeta, byte[] key, BytesKey member) {
int scanBatch = kvConfig.scanBatch();
byte[] startKey = keyDesign.zsetMemberSubKey1(keyMeta, key, new byte[0]);
byte[] startKey = keyDesign.zsetMemberSubKey2(keyMeta, key, new byte[0], new byte[0]);
byte[] prefix = startKey;
startKey = BytesUtils.nextBytes(startKey);
int index = 0;
Expand All @@ -191,8 +191,9 @@ private Pair<Integer, ZSetTuple> zrevrankFromKv(int slot, KeyMeta keyMeta, byte[
continue;
}
startKey = keyValue.getKey();
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey1(startKey, key), member.getKey())) {
return new Pair<>(index, new ZSetTuple(member, Utils.bytesToDouble(keyValue.getValue())));
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey2(startKey, key), member.getKey())) {
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
return new Pair<>(index, new ZSetTuple(member, score));
}
index++;
}
Expand Down
Loading

0 comments on commit 5443662

Please sign in to comment.