<HTML><BODY><div style="font-family: 'Droid Sans Mono', monospace, monospace, 'Droid Sans Fallback'; font-size: 14px; line-height: 19px; white-space: pre;" data-mce-style="font-family: 'Droid Sans Mono', monospace, monospace, 'Droid Sans Fallback'; font-size: 14px; line-height: 19px; white-space: pre;"><div>From 1a55132c453e3f6f2fb7f73cd1f1a10ffd885722 Mon Sep 17 00:00:00 2001</div><div>From: Ilya Kosarev <i.kosarev@tarantool.org></div><div>Date: Mon, 2 Sep 2019 14:37:19 +0300</div><div>Subject: [PATCH] refactoring: fix codestyle</div></div><p><br>switch .. case indentations are refactored.<br>Extra consequent whitespaces are replaced with tabs.<br>Suitable _xc function implemented.</p><p>Closes #4247<br>Branch: https://github.com/tarantool/tarantool/tree/i.kosarev/gh-4247-remove-exceptions-from-triggers <br>Issue: https://github.com/tarantool/tarantool/issues/4247</p><p>---<br> src/box/alter.cc | 311 +++++++++++++++++++++--------------------<br> src/box/replication.cc | 134 +++++++++---------<br> src/box/user.cc | 9 +-<br> src/box/vy_scheduler.c | 3 +-<br> 4 files changed, 232 insertions(+), 225 deletions(-)</p><p>diff --git a/src/box/alter.cc b/src/box/alter.cc<br>index 02d66741b..faa575559 100644<br>--- a/src/box/alter.cc<br>+++ b/src/box/alter.cc<br>@@ -1330,30 +1330,30 @@ MoveIndex::rollback(struct alter_space *alter)<br> class ModifyIndex: public AlterSpaceOp<br> {<br> public:<br>- ModifyIndex(struct alter_space *alter,<br>- struct index *index, struct index_def *def)<br>- : AlterSpaceOp(alter), old_index(index),<br>- new_index(NULL), new_index_def(def) {<br>- if (new_index_def->iid == 0 &&<br>- key_part_cmp(new_index_def->key_def->parts,<br>- new_index_def->key_def->part_count,<br>- old_index->def->key_def->parts,<br>- old_index->def->key_def->part_count) != 0) {<br>- /*<br>- * Primary parts have been changed -<br>- * update secondary indexes.<br>- */<br>- alter->pk_def = new_index_def->key_def;<br>- }<br>- }<br>- struct index *old_index;<br>- struct index *new_index;<br>- struct index_def *new_index_def;<br>- virtual void alter_def(struct alter_space *alter);<br>- virtual void alter(struct alter_space *alter);<br>- virtual void commit(struct alter_space *alter, int64_t lsn);<br>- virtual void rollback(struct alter_space *alter);<br>- virtual ~ModifyIndex();<br>+ ModifyIndex(struct alter_space *alter,<br>+ struct index *index, struct index_def *def)<br>+ : AlterSpaceOp(alter), old_index(index),<br>+ new_index(NULL), new_index_def(def) {<br>+ if (new_index_def->iid == 0 &&<br>+ key_part_cmp(new_index_def->key_def->parts,<br>+ new_index_def->key_def->part_count,<br>+ old_index->def->key_def->parts,<br>+ old_index->def->key_def->part_count) != 0) {<br>+ /*<br>+ * Primary parts have been changed -<br>+ * update secondary indexes.<br>+ */<br>+ alter->pk_def = new_index_def->key_def;<br>+ }<br>+ }<br>+ struct index *old_index;<br>+ struct index *new_index;<br>+ struct index_def *new_index_def;<br>+ virtual void alter_def(struct alter_space *alter);<br>+ virtual void alter(struct alter_space *alter);<br>+ virtual void commit(struct alter_space *alter, int64_t lsn);<br>+ virtual void rollback(struct alter_space *alter);<br>+ virtual ~ModifyIndex();<br> };<br> <br> /** Update the definition of the new space */<br>@@ -3111,16 +3111,16 @@ func_def_new_from_tuple(struct tuple *tuple)<br> uint32_t len;<br> const char *str = mp_decode_str(&exports, &len);<br> switch (STRN2ENUM(func_language, str, len)) {<br>- case FUNC_LANGUAGE_LUA:<br>- def->exports.lua = true;<br>- break;<br>- case FUNC_LANGUAGE_SQL:<br>- def->exports.sql = true;<br>- break;<br>- default:<br>- diag_set(ClientError, ER_CREATE_FUNCTION,<br>- def->name, "invalid exports value");<br>- return NULL;<br>+ case FUNC_LANGUAGE_LUA:<br>+ def->exports.lua = true;<br>+ break;<br>+ case FUNC_LANGUAGE_SQL:<br>+ def->exports.sql = true;<br>+ break;<br>+ default:<br>+ diag_set(ClientError, ER_CREATE_FUNCTION,<br>+ def->name, "invalid exports value");<br>+ return NULL;<br> }<br> }<br> const char *aggregate =<br>@@ -3278,9 +3278,10 @@ on_replace_dd_func(struct trigger * /* trigger */, void *event)<br> }<br> /* Can't' drop a builtin function. */<br> if (old_func->def->language == FUNC_LANGUAGE_SQL_BUILTIN) {<br>- tnt_raise(ClientError, ER_DROP_FUNCTION,<br>+ diag_set(ClientError, ER_DROP_FUNCTION,<br> (unsigned) old_func->def->uid,<br> "function is SQL built-in");<br>+ return -1;<br> }<br> struct trigger *on_commit =<br> txn_alter_trigger_new(on_drop_func_commit, old_func);<br>@@ -3579,17 +3580,17 @@ priv_def_create_from_tuple(struct priv_def *priv, struct tuple *tuple)<br> * So check for that first.<br> */<br> switch (mp_typeof(*data)) {<br>- case MP_STR:<br>- if (mp_decode_strl(&data) == 0) {<br>- /* Entity-wide privilege. */<br>- priv->object_id = 0;<br>- priv->object_type = schema_entity_type(priv->object_type);<br>- break;<br>- }<br>- FALLTHROUGH;<br>- default:<br>- if (tuple_field_u32(tuple,BOX_PRIV_FIELD_OBJECT_ID, &(priv->object_id)) != 0)<br>- return -1;<br>+ case MP_STR:<br>+ if (mp_decode_strl(&data) == 0) {<br>+ /* Entity-wide privilege. */<br>+ priv->object_id = 0;<br>+ priv->object_type = schema_entity_type(priv->object_type);<br>+ break;<br>+ }<br>+ FALLTHROUGH;<br>+ default:<br>+ if (tuple_field_u32(tuple,BOX_PRIV_FIELD_OBJECT_ID, &(priv->object_id)) != 0)<br>+ return -1;<br> }<br> if (priv->object_type == SC_UNKNOWN) {<br> diag_set(ClientError, ER_UNKNOWN_SCHEMA_OBJECT,<br>@@ -3631,121 +3632,121 @@ priv_def_check(struct priv_def *priv, enum priv_type priv_type)<br> priv->object_type, priv_type) != 0)<br> return -1;<br> switch (priv->object_type) {<br>- case SC_UNIVERSE:<br>- if (grantor->def->uid != ADMIN) {<br>- diag_set(AccessDeniedError,<br>- priv_name(priv_type),<br>- schema_object_name(SC_UNIVERSE),<br>- name,<br>- grantor->def->name);<br>- return -1;<br>- }<br>- break;<br>- case SC_SPACE: {<br>- struct space *space = space_cache_find(priv->object_id);<br>- if (space == NULL)<br>- return -1;<br>- if (space->def->uid != grantor->def->uid &&<br>- grantor->def->uid != ADMIN) {<br>- diag_set(AccessDeniedError,<br>- priv_name(priv_type),<br>- schema_object_name(SC_SPACE), name,<br>- grantor->def->name);<br>- return -1;<br>- }<br>- break;<br>+ case SC_UNIVERSE:<br>+ if (grantor->def->uid != ADMIN) {<br>+ diag_set(AccessDeniedError,<br>+ priv_name(priv_type),<br>+ schema_object_name(SC_UNIVERSE),<br>+ name,<br>+ grantor->def->name);<br>+ return -1;<br> }<br>- case SC_FUNCTION: {<br>- struct func *func = func_by_id(priv->object_id);<br>- if (func == NULL) {<br>- diag_set(ClientError, ER_NO_SUCH_FUNCTION, int2str(priv->object_id));<br>- return -1;<br>- }<br>- if (func->def->uid != grantor->def->uid &&<br>- grantor->def->uid != ADMIN) {<br>- diag_set(AccessDeniedError,<br>- priv_name(priv_type),<br>- schema_object_name(SC_FUNCTION), name,<br>- grantor->def->name);<br>- return -1;<br>- }<br>- break;<br>+ break;<br>+ case SC_SPACE: {<br>+ struct space *space = space_cache_find(priv->object_id);<br>+ if (space == NULL)<br>+ return -1;<br>+ if (space->def->uid != grantor->def->uid &&<br>+ grantor->def->uid != ADMIN) {<br>+ diag_set(AccessDeniedError,<br>+ priv_name(priv_type),<br>+ schema_object_name(SC_SPACE), name,<br>+ grantor->def->name);<br>+ return -1;<br> }<br>- case SC_SEQUENCE: {<br>- struct sequence *seq = sequence_by_id(priv->object_id);<br>- if (seq == NULL) {<br>- diag_set(ClientError, ER_NO_SUCH_SEQUENCE, int2str(priv->object_id));<br>- return -1;<br>- }<br>- if (seq->def->uid != grantor->def->uid &&<br>- grantor->def->uid != ADMIN) {<br>- diag_set(AccessDeniedError,<br>- priv_name(priv_type),<br>- schema_object_name(SC_SEQUENCE), name,<br>- grantor->def->name);<br>- return -1;<br>- }<br>- break;<br>+ break;<br>+ }<br>+ case SC_FUNCTION: {<br>+ struct func *func = func_by_id(priv->object_id);<br>+ if (func == NULL) {<br>+ diag_set(ClientError, ER_NO_SUCH_FUNCTION, int2str(priv->object_id));<br>+ return -1;<br> }<br>- case SC_ROLE: {<br>- struct user *role = user_by_id(priv->object_id);<br>- if (role == NULL || role->def->type != SC_ROLE) {<br>- diag_set(ClientError, ER_NO_SUCH_ROLE,<br>- role ? role->def->name :<br>- int2str(priv->object_id));<br>- return -1;<br>- }<br>- /*<br>- * Only the creator of the role can grant or revoke it.<br>- * Everyone can grant 'PUBLIC' role.<br>- */<br>- if (role->def->owner != grantor->def->uid &&<br>- grantor->def->uid != ADMIN &&<br>- (role->def->uid != PUBLIC || priv->access != PRIV_X)) {<br>- diag_set(AccessDeniedError,<br>- priv_name(priv_type),<br>- schema_object_name(SC_ROLE), name,<br>- grantor->def->name);<br>- return -1;<br>- }<br>- /* Not necessary to do during revoke, but who cares. */<br>- if (role_check(grantee, role) != 0)<br>- return -1;<br>- break;<br>+ if (func->def->uid != grantor->def->uid &&<br>+ grantor->def->uid != ADMIN) {<br>+ diag_set(AccessDeniedError,<br>+ priv_name(priv_type),<br>+ schema_object_name(SC_FUNCTION), name,<br>+ grantor->def->name);<br>+ return -1;<br> }<br>- case SC_USER: {<br>- struct user *user = user_by_id(priv->object_id);<br>- if (user == NULL || user->def->type != SC_USER) {<br>- diag_set(ClientError, ER_NO_SUCH_USER,<br>- user ? user->def->name :<br>- int2str(priv->object_id));<br>- return -1;<br>- }<br>- if (user->def->owner != grantor->def->uid &&<br>- grantor->def->uid != ADMIN) {<br>- diag_set(AccessDeniedError,<br>- priv_name(priv_type),<br>- schema_object_name(SC_USER), name,<br>- grantor->def->name);<br>- return -1;<br>- }<br>- break;<br>+ break;<br>+ }<br>+ case SC_SEQUENCE: {<br>+ struct sequence *seq = sequence_by_id(priv->object_id);<br>+ if (seq == NULL) {<br>+ diag_set(ClientError, ER_NO_SUCH_SEQUENCE, int2str(priv->object_id));<br>+ return -1;<br> }<br>- case SC_ENTITY_SPACE:<br>- case SC_ENTITY_FUNCTION:<br>- case SC_ENTITY_SEQUENCE:<br>- case SC_ENTITY_ROLE:<br>- case SC_ENTITY_USER: {<br>- /* Only admin may grant privileges on an entire entity. */<br>- if (grantor->def->uid != ADMIN) {<br>- diag_set(AccessDeniedError, priv_name(priv_type),<br>- schema_object_name(priv->object_type), name,<br>- grantor->def->name);<br>- return -1;<br>- }<br>+ if (seq->def->uid != grantor->def->uid &&<br>+ grantor->def->uid != ADMIN) {<br>+ diag_set(AccessDeniedError,<br>+ priv_name(priv_type),<br>+ schema_object_name(SC_SEQUENCE), name,<br>+ grantor->def->name);<br>+ return -1;<br> }<br>- default:<br>- break;<br>+ break;<br>+ }<br>+ case SC_ROLE: {<br>+ struct user *role = user_by_id(priv->object_id);<br>+ if (role == NULL || role->def->type != SC_ROLE) {<br>+ diag_set(ClientError, ER_NO_SUCH_ROLE,<br>+ role ? role->def->name :<br>+ int2str(priv->object_id));<br>+ return -1;<br>+ }<br>+ /*<br>+ * Only the creator of the role can grant or revoke it.<br>+ * Everyone can grant 'PUBLIC' role.<br>+ */<br>+ if (role->def->owner != grantor->def->uid &&<br>+ grantor->def->uid != ADMIN &&<br>+ (role->def->uid != PUBLIC || priv->access != PRIV_X)) {<br>+ diag_set(AccessDeniedError,<br>+ priv_name(priv_type),<br>+ schema_object_name(SC_ROLE), name,<br>+ grantor->def->name);<br>+ return -1;<br>+ }<br>+ /* Not necessary to do during revoke, but who cares. */<br>+ if (role_check(grantee, role) != 0)<br>+ return -1;<br>+ break;<br>+ }<br>+ case SC_USER: {<br>+ struct user *user = user_by_id(priv->object_id);<br>+ if (user == NULL || user->def->type != SC_USER) {<br>+ diag_set(ClientError, ER_NO_SUCH_USER,<br>+ user ? user->def->name :<br>+ int2str(priv->object_id));<br>+ return -1;<br>+ }<br>+ if (user->def->owner != grantor->def->uid &&<br>+ grantor->def->uid != ADMIN) {<br>+ diag_set(AccessDeniedError,<br>+ priv_name(priv_type),<br>+ schema_object_name(SC_USER), name,<br>+ grantor->def->name);<br>+ return -1;<br>+ }<br>+ break;<br>+ }<br>+ case SC_ENTITY_SPACE:<br>+ case SC_ENTITY_FUNCTION:<br>+ case SC_ENTITY_SEQUENCE:<br>+ case SC_ENTITY_ROLE:<br>+ case SC_ENTITY_USER: {<br>+ /* Only admin may grant privileges on an entire entity. */<br>+ if (grantor->def->uid != ADMIN) {<br>+ diag_set(AccessDeniedError, priv_name(priv_type),<br>+ schema_object_name(priv->object_type), name,<br>+ grantor->def->name);<br>+ return -1;<br>+ }<br>+ }<br>+ default:<br>+ break;<br> }<br> if (priv->access == 0) {<br> diag_set(ClientError, ER_GRANT,<br>diff --git a/src/box/replication.cc b/src/box/replication.cc<br>index 68bc1b064..bd3d4c23f 100644<br>--- a/src/box/replication.cc<br>+++ b/src/box/replication.cc<br>@@ -386,22 +386,22 @@ static void<br> replica_on_applier_disconnect(struct replica *replica)<br> {<br> switch (replica->applier_sync_state) {<br>- case APPLIER_SYNC:<br>- assert(replicaset.applier.synced > 0);<br>- replicaset.applier.synced--;<br>- FALLTHROUGH;<br>- case APPLIER_CONNECTED:<br>- assert(replicaset.applier.connected > 0);<br>- replicaset.applier.connected--;<br>- break;<br>- case APPLIER_LOADING:<br>- assert(replicaset.applier.loading > 0);<br>- replicaset.applier.loading--;<br>- break;<br>- case APPLIER_DISCONNECTED:<br>- break;<br>- default:<br>- unreachable();<br>+ case APPLIER_SYNC:<br>+ assert(replicaset.applier.synced > 0);<br>+ replicaset.applier.synced--;<br>+ FALLTHROUGH;<br>+ case APPLIER_CONNECTED:<br>+ assert(replicaset.applier.connected > 0);<br>+ replicaset.applier.connected--;<br>+ break;<br>+ case APPLIER_LOADING:<br>+ assert(replicaset.applier.loading > 0);<br>+ replicaset.applier.loading--;<br>+ break;<br>+ case APPLIER_DISCONNECTED:<br>+ break;<br>+ default:<br>+ unreachable();<br> }<br> replica->applier_sync_state = replica->applier->state;<br> if (replica->applier_sync_state == APPLIER_LOADING)<br>@@ -415,43 +415,43 @@ replica_on_applier_state_f(struct trigger *trigger, void *event)<br> struct replica *replica = container_of(trigger,<br> struct replica, on_applier_state);<br> switch (replica->applier->state) {<br>- case APPLIER_INITIAL_JOIN:<br>- replicaset.is_joining = true;<br>- break;<br>- case APPLIER_JOINED:<br>- replicaset.is_joining = false;<br>- break;<br>- case APPLIER_CONNECTED:<br>- try {<br>- if (tt_uuid_is_nil(&replica->uuid))<br>- replica_on_applier_connect(replica);<br>- else<br>- replica_on_applier_reconnect(replica);<br>- } catch (Exception *e) {<br>- return -1;<br>- }<br>- break;<br>- case APPLIER_LOADING:<br>- case APPLIER_DISCONNECTED:<br>- replica_on_applier_disconnect(replica);<br>- break;<br>- case APPLIER_FOLLOW:<br>- replica_on_applier_sync(replica);<br>- break;<br>- case APPLIER_OFF:<br>- /*<br>- * Connection to self, duplicate connection<br>- * to the same master, or the applier fiber<br>- * has been cancelled. Assume synced.<br>- */<br>- replica_on_applier_sync(replica);<br>- break;<br>- case APPLIER_STOPPED:<br>- /* Unrecoverable error. */<br>- replica_on_applier_disconnect(replica);<br>- break;<br>- default:<br>- break;<br>+ case APPLIER_INITIAL_JOIN:<br>+ replicaset.is_joining = true;<br>+ break;<br>+ case APPLIER_JOINED:<br>+ replicaset.is_joining = false;<br>+ break;<br>+ case APPLIER_CONNECTED:<br>+ try {<br>+ if (tt_uuid_is_nil(&replica->uuid))<br>+ replica_on_applier_connect(replica);<br>+ else<br>+ replica_on_applier_reconnect(replica);<br>+ } catch (Exception *e) {<br>+ return -1;<br>+ }<br>+ break;<br>+ case APPLIER_LOADING:<br>+ case APPLIER_DISCONNECTED:<br>+ replica_on_applier_disconnect(replica);<br>+ break;<br>+ case APPLIER_FOLLOW:<br>+ replica_on_applier_sync(replica);<br>+ break;<br>+ case APPLIER_OFF:<br>+ /*<br>+ * Connection to self, duplicate connection<br>+ * to the same master, or the applier fiber<br>+ * has been cancelled. Assume synced.<br>+ */<br>+ replica_on_applier_sync(replica);<br>+ break;<br>+ case APPLIER_STOPPED:<br>+ /* Unrecoverable error. */<br>+ replica_on_applier_disconnect(replica);<br>+ break;<br>+ default:<br>+ break;<br> }<br> fiber_cond_signal(&replicaset.applier.cond);<br> return 0;<br>@@ -472,11 +472,11 @@ replicaset_update(struct applier **appliers, int count)<br> struct applier *applier;<br> <br> auto uniq_guard = make_scoped_guard([&]{<br>- replica_hash_foreach_safe(&uniq, replica, next) {<br>- replica_hash_remove(&uniq, replica);<br>- replica_clear_applier(replica);<br>- replica_delete(replica);<br>- }<br>+ replica_hash_foreach_safe(&uniq, replica, next) {<br>+ replica_hash_remove(&uniq, replica);<br>+ replica_clear_applier(replica);<br>+ replica_delete(replica);<br>+ }<br> });<br> <br> /* Check for duplicate UUID */<br>@@ -596,15 +596,15 @@ applier_on_connect_f(struct trigger *trigger, void *event)<br> struct applier *applier = (struct applier *)event;<br> <br> switch (applier->state) {<br>- case APPLIER_OFF:<br>- case APPLIER_STOPPED:<br>- state->failed++;<br>- break;<br>- case APPLIER_CONNECTED:<br>- state->connected++;<br>- break;<br>- default:<br>- return 0;<br>+ case APPLIER_OFF:<br>+ case APPLIER_STOPPED:<br>+ state->failed++;<br>+ break;<br>+ case APPLIER_CONNECTED:<br>+ state->connected++;<br>+ break;<br>+ default:<br>+ return 0;<br> }<br> fiber_cond_signal(&state->wakeup);<br> applier_pause(applier);<br>diff --git a/src/box/user.cc b/src/box/user.cc<br>index 50614c6f2..366ebcd72 100644<br>--- a/src/box/user.cc<br>+++ b/src/box/user.cc<br>@@ -302,6 +302,12 @@ user_set_effective_access(struct user *user)<br> }<br> }<br> <br>+static void priv_def_create_from_tuple_xc(struct priv_def *priv, struct tuple *tuple)<br>+{<br>+ if (priv_def_create_from_tuple(priv, tuple) != 0)<br>+ diag_raise();<br>+}<br>+<br> /**<br> * Reload user privileges and re-grant them.<br> */<br>@@ -339,8 +345,7 @@ user_reload_privs(struct user *user)<br> struct tuple *tuple;<br> while ((tuple = iterator_next_xc(it)) != NULL) {<br> struct priv_def priv;<br>- if (priv_def_create_from_tuple(&priv, tuple) != 0)<br>- diag_raise();<br>+ priv_def_create_from_tuple_xc(&priv, tuple);<br> /**<br> * Skip role grants, we're only<br> * interested in real objects.<br>diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c<br>index ee361c31f..86bed8013 100644<br>--- a/src/box/vy_scheduler.c<br>+++ b/src/box/vy_scheduler.c<br>@@ -510,7 +510,7 @@ vy_scheduler_reset_stat(struct vy_scheduler *scheduler)<br> stat->compaction_output = 0;<br> }<br> <br>-static void<br>+static int<br> vy_scheduler_on_delete_lsm(struct trigger *trigger, void *event)<br> {<br> struct vy_lsm *lsm = event;<br>@@ -521,6 +521,7 @@ vy_scheduler_on_delete_lsm(struct trigger *trigger, void *event)<br> vy_compaction_heap_delete(&scheduler->compaction_heap, lsm);<br> trigger_clear(trigger);<br> free(trigger);<br>+ return 0;<br> }<br> <br> int<br>-- <br>2.17.1</p></BODY></HTML>