diff --git a/core/log_io.c b/core/log_io.c index 3d36719285ef250acd8516affed2a87f182e854d..963ab38368af36f0bc0353be908186e0a604240f 100644 --- a/core/log_io.c +++ b/core/log_io.c @@ -39,7 +39,7 @@ #include <fiber.h> #include <log_io.h> -#include "log_io_internal.h" +#include <log_io_internal.h> #include <palloc.h> #include <say.h> #include <third_party/crc32.h> @@ -77,18 +77,6 @@ struct log_io_iter { int io_rate_limit; }; -i64 -confirmed_lsn(struct recovery_state *r) -{ - return r->confirmed_lsn; -} - -struct child * -wal_writer(struct recovery_state *r) -{ - return r->wal_writer; -} - int confirm_lsn(struct recovery_state *r, i64 lsn) { @@ -893,7 +881,7 @@ recover_wal(struct recovery_state *r, struct log_io *l) while ((row = iter_inner(&i, (void *)1))) { i64 lsn = row_v11(row)->lsn; - if (r && lsn <= confirmed_lsn(r)) { + if (r && lsn <= r->confirmed_lsn) { say_debug("skipping too young row"); continue; } @@ -946,14 +934,14 @@ recover_remaining_wals(struct recovery_state *r) i64 current_lsn, wal_greatest_lsn; size_t rows_before; - current_lsn = confirmed_lsn(r) + 1; + current_lsn = r->confirmed_lsn + 1; wal_greatest_lsn = greatest_lsn(r->wal_prefered_class); /* if the caller already opened WAL for us, recover from it first */ if (r->current_wal != NULL) goto recover_current_wal; - while (confirmed_lsn(r) < wal_greatest_lsn) { + while (r->confirmed_lsn < wal_greatest_lsn) { /* if newer WAL appeared in directory before current_wal was fully read try reread last */ if (r->current_wal != NULL) { if (r->current_wal->retry++ < 3) { @@ -967,7 +955,7 @@ recover_remaining_wals(struct recovery_state *r) } } - current_lsn = confirmed_lsn(r) + 1; /* TODO: find better way looking for next xlog */ + current_lsn = r->confirmed_lsn + 1; /* TODO: find better way looking for next xlog */ next_wal = open_for_read(r, r->wal_class, current_lsn, suffix, NULL); if (next_wal == NULL) { if (suffix++ < 10) @@ -1014,7 +1002,7 @@ recover_remaining_wals(struct recovery_state *r) if (result == LOG_EOF) { say_info("done `%s' confirmed_lsn:%" PRIi64, r->current_wal->filename, - confirmed_lsn(r)); + r->confirmed_lsn); close_log(&r->current_wal); } suffix = 0; @@ -1024,7 +1012,7 @@ recover_remaining_wals(struct recovery_state *r) * it's not a fatal error then last wal is empty * but if we lost some logs it is fatal error */ - if (wal_greatest_lsn > confirmed_lsn(r) + 1) { + if (wal_greatest_lsn > r->confirmed_lsn + 1) { say_error("not all wals have been successfuly read"); result = -1; } @@ -1053,7 +1041,7 @@ recover(struct recovery_state *r, i64 lsn) } panic("snapshot recovery failed"); } - say_info("snapshot recovered, confirmed lsn:%" PRIi64, confirmed_lsn(r)); + say_info("snapshot recovered, confirmed lsn:%" PRIi64, r->confirmed_lsn); } else { /* * note, that recovery start with lsn _NEXT_ to confirmed one @@ -1066,7 +1054,7 @@ recover(struct recovery_state *r, i64 lsn) * so find wal which contains record with next lsn */ if (r->current_wal == NULL) { - i64 next_lsn = confirmed_lsn(r) + 1; + i64 next_lsn = r->confirmed_lsn + 1; i64 lsn = find_including_file(r->wal_prefered_class, next_lsn); if (lsn <= 0) { say_error("can't find wal containing record with lsn:%" PRIi64, next_lsn); @@ -1084,7 +1072,7 @@ recover(struct recovery_state *r, i64 lsn) result = recover_remaining_wals(r); if (result < 0) panic("recover failed"); - say_info("wals recovered, confirmed lsn: %" PRIi64, confirmed_lsn(r)); + say_info("wals recovered, confirmed lsn: %" PRIi64, r->confirmed_lsn); out: prelease(fiber->pool); return result; @@ -1119,7 +1107,7 @@ recover_follow_file(ev_stat *w, int revents __unused__) panic("recover failed"); if (result == LOG_EOF) { say_info("done `%s' confirmed_lsn:%" PRIi64, r->current_wal->filename, - confirmed_lsn(r)); + r->confirmed_lsn); close_log(&r->current_wal); recover_follow_dir((ev_timer *)w, 0); } @@ -1381,7 +1369,7 @@ snapshot_save(struct recovery_state *r, void (*f) (struct log_io_iter *)) memset(&i, 0, sizeof(i)); - snap = open_for_write(r, r->snap_prefered_class, confirmed_lsn(r), -1); + snap = open_for_write(r, r->snap_prefered_class, r->confirmed_lsn, -1); if (snap == NULL) panic("can't open snap for writing"); diff --git a/core/log_io_remote.c b/core/log_io_remote.c index cc0d6b7646c2a53cd2de08d46a7a185e4029820e..d25ca20456644356e01debde4be8e896e10f1035 100644 --- a/core/log_io_remote.c +++ b/core/log_io_remote.c @@ -36,11 +36,11 @@ #include <say.h> #include <log_io.h> -#include "log_io_internal.h" +#include <log_io_internal.h> struct remote_state { struct recovery_state *r; - int (*handler) (struct recovery_state *r, struct tbuf *row); + int (*handler) (struct recovery_state * r, struct tbuf *row); }; static struct tbuf * @@ -128,7 +128,7 @@ pull_from_remote(void *state) struct tbuf *row; for (;;) { - row = remote_read_row(confirmed_lsn(h->r) + 1); + row = remote_read_row(h->r->confirmed_lsn + 1); h->r->recovery_lag = ev_now() - row_v11(row)->tm; if (h->handler(h->r, row) < 0) diff --git a/core/tarantool.c b/core/tarantool.c index ef5a5d2e07d975f85d589f05e4b2b0dad4692557..08fa581d01e978be06a34cf8a031a82525d24cae 100644 --- a/core/tarantool.c +++ b/core/tarantool.c @@ -44,6 +44,7 @@ #include <fiber.h> #include <iproto.h> #include <log_io.h> +#include <log_io_internal.h> #include <palloc.h> #include <salloc.h> #include <say.h> @@ -111,8 +112,8 @@ sig_int(int signal) { say_info("SIGINT or SIGTERM recieved, terminating"); - if (recovery_state !=NULL) { - struct child *writer = wal_writer(recovery_state); + if (recovery_state != NULL) { + struct child *writer = recovery_state->wal_writer; if (writer && writer->out && writer->out->fd > 0) { close(writer->out->fd); usleep(1000); diff --git a/include/log_io.h b/include/log_io.h index 8643acf57b1e11cc9714796694b039aa5a75ffbd..76c7dd6fc96d2ba37b69a9ece5ca750106220827 100644 --- a/include/log_io.h +++ b/include/log_io.h @@ -85,9 +85,7 @@ bool wal_write(struct recovery_state *r, i64 lsn, struct tbuf *data); /* recovery accessors */ struct palloc_pool *recovery_pool(struct recovery_state *r); int confirm_lsn(struct recovery_state *r, i64 lsn); -int64_t confirmed_lsn(struct recovery_state *r); int64_t next_lsn(struct recovery_state *r, i64 new_lsn); -struct child *wal_writer(struct recovery_state *r); int read_log(const char *filename, row_reader reader, row_handler xlog_handler, row_handler snap_handler, void *state); diff --git a/core/log_io_internal.h b/include/log_io_internal.h similarity index 100% rename from core/log_io_internal.h rename to include/log_io_internal.h diff --git a/mod/silverbox/box.c b/mod/silverbox/box.c index f65dd87702635652528e3e905c27e64d1f46d621..869a06f2ce43e5f116b525c653a5207ca92e9af6 100644 --- a/mod/silverbox/box.c +++ b/mod/silverbox/box.c @@ -32,6 +32,7 @@ #include <fiber.h> #include <iproto.h> #include <log_io.h> +#include <log_io_internal.h> #include <pickle.h> #include <salloc.h> #include <say.h> @@ -1354,7 +1355,7 @@ snap_apply(struct recovery_state *r __unused__, struct tbuf *t) if (tbuf_peek(t, sizeof(struct row_v11)) == NULL) return -1; - u16 tag = read_u16(t); + u16 tag = read_u16(t); if (tag != 0) return -1; @@ -1630,7 +1631,8 @@ box_bound_to_primary(void *data __unused__) status = palloc(eter_pool, 64); snprintf(status, 64, "hot_standby/%s:%i%s", cfg.wal_feeder_ipaddr, cfg.wal_feeder_port, custom_proc_title); - recover_follow_remote(recovery_state, cfg.wal_feeder_ipaddr, cfg.wal_feeder_port, default_remote_row_handler); + recover_follow_remote(recovery_state, cfg.wal_feeder_ipaddr, cfg.wal_feeder_port, + default_remote_row_handler); title("hot_standby/%s:%i", cfg.wal_feeder_ipaddr, cfg.wal_feeder_port); } else { @@ -1881,8 +1883,8 @@ mod_info(struct tbuf *out) tbuf_printf(out, " version: \"%s\"\r\n", tarantool_version()); tbuf_printf(out, " uptime: %i\r\n", (int)tarantool_uptime()); tbuf_printf(out, " pid: %i\r\n", getpid()); - tbuf_printf(out, " wal_writer_pid: %" PRIi64 "\r\n", (i64)wal_writer(recovery_state)->pid); - tbuf_printf(out, " lsn: %" PRIi64 "\r\n", confirmed_lsn(recovery_state)); + tbuf_printf(out, " wal_writer_pid: %" PRIi64 "\r\n", (i64)recovery_state->wal_writer->pid); + tbuf_printf(out, " lsn: %" PRIi64 "\r\n", recovery_state->confirmed_lsn); tbuf_printf(out, " status: %s\r\n", status); }