From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 90EC96ECC0; Sat, 18 Dec 2021 02:31:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 90EC96ECC0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1639783890; bh=UB17iBIge6DeT1O65IKHSFG1E8RRth7814mAlq8ExE0=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZcX8onzhrvFfFRrhduoeGrg1wWggdmP4K6cR6kACEitAKbVgA0tvlpmMJFweo8//i +TY8a/SKt45Pz44gCxFdiKFVkYSrSy4roVsV667vo87ERgTnpHHtLPuz0aTnP15Qey 9tQuKRDaa6oa9wAwkegJY6nhDYkAx/3/Cpo84EK8= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id AAAEB6ECC0 for ; Sat, 18 Dec 2021 02:31:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AAAEB6ECC0 Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1myMhC-0000qj-W0; Sat, 18 Dec 2021 02:31:27 +0300 Message-ID: Date: Sat, 18 Dec 2021 00:31:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Content-Language: en-US To: Yan Shtunder Cc: tarantool-patches@dev.tarantool.org References: <20211216112257.81742-1-ya.shtunder@gmail.com> In-Reply-To: <20211216112257.81742-1-ya.shtunder@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9B5397E24C93BDA67CDE94F05641003F35C2F85B8FC8660E1182A05F53808504047B05CF6432AD75930C8D7113CA3DA41ED80EEE6C6F4CE29ED42A9CDD09776A3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79B4AFF82F0254274EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375E280A1EC162AD7D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A6A0DEB08F0EBBEBFD5C941480213530117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C64E7220B7C550592BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6D4DCF96145C64DAE76E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CE31A2885C41F97C443847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A54941830090CB56E0E8F06716B22CAFD5A6146590278A61F9D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759D2A03B9C34326B3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344A431191C56981FEF3FE3E8811425431E98E771604E9A3F737E352155900B924DB43B410AC1DC9811D7E09C32AA3244C10B3A3038466B367140E84632D53211AB038C9161EF167A1729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojieEIankJUzrYOaXisilQEQ== X-Mailru-Sender: 1F3202E75A95DDEFA8FDA09795F48B2412DA64F816655F24A11CAC713AA85F5FFCB7861228910ADA07784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6B0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH] net.box: add predefined system events for pub/sub X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! On 16.12.2021 12:22, Yan Shtunder wrote: > Adding predefined system event box.status Please, add ticket reference here as Part of #6260 On a new line. With an empty line before it. Like this: Your message. Line, More lines. Part of #6260 See 11 comments below. > diff --git a/src/box/box.cc b/src/box/box.cc > index 0413cbf44..8529e6925 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -160,6 +160,9 @@ static struct fiber_pool tx_fiber_pool; > */ > static struct cbus_endpoint tx_prio_endpoint; > > +void > +box_status_broadcast(void); 1. The function is never used outside of box.cc. You can make it 'static'. Also lets better call it box_broadcast_status(). It would look better if all built-in events would start with the same box_broadcast_*. > @@ -377,9 +382,11 @@ box_set_orphan(bool orphan) > if (is_orphan) { > say_crit("entering orphan mode"); > title("orphan"); > + box_status_broadcast(); 2. You can call this inside of title() function instead of duplicating its broadcast for each title() invocation. > } else { > say_crit("leaving orphan mode"); > title("running"); > + box_status_broadcast(); > } > } > @@ -3800,6 +3810,8 @@ box_cfg_xc(void) > assert(box_is_ro()); > /* If anyone is waiting for ro mode. */ > fiber_cond_broadcast(&ro_cond); > + /* Checking box.cfg.read_only change */ > + box_status_broadcast(); 3. The place didn't change is_ro_summary, so a broadcast here is not needed. > /* > * Yield to let ro condition waiters to handle the event. > * Without yield it may happen there won't be a context > @@ -3903,3 +3915,32 @@ box_reset_stat(void) > engine_reset_stat(); > space_foreach(box_reset_space_stat, NULL); > } > + > +void > +box_status_broadcast(void) > +{ > + size_t size = 0; > + > + size += mp_sizeof_map(3); > + size += mp_sizeof_str(strlen("is_ro")); > + size += mp_sizeof_bool(box_is_ro()); > + size += mp_sizeof_str(strlen("is_ro_cfg")); > + size += mp_sizeof_bool(cfg_geti("read_only")); > + size += mp_sizeof_str(strlen("status")); > + size += mp_sizeof_str(strlen(box_status())); > + > + char buf[size]; 4. Usage of non-constant values as a buffer size is not used in Tarantool code. Lets better avoid it. You can just use a big enough buffer like char buf[1024]; and add an assertion in the end of encodes below that you didn't go beyond the border. > + char *w = buf; > + > + w = mp_encode_map(w, 3); > + w = mp_encode_str(w, "is_ro", strlen("is_ro")); > + w = mp_encode_bool(w, box_is_ro()); > + w = mp_encode_str(w, "is_ro_cfg", strlen("is_ro_cfg")); > + w = mp_encode_bool(w, cfg_geti("read_only")); > + w = mp_encode_str(w, "status", strlen("status")); > + w = mp_encode_str(w, box_status(), strlen(box_status())); 5. It looks like a quite repetitive thing. mp_error.cc had the same problem and introduced mp_encode_str0(). I suggest you to make a preparatory commit which would move mp_encode_str0() from mp_error.cc into a common place from where you could reuse it. One option would be to make a patch for https://github.com/tarantool/msgpuck to add this new function. Or we could add it to trivia/util.h and src/util.c. The first option is better IMO. > + > + box_broadcast("box.status", strlen("box.status"), buf, w); > + > + assert(size == (size_t)(w - buf)); > +} > diff --git a/test/app-luatest/gh_6260_add_predefined_events_test.lua b/test/app-luatest/gh_6260_add_predefined_events_test.lua > new file mode 100644 > index 000000000..e6ff0e94e > --- /dev/null > +++ b/test/app-luatest/gh_6260_add_predefined_events_test.lua 6. You don't need to use imperative in file names. They are not commit titles. A simple gh_6260_builtin_events would be enough. > @@ -0,0 +1,61 @@ > +local t = require('luatest') > +local cluster = require('test.luatest_helpers.cluster') > +local helpers = require('test.luatest_helpers') > + > +local g = t.group('gh_6260', {{engine = 'memtx'}, {engine = 'vinyl'}}) 7. Why do you need different engines? The feature does not seem to be engine-dependent. You don't even use spaces in the test. > + > +g.before_each(function(cg) > + local engine = cg.params.engine > + > + cg.cluster = cluster:new({}) > + > + local box_cfg = { > + replication = { > + helpers.instance_uri('master') > + }, > + replication_timeout = 1, > + read_only = false > + } 8. Why do you need replication and replication_timeout from the beginning? It seems for your case it would be enough to start an instance without any particular options. > +g.test_box_status_event = function(cg) > + cg.master:eval([[ > + i = '' > + box.watch('box.status', function(...) i = {...} end) > + ]]) 9. Please, use :exec() function. It looks much better than :eval(). > + t.assert_equals(cg.master:eval("return i"), {"box.status", {is_ro = false, is_ro_cfg = false, status = "running"}}) 10. Try to keep line widths <= 80 symbols. > + > + cg.master:eval(([[ > + box.cfg{ > + replication = { > + "%s", > + "%s" > + }, > + replication_connect_timeout = 0.001, > + } > + ]]):format(helpers.instance_uri('master'), helpers.instance_uri('replica'))) > + t.assert_equals(cg.master:eval("return i"), {"box.status", {is_ro = true, is_ro_cfg = false, status = "orphan"}}) > + > + cg.master:eval(([[ > + box.cfg{ > + replication = { > + "%s", > + }, > + } > + ]]):format(helpers.instance_uri('master'))) > + t.assert_equals(cg.master:eval("return i"), {"box.status", {is_ro = false, is_ro_cfg = false, status = "running"}}) > + > + cg.master:eval("box.cfg{read_only = true}") > + t.assert_equals(cg.master:eval("return i"), {"box.status", {is_ro = true, is_ro_cfg = true, status = "running"}}) > +end 11. Please, at lest one test case for netbox. That a remote subscription also works.