Permalink
Browse files

Blueprint 'Enable manual slave-to-master propagation': review fixes.

  • Loading branch information...
1 parent 5514f4a commit caad447944a6c3764ad630178a8dc0bdb11433e4 @rtokarev rtokarev committed May 25, 2011
View
@@ -24,8 +24,52 @@ cmpNameAtoms(NameAtom *a, NameAtom *b) {
return (a == NULL && b == NULL) ? 1 : 0;
}
+void
+init_tarantool_cfg(tarantool_cfg *c) {
+ c->__confetti_flags = 0;
+
+ c->username = NULL;
+ c->coredump = 0;
+ c->admin_port = 0;
+ c->log_level = 0;
+ c->slab_alloc_arena = 0;
+ c->slab_alloc_minimal = 0;
+ c->slab_alloc_factor = 0;
+ c->work_dir = NULL;
+ c->pid_file = NULL;
+ c->logger = NULL;
+ c->logger_nonblock = 0;
+ c->io_collect_interval = 0;
+ c->backlog = 0;
+ c->readahead = 0;
+ c->snap_dir = NULL;
+ c->wal_dir = NULL;
+ c->primary_port = 0;
+ c->secondary_port = 0;
+ c->too_long_threshold = 0;
+ c->custom_proc_title = NULL;
+ c->memcached = 0;
+ c->memcached_namespace = 0;
+ c->memcached_expire_per_loop = 0;
+ c->memcached_expire_full_sweep = 0;
+ c->snap_io_rate_limit = 0;
+ c->rows_per_wal = 0;
+ c->wal_fsync_delay = 0;
+ c->wal_writer_inbox_size = 0;
+ c->local_hot_standby = 0;
+ c->wal_dir_rescan_delay = 0;
+ c->panic_on_snap_error = 0;
+ c->panic_on_wal_error = 0;
+ c->remote_hot_standby = 0;
+ c->wal_feeder_ipaddr = NULL;
+ c->wal_feeder_port = 0;
+ c->namespace = NULL;
+}
+
int
fill_default_tarantool_cfg(tarantool_cfg *c) {
+ c->__confetti_flags = 0;
+
c->username = NULL;
c->coredump = 0;
c->admin_port = 0;
View
@@ -170,6 +170,8 @@ typedef struct tarantool_cfg {
#define CNF_STRUCT_DEFINED(s) ((s) != NULL && ((s)->__confetti_flags & CNF_FLAG_STRUCT_NOTSET) == 0)
#endif
+void init_tarantool_cfg(tarantool_cfg *c);
+
int fill_default_tarantool_cfg(tarantool_cfg *c);
void parse_cfg_file_tarantool_cfg(tarantool_cfg *c, FILE *fh, int check_rdonly, int *n_accepted, int *n_skipped);
View
@@ -24,8 +24,34 @@ cmpNameAtoms(NameAtom *a, NameAtom *b) {
return (a == NULL && b == NULL) ? 1 : 0;
}
+void
+init_tarantool_cfg(tarantool_cfg *c) {
+ c->__confetti_flags = 0;
+
+ c->username = NULL;
+ c->coredump = 0;
+ c->admin_port = 0;
+ c->log_level = 0;
+ c->slab_alloc_arena = 0;
+ c->slab_alloc_minimal = 0;
+ c->slab_alloc_factor = 0;
+ c->work_dir = NULL;
+ c->pid_file = NULL;
+ c->logger = NULL;
+ c->logger_nonblock = 0;
+ c->io_collect_interval = 0;
+ c->backlog = 0;
+ c->readahead = 0;
+ c->wal_feeder_bind_ipaddr = NULL;
+ c->wal_feeder_bind_port = 0;
+ c->wal_feeder_dir = NULL;
+ c->custom_proc_title = NULL;
+}
+
int
fill_default_tarantool_cfg(tarantool_cfg *c) {
+ c->__confetti_flags = 0;
+
c->username = NULL;
c->coredump = 0;
c->admin_port = 0;
@@ -86,6 +86,8 @@ typedef struct tarantool_cfg {
#define CNF_STRUCT_DEFINED(s) ((s) != NULL && ((s)->__confetti_flags & CNF_FLAG_STRUCT_NOTSET) == 0)
#endif
+void init_tarantool_cfg(tarantool_cfg *c);
+
int fill_default_tarantool_cfg(tarantool_cfg *c);
void parse_cfg_file_tarantool_cfg(tarantool_cfg *c, FILE *fh, int check_rdonly, int *n_accepted, int *n_skipped);
View
@@ -56,7 +56,7 @@ set (recompiled_core_sources
set (common_sources tbuf.m palloc.m util.m diagnostics.m
salloc.m pickle.m coro.m stat.m log_io.m
- log_io_remote.m iproto.m exceptions.m errcode.c latch.c)
+ log_io_remote.m iproto.m exceptions.m errcode.c latch.m)
if (ENABLE_TRACE)
set (common_sources ${common_sources} trace.m)
@@ -27,21 +27,39 @@ void
tnt_latch_init(struct tnt_latch *latch)
{
latch->locked = false;
+ latch->owner = NULL;
}
-bool
+void
+tnt_latch_destroy(struct tnt_latch *latch)
+{
+ assert(latch->locked == false);
+
+ latch->owner = NULL;
+}
+
+int
tnt_latch_trylock(struct tnt_latch *latch)
{
- if (latch->locked)
- return false;
+ if (latch->locked) {
+ assert(latch->owner != fiber);
+
+ return -1;
+ }
+
+ assert(latch->owner == NULL);
latch->locked = true;
+ latch->owner = fiber;
- return true;
+ return 0;
}
void
tnt_latch_unlock(struct tnt_latch *latch)
{
+ assert(latch->owner == fiber);
+
latch->locked = false;
+ latch->owner = NULL;
}
View
@@ -133,22 +133,19 @@
struct remote_state *h = state;
struct tbuf *row;
- fiber_setcancelstate(true);
-
for (;;) {
+ fiber_setcancelstate(true);
row = remote_read_row(h->r->confirmed_lsn + 1);
+ fiber_setcancelstate(false);
+
h->r->recovery_lag = ev_now() - row_v11(row)->tm;
h->r->recovery_last_update_tstamp = ev_now();
- fiber_setcancelstate(false);
-
if (h->handler(h->r, row) < 0) {
fiber_close();
continue;
}
- fiber_setcancelstate(true);
-
fiber_gc();
}
}
View
@@ -70,7 +70,7 @@
extern int daemonize(int nochdir, int noclose);
static i32
-load_cfg(struct tarantool_cfg *conf, i32 check_rdonly, bool reload)
+load_cfg(struct tarantool_cfg *conf, i32 check_rdonly)
{
FILE *f;
i32 n_accepted, n_skipped;
@@ -97,87 +97,86 @@
if (n_accepted == 0 || n_skipped != 0)
return -1;
- return mod_check_config(conf, reload);
+ return mod_check_config(conf);
}
-static i32
-reload_cfg_safe(struct tbuf *out)
+static void
+swap_tarantool_cfg(struct tarantool_cfg *old_cfg, struct tarantool_cfg *new_cfg)
{
- struct tarantool_cfg new_cfg1, new_cfg2;
- i32 ret;
-
- // Load with checking readonly params
- if (dup_tarantool_cfg(&new_cfg1, &cfg) != 0) {
- destroy_tarantool_cfg(&new_cfg1);
-
- return -1;
- }
- ret = load_cfg(&new_cfg1, 1, true);
- if (ret == -1) {
- tbuf_append(out, cfg_out->data, cfg_out->len);
-
- destroy_tarantool_cfg(&new_cfg1);
-
- return -1;
- }
- // Load without checking readonly params
- if (fill_default_tarantool_cfg(&new_cfg2) != 0) {
- destroy_tarantool_cfg(&new_cfg2);
-
- return -1;
- }
- ret = load_cfg(&new_cfg2, 0, true);
- if (ret == -1) {
- tbuf_append(out, cfg_out->data, cfg_out->len);
-
- destroy_tarantool_cfg(&new_cfg1);
-
- return -1;
- }
- // Compare only readonly params
- char *diff = cmp_tarantool_cfg(&new_cfg1, &new_cfg2, 1);
- if (diff != NULL) {
- destroy_tarantool_cfg(&new_cfg1);
- destroy_tarantool_cfg(&new_cfg2);
+ struct tarantool_cfg tmp;
- out_warning(0, "Could not accept read only '%s' option", diff);
- tbuf_append(out, cfg_out->data, cfg_out->len);
-
- return -1;
- }
- destroy_tarantool_cfg(&new_cfg1);
-
- mod_reload_config(&cfg, &new_cfg2);
-
- destroy_tarantool_cfg(&cfg);
-
- cfg = new_cfg2;
-
- return 0;
+ tmp = *old_cfg;
+ *old_cfg = *new_cfg;
+ *new_cfg = tmp;
}
i32
reload_cfg(struct tbuf *out)
{
static struct tnt_latch *latch = NULL;
- i32 ret;
+ struct tarantool_cfg new_cfg, aux_cfg;
if (latch == NULL) {
latch = palloc(eter_pool, sizeof(*latch));
tnt_latch_init(latch);
}
- if (tnt_latch_trylock(latch) == false) {
- out_warning(0, "Could not reload configuration: it is reloading right now");
+ if (tnt_latch_trylock(latch) == -1) {
+ out_warning(0, "Could not reload configuration: it is being reloaded right now");
+ tbuf_append(out, cfg_out->data, cfg_out->len);
return -1;
}
- ret = reload_cfg_safe(out);
+ @try {
+ init_tarantool_cfg(&new_cfg);
+ init_tarantool_cfg(&aux_cfg);
- tnt_latch_unlock(latch);
+ /*
+ Prepare a copy of the original config file
+ for confetti, so that it can compare the new
+ file with the old one when loading the new file.
+ Load the new file and return an error if the it
+ contains a different value for some read-only
+ parameter.
+ */
+ if (dup_tarantool_cfg(&aux_cfg, &cfg) != 0 ||
+ load_cfg(&aux_cfg, 1) != 0)
+ return -1;
+ /*
+ Load the new configuration file, but
+ skip the check for read only parameters.
+ new_cfg contains only defaults and
+ new settings.
+ */
+ if (fill_default_tarantool_cfg(&new_cfg) != 0 ||
+ load_cfg(&new_cfg, 0) != 0)
+ return -1;
+
+ /* Check that no default value has been changed. */
+ char *diff = cmp_tarantool_cfg(&aux_cfg, &new_cfg, 1);
+ if (diff != NULL) {
+ out_warning(0, "Could not accept read only '%s' option", diff);
+ return -1;
+ }
+
+ /* Now pass the config to the module, to take action. */
+ if (mod_reload_config(&cfg, &new_cfg) != 0)
+ return -1;
+ /* All OK, activate the config. */
+ swap_tarantool_cfg(&cfg, &new_cfg);
+ }
+ @finally {
+ destroy_tarantool_cfg(&aux_cfg);
+ destroy_tarantool_cfg(&new_cfg);
- return ret;
+ if (cfg_out->len != 0)
+ tbuf_append(out, cfg_out->data, cfg_out->len);
+
+ tnt_latch_unlock(latch);
+ }
+
+ return 0;
}
const char *
@@ -445,7 +444,7 @@
assert(cfg_out);
if (gopt(opt, 'k')) {
- if (fill_default_tarantool_cfg(&cfg) != 0 || load_cfg(&cfg, 0, false) != 0) {
+ if (fill_default_tarantool_cfg(&cfg) != 0 || load_cfg(&cfg, 0) != 0) {
say_error("check_config FAILED"
"%.*s", cfg_out->len, (char *)cfg_out->data);
@@ -455,7 +454,7 @@
return 0;
}
- if (fill_default_tarantool_cfg(&cfg) != 0 || load_cfg(&cfg, 0, false) != 0)
+ if (fill_default_tarantool_cfg(&cfg) != 0 || load_cfg(&cfg, 0) != 0)
panic("can't load config:"
"%.*s", cfg_out->len, (char *)cfg_out->data);
View
@@ -23,16 +23,20 @@
* SUCH DAMAGE.
*/
+#include <fiber.h>
+
#include <stdbool.h>
/*
* Internal implementation of a container for a mutex like object
* with similar interface. It's used boolean variable because of
* single threaded nature of tarantool. But it's rather simple to change
- * this varibable to a mutex object to maintain multi threaded aproach.
+ * this variable to a mutex object to maintain multi threaded approach.
*/
struct tnt_latch {
bool locked;
+
+ struct fiber *owner;
};
/**
@@ -42,12 +46,16 @@ struct tnt_latch {
*/
void tnt_latch_init(struct tnt_latch *latch);
/**
+ * Destroy the given latch.
+ */
+void tnt_latch_destroy(struct tnt_latch *latch);
+/**
* Set the latch to the locked state. If it's already locked
- * returns false value immediatly.
+ * returns -1 value immediately otherwise returns 0.
*
* @param latch Latch to be locked.
*/
-bool tnt_latch_trylock(struct tnt_latch *latch);
+int tnt_latch_trylock(struct tnt_latch *latch);
/**
* Unlock the locked latch.
*
Oops, something went wrong.

0 comments on commit caad447

Please sign in to comment.