Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

26 changes: 21 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ memcached_SOURCES = memcached.c memcached.h \
crawler.c crawler.h \
itoa_ljust.c itoa_ljust.h \
slab_automove.c slab_automove.h \
slabs_mover.c slabs_mover.h \
authfile.c authfile.h \
restart.c restart.h \
proto_text.c proto_text.h \
Expand Down Expand Up @@ -57,12 +58,20 @@ endif

if ENABLE_PROXY
memcached_SOURCES += proto_proxy.c proto_proxy.h vendor/mcmc/mcmc.h \
vendor/mcmc/mcmc.c \
proxy_xxhash.c proxy.h \
proxy_await.c proxy_ustats.c \
proxy_ustats.c \
proxy_ratelim.c \
proxy_jump_hash.c proxy_request.c \
proxy_result.c proxy_inspector.c \
proxy_mutator.c \
proxy_network.c proxy_lua.c \
proxy_luafgen.c \
proxy_config.c proxy_ring_hash.c \
md5.c md5.h
proxy_internal.c \
proxy_tls.c proxy_tls.h \
md5.c md5.h \
vendor/routelib/routelib.h
endif

if ENABLE_EXTSTORE
Expand All @@ -82,6 +91,8 @@ memcached_debug_LDADD = @PROFILER_LDFLAGS@
memcached_debug_CFLAGS = @PROFILER_FLAGS@

memcached_LDADD =
memcached_LDFLAGS =
memcached_debug_LDFLAGS =
memcached_DEPENDENCIES =
memcached_debug_DEPENDENCIES =
CLEANFILES=
Expand All @@ -105,8 +116,10 @@ CLEANFILES += memcached_dtrace.o memcached_debug_dtrace.o
endif

if ENABLE_PROXY
memcached_LDADD += vendor/lua/src/liblua.a vendor/mcmc/mcmc.o
memcached_debug_LDADD += vendor/lua/src/liblua.a vendor/mcmc/mcmc.o
memcached_LDADD += vendor/lua/src/liblua.a
memcached_debug_LDADD += vendor/lua/src/liblua.a
memcached_LDFLAGS += -rdynamic
memcached_debug_LDFLAGS += -rdynamic
endif

