[Tarantool-patches] [PATCH 1/2] errinj: introduce delayed injection
Nikita Pettik
korablev at tarantool.org
Thu Apr 30 23:55:30 MSK 2020
On 30 Apr 23:15, Konstantin Osipov wrote:
> * Nikita Pettik <korablev at tarantool.org> [20/04/30 22:51]:
>
> This is not exactly a time delay, this is a skip-first-n kind of
> postponed enable?
Yep, it's more accurate definition. I can rename to
ERROR_INJECT_POSPONED, if it fits better.
> 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
More information about the Tarantool-patches
mailing list