[Tarantool-patches] [PATCH v3] net.box: add predefined system events for pub/sub

Vladimir Davydov vdavydov at tarantool.org
Sat Feb 12 17:48:02 MSK 2022


On Sat, Feb 12, 2022 at 04:18:03AM +0300, Yan Shtunder via Tarantool-patches wrote:
> Adding predefined system events: box.status, box.id, box.election
> and box.schema.
> 
> Closes #6260
> 
> NO_CHANGELOG=test stuff
> NO_DOC=testing stuff

This change definitely needs both a changelog and a doc request.

> ---
> Issue: https://github.com/tarantool/tarantool/issues/6260
> Patch: https://github.com/tarantool/tarantool/tree/yshtunder/gh-6260-events-v3

I recommend to create a pull request from your own GitHub fork instead
of pushing to a dev branch and sending patches to the mailing list,
because dev branches in the main repo are likely to be banned soon and
the mailing list is probably going to be shut down (or left for LuaJIT
patches only).

> diff --git a/src/box/box.cc b/src/box/box.cc
> index 6a33203df..d72bd3dad 100644
> --- a/src/box/box.cc
> +++ b/src/box/box.cc
> @@ -3933,3 +3943,82 @@ box_reset_stat(void)
>  	engine_reset_stat();
>  	space_foreach(box_reset_space_stat, NULL);
>  }
> +
> +void
> +box_broadcast_id(void)
> +{
> +	char buf[1024];
> +	char *w = buf;
> +
> +	struct replica *replica = replica_by_uuid(&INSTANCE_UUID);
> +	uint32_t id = (replica == NULL) ? 0 : replica->id;
> +
> +	w = mp_encode_map(w, 3);
> +	w = mp_encode_str0(w, "id");
> +	w = mp_encode_uint(w, id);
> +	w = mp_encode_str0(w, "instance_uuid");
> +	w = mp_encode_uuid(w, &INSTANCE_UUID);
> +	w = mp_encode_str0(w, "replicaset_uuid");
> +	w = mp_encode_uuid(w, &REPLICASET_UUID);
> +
> +	box_broadcast("box.id", strlen("box.id"), buf, w);

You can use box_broadcast_fmt instead. AFAIU events added in this patch
are not triggered from hot paths so it should be fine performance-wise.

https://github.com/tarantool/tarantool/blob/17f08c821ea44531a2f4882653527b672d8e447f/src/box/watcher.h#L254-L260


More information about the Tarantool-patches mailing list