INTERNAL: Refactor textual_value_fetch logic#390
Conversation
672ab98 to
3668cab
Compare
|
리뷰 부탁드립니다. |
| cur_ptr= str_ptr; | ||
| while (!iscntrl(*cur_ptr) && !isspace(*cur_ptr)) | ||
| { | ||
| if (cur_ptr >= end_ptr) return MEMCACHED_PARTIAL_READ; |
There was a problem hiding this comment.
" abc def" 값을 가정하면, MEMCACHED_PARTIAL_READ 오류가 발생할 것 같습니다.
마지막 charactor는 반드시 control 또는 space charactor이어야 하나요?
There was a problem hiding this comment.
iscntrl() 문자가 아니어야 하는 이유가 무엇이라 생각하나요?
\r, \n 문자는 isspace()로 검사가 가능하네요.
문자열 끝을 나타내는 \0(Null) 문자는 control 문자입니다.
There was a problem hiding this comment.
우선, 응답으로 "abc def"와 같은 문자열 형태나 \0이 포함되지 않는다는 전제를 바탕으로 코드가 구현되어 있습니다.
해당 문자열은 서버에서 전송되는 값으로, 반드시 VALUE <key> <flags> <bytes> [<cas unique>]\r\n 형식을 따른다고 가정하고 parsing을 수행합니다.
말씀하신 경우들은 극히 드문 상황에 대한 프로토콜 에러에 가깝습니다.
다만, 기존 코드에서는 이러한 상황을 별도로 처리하고 있지 않습니다.
There was a problem hiding this comment.
tokenize() 용어의 함수는 tokernize하는 역할을 수행하는 것입니다.
token 수를 리턴하는 것이 좋은 인터페이스이고,
MEMCACHED_PARTIAL_READ를 리턴하는 것은 상식적이지 않습니다.
jhpark816
left a comment
There was a problem hiding this comment.
이전 리뷰에 대해 수정이 이루어지지 않은 것 같습니다.
확인 바랍니다.
| cur_ptr= str_ptr; | ||
| while (!iscntrl(*cur_ptr) && !isspace(*cur_ptr)) | ||
| { | ||
| if (cur_ptr >= end_ptr) return MEMCACHED_PARTIAL_READ; |
There was a problem hiding this comment.
tokenize() 용어의 함수는 tokernize하는 역할을 수행하는 것입니다.
token 수를 리턴하는 것이 좋은 인터페이스이고,
MEMCACHED_PARTIAL_READ를 리턴하는 것은 상식적이지 않습니다.
ccb5a0a to
9e9a908
Compare
| result->key_length= key_length; | ||
| } else { | ||
| snprintf(key + MEMCACHED_MAX_KEY - 4, 4, "..."); | ||
| result->key_length= MEMCACHED_MAX_KEY - 1; |
There was a problem hiding this comment.
키 문자열을 읽어내는 부분은 기존 코드를 그대로 유지합시다.
키 문자열의 tokenize와 숫자형 문자열의 tokenize 방식이 다르고,
키 문자열의 tokenize하는 기존 코드가 충분히 이해하기 쉽기 때문입니다.
| goto read_error; | ||
|
|
||
| for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++) {}; | ||
| result->item_flags= (uint32_t) strtoul(next_ptr, &string_ptr, 10); |
There was a problem hiding this comment.
숫자형의 문자열만을 토큰화하도록 합시다.
기존처럼 isdigit() 함수를 이용하여 tokenize 한다면, strtoul() 후에 validation check는 없어도 됩니다.
int tokenize_numbers(char *buffer, size_t length, char **tokens, size_t max_tokens)There was a problem hiding this comment.
토큰화 방식을 활용해 리팩토링을 진행하는 경우, 결과에서 key 부분만 따로 파싱하고 나머지 부분은 토큰화하여 처리하는 방식은 개인적으로는 다소 부자연스럽게 느껴집니다.
java-client의 구현 방식을 살펴본 결과, 전체 결과를 모두 토큰화한 뒤 파싱하는 방식을 사용하고 있었습니다.
| size_t ntoken; | ||
| size_t end_idx; | ||
| size_t start_idx= 0; | ||
| for (ntoken= 0; ntoken < max_tokens; ntoken++) |
There was a problem hiding this comment.
length 기준의 loop를 사용하고, 아래 중의 하나가 만족 될 때까지 tokenize하면 좋겠습니다.
- new line이 나올 때까지
- length까지 다다를 때까지
- max_tokens 만큼 tokenize할 때까지
4597f99 to
da4fa79
Compare
|
@ing-eoking |
🔗 Related Issue
⌨️ What I did
textual_value_fetch로직을 리팩토링했습니다.char *배열에 저장하도록 변경했습니다.