summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Lin <developer@kevinlin.info>2020-11-15 10:43:52 -0800
committerdormando <dormando@rydia.net>2020-11-20 12:23:47 -0800
commit2d118d43d4607d86f2312f0dd44815833da39a59 (patch)
tree2e8d30cf3c8894c521db4557883e50368449f509
parentb2cee81823ba32adf09a6666d92aee56a8d98056 (diff)
downloadmemcached-2d118d43d4607d86f2312f0dd44815833da39a59.tar.gz
Expose memory_file path in stats settings
-rw-r--r--doc/protocol.txt1
-rw-r--r--memcached.c13
-rw-r--r--memcached.h1
-rw-r--r--t/restart.t6
4 files changed, 15 insertions, 6 deletions
diff --git a/doc/protocol.txt b/doc/protocol.txt
index 9a48aa7..625db25 100644
--- a/doc/protocol.txt
+++ b/doc/protocol.txt
@@ -1394,6 +1394,7 @@ other stats command.
| | bool | Does nothing as of 1.5.15 |
| drop_privileges | bool | If yes, and available, drop unused syscalls |
| | | (see seccomp on Linux, pledge on OpenBSD) |
+| memory_file | char | Warm restart memory file path, if enabled |
|-------------------+----------+----------------------------------------------|
diff --git a/memcached.c b/memcached.c
index e21c166..b4bac62 100644
--- a/memcached.c
+++ b/memcached.c
@@ -289,6 +289,7 @@ static void settings_init(void) {
settings.relaxed_privileges = false;
#endif
settings.num_napi_ids = 0;
+ settings.memory_file = NULL;
}
extern pthread_mutex_t conn_lock;
@@ -1877,6 +1878,7 @@ void process_stat_settings(ADD_STAT add_stats, void *c) {
APPEND_STAT("ssl_session_cache", "%s", settings.ssl_session_cache ? "yes" : "no");
#endif
APPEND_STAT("num_napi_ids", "%s", settings.num_napi_ids);
+ APPEND_STAT("memory_file", "%s", settings.memory_file);
}
static int nz_strcmp(int nzlength, const char *nz, const char *z) {
@@ -4494,7 +4496,6 @@ int main (int argc, char **argv) {
int maxcore = 0;
char *username = NULL;
char *pid_file = NULL;
- char *memory_file = NULL;
struct passwd *pw;
struct rlimit rlim;
char *buf;
@@ -4847,7 +4848,7 @@ int main (int argc, char **argv) {
pid_file = optarg;
break;
case 'e':
- memory_file = optarg;
+ settings.memory_file = optarg;
break;
case 'f':
settings.factor = atof(optarg);
@@ -5666,13 +5667,13 @@ int main (int argc, char **argv) {
bool reuse_mem = false;
void *mem_base = NULL;
bool prefill = false;
- if (memory_file != NULL) {
+ if (settings.memory_file != NULL) {
preallocate = true;
// Easier to manage memory if we prefill the global pool when reusing.
prefill = true;
restart_register("main", _mc_meta_load_cb, _mc_meta_save_cb, meta);
reuse_mem = restart_mmap_open(settings.maxbytes,
- memory_file,
+ settings.memory_file,
&mem_base);
// The "save" callback gets called when we're closing out the mmap,
// but we don't know what the mmap_base is until after we call open.
@@ -5714,7 +5715,7 @@ int main (int argc, char **argv) {
if (prefill)
slabs_prefill_global();
/* In restartable mode and we've decided to issue a fixup on memory */
- if (memory_file != NULL && reuse_mem) {
+ if (settings.memory_file != NULL && reuse_mem) {
mc_ptr_t old_base = meta->old_base;
assert(old_base == meta->old_base);
@@ -5903,7 +5904,7 @@ int main (int argc, char **argv) {
}
stop_threads();
- if (memory_file != NULL && stop_main_loop == GRACE_STOP) {
+ if (settings.memory_file != NULL && stop_main_loop == GRACE_STOP) {
restart_mmap_close();
}
diff --git a/memcached.h b/memcached.h
index 776f687..8149cf4 100644
--- a/memcached.h
+++ b/memcached.h
@@ -489,6 +489,7 @@ struct settings {
bool ssl_session_cache; /* enable SSL server session caching */
#endif
int num_napi_ids; /* maximum number of NAPI IDs */
+ char *memory_file; /* warm restart memory file path */
};
extern struct stats stats;
diff --git a/t/restart.t b/t/restart.t
index dde0b31..277bcae 100644
--- a/t/restart.t
+++ b/t/restart.t
@@ -24,6 +24,12 @@ my $mem_path = "/tmp/mc_restart.$$";
my $server = new_memcached("-m 128 -e $mem_path -I 2m");
my $sock = $server->sock;
+diag "restart basic stats";
+{
+ my $stats = mem_stats($server->sock, ' settings');
+ is($stats->{memory_file}, $mem_path);
+}
+
diag "Set some values, various sizes.";
{
my $cur = 2;