From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4C9564696C3 for ; Thu, 30 Apr 2020 23:15:22 +0300 (MSK) Received: by mail-lj1-f195.google.com with SMTP id f18so656671lja.13 for ; Thu, 30 Apr 2020 13:15:22 -0700 (PDT) Date: Thu, 30 Apr 2020 23:15:19 +0300 From: Konstantin Osipov Message-ID: <20200430201519.GG6499@atlas> References: <1fb821b72a258f638109ea5e2e9a6bfd6106b9da.1588273848.git.korablev@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1fb821b72a258f638109ea5e2e9a6bfd6106b9da.1588273848.git.korablev@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH 1/2] errinj: introduce delayed injection List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nikita Pettik Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org * Nikita Pettik [20/04/30 22:51]: This is not exactly a time delay, this is a skip-first-n kind of postponed enable? Having a time delay is not such a bad idea (as well as a probabilistic failure). > With new macro ERROR_INJECT_DELAYED it is possible to delay error > injection by DELAY parameter: injection will be set only after DELAY > times the path is executed. For instance: > > void > foo(int i) > { > /* 2 is delay counter. */ > ERROR_INJECT_DELAYED(ERRINJ_FOO, 2, { > printf("Error injection on %d cycle!\n", i); > }); > } > > void > boo(void) > { > for (int i = 0; i < 10; ++i) > foo(i); > } > > The result is "Error injection on 2 cycle!". This type of error > injection can turn out to be useful to set injection in the middle of > query processing. Imagine following scenario: > > void > foo(void) > { > int *fds[10]; > for (int i = 0; i < 10; ++i) { > fds[i] = malloc(sizeof(int)); > if (fds[i] == NULL) > goto cleanup; > } > cleanup: > free(fds[0]); > } > > "cleanup" section obviously contains error and leads to memory leak. > But using means of casual error injection without delay such situation > can't be detected: OOM can be set only for first cycle iteration and in > this particular case no leaks take place. > --- > src/errinj.h | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/src/errinj.h b/src/errinj.h > index 2cb090b68..990f4921d 100644 > --- a/src/errinj.h > +++ b/src/errinj.h > @@ -149,6 +149,7 @@ errinj_foreach(errinj_cb cb, void *cb_ctx); > #ifdef NDEBUG > # define ERROR_INJECT(ID, CODE) > # define errinj(ID, TYPE) ((struct errinj *) NULL) > +# define ERROR_INJECT_DELAYED(ID, DELAY, CODE) > #else > # /* Returns the error injection by id */ > # define errinj(ID, TYPE) \ > @@ -162,6 +163,14 @@ errinj_foreach(errinj_cb cb, void *cb_ctx); > if (errinj(ID, ERRINJ_BOOL)->bparam) \ > CODE; \ > } while (0) > +# define ERROR_INJECT_DELAYED(ID, DELAY, CODE) \ > + do { \ > + static int _DELAY##ID = DELAY; \ > + if (errinj(ID, ERRINJ_BOOL)->bparam) { \ > + if (_DELAY##ID-- == 0) \ > + CODE; \ > + } \ > + } while (0) > #endif > > #define ERROR_INJECT_RETURN(ID) ERROR_INJECT(ID, return -1) > -- > 2.17.1 > -- Konstantin Osipov, Moscow, Russia https://scylladb.com