From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6068C2846C for ; Fri, 16 Aug 2019 14:38:39 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id spUxZiwBAaUg for ; Fri, 16 Aug 2019 14:38:39 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id C47A628462 for ; Fri, 16 Aug 2019 14:38:38 -0400 (EDT) From: Ilya Kosarev Subject: [tarantool-patches] [PATCH v2 1/6] refactoring: remove exceptions from triggers except alter.cc Date: Fri, 16 Aug 2019 21:37:47 +0300 Message-Id: <0bc89d20f2b2e45a1e46ab55d9ab517a1d0410cc.1565979897.git.i.kosarev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: georgy@tarantool.org, i.kosarev@corp.mail.ru, Ilya Kosarev Triggers' signatures are updated so that they will be able to return error codes instead of throwing exceptions. In files except alter.cc triggers don't throw exceptions any more. --- src/box/alter.cc | 182 ++++++++++++++++++++++++------------ src/box/applier.cc | 18 ++-- src/box/ck_constraint.c | 9 +- src/box/ck_constraint.h | 2 +- src/box/iproto.cc | 3 +- src/box/lua/call.c | 5 +- src/box/lua/sequence.c | 3 +- src/box/lua/space.cc | 3 +- src/box/memtx_space.c | 17 ++-- src/box/relay.cc | 5 +- src/box/replication.cc | 80 ++++++++-------- src/box/session.cc | 3 +- src/box/txn.c | 10 +- src/box/vinyl.c | 44 +++++---- src/lib/core/fiber.c | 3 +- src/lib/core/trigger.cc | 18 ++-- src/lib/core/trigger.h | 2 +- src/lua/trigger.c | 7 +- src/main.cc | 3 +- test/unit/cbus.c | 3 +- test/unit/swim.c | 6 +- test/unit/swim_test_utils.c | 3 +- 22 files changed, 262 insertions(+), 167 deletions(-) diff --git a/src/box/alter.cc b/src/box/alter.cc index 4f2e34bf0..81edd62b5 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -858,7 +858,7 @@ struct mh_i32_t *AlterSpaceLock::registry; * of the dropped indexes. * Replace the old space with a new one in the space cache. */ -static void +static int alter_space_commit(struct trigger *trigger, void *event) { struct txn *txn = (struct txn *) event; @@ -888,6 +888,7 @@ alter_space_commit(struct trigger *trigger, void *event) space_delete(alter->old_space); alter->old_space = NULL; alter_space_delete(alter); + return 0; } /** @@ -898,7 +899,7 @@ alter_space_commit(struct trigger *trigger, void *event) * Keep in mind that we may end up here in case of * alter_space_commit() failure (unlikely) */ -static void +static int alter_space_rollback(struct trigger *trigger, void * /* event */) { struct alter_space *alter = (struct alter_space *) trigger->data; @@ -917,6 +918,7 @@ alter_space_rollback(struct trigger *trigger, void * /* event */) space_swap_fk_constraints(alter->new_space, alter->old_space); space_cache_replace(alter->new_space, alter->old_space); alter_space_delete(alter); + return 0; } /** @@ -1644,12 +1646,13 @@ MoveCkConstraints::rollback(struct alter_space *alter) /** * Delete the space. It is already removed from the space cache. */ -static void +static int on_drop_space_commit(struct trigger *trigger, void *event) { (void) event; struct space *space = (struct space *)trigger->data; space_delete(space); + return 0; } /** @@ -1657,12 +1660,13 @@ on_drop_space_commit(struct trigger *trigger, void *event) * of all other events happened after the space was removed were * reverted by the cascading rollback. */ -static void +static int on_drop_space_rollback(struct trigger *trigger, void *event) { (void) event; struct space *space = (struct space *)trigger->data; space_cache_replace(NULL, space); + return 0; } /** @@ -1672,13 +1676,14 @@ on_drop_space_rollback(struct trigger *trigger, void *event) * By the time the space is removed, it should be empty: we * rely on cascading rollback. */ -static void +static int on_create_space_rollback(struct trigger *trigger, void *event) { (void) event; struct space *space = (struct space *)trigger->data; space_cache_replace(space, NULL); space_delete(space); + return 0; } /** @@ -1780,12 +1785,13 @@ update_view_references(struct Select *select, int update_value, * Trigger which is fired to commit creation of new SQL view. * Its purpose is to release memory of SELECT. */ -static void +static int on_create_view_commit(struct trigger *trigger, void *event) { (void) event; struct Select *select = (struct Select *)trigger->data; sql_select_delete(sql_get(), select); + return 0; } /** @@ -1793,13 +1799,14 @@ on_create_view_commit(struct trigger *trigger, void *event) * Decrements view reference counters of dependent spaces and * releases memory for SELECT. */ -static void +static int on_create_view_rollback(struct trigger *trigger, void *event) { (void) event; struct Select *select = (struct Select *)trigger->data; update_view_references(select, -1, true, NULL); sql_select_delete(sql_get(), select); + return 0; } /** @@ -1807,12 +1814,13 @@ on_create_view_rollback(struct trigger *trigger, void *event) * Its purpose is to decrement view reference counters of * dependent spaces and release memory for SELECT. */ -static void +static int on_drop_view_commit(struct trigger *trigger, void *event) { (void) event; struct Select *select = (struct Select *)trigger->data; sql_select_delete(sql_get(), select); + return 0; } /** @@ -1820,13 +1828,14 @@ on_drop_view_commit(struct trigger *trigger, void *event) * Release memory for struct SELECT compiled in * on_replace_dd_space trigger. */ -static void +static int on_drop_view_rollback(struct trigger *trigger, void *event) { (void) event; struct Select *select = (struct Select *)trigger->data; update_view_references(select, 1, true, NULL); sql_select_delete(sql_get(), select); + return 0; } /** @@ -1879,7 +1888,7 @@ on_drop_view_rollback(struct trigger *trigger, void *event) * dynamic space configuration such a check would be particularly * clumsy, so it is simply not done. */ -static void +static int on_replace_dd_space(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -2115,6 +2124,7 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event) alter_space_do(stmt, alter); alter_guard.is_active = false; } + return 0; } /** @@ -2175,7 +2185,7 @@ index_is_used_by_fk_constraint(struct rlist *fk_list, uint32_t iid) * for offsets is relinquished to the slab allocator as tuples * are modified. */ -static void +static int on_replace_dd_index(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -2352,6 +2362,7 @@ on_replace_dd_index(struct trigger * /* trigger */, void *event) (void) new UpdateSchemaVersion(alter); alter_space_do(stmt, alter); scoped_guard.is_active = false; + return 0; } /** @@ -2365,7 +2376,7 @@ on_replace_dd_index(struct trigger * /* trigger */, void *event) * This is OK, because a WAL write error implies cascading * rollback of all transactions following this one. */ -static void +static int on_replace_dd_truncate(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -2374,7 +2385,7 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event) if (new_tuple == NULL) { /* Space drop - nothing to do. */ - return; + return 0; } uint32_t space_id = @@ -2386,7 +2397,7 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event) * Space creation during initial recovery - * nothing to do. */ - return; + return 0; } /* @@ -2428,6 +2439,7 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event) (void) new MoveCkConstraints(alter); alter_space_do(stmt, alter); scoped_guard.is_active = false; + return 0; } /* {{{ access control */ @@ -2572,15 +2584,16 @@ user_def_new_from_tuple(struct tuple *tuple) return user; } -static void +static int user_cache_remove_user(struct trigger *trigger, void * /* event */) { struct tuple *tuple = (struct tuple *)trigger->data; uint32_t uid = tuple_field_u32_xc(tuple, BOX_USER_FIELD_ID); user_cache_delete(uid); + return 0; } -static void +static int user_cache_alter_user(struct trigger *trigger, void * /* event */) { struct tuple *tuple = (struct tuple *)trigger->data; @@ -2589,12 +2602,13 @@ user_cache_alter_user(struct trigger *trigger, void * /* event */) /* Can throw if, e.g. too many users. */ user_cache_replace(user); def_guard.is_active = false; + return 0; } /** * A trigger invoked on replace in the user table. */ -static void +static int on_replace_dd_user(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -2654,6 +2668,7 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event) txn_alter_trigger_new(user_cache_alter_user, old_tuple); txn_stmt_on_rollback(stmt, on_rollback); } + return 0; } /** @@ -2848,7 +2863,7 @@ func_def_new_from_tuple(struct tuple *tuple) return def; } -static void +static int on_create_func_rollback(struct trigger *trigger, void * /* event */) { /* Remove the new function from the cache and delete it. */ @@ -2856,30 +2871,33 @@ on_create_func_rollback(struct trigger *trigger, void * /* event */) func_cache_delete(func->def->fid); trigger_run_xc(&on_alter_func, func); func_delete(func); + return 0; } -static void +static int on_drop_func_commit(struct trigger *trigger, void * /* event */) { /* Delete the old function. */ struct func *func = (struct func *)trigger->data; func_delete(func); + return 0; } -static void +static int on_drop_func_rollback(struct trigger *trigger, void * /* event */) { /* Insert the old function back into the cache. */ struct func *func = (struct func *)trigger->data; func_cache_insert(func); trigger_run_xc(&on_alter_func, func); + return 0; } /** * A trigger invoked on replace in a space containing * functions on which there were defined any grants. */ -static void +static int on_replace_dd_func(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -2952,6 +2970,7 @@ on_replace_dd_func(struct trigger * /* trigger */, void *event) "alter"); } } + return 0; } /** Create a collation identifier definition from tuple. */ @@ -3040,27 +3059,29 @@ coll_id_def_new_from_tuple(struct tuple *tuple, struct coll_id_def *def) } /** Delete the new collation identifier. */ -static void +static int on_create_collation_rollback(struct trigger *trigger, void *event) { (void) event; struct coll_id *coll_id = (struct coll_id *) trigger->data; coll_id_cache_delete(coll_id); coll_id_delete(coll_id); + return 0; } /** Free a deleted collation identifier on commit. */ -static void +static int on_drop_collation_commit(struct trigger *trigger, void *event) { (void) event; struct coll_id *coll_id = (struct coll_id *) trigger->data; coll_id_delete(coll_id); + return 0; } /** Put the collation identifier back on rollback. */ -static void +static int on_drop_collation_rollback(struct trigger *trigger, void *event) { (void) event; @@ -3069,13 +3090,14 @@ on_drop_collation_rollback(struct trigger *trigger, void *event) if (coll_id_cache_replace(coll_id, &replaced_id) != 0) panic("Out of memory on insertion into collation cache"); assert(replaced_id == NULL); + return 0; } /** * A trigger invoked on replace in a space containing * collations that a user defined. */ -static void +static int on_replace_dd_collation(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -3143,6 +3165,7 @@ on_replace_dd_collation(struct trigger * /* trigger */, void *event) assert(new_tuple != NULL && old_tuple != NULL); tnt_raise(ClientError, ER_UNSUPPORTED, "collation", "alter"); } + return 0; } /** @@ -3349,7 +3372,7 @@ grant_or_revoke(struct priv_def *priv) } /** A trigger called on rollback of grant. */ -static void +static int revoke_priv(struct trigger *trigger, void *event) { (void) event; @@ -3358,10 +3381,11 @@ revoke_priv(struct trigger *trigger, void *event) priv_def_create_from_tuple(&priv, tuple); priv.access = 0; grant_or_revoke(&priv); + return 0; } /** A trigger called on rollback of revoke or modify. */ -static void +static int modify_priv(struct trigger *trigger, void *event) { (void) event; @@ -3369,13 +3393,14 @@ modify_priv(struct trigger *trigger, void *event) struct priv_def priv; priv_def_create_from_tuple(&priv, tuple); grant_or_revoke(&priv); + return 0; } /** * A trigger invoked on replace in the space containing * all granted privileges. */ -static void +static int on_replace_dd_priv(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -3408,6 +3433,7 @@ on_replace_dd_priv(struct trigger * /* trigger */, void *event) txn_alter_trigger_new(modify_priv, old_tuple); txn_stmt_on_rollback(stmt, on_rollback); } + return 0; } /* }}} access control */ @@ -3423,7 +3449,7 @@ on_replace_dd_priv(struct trigger * /* trigger */, void *event) * concern us, we can safely change the cluster id in before-replace * event, not in after-replace event. */ -static void +static int on_replace_dd_schema(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -3440,6 +3466,7 @@ on_replace_dd_schema(struct trigger * /* trigger */, void *event) REPLICASET_UUID = uu; say_info("cluster uuid %s", tt_uuid_str(&uu)); } + return 0; } /** @@ -3447,7 +3474,7 @@ on_replace_dd_schema(struct trigger * /* trigger */, void *event) * write ahead log. Update the cluster configuration cache * with it. */ -static void +static int register_replica(struct trigger *trigger, void * /* event */) { struct tuple *new_tuple = (struct tuple *)trigger->data; @@ -3466,9 +3493,10 @@ register_replica(struct trigger *trigger, void * /* event */) panic("Can't register replica: %s", e->errmsg); } } + return 0; } -static void +static int unregister_replica(struct trigger *trigger, void * /* event */) { struct tuple *old_tuple = (struct tuple *)trigger->data; @@ -3479,6 +3507,7 @@ unregister_replica(struct trigger *trigger, void * /* event */) struct replica *replica = replica_by_uuid(&old_uuid); assert(replica != NULL); replica_clear_id(replica); + return 0; } /** @@ -3499,7 +3528,7 @@ unregister_replica(struct trigger *trigger, void * /* event */) * replica set can not by mistake join/follow another replica * set without first being reset (emptied). */ -static void +static int on_replace_dd_cluster(struct trigger *trigger, void *event) { (void) trigger; @@ -3553,6 +3582,7 @@ on_replace_dd_cluster(struct trigger *trigger, void *event) old_tuple); txn_stmt_on_commit(stmt, on_commit); } + return 0; } /* }}} cluster configuration */ @@ -3600,7 +3630,7 @@ sequence_def_new_from_tuple(struct tuple *tuple, uint32_t errcode) return def; } -static void +static int on_create_sequence_rollback(struct trigger *trigger, void * /* event */) { /* Remove the new sequence from the cache and delete it. */ @@ -3608,35 +3638,39 @@ on_create_sequence_rollback(struct trigger *trigger, void * /* event */) sequence_cache_delete(seq->def->id); trigger_run_xc(&on_alter_sequence, seq); sequence_delete(seq); + return 0; } -static void +static int on_drop_sequence_commit(struct trigger *trigger, void * /* event */) { /* Delete the old sequence. */ struct sequence *seq = (struct sequence *)trigger->data; sequence_delete(seq); + return 0; } -static void +static int on_drop_sequence_rollback(struct trigger *trigger, void * /* event */) { /* Insert the old sequence back into the cache. */ struct sequence *seq = (struct sequence *)trigger->data; sequence_cache_insert(seq); trigger_run_xc(&on_alter_sequence, seq); + return 0; } -static void +static int on_alter_sequence_commit(struct trigger *trigger, void * /* event */) { /* Delete the old old sequence definition. */ struct sequence_def *def = (struct sequence_def *)trigger->data; free(def); + return 0; } -static void +static int on_alter_sequence_rollback(struct trigger *trigger, void * /* event */) { /* Restore the old sequence definition. */ @@ -3646,13 +3680,14 @@ on_alter_sequence_rollback(struct trigger *trigger, void * /* event */) free(seq->def); seq->def = def; trigger_run_xc(&on_alter_sequence, seq); + return 0; } /** * A trigger invoked on replace in space _sequence. * Used to alter a sequence definition. */ -static void +static int on_replace_dd_sequence(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -3716,10 +3751,11 @@ on_replace_dd_sequence(struct trigger * /* trigger */, void *event) def_guard.is_active = false; trigger_run_xc(&on_alter_sequence, seq); + return 0; } /** Restore the old sequence value on rollback. */ -static void +static int on_drop_sequence_data_rollback(struct trigger *trigger, void * /* event */) { struct tuple *tuple = (struct tuple *)trigger->data; @@ -3730,13 +3766,14 @@ on_drop_sequence_data_rollback(struct trigger *trigger, void * /* event */) assert(seq != NULL); if (sequence_set(seq, val) != 0) panic("Can't restore sequence value"); + return 0; } /** * A trigger invoked on replace in space _sequence_data. * Used to update a sequence value. */ -static void +static int on_replace_dd_sequence_data(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -3767,6 +3804,7 @@ on_replace_dd_sequence_data(struct trigger * /* trigger */, void *event) txn_stmt_on_rollback(stmt, on_rollback); sequence_reset(seq); } + return 0; } /** @@ -3808,7 +3846,7 @@ sequence_field_from_tuple(struct space *space, struct tuple *tuple, } /** Attach a sequence to a space on rollback in _space_sequence. */ -static void +static int set_space_sequence(struct trigger *trigger, void * /* event */) { struct tuple *tuple = (struct tuple *)trigger->data; @@ -3830,10 +3868,11 @@ set_space_sequence(struct trigger *trigger, void * /* event */) free(space->sequence_path); space->sequence_path = path; trigger_run_xc(&on_alter_space, space); + return 0; } /** Detach a sequence from a space on rollback in _space_sequence. */ -static void +static int clear_space_sequence(struct trigger *trigger, void * /* event */) { struct tuple *tuple = (struct tuple *)trigger->data; @@ -3848,13 +3887,14 @@ clear_space_sequence(struct trigger *trigger, void * /* event */) free(space->sequence_path); space->sequence_path = NULL; trigger_run_xc(&on_alter_space, space); + return 0; } /** * A trigger invoked on replace in space _space_sequence. * Used to update space <-> sequence mapping. */ -static void +static int on_replace_dd_space_sequence(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -3933,12 +3973,13 @@ on_replace_dd_space_sequence(struct trigger * /* trigger */, void *event) txn_stmt_on_rollback(stmt, on_rollback); } trigger_run_xc(&on_alter_space, space); + return 0; } /* }}} sequence */ /** Delete the new trigger on rollback of an INSERT statement. */ -static void +static int on_create_trigger_rollback(struct trigger *trigger, void * /* event */) { struct sql_trigger *old_trigger = (struct sql_trigger *)trigger->data; @@ -3950,28 +3991,30 @@ on_create_trigger_rollback(struct trigger *trigger, void * /* event */) assert(rc == 0); assert(new_trigger == old_trigger); sql_trigger_delete(sql_get(), new_trigger); + return 0; } /** Restore the old trigger on rollback of a DELETE statement. */ -static void +static int on_drop_trigger_rollback(struct trigger *trigger, void * /* event */) { struct sql_trigger *old_trigger = (struct sql_trigger *)trigger->data; struct sql_trigger *new_trigger; if (old_trigger == NULL) - return; + return 0; if (sql_trigger_replace(sql_trigger_name(old_trigger), sql_trigger_space_id(old_trigger), old_trigger, &new_trigger) != 0) panic("Out of memory on insertion into trigger hash"); assert(new_trigger == NULL); + return 0; } /** * Restore the old trigger and delete the new trigger on rollback * of a REPLACE statement. */ -static void +static int on_replace_trigger_rollback(struct trigger *trigger, void * /* event */) { struct sql_trigger *old_trigger = (struct sql_trigger *)trigger->data; @@ -3981,24 +4024,26 @@ on_replace_trigger_rollback(struct trigger *trigger, void * /* event */) old_trigger, &new_trigger) != 0) panic("Out of memory on insertion into trigger hash"); sql_trigger_delete(sql_get(), new_trigger); + return 0; } /** * Trigger invoked on commit in the _trigger space. * Drop useless old sql_trigger AST object if any. */ -static void +static int on_replace_trigger_commit(struct trigger *trigger, void * /* event */) { struct sql_trigger *old_trigger = (struct sql_trigger *)trigger->data; sql_trigger_delete(sql_get(), old_trigger); + return 0; } /** * A trigger invoked on replace in a space containing * SQL triggers. */ -static void +static int on_replace_dd_trigger(struct trigger * /* trigger */, void *event) { struct txn *txn = (struct txn *) event; @@ -4093,6 +4138,7 @@ on_replace_dd_trigger(struct trigger * /* trigger */, void *event) txn_stmt_on_rollback(stmt, on_rollback); txn_stmt_on_commit(stmt, on_commit); + return 0; } /** @@ -4286,7 +4332,7 @@ space_reset_fk_constraint_mask(struct space *space) * from parent's and child's lists of constraints and * release memory. */ -static void +static int on_create_fk_constraint_rollback(struct trigger *trigger, void *event) { (void) event; @@ -4296,10 +4342,11 @@ on_create_fk_constraint_rollback(struct trigger *trigger, void *event) space_reset_fk_constraint_mask(space_by_id(fk->def->parent_id)); space_reset_fk_constraint_mask(space_by_id(fk->def->child_id)); fk_constraint_delete(fk); + return 0; } /** Return old FK and release memory for the new one. */ -static void +static int on_replace_fk_constraint_rollback(struct trigger *trigger, void *event) { (void) event; @@ -4314,10 +4361,11 @@ on_replace_fk_constraint_rollback(struct trigger *trigger, void *event) rlist_add_entry(&parent->parent_fk_constraint, old_fk, in_parent_space); space_reset_fk_constraint_mask(parent); space_reset_fk_constraint_mask(child); + return 0; } /** On rollback of drop simply return back FK to DD. */ -static void +static int on_drop_fk_constraint_rollback(struct trigger *trigger, void *event) { (void) event; @@ -4330,6 +4378,7 @@ on_drop_fk_constraint_rollback(struct trigger *trigger, void *event) FIELD_LINK_CHILD); fk_constraint_set_mask(old_fk, &parent->fk_constraint_mask, FIELD_LINK_PARENT); + return 0; } /** @@ -4337,11 +4386,12 @@ on_drop_fk_constraint_rollback(struct trigger *trigger, void *event) * foreign key entry from both (parent's and child's) lists, * so just release memory. */ -static void +static int on_drop_or_replace_fk_constraint_commit(struct trigger *trigger, void *event) { (void) event; fk_constraint_delete((struct fk_constraint *) trigger->data); + return 0; } /** @@ -4380,7 +4430,7 @@ error: } /** A trigger invoked on replace in the _fk_constraint space. */ -static void +static int on_replace_dd_fk_constraint(struct trigger * /* trigger*/, void *event) { struct txn *txn = (struct txn *) event; @@ -4548,6 +4598,7 @@ on_replace_dd_fk_constraint(struct trigger * /* trigger*/, void *event) space_reset_fk_constraint_mask(child_space); space_reset_fk_constraint_mask(parent_space); } + return 0; } /** Create an instance of check constraint definition by tuple. */ @@ -4587,7 +4638,7 @@ ck_constraint_def_new_from_tuple(struct tuple *tuple) } /** Rollback INSERT check constraint. */ -static void +static int on_create_ck_constraint_rollback(struct trigger *trigger, void * /* event */) { struct ck_constraint *ck = (struct ck_constraint *)trigger->data; @@ -4599,19 +4650,21 @@ on_create_ck_constraint_rollback(struct trigger *trigger, void * /* event */) space_remove_ck_constraint(space, ck); ck_constraint_delete(ck); trigger_run_xc(&on_alter_space, space); + return 0; } /** Commit DELETE check constraint. */ -static void +static int on_drop_ck_constraint_commit(struct trigger *trigger, void * /* event */) { struct ck_constraint *ck = (struct ck_constraint *)trigger->data; assert(ck != NULL); ck_constraint_delete(ck); + return 0; } /** Rollback DELETE check constraint. */ -static void +static int on_drop_ck_constraint_rollback(struct trigger *trigger, void * /* event */) { struct ck_constraint *ck = (struct ck_constraint *)trigger->data; @@ -4623,19 +4676,21 @@ on_drop_ck_constraint_rollback(struct trigger *trigger, void * /* event */) if (space_add_ck_constraint(space, ck) != 0) panic("Can't recover after CK constraint drop rollback"); trigger_run_xc(&on_alter_space, space); + return 0; } /** Commit REPLACE check constraint. */ -static void +static int on_replace_ck_constraint_commit(struct trigger *trigger, void * /* event */) { struct ck_constraint *ck = (struct ck_constraint *)trigger->data; if (ck != NULL) ck_constraint_delete(ck); + return 0; } /** Rollback REPLACE check constraint. */ -static void +static int on_replace_ck_constraint_rollback(struct trigger *trigger, void * /* event */) { struct ck_constraint *ck = (struct ck_constraint *)trigger->data; @@ -4649,10 +4704,11 @@ on_replace_ck_constraint_rollback(struct trigger *trigger, void * /* event */) rlist_add_entry(&space->ck_constraint, ck, link); ck_constraint_delete(new_ck); trigger_run_xc(&on_alter_space, space); + return 0; } /** A trigger invoked on replace in the _ck_constraint space. */ -static void +static int on_replace_dd_ck_constraint(struct trigger * /* trigger*/, void *event) { struct txn *txn = (struct txn *) event; @@ -4737,10 +4793,11 @@ on_replace_dd_ck_constraint(struct trigger * /* trigger*/, void *event) txn_stmt_on_commit(stmt, on_commit); trigger_run_xc(&on_alter_space, space); + return 0; } /** A trigger invoked on replace in the _func_index space. */ -static void +static int on_replace_dd_func_index(struct trigger *trigger, void *event) { (void) trigger; @@ -4788,7 +4845,7 @@ on_replace_dd_func_index(struct trigger *trigger, void *event) * function. Index rebuild is not required. */ if (index_def_get_func(index->def) == func) - return; + return 0; alter = alter_space_new(space); auto scoped_guard = make_scoped_guard([=] {alter_space_delete(alter);}); @@ -4801,6 +4858,7 @@ on_replace_dd_func_index(struct trigger *trigger, void *event) alter_space_do(stmt, alter); scoped_guard.is_active = false; + return 0; } struct trigger alter_space_on_replace_space = { diff --git a/src/box/applier.cc b/src/box/applier.cc index cf03ea160..e770dea58 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -604,7 +604,7 @@ applier_read_tx(struct applier *applier, struct stailq *rows) next)->row.is_commit); } -static void +static int applier_txn_rollback_cb(struct trigger *trigger, void *event) { (void) trigger; @@ -615,14 +615,16 @@ applier_txn_rollback_cb(struct trigger *trigger, void *event) trigger_run(&replicaset.applier.on_rollback, event); /* Rollback applier vclock to the committed one. */ vclock_copy(&replicaset.applier.vclock, &replicaset.vclock); + return 0; } -static void +static int applier_txn_commit_cb(struct trigger *trigger, void *event) { (void) trigger; /* Broadcast the commit event across all appliers. */ trigger_run(&replicaset.applier.on_commit, event); + return 0; } /** @@ -738,18 +740,19 @@ fail: /* * A trigger to update an applier state after a replication commit. */ -static void +static int applier_on_commit(struct trigger *trigger, void *event) { (void) event; struct applier *applier = (struct applier *)trigger->data; fiber_cond_signal(&applier->writer_cond); + return 0; } /* * A trigger to update an applier state after a replication rollback. */ -static void +static int applier_on_rollback(struct trigger *trigger, void *event) { (void) event; @@ -761,6 +764,7 @@ applier_on_rollback(struct trigger *trigger, void *event) } /* Stop the applier fiber. */ fiber_cancel(applier->reader); + return 0; } /** @@ -1124,7 +1128,7 @@ struct applier_on_state { struct fiber_cond wakeup; }; -static void +static int applier_on_state_f(struct trigger *trigger, void *event) { (void) event; @@ -1136,12 +1140,14 @@ applier_on_state_f(struct trigger *trigger, void *event) if (applier->state != APPLIER_OFF && applier->state != APPLIER_STOPPED && applier->state != on_state->desired_state) - return; + return 0; /* Wake up waiter */ fiber_cond_signal(&on_state->wakeup); applier_pause(applier); + + return 0; } static inline void diff --git a/src/box/ck_constraint.c b/src/box/ck_constraint.c index 1cde27022..2e0fa24a5 100644 --- a/src/box/ck_constraint.c +++ b/src/box/ck_constraint.c @@ -175,7 +175,7 @@ ck_constraint_program_run(struct ck_constraint *ck_constraint, return sql_reset(ck_constraint->stmt); } -void +int ck_constraint_on_replace_trigger(struct trigger *trigger, void *event) { (void) trigger; @@ -184,7 +184,7 @@ ck_constraint_on_replace_trigger(struct trigger *trigger, void *event) assert(stmt != NULL); struct tuple *new_tuple = stmt->new_tuple; if (new_tuple == NULL) - return; + return 0; struct space *space = stmt->space; assert(space != NULL); @@ -195,15 +195,16 @@ ck_constraint_on_replace_trigger(struct trigger *trigger, void *event) if (field_ref == NULL) { diag_set(OutOfMemory, field_ref_sz, "region_alloc", "field_ref"); - diag_raise(); + return -1; } vdbe_field_ref_prepare_tuple(field_ref, new_tuple); struct ck_constraint *ck_constraint; rlist_foreach_entry(ck_constraint, &space->ck_constraint, link) { if (ck_constraint_program_run(ck_constraint, field_ref) != 0) - diag_raise(); + return -1; } + return 0; } struct ck_constraint * diff --git a/src/box/ck_constraint.h b/src/box/ck_constraint.h index f26f77a38..6af82afe6 100644 --- a/src/box/ck_constraint.h +++ b/src/box/ck_constraint.h @@ -198,7 +198,7 @@ ck_constraint_delete(struct ck_constraint *ck_constraint); * Raises an exception when some ck constraint is unsatisfied. * The diag message is set. */ -void +int ck_constraint_on_replace_trigger(struct trigger *trigger, void *event); /** diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 8f899fed8..34c8f469a 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1505,7 +1505,7 @@ error: tx_reply_error(msg); } -static void +static int tx_process_call_on_yield(struct trigger *trigger, void *event) { (void)event; @@ -1513,6 +1513,7 @@ tx_process_call_on_yield(struct trigger *trigger, void *event) TRASH(&msg->call); tx_discard_input(msg); trigger_clear(trigger); + return 0; } static void diff --git a/src/box/lua/call.c b/src/box/lua/call.c index 0ac2eb7a6..c77be6698 100644 --- a/src/box/lua/call.c +++ b/src/box/lua/call.c @@ -949,17 +949,18 @@ lbox_func_delete(struct lua_State *L, struct func *func) lua_pop(L, 2); /* box, func */ } -static void +static int lbox_func_new_or_delete(struct trigger *trigger, void *event) { struct lua_State *L = (struct lua_State *) trigger->data; struct func *func = (struct func *)event; if (!func->def->exports.lua) - return; + return 0; if (func_by_id(func->def->fid) != NULL) lbox_func_new(L, func); else lbox_func_delete(L, func); + return 0; } static struct trigger on_alter_func_in_lua = { diff --git a/src/box/lua/sequence.c b/src/box/lua/sequence.c index bd9ec7589..bf0714c1a 100644 --- a/src/box/lua/sequence.c +++ b/src/box/lua/sequence.c @@ -157,7 +157,7 @@ lbox_sequence_delete(struct lua_State *L, struct sequence *seq) lua_pop(L, 2); /* box, sequence */ } -static void +static int lbox_sequence_new_or_delete(struct trigger *trigger, void *event) { struct lua_State *L = trigger->data; @@ -166,6 +166,7 @@ lbox_sequence_new_or_delete(struct trigger *trigger, void *event) lbox_sequence_new(L, seq); else lbox_sequence_delete(L, seq); + return 0; } void diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index d0a7e7815..ea8294f95 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -500,7 +500,7 @@ box_lua_space_delete(struct lua_State *L, uint32_t id) lua_pop(L, 2); /* box, space */ } -static void +static int box_lua_space_new_or_delete(struct trigger *trigger, void *event) { struct lua_State *L = (struct lua_State *) trigger->data; @@ -511,6 +511,7 @@ box_lua_space_new_or_delete(struct trigger *trigger, void *event) } else { box_lua_space_delete(L, space->def->id); } + return 0; } static struct trigger on_alter_space_in_lua = { diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c index cf29cf328..862a1adcc 100644 --- a/src/box/memtx_space.c +++ b/src/box/memtx_space.c @@ -864,7 +864,7 @@ struct memtx_ddl_state { int rc; }; -static void +static int memtx_check_on_replace(struct trigger *trigger, void *event) { struct txn *txn = event; @@ -873,11 +873,11 @@ memtx_check_on_replace(struct trigger *trigger, void *event) /* Nothing to check on DELETE. */ if (stmt->new_tuple == NULL) - return; + return 0; /* We have already failed. */ if (state->rc != 0) - return; + return 0; /* * Only check format for already processed part of the space, @@ -886,11 +886,12 @@ memtx_check_on_replace(struct trigger *trigger, void *event) */ if (tuple_compare(state->cursor, HINT_NONE, stmt->new_tuple, HINT_NONE, state->cmp_def) < 0) - return; + return 0; state->rc = tuple_validate(state->format, stmt->new_tuple); if (state->rc != 0) diag_move(diag_get(), &state->diag); + return 0; } static int @@ -987,7 +988,7 @@ memtx_init_ephemeral_space(struct space *space) memtx_space_add_primary_key(space); } -static void +static int memtx_build_on_replace(struct trigger *trigger, void *event) { struct txn *txn = event; @@ -1002,13 +1003,13 @@ memtx_build_on_replace(struct trigger *trigger, void *event) */ if (tuple_compare(state->cursor, HINT_NONE, cmp_tuple, HINT_NONE, state->cmp_def) < 0) - return; + return 0; if (stmt->new_tuple != NULL && tuple_validate(state->format, stmt->new_tuple) != 0) { state->rc = -1; diag_move(diag_get(), &state->diag); - return; + return 0; } struct tuple *delete = NULL; @@ -1021,7 +1022,7 @@ memtx_build_on_replace(struct trigger *trigger, void *event) if (state->rc != 0) { diag_move(diag_get(), &state->diag); } - return; + return 0; } static int diff --git a/src/box/relay.cc b/src/box/relay.cc index efa3373f9..b99d45a15 100644 --- a/src/box/relay.cc +++ b/src/box/relay.cc @@ -386,7 +386,7 @@ tx_gc_advance(struct cmsg *msg) free(m); } -static void +static int relay_on_close_log_f(struct trigger *trigger, void * /* event */) { static const struct cmsg_hop route[] = { @@ -396,7 +396,7 @@ relay_on_close_log_f(struct trigger *trigger, void * /* event */) struct relay_gc_msg *m = (struct relay_gc_msg *)malloc(sizeof(*m)); if (m == NULL) { say_warn("failed to allocate relay gc message"); - return; + return 0; } cmsg_init(&m->msg, route); m->relay = relay; @@ -407,6 +407,7 @@ relay_on_close_log_f(struct trigger *trigger, void * /* event */) * sent xlog. */ stailq_add_tail_entry(&relay->pending_gc, m, in_pending); + return 0; } /** diff --git a/src/box/replication.cc b/src/box/replication.cc index 28f7acedc..41b83a3ad 100644 --- a/src/box/replication.cc +++ b/src/box/replication.cc @@ -147,7 +147,7 @@ replica_is_orphan(struct replica *replica) relay_get_state(replica->relay) != RELAY_FOLLOW; } -static void +static int replica_on_applier_state_f(struct trigger *trigger, void *event); static struct replica * @@ -401,48 +401,53 @@ replica_on_applier_disconnect(struct replica *replica) replicaset.applier.loading++; } -static void +static int replica_on_applier_state_f(struct trigger *trigger, void *event) { (void)event; struct replica *replica = container_of(trigger, struct replica, on_applier_state); switch (replica->applier->state) { - case APPLIER_INITIAL_JOIN: - replicaset.is_joining = true; - break; - case APPLIER_JOINED: - replicaset.is_joining = false; - break; - case APPLIER_CONNECTED: - if (tt_uuid_is_nil(&replica->uuid)) - replica_on_applier_connect(replica); - else - replica_on_applier_reconnect(replica); - break; - case APPLIER_LOADING: - case APPLIER_DISCONNECTED: - replica_on_applier_disconnect(replica); - break; - case APPLIER_FOLLOW: - replica_on_applier_sync(replica); - break; - case APPLIER_OFF: - /* - * Connection to self, duplicate connection - * to the same master, or the applier fiber - * has been cancelled. Assume synced. - */ - replica_on_applier_sync(replica); - break; - case APPLIER_STOPPED: - /* Unrecoverable error. */ - replica_on_applier_disconnect(replica); - break; - default: - break; + case APPLIER_INITIAL_JOIN: + replicaset.is_joining = true; + break; + case APPLIER_JOINED: + replicaset.is_joining = false; + break; + case APPLIER_CONNECTED: + try { + if (tt_uuid_is_nil(&replica->uuid)) + replica_on_applier_connect(replica); + else + replica_on_applier_reconnect(replica); + } catch (Exception *e) { + return -1; + } + break; + case APPLIER_LOADING: + case APPLIER_DISCONNECTED: + replica_on_applier_disconnect(replica); + break; + case APPLIER_FOLLOW: + replica_on_applier_sync(replica); + break; + case APPLIER_OFF: + /* + * Connection to self, duplicate connection + * to the same master, or the applier fiber + * has been cancelled. Assume synced. + */ + replica_on_applier_sync(replica); + break; + case APPLIER_STOPPED: + /* Unrecoverable error. */ + replica_on_applier_disconnect(replica); + break; + default: + break; } fiber_cond_signal(&replicaset.applier.cond); + return 0; } /** @@ -575,7 +580,7 @@ struct applier_on_connect { struct replicaset_connect_state *state; }; -static void +static int applier_on_connect_f(struct trigger *trigger, void *event) { struct applier_on_connect *on_connect = container_of(trigger, @@ -592,10 +597,11 @@ applier_on_connect_f(struct trigger *trigger, void *event) state->connected++; break; default: - return; + return 0; } fiber_cond_signal(&state->wakeup); applier_pause(applier); + return 0; } void diff --git a/src/box/session.cc b/src/box/session.cc index 59bf226dd..d69b6572f 100644 --- a/src/box/session.cc +++ b/src/box/session.cc @@ -80,7 +80,7 @@ sid_max() return sid_max; } -static void +static int session_on_stop(struct trigger *trigger, void * /* event */) { /* @@ -91,6 +91,7 @@ session_on_stop(struct trigger *trigger, void * /* event */) trigger_clear(trigger); /* Destroy the session */ session_destroy(fiber_get_session(fiber())); + return 0; } static int diff --git a/src/box/txn.c b/src/box/txn.c index 53ebfc053..ce0354a69 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -40,10 +40,10 @@ double too_long_threshold; /* Txn cache. */ static struct stailq txn_cache = {NULL, &txn_cache.first}; -static void +static int txn_on_stop(struct trigger *trigger, void *event); -static void +static int txn_on_yield(struct trigger *trigger, void *event); static void @@ -787,12 +787,13 @@ box_txn_rollback_to_savepoint(box_txn_savepoint_t *svp) return 0; } -static void +static int txn_on_stop(struct trigger *trigger, void *event) { (void) trigger; (void) event; txn_rollback(in_txn()); /* doesn't yield or fail */ + return 0; } /** @@ -812,7 +813,7 @@ txn_on_stop(struct trigger *trigger, void *event) * So much hassle to be user-friendly until we have a true * interactive transaction support in memtx. */ -static void +static int txn_on_yield(struct trigger *trigger, void *event) { (void) trigger; @@ -822,4 +823,5 @@ txn_on_yield(struct trigger *trigger, void *event) assert(!txn_has_flag(txn, TXN_CAN_YIELD)); txn_rollback_to_svp(txn, NULL); txn_set_flag(txn, TXN_IS_ABORTED_BY_YIELD); + return 0; } diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 0dd73045f..cad5f2b3a 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -1040,7 +1040,7 @@ struct vy_check_format_ctx { * This is an on_replace trigger callback that checks inserted * tuples against a new format. */ -static void +static int vy_check_format_on_replace(struct trigger *trigger, void *event) { struct txn *txn = event; @@ -1048,15 +1048,16 @@ vy_check_format_on_replace(struct trigger *trigger, void *event) struct vy_check_format_ctx *ctx = trigger->data; if (stmt->new_tuple == NULL) - return; /* DELETE, nothing to do */ + return 0; /* DELETE, nothing to do */ if (ctx->is_failed) - return; /* already failed, nothing to do */ + return 0; /* already failed, nothing to do */ if (tuple_validate(ctx->format, stmt->new_tuple) != 0) { ctx->is_failed = true; diag_move(diag_get(), &ctx->diag); } + return 0; } static int @@ -3709,13 +3710,14 @@ fail: /* {{{ Cursor */ -static void +static int vinyl_iterator_on_tx_destroy(struct trigger *trigger, void *event) { (void)event; struct vinyl_iterator *it = container_of(trigger, struct vinyl_iterator, on_tx_destroy); it->tx = NULL; + return 0; } static int @@ -4008,7 +4010,7 @@ struct vy_build_ctx { * This is an on_replace trigger callback that forwards DML requests * to the index that is currently being built. */ -static void +static int vy_build_on_replace(struct trigger *trigger, void *event) { struct txn *txn = event; @@ -4019,7 +4021,7 @@ vy_build_on_replace(struct trigger *trigger, void *event) struct vy_lsm *lsm = ctx->lsm; if (ctx->is_failed) - return; /* already failed, nothing to do */ + return 0; /* already failed, nothing to do */ /* Check new tuples for conformity to the new format. */ if (stmt->new_tuple != NULL && @@ -4056,7 +4058,7 @@ vy_build_on_replace(struct trigger *trigger, void *event) if (rc != 0) goto err; } - return; + return 0; err: /* * No need to abort the DDL request if this transaction @@ -4066,9 +4068,10 @@ err: * context isn't valid and so we must not modify it. */ if (tx->state == VINYL_TX_ABORT) - return; + return 0; ctx->is_failed = true; diag_move(diag_get(), &ctx->diag); + return 0; } /** @@ -4464,7 +4467,7 @@ out: /* {{{ Deferred DELETE handling */ -static void +static int vy_deferred_delete_on_commit(struct trigger *trigger, void *event) { struct txn *txn = event; @@ -4477,15 +4480,17 @@ vy_deferred_delete_on_commit(struct trigger *trigger, void *event) mem->dump_lsn = txn->signature; /* Unpin the mem pinned in vy_deferred_delete_on_replace(). */ vy_mem_unpin(mem); + return 0; } -static void +static int vy_deferred_delete_on_rollback(struct trigger *trigger, void *event) { (void)event; struct vy_mem *mem = trigger->data; /* Unpin the mem pinned in vy_deferred_delete_on_replace(). */ vy_mem_unpin(mem); + return 0; } /** @@ -4512,7 +4517,7 @@ vy_deferred_delete_on_rollback(struct trigger *trigger, void *event) * one of the trees got dumped while the other didn't, we would * mistakenly skip both statements on recovery. */ -static void +static int vy_deferred_delete_on_replace(struct trigger *trigger, void *event) { (void)trigger; @@ -4522,7 +4527,7 @@ vy_deferred_delete_on_replace(struct trigger *trigger, void *event) bool is_first_statement = txn_is_first_statement(txn); if (stmt->new_tuple == NULL) - return; + return 0; /* * Extract space id, LSN of the deferred DELETE statement, * and the deleted tuple from the system space row. @@ -4531,27 +4536,27 @@ vy_deferred_delete_on_replace(struct trigger *trigger, void *event) tuple_rewind(&it, stmt->new_tuple); uint32_t space_id; if (tuple_next_u32(&it, &space_id) != 0) - diag_raise(); + return -1; uint64_t lsn; if (tuple_next_u64(&it, &lsn) != 0) - diag_raise(); + return -1; const char *delete_data = tuple_next_with_type(&it, MP_ARRAY); if (delete_data == NULL) - diag_raise(); + return -1; const char *delete_data_end = delete_data; mp_next(&delete_data_end); /* Look up the space. */ struct space *space = space_cache_find(space_id); if (space == NULL) - diag_raise(); + return -1; /* * All secondary indexes could have been dropped, in * which case we don't need to generate deferred DELETE * statements anymore. */ if (space->index_count <= 1) - return; + return 0; /* * Wait for memory quota if necessary before starting to * process the batch (we can't yield between statements). @@ -4565,7 +4570,7 @@ vy_deferred_delete_on_replace(struct trigger *trigger, void *event) struct tuple *delete = vy_stmt_new_delete(pk->mem_format, delete_data, delete_data_end); if (delete == NULL) - diag_raise(); + return -1; /* * A deferred DELETE may be generated after new statements * were committed for the deleted key. So we must use the @@ -4657,7 +4662,8 @@ vy_deferred_delete_on_replace(struct trigger *trigger, void *event) tuple_unref(delete); if (rc != 0) - diag_raise(); + return -1; + return 0; } static struct trigger on_replace_vinyl_deferred_delete = { diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c index ce90f930c..710940838 100644 --- a/src/lib/core/fiber.c +++ b/src/lib/core/fiber.c @@ -1292,12 +1292,13 @@ cord_cojoin(struct cord *cord) return cord_join(cord); } -void +int break_ev_loop_f(struct trigger *trigger, void *event) { (void) trigger; (void) event; ev_break(loop(), EVBREAK_ALL); + return 0; } struct costart_ctx diff --git a/src/lib/core/trigger.cc b/src/lib/core/trigger.cc index 4a43151e1..9f8a477c1 100644 --- a/src/lib/core/trigger.cc +++ b/src/lib/core/trigger.cc @@ -36,11 +36,12 @@ int trigger_run(struct rlist *list, void *event) { try { - struct trigger *trigger, *tmp; - rlist_foreach_entry_safe(trigger, list, link, tmp) - trigger->run(trigger, event); + struct trigger *trigger, *tmp; + rlist_foreach_entry_safe(trigger, list, link, tmp) + if (trigger->run(trigger, event) != 0) + return -1; } catch (Exception *e) { - return -1; + return -1; } return 0; } @@ -49,11 +50,12 @@ int trigger_run_reverse(struct rlist *list, void *event) { try { - struct trigger *trigger, *tmp; - rlist_foreach_entry_safe_reverse(trigger, list, link, tmp) - trigger->run(trigger, event); + struct trigger *trigger, *tmp; + rlist_foreach_entry_safe_reverse(trigger, list, link, tmp) + if (trigger->run(trigger, event) != 0) + return -1; } catch (Exception *e) { - return -1; + return -1; } return 0; } diff --git a/src/lib/core/trigger.h b/src/lib/core/trigger.h index 76fa6345d..7b500dd92 100644 --- a/src/lib/core/trigger.h +++ b/src/lib/core/trigger.h @@ -40,7 +40,7 @@ extern "C" { * on an event. */ struct trigger; -typedef void (*trigger_f)(struct trigger *trigger, void *event); +typedef int (*trigger_f)(struct trigger *trigger, void *event); typedef void (*trigger_f0)(struct trigger *trigger); struct trigger diff --git a/src/lua/trigger.c b/src/lua/trigger.c index 4803e85c5..83718ddc3 100644 --- a/src/lua/trigger.c +++ b/src/lua/trigger.c @@ -62,7 +62,7 @@ lbox_trigger_destroy(struct trigger *ptr) free(ptr); } -static void +static int lbox_trigger_run(struct trigger *ptr, void *event) { struct lbox_trigger *trigger = (struct lbox_trigger *) ptr; @@ -97,14 +97,14 @@ lbox_trigger_run(struct trigger *ptr, void *event) } if (luaT_call(L, nargs, LUA_MULTRET)) { luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref); - diag_raise(); + return -1; } int nret = lua_gettop(L) - top; if (trigger->pop_event != NULL && trigger->pop_event(L, nret, event) != 0) { lua_settop(L, top); luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref); - diag_raise(); + return -1; } /* * Clear the stack after pop_event saves all @@ -112,6 +112,7 @@ lbox_trigger_run(struct trigger *ptr, void *event) */ lua_settop(L, top); luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref); + return 0; } static struct lbox_trigger * diff --git a/src/main.cc b/src/main.cc index 5776aa41d..d40e4740a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -671,10 +671,11 @@ print_help(const char *program) puts("to see online documentation, submit bugs or contribute a patch."); } -static void +static int break_loop(struct trigger *, void *) { ev_break(loop(), EVBREAK_ALL); + return 0; } int diff --git a/test/unit/cbus.c b/test/unit/cbus.c index be930ab8f..ecf5fce72 100644 --- a/test/unit/cbus.c +++ b/test/unit/cbus.c @@ -43,13 +43,14 @@ do_nothing(struct cmsg *m) } /** Callback called on each flush to the main thread. */ -static void +static int flush_cb(struct trigger *t, void *e) { (void) t; (void) e; ++flushed_cnt; printf("flush event, counter = %d\n", flushed_cnt); + return 0; } /** Callback to finish the test. It breaks the main event loop. */ diff --git a/test/unit/swim.c b/test/unit/swim.c index 1371e7d26..bb12baf8d 100644 --- a/test/unit/swim.c +++ b/test/unit/swim.c @@ -827,7 +827,7 @@ struct trigger_ctx { struct swim_on_member_event_ctx ctx; }; -static void +static int swim_on_member_event_save(struct trigger *t, void *event) { struct trigger_ctx *c = (struct trigger_ctx *) t->data; @@ -836,9 +836,10 @@ swim_on_member_event_save(struct trigger *t, void *event) swim_member_unref(c->ctx.member); c->ctx = *((struct swim_on_member_event_ctx *) event); swim_member_ref(c->ctx.member); + return 0; } -static void +static int swim_on_member_event_yield(struct trigger *t, void *event) { struct trigger_ctx *c = (struct trigger_ctx *) t->data; @@ -846,6 +847,7 @@ swim_on_member_event_yield(struct trigger *t, void *event) c->f = fiber(); while (c->need_sleep) fiber_yield(); + return 0; } static void diff --git a/test/unit/swim_test_utils.c b/test/unit/swim_test_utils.c index 7da82d93c..9dbd28a9f 100644 --- a/test/unit/swim_test_utils.c +++ b/test/unit/swim_test_utils.c @@ -176,7 +176,7 @@ swim_cluster_id_to_uri(char *buffer, int id) * A trigger to check correctness of event context, and ability * to yield. */ -void +int swim_test_event_cb(struct trigger *trigger, void *event) { (void) trigger; @@ -186,6 +186,7 @@ swim_test_event_cb(struct trigger *trigger, void *event) assert((ctx->events & SWIM_EV_NEW) == 0 || (ctx->events & SWIM_EV_DROP) == 0); fiber_sleep(0); + return 0; } /** Create a SWIM cluster node @a n with a 0-based @a id. */ -- 2.17.1