Skip to content

Commit

Permalink
untested progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kentslaney committed Nov 20, 2023
1 parent ce0d6bc commit db189f1
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
with:
go-version: ${{ matrix.gover }}
- name: Start memcached servers
run: ./misc/memcached_server start
run: ./misc/memcached_server startall
- name: Run gotest
run: |
if [[ ${{ matrix.compiler }} = "gcc" ]]; then export CC=gcc CXX=g++; fi
if [[ ${{ matrix.compiler }} = "clang" ]]; then export CC=clang CXX=clang++; fi
./misc/travis/gotest.sh
- name: Stop memcached servers
run: ./misc/memcached_server stop
run: ./misc/memcached_server stopall
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:
python -m pip install --upgrade pip
pip install setuptools future pytest greenify gevent numpy
- name: Start memcached servers
run: ./misc/memcached_server start
run: ./misc/memcached_server startall
- name: Run unittest
run: |
if [[ ${{ matrix.compiler }} = "gcc" ]]; then export CC=gcc CXX=g++; fi
if [[ ${{ matrix.compiler }} = "clang" ]]; then export CC=clang CXX=clang++; fi
./misc/travis/unittest.sh
- name: Stop memcached servers
run: ./misc/memcached_server stop
run: ./misc/memcached_server stopall

benchmark:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ typedef enum {
} op_code_t;

const char* errCodeToString(err_code_t err);
bool isLocalSocket(const char* host);
char** splitServerString(char* input);

} // namespace mc
} // namespace douban
4 changes: 3 additions & 1 deletion libmc/_client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ cdef extern from "Common.h" namespace "douban::mc":
VERSION_OP
QUIT_OP

#bool isLocalSocket(const char* host) nogil


cdef extern from "Export.h":
ctypedef enum config_options_t:
Expand Down Expand Up @@ -382,7 +384,7 @@ cdef class PyClient:
addr = addr_alias[0]
if len(addr_alias) == 1:
alias = None
elif addr.endswith("\\"):
elif (len(addr) - len(addr.rstrip("\\"))) % 2 == 1:
addr = srv
alias = None
else:
Expand Down
9 changes: 8 additions & 1 deletion misc/memcached_server
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ case "$1" in
shift
unix $@
;;
unixstop)
startall)
unix &
for port in $PORTS; do
start $port &
done
wait
;;
stopall)
if [ `ls $basedir/var/run/ | grep -c .pid` -ge 1 ]; then
names="`basename $basedir/var/run/*.pid | cut -d. -f1`"
for name in $names; do
Expand Down
4 changes: 2 additions & 2 deletions misc/travis/cpptest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -ex

echo "CXX=${CXX}"
./misc/memcached_server start &>/dev/null &
./misc/memcached_server startall &>/dev/null &
python misc/generate_hash_dataset.py tests/resources/keys.txt &>/dev/null &
mkdir -p build
cd build
Expand All @@ -11,4 +11,4 @@ make -j8 &>/dev/null
wait
ARGS=-V make test
cd ..
./misc/memcached_server stop &>/dev/null &
./misc/memcached_server stopall &>/dev/null &
31 changes: 31 additions & 0 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,36 @@ const char* errCodeToString(err_code_t err) {
}
}

bool isLocalPath(const char* host) {
return host[0] == '/';
}

char** splitServerString(char* input) {
bool escaped = false;
char *res[3] = { input--, NULL, NULL };
for (;;) {
switch (*(++input))
{
case ':': // invalid in a UNIX path
*input = '\0';
res[1] = input + 1;
case '\0':
break;
case ' ':
if (!escaped) {
*input = '\0';
res[2] = input + 1;
break;
}
default:
escaped = false;
continue;
case '\\':
escaped ^= 1;
}
}
return res;
}

} // namespace mc
} // namespace douban
4 changes: 2 additions & 2 deletions src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Connection::~Connection() {
int Connection::init(const char* host, uint32_t port, const char* alias) {
snprintf(m_host, sizeof m_host, "%s", host);
m_port = port;
m_local = m_host[0] == '/'; // un.h UNIX_PATH_MAX < netdb.h NI_MAXHOST
m_local = isLocalSocket(m_host); // un.h UNIX_PATH_MAX < netdb.h NI_MAXHOST
if (alias == NULL) {
m_hasAlias = false;
if (m_local) {
Expand Down Expand Up @@ -131,7 +131,7 @@ int Connection::connect() {
return m_alive ? 0 : -1;
}

inline int Connection::local() {
int Connection::local() {
int fd, flags, opt_keepalive = 1;

if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
Expand Down
1 change: 1 addition & 0 deletions src/golibmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func (client *Client) newConn() (*conn, error) {
cAliases := make([]*C.char, n)

for i, srv := range client.servers {
// TODO: UNIX paths
addrAndAlias := strings.Split(srv, " ")

addr := addrAndAlias[0]
Expand Down
32 changes: 16 additions & 16 deletions tests/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ void gen_random(char *s, const int len) {
}


mc::Client* md5Client(const char* const * hosts, const uint32_t* ports, const size_t n,
const char* const * aliases = NULL) {
mc::Client* client = new mc::Client();
client->config(CFG_HASH_FUNCTION, OPT_HASH_MD5);
client->init(hosts, ports, n, aliases);
broadcast_result_t* results;
size_t nHosts;
int ret = client->version(&results, &nHosts);
client->destroyBroadcastResult();
if (ret != 0) {
delete client;
return NULL;
}
return client;
}

mc::Client* newClient(int n) {
assert(n <= 20);
const char * hosts[] = {
Expand Down Expand Up @@ -76,22 +92,6 @@ mc::Client* newClient(int n) {
return md5Client(hosts, ports, n, aliases);
}

mc::Client* md5Client(const char* const * hosts, const uint32_t* ports, const size_t n,
const char* const * aliases = NULL) {
mc::Client* client = new mc::Client();
client->config(CFG_HASH_FUNCTION, OPT_HASH_MD5);
client->init(hosts, ports, n, aliases);
broadcast_result_t* results;
size_t nHosts;
int ret = client->version(&results, &nHosts);
client->destroyBroadcastResult();
if (ret != 0) {
delete client;
return NULL;
}
return client;
}

mc::Client* newUnixClient() {
const char * hosts[] = { "/tmp/env_mc_dev/var/run/unix_test.socket" };
const uint32_t ports[] = { 0 };
Expand Down

0 comments on commit db189f1

Please sign in to comment.