Skip to content

Commit

Permalink
INTERNAL: Extend bkey/eflag max length
Browse files Browse the repository at this point in the history
  • Loading branch information
namsic committed Jan 10, 2025
1 parent c3340cb commit 3d68197
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/ascii-protocol/ch02-collection-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ B+tree collection에서 사용가능한 bkey 데이터 유형은 아래 두 가

"0x"로 시작하는 짝수 개의 hexadecimal 문자열로 표현하며, 대소문자 모두 사용 가능하다.
ARCUS cache server는 두 hexadecimal 문자를 1 byte로 저장하며,
1 ~ 31 길이의 variable length byte array로 저장한다.
1 ~ 63 길이의 variable length byte array로 저장한다.

hexadecimal 표현이 올바른 경우의 저장 바이트 수와 잘못된 경우의 이유는 아래와 같다.

Expand Down
2 changes: 1 addition & 1 deletion docs/ascii-protocol/ch03-item-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ARCUS Cache Server는 collection 기능 지원으로 인해,
| readable | collection | readable/unreadable | "on", "off" | "on" |
|-----------------------------------------------------------------------------------------------------------------|
| maxbkeyrange | b+tree only | maximum bkey range | 8 bytes unsigned integer or | 0 |
| | | | hexadecimal (max 31 bytes) | |
| | | | hexadecimal (max 63 bytes) | |
|-----------------------------------------------------------------------------------------------------------------|
```

Expand Down
16 changes: 8 additions & 8 deletions engines/default/cmdlogrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ static void lrec_it_link_print(LogRec *logrec)
struct lrec_item_common *cm = (struct lrec_item_common*)&body->cm;
char *keyptr = body->data;

char metastr[180];
char metastr[MAX_BKEY_LENG*2 + 90];
if (cm->ittype == ITEM_TYPE_KV) {
sprintf(metastr, "cas=%"PRIu64, body->ptr.cas);
} else {
Expand Down Expand Up @@ -1042,8 +1042,8 @@ static void lrec_bt_elem_insert_print(LogRec *logrec)
unsigned char *eflagptr = bkeyptr + real_nbkey;
char *attrptr = (char*)(eflagptr + log->body.neflag + log->body.vallen);

char bkeystr[90];
char eflagstr[90];
char bkeystr[MAX_BKEY_LENG*2 + 20];
char eflagstr[MAX_EFLAG_LENG*2 + 20];
char attrstr[180];
lrec_bkey_print(log->body.nbkey, bkeyptr, bkeystr);
if (log->body.neflag > 0) {
Expand Down Expand Up @@ -1110,7 +1110,7 @@ static void lrec_bt_elem_delete_print(LogRec *logrec)
char *keyptr = log->body.data;
unsigned char *bkeyptr = (unsigned char*)(keyptr + log->body.keylen);

char bkeystr[90];
char bkeystr[MAX_BKEY_LENG*2 + 20];
lrec_bkey_print(log->body.nbkey, bkeyptr, bkeystr);
lrec_header_print(&log->header);
fprintf(stderr, "[BODY ] keylen=%u | keystr=%.*s | bkey=%s | drop=%s\r\n",
Expand Down Expand Up @@ -1210,8 +1210,8 @@ static void lrec_bt_elem_delete_logical_print(LogRec *logrec)
char *fbkeyptr = keyptr + log->body.keylen;
char *tbkeyptr = fbkeyptr + BTREE_REAL_NBKEY(log->body.from_nbkey);

char fbkeystr[90];
char tbkeystr[90];
char fbkeystr[MAX_BKEY_LENG*2 + 20];
char tbkeystr[MAX_BKEY_LENG*2 + 20];
lrec_bkey_print(log->body.from_nbkey, (unsigned char *)fbkeyptr, fbkeystr);
lrec_bkey_print(log->body.to_nbkey, (unsigned char*)tbkeyptr, tbkeystr);

Expand Down Expand Up @@ -1337,8 +1337,8 @@ static void lrec_snapshot_elem_link_print(LogRec *logrec)
body->nekey, body->nekey, valptr,
body->nbytes, (body->nbytes-2 <= 250 ? body->nbytes-2 : 250), (valptr + body->nekey));
} else if (log->header.updtype == UPD_BT_ELEM_INSERT) {
char bkeystr[90];
char eflagstr[90];
char bkeystr[MAX_BKEY_LENG*2 + 20];
char eflagstr[MAX_EFLAG_LENG*2 + 20];
unsigned char *bkeyptr = (unsigned char*)valptr;
unsigned char *eflagptr = (unsigned char*)(valptr + BTREE_REAL_NBKEY(body->nekey));
lrec_bkey_print(body->nekey, bkeyptr, bkeystr);
Expand Down
4 changes: 2 additions & 2 deletions include/memcached/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ extern "C" {
* bkey and eflag
*/
#define MIN_BKEY_LENG 1
#define MAX_BKEY_LENG 31
#define MAX_EFLAG_LENG 31
#define MAX_BKEY_LENG 63
#define MAX_EFLAG_LENG 63
#define MAX_FIELD_LENG 250
#define BKEY_NULL 255
#define EFLAG_NULL 255
Expand Down
2 changes: 1 addition & 1 deletion lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "memcached/util.h"

#define LQ_THRESHOLD_DEFAULT 4000
#define LQ_QUERY_SIZE (64*2+64) /* bop get (longest query) : "<longest bkey>..<longest bkey> efilter <offset> <count> delete" */
#define LQ_QUERY_SIZE (MAX_BKEY_LENG*2*2+64) /* bop get (longest query) : "<longest bkey>..<longest bkey> efilter <offset> <count> delete" */
#define LQ_KEY_SIZE 250 /* the max size of key string */
#define LQ_SAVE_CNT 20 /* save key count */
#define LQ_INPUT_SIZE 500 /* the size of input(time, ip, command, argument) */
Expand Down
5 changes: 2 additions & 3 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -13272,10 +13272,9 @@ static int try_read_command_ascii(conn *c)
}
/* Check KEY_MAX_LENGTH and eflag filter length
* - KEY_MAX_LENGTH : 16000
* - IN eflag filter : > 6400 (64*100)
* - IN eflag filter : > 12800 (128*100)
*/
if (c->rbytes > ((16+8)*1024)) {
/* The length of "stats prefixes" command cannot exceed 24 KB. */
if (c->rbytes > ((16+16)*1024)) {
if (strncmp(ptr, "get ", 4) && strncmp(ptr, "gets ", 5)) {
char buffer[16];
memcpy(buffer, ptr, 15); buffer[15] = '\0';
Expand Down
4 changes: 2 additions & 2 deletions t/coll_bop_delete.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bop delete bkey1 0..0xFF: CLIENT_ERROR bad command line format
bop delete bkey1 0x00..0xFFF: CLIENT_ERROR bad command line format
bop delete bkey1 0x11..0xFFFF: NOT_FOUND_ELEMENT
bop delete bkey1 0x00..0xFF 1 EQ 0x05: NOT_FOUND_ELEMENT
bop delete bkey1 0x00..0xFF 32 EQ 0x05: CLIENT_ERROR bad command line format
bop delete bkey1 0x00..0xFF 64 EQ 0x05: CLIENT_ERROR bad command line format
bop delete bkey1 0x00..0xFF 1 XX 0x05: CLIENT_ERROR bad command line format
bop delete bkey1 0x00..0xFF 0 & 0xFFFFFF EQ 0x03: CLIENT_ERROR bad command line format
bop delete bkey1 0x00..0xFF 0 & 0xFFFFFF EQ 0x030303: NOT_FOUND_ELEMENT
Expand Down Expand Up @@ -115,7 +115,7 @@ $cmd = "bop delete bkey1 0x11..0xFFFF"; $rst = "NOT_FOUND_ELEMENT";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop delete bkey1 0x00..0xFF 1 EQ 0x05"; $rst = "NOT_FOUND_ELEMENT";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop delete bkey1 0x00..0xFF 32 EQ 0x05"; $rst = "CLIENT_ERROR bad command line format";
$cmd = "bop delete bkey1 0x00..0xFF 64 EQ 0x05"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop delete bkey1 0x00..0xFF 1 XX 0x05"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
Expand Down
8 changes: 4 additions & 4 deletions t/coll_bop_insert.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ datum1
setattr bkey1 maxcount=4000
bop insert bkey1 0x020 6
datum2
bop insert bkey1 0x0202020202020202020202020202020202020202020202020202020202020202 6
bop insert bkey1 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6
datum2
bop insert bkey1 0x0202 0x020 6
datum2
bop insert bkey1 0x0202 0x0202020202020202020202020202020202020202020202020202020202020202 6
bop insert bkey1 0x0202 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6
datum2
bop insert bkey1 0x0202 02 6
datum2
Expand Down Expand Up @@ -130,11 +130,11 @@ $cmd = "setattr bkey1 maxcount=4000"; $rst = "OK";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop insert bkey1 0x020 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop insert bkey1 0x0202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
$cmd = "bop insert bkey1 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop insert bkey1 0x0202 0x020 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop insert bkey1 0x0202 0x0202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
$cmd = "bop insert bkey1 0x0202 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop insert bkey1 0x0202 02 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
Expand Down
4 changes: 2 additions & 2 deletions t/coll_bop_update.t
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ datum2
bop update bkey2 0x20 1 | 0xFF -1
bop update bkey2 0x0020 1 | 0xFF -1
bop update bkey2 0x0040 4 | 0xFF -1
bop update bkey2 0x0040 32 | 0xFF -1
bop update bkey2 0x0040 64 | 0xFF -1
delete bkey1
delete bkey2
Expand Down Expand Up @@ -325,7 +325,7 @@ $cmd = "bop update bkey2 0x0020 1 | 0xFF -1"; $rst = "EFLAG_MISMATCH";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop update bkey2 0x0040 4 | 0xFF -1"; $rst = "EFLAG_MISMATCH";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop update bkey2 0x0040 32 | 0xFF -1"; $rst = "CLIENT_ERROR bad command line format";
$cmd = "bop update bkey2 0x0040 64 | 0xFF -1"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);

# Finalize
Expand Down
8 changes: 4 additions & 4 deletions t/coll_bop_upsert.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ datum1
setattr bkey1 maxcount=4000
bop upsert bkey1 0x020 6
datum2
bop upsert bkey1 0x0202020202020202020202020202020202020202020202020202020202020202 6
bop upsert bkey1 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6
datum2
bop upsert bkey1 0x0202 0x020 6
datum2
bop upsert bkey1 0x0202 0x0202020202020202020202020202020202020202020202020202020202020202 6
bop upsert bkey1 0x0202 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6
datum2
bop upsert bkey1 0x0202 02 6
datum2
Expand Down Expand Up @@ -131,11 +131,11 @@ $cmd = "setattr bkey1 maxcount=4000"; $rst = "OK";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop upsert bkey1 0x020 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop upsert bkey1 0x0202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
$cmd = "bop upsert bkey1 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop upsert bkey1 0x0202 0x020 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop upsert bkey1 0x0202 0x0202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
$cmd = "bop upsert bkey1 0x0202 0x02020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
$cmd = "bop upsert bkey1 0x0202 02 6"; $rst = "CLIENT_ERROR bad command line format";
mem_cmd_is($sock, $cmd, "", $rst);
Expand Down

0 comments on commit 3d68197

Please sign in to comment.