if ENABLE_PROXY_URING
Expand Down Expand Up @@ -138,7 +151,10 @@ memcached_debug_dtrace.o: $(memcached_debug_OBJECTS)
SUBDIRS = doc
DIST_DIRS = scripts
EXTRA_DIST = doc scripts t memcached.spec memcached_dtrace.d version.m4 README.md LICENSE.bipbuffer
EXTRA_DIST += vendor/Makefile vendor/lua vendor/mcmc
EXTRA_DIST += vendor/Makefile vendor/lua/doc/* vendor/lua/Makefile vendor/lua/README
EXTRA_DIST += vendor/lua/src/*.c vendor/lua/src/*.h vendor/lua/src/Makefile
EXTRA_DIST += vendor/mcmc/LICENSE vendor/mcmc/Makefile vendor/mcmc/README.md vendor/mcmc/*.c vendor/mcmc/*.h
EXTRA_DIST += vendor/routelib/*.h vendor/routelib/*.lua

if ENABLE_PROXY
SUBDIRS += vendor
Expand Down
478 changes: 403 additions & 75 deletions Makefile.in

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,79 @@ list to ask questions, github issues aren't seen by everyone!
* openssl (optional) - enables TLS support. need relatively up to date
version. pkg-config is needed to find openssl dependencies (such as -lz).

## Building from tarball

If you downloaded this from the tarball, compilation is the standard process:

```
./configure
make
make test # optional
make install
```

If you want TLS support, install OpenSSL's development packages and change the
configure line:

```
./configure --enable-tls
```

If you want to enable the memcached proxy:

```
./configure --enable-proxy
```

## Building from git

To build memcached in your machine from local repo you will have to install
autotools, automake and libevent. In a debian based system that will look
like this

```
sudo apt-get install autotools-dev automake libevent-dev
```

After that you can build memcached binary using automake

```
cd memcached
./autogen.sh
./configure
make
make test
```

It should create the binary in the same folder, which you can run

```
./memcached
```

You can telnet into that memcached to ensure it is up and running

```
telnet 127.0.0.1 11211
stats
```

IF BUILDING PROXY, AN EXTRA STEP IS NECESSARY:

The proxy has some additional vendor dependency code that we keep out of the
tree.

```
cd memcached
cd vendor
./fetch.sh
cd ..
./autogen.sh
./configure --enable-proxy
make
make test
```

## Environment

Be warned that the -k (mlockall) option to memcached might be
Expand Down
90 changes: 79 additions & 11 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])

# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
# pkg.m4 - Macros to locate and use pkg-config. -*- Autoconf -*-
# serial 12 (pkg-config-0.29.2)

dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
Expand Down Expand Up @@ -108,7 +108,7 @@ dnl Check to see whether a particular set of modules exists. Similar to
dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
dnl
dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
dnl only at the first occurence in configure.ac, so if the first place
dnl only at the first occurrence in configure.ac, so if the first place
dnl it's called might be skipped (such as if it is within an "if", you
dnl have to call PKG_CHECK_EXISTS manually
AC_DEFUN([PKG_CHECK_EXISTS],
Expand Down Expand Up @@ -177,14 +177,14 @@ if test $pkg_failed = yes; then
AC_MSG_RESULT([no])
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD

m4_default([$4], [AC_MSG_ERROR(
m4_default([$4], [AC_MSG_ERROR(
[Package requirements ($2) were not met:

$$1_PKG_ERRORS
Expand All @@ -196,7 +196,7 @@ _PKG_TEXT])[]dnl
])
elif test $pkg_failed = untried; then
AC_MSG_RESULT([no])
m4_default([$4], [AC_MSG_FAILURE(
m4_default([$4], [AC_MSG_FAILURE(
[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
Expand All @@ -206,10 +206,10 @@ _PKG_TEXT
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
])
else
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
AC_MSG_RESULT([yes])
$3
$3
fi[]dnl
])dnl PKG_CHECK_MODULES

Expand Down Expand Up @@ -296,6 +296,74 @@ AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
])dnl PKG_CHECK_VAR

dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
dnl [DESCRIPTION], [DEFAULT])
dnl ------------------------------------------
dnl
dnl Prepare a "--with-" configure option using the lowercase
dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
dnl PKG_CHECK_MODULES in a single macro.
AC_DEFUN([PKG_WITH_MODULES],
[
m4_pushdef([with_arg], m4_tolower([$1]))

m4_pushdef([description],
[m4_default([$5], [build with ]with_arg[ support])])

m4_pushdef([def_arg], [m4_default([$6], [auto])])
m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])

m4_case(def_arg,
[yes],[m4_pushdef([with_without], [--without-]with_arg)],
[m4_pushdef([with_without],[--with-]with_arg)])

AC_ARG_WITH(with_arg,
AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
[AS_TR_SH([with_]with_arg)=def_arg])

AS_CASE([$AS_TR_SH([with_]with_arg)],
[yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
[auto],[PKG_CHECK_MODULES([$1],[$2],
[m4_n([def_action_if_found]) $3],
[m4_n([def_action_if_not_found]) $4])])

m4_popdef([with_arg])
m4_popdef([description])
m4_popdef([def_arg])

])dnl PKG_WITH_MODULES

dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [DESCRIPTION], [DEFAULT])
dnl -----------------------------------------------
dnl
dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
dnl check._[VARIABLE-PREFIX] is exported as make variable.
AC_DEFUN([PKG_HAVE_WITH_MODULES],
[
PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])

AM_CONDITIONAL([HAVE_][$1],
[test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
])dnl PKG_HAVE_WITH_MODULES

dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [DESCRIPTION], [DEFAULT])
dnl ------------------------------------------------------
dnl
dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
dnl and preprocessor variable.
AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
[
PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])

AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
[AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
])dnl PKG_HAVE_DEFINE_WITH_MODULES

# Copyright (C) 2002-2021 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
Expand Down
19 changes: 14 additions & 5 deletions assoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,18 @@ item *assoc_find(const char *key, const size_t nkey, const uint32_t hv) {
}

item *ret = NULL;
#ifdef ENABLE_DTRACE
int depth = 0;
#endif
while (it) {
if ((nkey == it->nkey) && (memcmp(key, ITEM_key(it), nkey) == 0)) {
ret = it;
break;
}
it = it->h_next;
#ifdef ENABLE_DTRACE
++depth;
#endif
}
MEMCACHED_ASSOC_FIND(key, nkey, depth);
return ret;
Expand Down Expand Up @@ -229,7 +233,7 @@ static void *assoc_maintenance_thread(void *arg) {
}

} else {
usleep(10*1000);
usleep(10*1000 - 1);
}

if (item_lock) {
Expand Down Expand Up @@ -261,7 +265,7 @@ static void *assoc_maintenance_thread(void *arg) {

static pthread_t maintenance_tid;

int start_assoc_maintenance_thread() {
int start_assoc_maintenance_thread(void) {
int ret;
char *env = getenv("MEMCACHED_HASH_BULK_MOVE");
if (env != NULL) {
Expand All @@ -276,10 +280,11 @@ int start_assoc_maintenance_thread() {
fprintf(stderr, "Can't create thread: %s\n", strerror(ret));
return -1;
}
thread_setname(maintenance_tid, "mc-assocmaint");
return 0;
}

void stop_assoc_maintenance_thread() {
void stop_assoc_maintenance_thread(void) {
mutex_lock(&maintenance_lock);
do_run_maintenance_thread = 0;
pthread_cond_signal(&maintenance_cond);
Expand All @@ -302,8 +307,12 @@ void *assoc_get_iterator(void) {
return NULL;
}
// this will hang the caller while a hash table expansion is running.
mutex_lock(&maintenance_lock);
return iter;
if (mutex_trylock(&maintenance_lock) == 0) {
return iter;
} else {
free(iter);
return NULL;
}
}

bool assoc_iterate(void *iterp, item **it) {
Expand Down
5 changes: 3 additions & 2 deletions assoc.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* associative array */
void assoc_init(const int hashpower_init);

