diff --git a/doc/box-protocol.txt b/doc/box-protocol.txt index c5a4545fcdc6b535042759a077d0cfc338dec598..a2aa00b1110b68aba71009c81deb6ce38c1a0098 100644 --- a/doc/box-protocol.txt +++ b/doc/box-protocol.txt @@ -85,6 +85,9 @@ ; the missing value is always assumed to be 0. If the ; missing key assumes a string value, the string is assumed ; to be empty. +; If a body has no keys, entire msgpack map for the body +; may be missing. Such is the case, for example, in <ping> +; request. <key> ::= <header_key> | <body_key> diff --git a/src/box/box.cc b/src/box/box.cc index 917e771766786c752f33186c4fa0b50a7568bd61..9c3dcad5849a9a64b46b1363d4a51206e373e100 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -300,33 +300,33 @@ boxk(enum iproto_request_type type, uint32_t space_id, } /** - * @brief Called when recovery/replication wants to add a new node + * @brief Called when recovery/replication wants to add a new server * to cluster. - * cluster_add_node() is called as a commit trigger on _cluster - * space and actually adds the node to the cluster. - * @param node_uuid + * cluster_add_server() is called as a commit trigger on _cluster + * space and actually adds the server to the cluster. + * @param server_uuid */ static void -box_on_cluster_join(const tt_uuid *node_uuid) +box_on_cluster_join(const tt_uuid *server_uuid) { - /** Find the largest existing node id. */ + /** Find the largest existing server id. */ struct space *space = space_cache_find(SC_CLUSTER_ID); class Index *index = index_find(space, 0); struct iterator *it = index->position(); index->initIterator(it, ITER_LE, NULL, 0); struct tuple *tuple = it->next(it); - /** Assign a new node id. */ + /** Assign a new server id. */ uint32_t server_id = tuple ? tuple_field_u32(tuple, 0) + 1 : 1; if (server_id >= VCLOCK_MAX) tnt_raise(ClientError, ER_REPLICA_MAX, server_id); boxk(IPROTO_INSERT, SC_CLUSTER_ID, "%u%s", - (unsigned) server_id, tt_uuid_str(node_uuid)); + (unsigned) server_id, tt_uuid_str(server_uuid)); } -/** Replace the current node id in _cluster */ +/** Replace the current server id in _cluster */ static void -box_set_node_uuid() +box_set_server_uuid() { tt_uuid_create(&recovery_state->server_uuid); assert(recovery_state->server_id == 0); @@ -334,7 +334,7 @@ box_set_node_uuid() vclock_del_server(&recovery_state->vclock, 1); boxk(IPROTO_REPLACE, SC_CLUSTER_ID, "%u%s", 1, tt_uuid_str(&recovery_state->server_uuid)); - /* Remove surrogate node */ + /* Remove surrogate server */ vclock_del_server(&recovery_state->vclock, 0); assert(recovery_state->server_id == 1); assert(vclock_has(&recovery_state->vclock, 1)); @@ -414,10 +414,10 @@ box_init() replica_bootstrap(recovery_state); snapshot_save(recovery_state); } else { - /* Initialize a master node of a new cluster */ + /* Initialize the first server of a new cluster */ recovery_bootstrap(recovery_state); box_set_cluster_uuid(); - box_set_node_uuid(); + box_set_server_uuid(); snapshot_save(recovery_state); } diff --git a/src/box/cluster.cc b/src/box/cluster.cc index 7d05365c8b46c89ee9fc8221e2aebecbdf88fa26..a5bf9664222f4f2c677b2c33d5e426d72bd2fd1d 100644 --- a/src/box/cluster.cc +++ b/src/box/cluster.cc @@ -39,22 +39,22 @@ tt_uuid cluster_id; extern "C" struct vclock * cluster_clock() { - return &recovery_state->vclock; + return &recovery_state->vclock; } void -cluster_add_server(const tt_uuid *server_uuid, cserver_id_t server_id) +cluster_add_server(const tt_uuid *server_uuid, uint32_t server_id) { struct recovery_state *r = recovery_state; /** Checked in the before-commit trigger */ assert(!tt_uuid_is_nil(server_uuid)); assert(!cserver_id_is_reserved(server_id)); - /* Add node */ + /* Add server */ vclock_add_server(&r->vclock, server_id); if (tt_uuid_cmp(&r->server_uuid, server_uuid) == 0) { - /* Assign local node id */ + /* Assign local server id */ assert(r->server_id == 0); r->server_id = server_id; } diff --git a/src/box/cluster.h b/src/box/cluster.h index 991b749c800e7c0486a695a1d2300437dc17bf8a..257e4b8c69ae8ab23730628a935161707a054ee1 100644 --- a/src/box/cluster.h +++ b/src/box/cluster.h @@ -87,15 +87,12 @@ cluster_clock(); /* }}} */ -/** {{{ Cluster node id API **/ - -/** Cluster-local server identifier. */ -typedef uint32_t cserver_id_t; +/** {{{ Cluster server id API **/ static inline bool -cserver_id_is_reserved(cserver_id_t id) +cserver_id_is_reserved(uint32_t id) { - return id == 0; + return id == 0; } /** @@ -106,7 +103,7 @@ cserver_id_is_reserved(cserver_id_t id) * The server is added to the cluster lsn table with LSN 0. */ void -cluster_add_server(const tt_uuid *server_uuid, cserver_id_t id); +cluster_add_server(const tt_uuid *server_uuid, uint32_t id); /** }}} **/ diff --git a/src/box/log_io.cc b/src/box/log_io.cc index 83c41a1827abd945f322acf0d302c6e0358d5dca..c0e719e38aba3fc773d03ef1d349300550a51bd5 100644 --- a/src/box/log_io.cc +++ b/src/box/log_io.cc @@ -84,7 +84,6 @@ vclockset_clean(vclockset_t *set) { while (cur != NULL) { struct vclock *next = vclockset_next(set, cur); vclockset_remove(set, cur); - vclock_destroy(cur); free(cur); cur = next; } @@ -167,8 +166,8 @@ log_dir_scan(struct log_dir *dir) closedir(dh); }); - int64_t *signs = NULL; - size_t signs_capacity = 0, signs_size = 0; + int64_t *signts = NULL; + size_t signts_capacity = 0, signts_size = 0; errno = 0; struct dirent *dent; @@ -193,62 +192,63 @@ log_dir_scan(struct log_dir *dir) if (!ext_is_ok) continue; - long long sign = strtoll(dent->d_name, &ext, 10); + long long signt = strtoll(dent->d_name, &ext, 10); if (strncmp(ext, dir->filename_ext, ext_len) != 0) { /* d_name doesn't parse entirely, ignore it */ say_warn("can't parse `%s', skipping", dent->d_name); continue; } - if (sign == LLONG_MAX || sign == LLONG_MIN) { + if (signt == LLONG_MAX || signt == LLONG_MIN) { say_warn("can't parse `%s', skipping", dent->d_name); continue; } - if (signs_size == signs_capacity) { - size_t capacity = signs_capacity > 0 ? - 2 * signs_capacity : 16; - int64_t *new_signs = (int64_t *) region_alloc( - &fiber()->gc, sizeof(*signs) * capacity); - memcpy(new_signs, signs, sizeof(*signs) * signs_size); - signs = new_signs; - signs_capacity = capacity; + if (signts_size == signts_capacity) { + size_t capacity = signts_capacity > 0 ? + 2 * signts_capacity : 16; + int64_t *new_signts = (int64_t *) region_alloc( + &fiber()->gc, sizeof(*signts) * capacity); + memcpy(new_signts, signts, sizeof(*signts) * signts_size); + signts = new_signts; + signts_capacity = capacity; } - signs[signs_size++] = sign; + signts[signts_size++] = signt; } - if (signs_size == 0) { + if (signts_size == 0) { /* Empty directory */ vclockset_clean(&dir->index); return 0; } - qsort(signs, signs_size, sizeof(*signs), cmp_i64); + qsort(signts, signts_size, sizeof(*signts), cmp_i64); struct vclock *cur = vclockset_first(&dir->index); - for (size_t i = 0; i < signs_size; i++) { + for (size_t i = 0; i < signts_size; i++) { while (cur != NULL) { - int64_t sign = vclock_signature(cur); - if (sign < signs[i]) { - struct vclock *next = vclockset_next(&dir->index, cur); + int64_t signt = vclock_signature(cur); + if (signt < signts[i]) { + struct vclock *next = + vclockset_next(&dir->index, cur); vclockset_remove(&dir->index, cur); - vclock_destroy(cur); free(cur); cur = next; continue; - } else if (sign == signs[i]) { + } else if (signt == signts[i]) { cur = vclockset_next(&dir->index, cur); goto skip; /* already exists */ - } else /* sign > lsns[i] */ { + } else /* signt > lsns[i] */ { break; } } try { - log_dir_add_to_index(dir, signs[i]); + log_dir_add_to_index(dir, signts[i]); } catch (ClientError *e) { e->log(); - say_warn("failed to scan %s", format_filename(dir, signs[i], NONE)); + say_warn("failed to scan %s", + format_filename(dir, signts[i], NONE)); if (dir->panic_if_error) throw; } @@ -259,12 +259,12 @@ log_dir_scan(struct log_dir *dir) } char * -format_filename(struct log_dir *dir, int64_t lsn, enum log_suffix suffix) +format_filename(struct log_dir *dir, int64_t signt, enum log_suffix suffix) { static __thread char filename[PATH_MAX + 1]; const char *suffix_str = suffix == INPROGRESS ? inprogress_suffix : ""; snprintf(filename, PATH_MAX, "%s/%020lld%s%s", - dir->dirname, (long long)lsn, dir->filename_ext, suffix_str); + dir->dirname, (long long)signt, dir->filename_ext, suffix_str); return filename; } @@ -561,8 +561,6 @@ log_io_close(struct log_io **lptr) log_io_sync(l); if (l->is_inprogress && inprogress_log_rename(l) != 0) panic("can't rename 'inprogress' WAL"); - } else if (l->mode == LOG_READ) { - vclock_destroy(&l->vclock); } r = fclose(l->f); @@ -753,7 +751,6 @@ log_io_open_stream_for_read(struct log_dir *dir, const char *filename, return l; error_3: - vclock_destroy(&l->vclock); free(l); error_2: fclose(file); @@ -763,13 +760,13 @@ log_io_open_stream_for_read(struct log_dir *dir, const char *filename, } struct log_io * -log_io_open_for_read(struct log_dir *dir, int64_t sign, +log_io_open_for_read(struct log_dir *dir, int64_t signature, const tt_uuid *server_uuid, enum log_suffix suffix) { - const char *filename = format_filename(dir, sign, suffix); + const char *filename = format_filename(dir, signature, suffix); FILE *f = fopen(filename, "r"); if (suffix == INPROGRESS && f == NULL) { - filename = format_filename(dir, sign, NONE); + filename = format_filename(dir, signature, NONE); f = fopen(filename, "r"); suffix = NONE; } @@ -788,14 +785,14 @@ log_io_open_for_write(struct log_dir *dir, const tt_uuid *server_uuid, FILE *f = NULL; struct log_io *l = NULL; - int64_t sign = vclock_signature(vclock); - assert(sign >= 0); + int64_t signt = vclock_signature(vclock); + assert(signt >= 0); /* * Check whether a file with this name already exists. * We don't overwrite existing files. */ - filename = format_filename(dir, sign, NONE); + filename = format_filename(dir, signt, NONE); if (access(filename, F_OK) == 0) { errno = EEXIST; goto error; @@ -805,7 +802,7 @@ log_io_open_for_write(struct log_dir *dir, const tt_uuid *server_uuid, * Open the <lsn>.<suffix>.inprogress file. If it exists, * open will fail. */ - filename = format_filename(dir, sign, INPROGRESS); + filename = format_filename(dir, signt, INPROGRESS); f = fiob_open(filename, dir->open_wflags); if (!f) goto error; diff --git a/src/box/log_io.h b/src/box/log_io.h index 931f820d4a4cd603f16a3fbd035d9fda873678e1..7cc63892b2249f71cc5384a2b098d0d2539acb31 100644 --- a/src/box/log_io.h +++ b/src/box/log_io.h @@ -81,7 +81,7 @@ int log_dir_scan(struct log_dir *dir); char * -format_filename(struct log_dir *dir, int64_t lsn, enum log_suffix suffix); +format_filename(struct log_dir *dir, int64_t signature, enum log_suffix suffix); struct log_io { struct log_dir *dir; @@ -100,7 +100,7 @@ struct log_io { }; struct log_io * -log_io_open_for_read(struct log_dir *dir, int64_t sign, +log_io_open_for_read(struct log_dir *dir, int64_t signature, const tt_uuid *server_uuid, enum log_suffix suffix); struct log_io * diff --git a/src/box/recovery.cc b/src/box/recovery.cc index 426cb802519919d96651518314b13cd700474ed8..70b2990f21f272b714ea3445f6a5c98c9673a07c 100644 --- a/src/box/recovery.cc +++ b/src/box/recovery.cc @@ -166,7 +166,7 @@ recovery_init(const char *snap_dirname, const char *wal_dirname, r->row_handler = row_handler; r->row_handler_param = row_handler_param; - r->lsnsum = -1; + r->signature = -1; r->snapshot_handler = snapshot_handler; r->join_handler = join_handler; @@ -226,8 +226,6 @@ recovery_free() log_io_close(&r->current_wal); } - vclock_destroy(&r->vclock); - recovery_state = NULL; } @@ -242,8 +240,8 @@ void recovery_process(struct recovery_state *r, struct iproto_header *row) { /* Check lsn */ - int64_t current_lsn = vclock_get(&r->vclock, row->server_id); - if (current_lsn >=0 && row->lsn <= current_lsn) { + int64_t current_signt = vclock_get(&r->vclock, row->server_id); + if (current_signt >=0 && row->lsn <= current_signt) { say_debug("skipping too young row"); return; } @@ -357,7 +355,7 @@ recover_remaining_wals(struct recovery_state *r) { int result = 0; struct log_io *next_wal; - int64_t current_lsn, wal_greatest_lsn; + int64_t current_signt, last_signt; struct vclock *current_vclock; size_t rows_before; enum log_suffix suffix; @@ -366,8 +364,8 @@ recover_remaining_wals(struct recovery_state *r) return -1; current_vclock = vclockset_last(&r->wal_dir.index); - wal_greatest_lsn = current_vclock != NULL ? - vclock_signature(current_vclock) : -1; + last_signt = current_vclock != NULL ? + vclock_signature(current_vclock) : -1; /* if the caller already opened WAL for us, recover from it first */ if (r->current_wal != NULL) goto recover_current_wal; @@ -377,12 +375,12 @@ recover_remaining_wals(struct recovery_state *r) if (current_vclock == NULL) break; /* No more WALs */ - current_lsn = vclock_signature(current_vclock); - if (current_lsn == r->lsnsum) { - if (current_lsn != wal_greatest_lsn) { + current_signt = vclock_signature(current_vclock); + if (current_signt == r->signature) { + if (current_signt != last_signt) { say_error("missing xlog between %020lld and %020lld", - (long long) current_lsn, - (long long) wal_greatest_lsn); + (long long) current_signt, + (long long) last_signt); } break; } @@ -393,16 +391,14 @@ recover_remaining_wals(struct recovery_state *r) * .xlog, with no risk of a concurrent * inprogress_log_rename(). */ - suffix = current_lsn == wal_greatest_lsn ? INPROGRESS : NONE; - next_wal = log_io_open_for_read(&r->wal_dir, current_lsn, + suffix = current_signt == last_signt ? INPROGRESS : NONE; + next_wal = log_io_open_for_read(&r->wal_dir, current_signt, &r->server_uuid, suffix); /* * When doing final recovery, and dealing with the * last file, try opening .<ext>.inprogress. */ if (next_wal == NULL) { - say_warn("open fail: %lld", - (long long) current_lsn); if (r->finalize && suffix == INPROGRESS) { /* * There is an .inprogress file, but @@ -410,14 +406,14 @@ recover_remaining_wals(struct recovery_state *r) * delete it. */ if (inprogress_log_unlink(format_filename( - &r->wal_dir, current_lsn, INPROGRESS)) != 0) + &r->wal_dir, current_signt, INPROGRESS)) != 0) panic("can't unlink 'inprogres' WAL"); } result = 0; break; } assert(r->current_wal == NULL); - r->lsnsum = current_lsn; + r->signature = current_signt; r->current_wal = next_wal; say_info("recover from `%s'", r->current_wal->filename); @@ -444,7 +440,7 @@ recover_remaining_wals(struct recovery_state *r) say_info("done `%s'", r->current_wal->filename); log_io_close(&r->current_wal); /* goto find_next_wal; */ - } else if (r->lsnsum == wal_greatest_lsn) { + } else if (r->signature == last_signt) { /* last file is not finished */ break; } else if (r->finalize && r->current_wal->is_inprogress) { @@ -471,7 +467,7 @@ recover_remaining_wals(struct recovery_state *r) * It's not a fatal error when last WAL is empty, but if * we lose some logs it is a fatal error. */ - if (wal_greatest_lsn > r->lsnsum) { + if (last_signt > r->signature) { say_error("not all WALs have been successfully read"); result = -1; } @@ -510,7 +506,7 @@ recovery_finalize(struct recovery_state *r) say_warn("unlink broken %s WAL", r->current_wal->filename); if (inprogress_log_unlink(r->current_wal->filename) != 0) panic("can't unlink 'inprogress' WAL"); - } else if (r->current_wal->rows <= 2 /* SETLSN + one row */) { + } else if (r->current_wal->rows <= 1 /* one row */) { /* Rename inprogress wal with one row */ say_warn("rename unfinished %s WAL", r->current_wal->filename); if (inprogress_log_rename(r->current_wal) != 0) @@ -702,7 +698,7 @@ wal_writer_child() static void wal_writer_init_once() { - (void) tt_pthread_atfork(NULL, NULL, wal_writer_child); + (void) tt_pthread_atfork(NULL, NULL, wal_writer_child); } /** @@ -807,7 +803,6 @@ wal_writer_destroy(struct wal_writer *writer) (void) tt_pthread_mutex_destroy(&writer->mutex); (void) tt_pthread_cond_destroy(&writer->cond); free(writer->batch); - vclock_destroy(&writer->vclock); } /** WAL writer thread routine. */ diff --git a/src/box/recovery.h b/src/box/recovery.h index 513ca682291409c445c4cf3539242794aa7bf486..18fd4ae73b71deb641b94c8bdc86491a2e41a9bd 100644 --- a/src/box/recovery.h +++ b/src/box/recovery.h @@ -66,7 +66,7 @@ struct recovery_state { struct log_io *current_wal; struct log_dir snap_dir; struct log_dir wal_dir; - int64_t lsnsum; /* used to find missing xlog files */ + int64_t signature; /* used to find missing xlog files */ struct wal_writer *writer; struct wal_watcher *watcher; struct remote remote; diff --git a/src/box/replica.cc b/src/box/replica.cc index 462297b8bce48c1514e0bee9cebe636ee09446a9..03bd587376171998361f45dd9b557b656a38bca1 100644 --- a/src/box/replica.cc +++ b/src/box/replica.cc @@ -228,7 +228,6 @@ replica_bootstrap(struct recovery_state *r) /* Decode end of stream packet */ struct vclock vclock; vclock_create(&vclock); - auto vclock_guard = make_scoped_guard([&]{ vclock_destroy(&vclock); }); assert(row.type == IPROTO_JOIN); iproto_decode_eos(&row, &vclock); diff --git a/src/box/replication.cc b/src/box/replication.cc index 9b7f712c0ef2bb6046b4083de6649f1e49b44c1f..856e802ce818b02fc90eafe2b2c6f1d63e874016 100644 --- a/src/box/replication.cc +++ b/src/box/replication.cc @@ -169,7 +169,7 @@ replication_prefork(const char *snap_dir, const char *wal_dir) /* * Create UNIX sockets to communicate between the main and * spawner processes. - */ + */ if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sockpair) != 0) panic_syserror("socketpair"); @@ -216,7 +216,7 @@ replication_join(int fd, struct iproto_header *header) struct tt_uuid server_uuid = uuid_nil; iproto_decode_join(header, &server_uuid); - /* Notify box about new cluster node */ + /* Notify box about new cluster server */ recovery_state->join_handler(&server_uuid); struct replication_request *request = (struct replication_request *) @@ -239,16 +239,15 @@ replication_join(int fd, struct iproto_header *header) void replication_subscribe(int fd, struct iproto_header *packet) { - struct tt_uuid uu = uuid_nil, node_uuid = uuid_nil; + struct tt_uuid uu = uuid_nil, server_uuid = uuid_nil; struct vclock vclock; vclock_create(&vclock); - auto vclock_guard = make_scoped_guard([&]{ vclock_destroy(&vclock); }); - iproto_decode_subscribe(packet, &uu, &node_uuid, &vclock); + iproto_decode_subscribe(packet, &uu, &server_uuid, &vclock); /** * Check that the given UUID matches the UUID of the - * cluster this node belongs to. Used to handshake + * cluster this server belongs to. Used to handshake * replica connect, and refuse a connection from a replica * which belongs to a different cluster. */ @@ -257,13 +256,13 @@ replication_subscribe(int fd, struct iproto_header *packet) tt_uuid_str(&uu), tt_uuid_str(&cluster_id)); } - /* Check Node-UUID */ + /* Check server uuid */ uint32_t server_id; server_id = schema_find_id(SC_CLUSTER_ID, 1, - tt_uuid_str(&node_uuid), UUID_STR_LEN); + tt_uuid_str(&server_uuid), UUID_STR_LEN); if (server_id == SC_ID_NIL) { tnt_raise(ClientError, ER_UNKNOWN_SERVER, - tt_uuid_str(&node_uuid)); + tt_uuid_str(&server_uuid)); } struct replication_request *request = (struct replication_request *) diff --git a/src/box/vclock.c b/src/box/vclock.c index 49ab91b57859a234d2f6e88088398b684f285c7f..00953fd6c179eca1411fe46383d232a88b7c424a 100644 --- a/src/box/vclock.c +++ b/src/box/vclock.c @@ -49,24 +49,6 @@ vclock_follow(struct vclock *vclock, uint32_t server_id, int64_t lsn) return prev_lsn; } -void -vclock_merge(struct vclock *to, const struct vclock *with) -{ - /* Botched logic: - * - imagine there is 5.snap and 1.xlog - * - 5.snap has 1: 5 vclock - * - 1.xlog has 1: 1 vclock - * We begin reading the xlog after snap, - * but we don't skip setlsn (we never skip setlsn). - * So we must not update server id 1 with lsn 1, - * hence the code below only updates target if it - * is less than the source. - */ - for (int i = 0; i < VCLOCK_MAX; i++) - if (with->lsn[i] > to->lsn[i]) - to->lsn[i] = with->lsn[i]; -} - static inline __attribute__ ((format(FORMAT_PRINTF, 4, 0))) int rsnprintf(char **buf, char **pos, char **end, const char *fmt, ...) { @@ -112,11 +94,9 @@ vclock_to_string(const struct vclock *vclock) return NULL; const char *sep = ""; - for (uint32_t node_id = 0; node_id < VCLOCK_MAX; node_id++) { - if (vclock->lsn[node_id] < 0) - continue; - if (rsnprintf(&buf, &pos, &end, "%s%u: %lld", sep, node_id, - (long long) vclock->lsn[node_id]) != 0) + vclock_foreach(vclock, it) { + if (rsnprintf(&buf, &pos, &end, "%s%u: %lld", sep, it.id, + (long long) it.lsn) != 0) return NULL; sep = ", "; } @@ -130,40 +110,43 @@ vclock_to_string(const struct vclock *vclock) size_t vclock_from_string(struct vclock *vclock, const char *str) { - long node_id; + long server_id; long long lsn; const char *p = str; begin: if (*p == '{') { ++p; - /* goto key; */ + goto key; } else if (isblank(*p)) { ++p; goto begin; - } else goto error; + } + goto error; key: if (isdigit(*p)) { errno = 0; - node_id = strtol(p, (char **) &p, 10); - if (errno != 0 || node_id < 0 || node_id >= VCLOCK_MAX) + server_id = strtol(p, (char **) &p, 10); + if (errno != 0 || server_id < 0 || server_id >= VCLOCK_MAX) goto error; - /* goto sep; */ + goto sep; } else if (*p == '}') { ++p; goto end; } else if (isblank(*p)) { ++p; goto key; - } else goto error; + } + goto error; sep: if (*p == ':') { ++p; - /* goto val; */ + goto val; } else if (isblank(*p)) { ++p; goto sep; - } else goto error; + } + goto error; val: if (isblank(*p)) { ++p; @@ -172,29 +155,32 @@ vclock_from_string(struct vclock *vclock, const char *str) errno = 0; lsn = strtoll(p, (char **) &p, 10); if (errno != 0 || lsn < 0 || lsn > INT64_MAX || - vclock->lsn[node_id] != -1) + vclock->lsn[server_id] != -1) goto error; - vclock->lsn[node_id] = lsn; - /* goto comma; */ - } else goto error; + vclock->lsn[server_id] = lsn; + goto comma; + } + goto error; comma: if (isspace(*p)) { ++p; goto comma; } else if (*p == '}') { ++p; - /* goto end; */ + goto end; } else if (*p == ',') { ++p; goto key; - } else goto error; + } + goto error; end: if (*p == '\0') { return 0; } else if (isblank(*p)) { ++p; goto end; - } else goto error; + } + /* goto error; */ error: return p - str + 1; /* error */ } diff --git a/src/box/vclock.h b/src/box/vclock.h index 684b6189cbd10b8bc4677631e3d699cb29e0a4fa..80713f186d2048c66b8d69b29470cf0e3e9184f4 100644 --- a/src/box/vclock.h +++ b/src/box/vclock.h @@ -67,12 +67,6 @@ vclock_create(struct vclock *vclock) memset(vclock, 0xff, sizeof(*vclock)); } -static inline void -vclock_destroy(struct vclock *vclock) -{ - (void) vclock; -} - static inline bool vclock_has(const struct vclock *vclock, uint32_t server_id) { @@ -110,21 +104,18 @@ vclock_size(const struct vclock *vclock) static inline int64_t vclock_signature(const struct vclock *vclock) { - int64_t sum = 0; + int64_t signt = 0; vclock_foreach(vclock, server) - sum += server.lsn; - return sum; + signt += server.lsn; + return signt; } int64_t vclock_follow(struct vclock *vclock, uint32_t server_id, int64_t lsn); -void -vclock_merge(struct vclock *to, const struct vclock *with); - /** * \brief Format vclock to YAML-compatible string representation: - * { node_id: lsn, node_id:lsn }) + * { server_id: lsn, server_id:lsn }) * \param vclock vclock * \return fomatted string. This pointer should be passed to free(3) to * release the allocated storage when it is no longer needed. @@ -158,9 +149,9 @@ static inline int vclock_compare(const struct vclock *a, const struct vclock *b) { bool le = true, ge = true; - for (uint32_t node_id = 0; node_id < VCLOCK_MAX; node_id++) { - int64_t lsn_a = vclock_get(a, node_id); - int64_t lsn_b = vclock_get(b, node_id); + for (uint32_t server_id = 0; server_id < VCLOCK_MAX; server_id++) { + int64_t lsn_a = vclock_get(a, server_id); + int64_t lsn_b = vclock_get(b, server_id); le = le && lsn_a <= lsn_b; ge = ge && lsn_a >= lsn_b; if (!ge && !le) diff --git a/test/unit/vclock.cc b/test/unit/vclock.cc index 8ae537524918b6a970a79eab9010ee33516a9b44..bf3bb4688f8c4d71f360b3737e798e6e9b4d968e 100644 --- a/test/unit/vclock.cc +++ b/test/unit/vclock.cc @@ -59,10 +59,7 @@ test_compare_one(uint32_t a_count, const int64_t *lsns_a, vclock_follow(&b, node_id, lsns_b[node_id]); } - int result = vclock_compare(&a, &b); - vclock_destroy(&a); - vclock_destroy(&b); - return result; + return vclock_compare(&a, &b); } #define test2(xa, xb, res) ({\ @@ -137,7 +134,6 @@ testset_destroy(vclockset_t *set) while (cur != NULL) { struct vclock *next = vclockset_next(set, cur); vclockset_remove(set, cur); - vclock_destroy(cur); free(cur); cur = next; } @@ -239,8 +235,6 @@ test_isearch() struct vclock *res = vclockset_isearch(&set, &vclock); int64_t value = res != NULL ? vclock_signature(res) : INT64_MAX; is(value, check, "query #%d", q + 1); - - vclock_destroy(&vclock); } testset_destroy(&set); @@ -260,7 +254,6 @@ test_tostring_one(uint32_t count, const int64_t *lsns, const char *res) char *str = vclock_to_string(&vclock); int result = strcmp(str, res) == 0; free(str); - vclock_destroy(&vclock); return result; } @@ -301,11 +294,7 @@ test_fromstring_one(const char *str, uint32_t count, const int64_t *lsns) check.lsn[node_id] = lsns[node_id]; } - int result = (rc != 0 || vclock_compare(&vclock, &check) != 0); - - vclock_destroy(&vclock); - vclock_destroy(&check); - return result; + return (rc != 0 || vclock_compare(&vclock, &check) != 0); } #define test(s, xa) ({\ @@ -341,8 +330,7 @@ test_fromstring() struct vclock tmp; \ vclock_create(&tmp); \ is(vclock_from_string(&tmp, str), offset, \ - "fromstring \"%s\" => %u", str, offset) \ - vclock_destroy(&tmp); }) + "fromstring \"%s\" => %u", str, offset)}) int test_fromstring_invalid()