Skip to content

Commit

Permalink
feat: update block size (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Jan 10, 2025
1 parent 22c8f97 commit 87baac7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import static com.netease.nim.camellia.redis.proxy.upstream.local.storage.constants.LocalStorageConstants.key_max_len;

/**
* Created by caojiajun on 2025/1/3
*/
Expand Down Expand Up @@ -62,7 +64,7 @@ public void sendCommand(int db, List<Command> commands, List<CompletableFuture<R
} else {
List<byte[]> keys = command.getKeys();
for (byte[] key : keys) {
if (key.length > 1024) {
if (key.length > key_max_len) {
future.complete(ErrorReply.KEY_TOO_LONG);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void compact(short slot) {
recycle = decodeResult.remaining() > BlockType._32k.getBlockSize();
} else if (blockType == BlockType._1024k) {
recycle = decodeResult.remaining() > BlockType._256k.getBlockSize();
} else if (blockType == BlockType._10m) {
} else if (blockType == BlockType._8m) {
recycle = decodeResult.remaining() > BlockType._1024k.getBlockSize();
}
}
Expand Down Expand Up @@ -151,8 +151,8 @@ private BlockType nextBlockType(short slot) {
case _4k -> nextBlockTypeMap.put(slot, BlockType._32k);
case _32k -> nextBlockTypeMap.put(slot, BlockType._256k);
case _256k -> nextBlockTypeMap.put(slot, BlockType._1024k);
case _1024k -> nextBlockTypeMap.put(slot, BlockType._10m);
case _10m -> nextBlockTypeMap.put(slot, BlockType._4k);
case _1024k -> nextBlockTypeMap.put(slot, BlockType._8m);
case _8m -> nextBlockTypeMap.put(slot, BlockType._4k);
}
return blockType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
*/
public class LocalStorageConstants {

public static final int key_max_len = 1024;

public static final int _4k = 4*1024;
public static final int _32k = 32*1024;
public static final int _64k = 64*1024;
public static final int _256k = 256*1024;
public static final int _1024k = 1024*1024;
public static final int _10m = 10*1024*1024;
public static final int _8m = 8*1024*1024;
public static final int key_manifest_bit_size = (int)(16*1024*1024*1024L / _64k);//16Gib
public static final long data_file_size = 192*1024*1024*1024L;//128Gib
public static final int block_header_len = 4+4+2+1+4+4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum BlockType {
_32k(2, 32*1024, 2),
_256k(3, 256*1024, 4),
_1024k(4, 1024*1024, 4),
_10m(5, 10*1024*1024, 4),
_8m(5, 8*1024*1024, 4),
;

private final int type;
Expand Down Expand Up @@ -54,8 +54,8 @@ public static BlockType fromData(byte[] data) {
return BlockType._256k;
} else if (data.length + 4 + 4 < LocalStorageConstants._1024k) {
return BlockType._1024k;
} else if (data.length + 4 + 4 < LocalStorageConstants._10m) {
return BlockType._10m;
} else if (data.length + 4 + 4 < LocalStorageConstants._8m) {
return BlockType._8m;
} else {
throw new IllegalArgumentException("data too long");
}
Expand Down

0 comments on commit 87baac7

Please sign in to comment.