item *assoc_find(const char *key, const size_t nkey, const uint32_t hv);
int assoc_insert(item *item, const uint32_t hv);
void assoc_delete(const char *key, const size_t nkey, const uint32_t hv);
void do_assoc_move_next_bucket(void);

int start_assoc_maintenance_thread(void);
void stop_assoc_maintenance_thread(void);
void assoc_start_expand(uint64_t curr_items);

/* walk functions */
void *assoc_get_iterator(void);
bool assoc_iterate(void *iterp, item **it);
void assoc_iterate_final(void *iterp);

extern unsigned int hashpower;
extern unsigned int item_lock_hashpower;
7 changes: 5 additions & 2 deletions authfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ enum authfile_ret authfile_load(const char *file) {
return AUTHFILE_STATFAIL;
}

auth_data = calloc(1, sb.st_size + 1);
auth_data = calloc(1, sb.st_size + 2);

char *auth_cur = auth_data;
char *auth_end = auth_data + sb.st_size;
// fgets will stop at EOF or a newline, reading at most one bytes less
// than the size limit. If a user supplies a file without an ending
// newline we will end up chopping the last character of the password.
char *auth_end = auth_data + sb.st_size + 1;
auth_t *entry_cur = auth_entries;
int used = 0;

Expand Down
Loading
Loading