Skip to content

Commit

Permalink
redis protocol: tokenizer, hash and zset (#146)
Browse files Browse the repository at this point in the history

* update osx entries in travis

* compose/parse commands

* Squashed 'deps/ccommon/' changes from bb298bc..ce0b9ea

ce0b9ea allow printing negative integers in cc_print (#141)
ab0edc8 add metrics to track buf_sock objects (#138)
ae02038 add travis ci (copied from pelikan) (#139)
964645a Merge pull request #135 from paegun/fix_cmake_install
70710c2 fixed and re-added cmake install instructions, w/ following notes: include directory made proper relative; opened pattern match b/c include directory should only contain files meant for inclusion.
5b095bc Merge pull request #126 from kevyang/kevyang/120
426d56a return NULL when cc_alloc/cc_realloc is called with size == 0
ad271d4 Merge pull request #133 from kevyang/132
47dbdba suppress unused parameter warning in debug_log_flush
648d19e Merge pull request #127 from kevyang/56
780941a Merge pull request #130 from kevyang/129
b8af6c0 Merge pull request #131 from kevyang/128
6ecc318 fix duplicate symbols in cc_signal
080c41d cc_array - stop doing arithmetic on void *
d526f7a add debug oriented memory management
a4fb927 Update bool member rules in style guide
05c6e1e explicitly make ccommon a C project to avoid checking for CXX related variables

git-subtree-dir: deps/ccommon
git-subtree-split: ce0b9ea

* use new macro imported from ccommon

* more tests

* modify response for redis

* add response check

* add response parse/compose

* Squashed 'deps/ccommon/' changes from ce0b9ea..b1babb2

b1babb2 change wheel's sleep timer to make it less flaky (#143)

git-subtree-dir: deps/ccommon
git-subtree-split: b1babb2

* grep for error in unittest logs

* change nelem type in token_array_nelem

* changes reflected Kevin's review on Mar 22

* address most comments

* Squashed 'deps/ccommon/' changes from b1babb2..9264bbb

9264bbb Zero byte (#147) (emergency fix needed for pelikan)
d4002d7 simplify cc_print_int64 (#146)
b164fcf Clean-up hash functions and introduce MurmurHash3 (#145)

git-subtree-dir: deps/ccommon
git-subtree-split: 9264bbb

* changes needed to use new hash function names

* add more tests and fix corresponding bugs

* temporarily disable flaky build

* feedback from seppo0010

* adding comment to token.h
  • Loading branch information
Yao Yue authored Apr 4, 2017
1 parent 524922d commit 8a7e319
Show file tree
Hide file tree
Showing 39 changed files with 2,717 additions and 557 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ matrix:

# clang 3.7 on osx
- os: osx
osx_image: xcode7.1
osx_image: xcode7.3
env: C_COMPILER=clang

# # clang 4.2 on osx
# - os: osx
# osx_image: xcode8.2
# env: C_COMPILER=clang


before_install:
# for osx: 0. update brew; 1. install cmake if missing; 2. (gcc) unlink pre-installed gcc; 3. (gcc) install desired version of gcc
Expand All @@ -93,4 +98,5 @@ script:
- cmake ..
- make -j
- make check
- egrep -r ":F:|:E:" . || true
- cd ../test/integration && python test_twemcache.py
6 changes: 6 additions & 0 deletions deps/ccommon/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ matrix:
osx_image: xcode7.1
env: C_COMPILER=clang

# # clang 4.2 on osx
# - os: osx
# osx_image: xcode8.2
# env: C_COMPILER=clang


before_install:
# for osx: 0. update brew; 1. install cmake if missing; 2. (gcc) unlink pre-installed gcc; 3. (gcc) install desired version of gcc
Expand All @@ -93,3 +98,4 @@ script:
- cmake ..
- make -j
- make check
- egrep -r ":F:|:E:" . || true
2 changes: 1 addition & 1 deletion deps/ccommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endif()

# version info
set(${PROJECT_NAME}_VERSION_MAJOR 1)
set(${PROJECT_NAME}_VERSION_MINOR 1)
set(${PROJECT_NAME}_VERSION_MINOR 2)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}
Expand Down
4 changes: 4 additions & 0 deletions deps/ccommon/include/buffer/cc_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ buf_read(char *dst, struct buf *src, uint32_t count)
static inline uint32_t
buf_write(struct buf *dst, char *src, uint32_t count)
{
if (count == 0) {
return 0;
}

ASSERT(dst != NULL && src != NULL);

uint32_t len = MIN(buf_wsize(dst), count);
Expand Down
38 changes: 0 additions & 38 deletions deps/ccommon/include/cc_lookup3.h

This file was deleted.

3 changes: 3 additions & 0 deletions deps/ccommon/include/cc_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ extern "C" {

/* behavior undefined if there isn't enough space in buf */
size_t cc_print_uint64_unsafe(char *buf, uint64_t n);
size_t cc_print_int64_unsafe(char *buf, int64_t n);

size_t cc_print_uint64(char *buf, size_t size, uint64_t n);
size_t cc_print_int64(char *buf, size_t size, int64_t n);

size_t _scnprintf(char *buf, size_t size, const char *fmt, ...);
size_t _vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
Expand Down
4 changes: 4 additions & 0 deletions deps/ccommon/include/cc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ extern "C" {
* # define UINT16_MAX (65535)
* # define UINT32_MAX (4294967295U)
* # define UINT64_MAX (__UINT64_C(18446744073709551615))
*
* # define INT64_MIN -9223372036854775808LL
*/
#define CC_UINT8_MAXLEN (3 + 1)
#define CC_UINT16_MAXLEN (5 + 1)
#define CC_UINT32_MAXLEN (10 + 1)
#define CC_UINT64_MAXLEN (20 + 1)
#define CC_UINTMAX_MAXLEN CC_UINT64_MAXLEN

#define CC_INT64_MAXLEN (1 + 19 + 1)

/* alignment */
/* Make data 'd' or pointer 'p', n-byte aligned, where n is a power of 2 */
#define CC_ALIGNMENT sizeof(unsigned long) /* platform word */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>

uint32_t hash(const void *key, size_t length, const uint32_t initval);
uint32_t hash_lookup3(const void *key, size_t length, const uint32_t initval);

#ifdef __cplusplus
}
Expand Down
39 changes: 39 additions & 0 deletions deps/ccommon/include/hash/cc_murmur3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* ccommon - a cache common library.
* Copyright (C) 2013 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* The cc_murmur3.[ch] are adapated from the canonical implementation of
* MurmurHash3 by Austin Appleby, released as part of SMHasher:
* https://github.com/aappleby/smhasher
*
* Changes include renaming fuctions, removing MSVC-related code, adding "static"
* keyword to local-scope functions according to C language spec (original code is
* in C++), to better fit them into the scope and style of ccommon
*
* The actual implementation is untouched.
*/

#pragma once

#include <stdint.h>


void hash_murmur3_32 ( const void * key, int len, uint32_t seed, void * out );

void hash_murmur3_128_x86 ( const void * key, int len, uint32_t seed, void * out );

void hash_murmur3_128_x64 ( const void * key, int len, uint32_t seed, void * out );
39 changes: 39 additions & 0 deletions deps/ccommon/src/cc_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* implementation as a reference (folly/Conv.h)
*/

/* use our own macro instead of llabs() to make sure it works with INT64_MIN */
#define abs_int64(_x) ((_x) >= 0 ? (_x) : -(_x))

static inline void
_print_uint64(char *buf, size_t d, uint64_t n)
{
Expand All @@ -46,6 +49,22 @@ cc_print_uint64_unsafe(char *buf, uint64_t n)
return d;
}

size_t
cc_print_int64_unsafe(char *buf, int64_t n)
{
size_t d;
uint64_t ab = abs_int64(n);

if (n < 0) {
*buf++ = '-';
}

d = digits(ab);
_print_uint64(buf, d, ab);

return d + (n < 0);
}

size_t
cc_print_uint64(char *buf, size_t size, uint64_t n)
{
Expand All @@ -61,6 +80,26 @@ cc_print_uint64(char *buf, size_t size, uint64_t n)
return d;
}

size_t
cc_print_int64(char *buf, size_t size, int64_t n)
{
size_t d;
uint64_t ab = abs_int64(n);

d = digits(ab);
if (size < d + (n < 0)) {
return 0;
}

if (n < 0) {
*buf++ = '-';
}

_print_uint64(buf, d, n);

return d + (n < 0);
}

size_t
_vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
Expand Down
2 changes: 1 addition & 1 deletion deps/ccommon/src/hash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(SOURCE
${SOURCE}
hash/cc_hash.c
hash/cc_lookup3.c
hash/cc_murmur3.c
PARENT_SCOPE)
Loading

0 comments on commit 8a7e319

Please sign in to comment.