[tarantool-patches] [PATCH 1/2] Update lua space cache just after creation

Vladimir Davydov vdavydov.dev at gmail.com
Thu Aug 30 15:06:57 MSK 2018


On Tue, Aug 28, 2018 at 07:19:12PM +0300, Georgy Kirichenko wrote:
> The lua space cache (box.space.*) should be valid just after space is
> created because space is ready to accept new records or does not exists
> before wal would be written. So invoke a space create/drop trigger after
> a space is changed and recall it in a case of rollback.
> 
> Relates: 3159

Nit: should be

Needed for #3159

> diff --git a/src/box/alter.cc b/src/box/alter.cc
> index a6299a12e..b2758a4d9 100644
> --- a/src/box/alter.cc
> +++ b/src/box/alter.cc
> @@ -1626,12 +1616,10 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event)
>  		 * so it's safe to simply drop the space on
>  		 * rollback.
>  		 */
> -		struct trigger *on_commit =
> -			txn_alter_trigger_new(on_create_space_commit, space);
> -		txn_on_commit(txn, on_commit);
>  		struct trigger *on_rollback =
>  			txn_alter_trigger_new(on_create_space_rollback, space);
>  		txn_on_rollback(txn, on_rollback);
> +		trigger_run_xc(&on_alter_space, space);
>  	} else if (new_tuple == NULL) { /* DELETE */
>  		access_check_ddl(old_space->def->name, old_space->def->id,
>  				 old_space->def->uid, SC_SPACE, PRIV_D, true);
> @@ -1674,6 +1662,7 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event)
>  		struct trigger *on_rollback =
>  			txn_alter_trigger_new(on_drop_space_rollback, space);
>  		txn_on_rollback(txn, on_rollback);
> +		trigger_run_xc(&on_alter_space, old_space);
>  	} else { /* UPDATE, REPLACE */
>  		assert(old_space != NULL && new_tuple != NULL);
>  		struct space_def *def =
> @@ -1730,6 +1719,7 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event)
>  		(void) new UpdateSchemaVersion(alter);
>  		alter_space_do(txn, alter);
>  		alter_guard.is_active = false;
> +		trigger_run_xc(&on_alter_space, alter->new_space);
>  	}
>  }
>  
> @@ -1931,6 +1921,7 @@ on_replace_dd_index(struct trigger * /* trigger */, void *event)
>  	(void) new UpdateSchemaVersion(alter);
>  	alter_space_do(txn, alter);
>  	scoped_guard.is_active = false;
> +	trigger_run_xc(&on_alter_space, alter->new_space);
>  }

Why not call this trigger from alter_space_do?

> diff --git a/test/box/errinj.test.lua b/test/box/errinj.test.lua
> index a3ea659aa..32569f605 100644
> --- a/test/box/errinj.test.lua
> +++ b/test/box/errinj.test.lua
> @@ -557,3 +557,30 @@ fio = require('fio')
>  #fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*.index.inprogress')) == 0
>  
>  box.space.test:drop()
> +
> +
> +-- allocate a space id to prevent max space id update

Why?

> +trig = box.schema.space.create('trig')
> +trig_id = trig.id
> +trig:drop()
> +trig = nil
> +fiber = require('fiber')
> +ch = fiber.channel(1)
> +errinj = box.error.injection
> +test_run:cmd("setopt delimiter ';'")
> +-- check space exists just after creation
> +errinj.set("ERRINJ_WAL_WRITE", true);
> +_ = fiber.create(function ()
> +        fiber.create(function ()
> +            pcall(box.schema.space.create, 'trig', {id = trig_id})
> +            ch:put(true)
> +        end)
> +        trig = box.space.trig
> +    end);
> +trig ~= nil;
> +ch:get();
> +--and not exists after rollback
> +box.space.trig;
> +test_run:cmd("setopt delimiter ''");
> +
> +errinj.set("ERRINJ_WAL_WRITE", false)



More information about the Tarantool-patches mailing list