Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: Konstantin Osipov <kostja.osipov@gmail.com>,
	tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org,
	alyapunov@tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 1/2] errinj: introduce delayed injection
Date: Thu, 30 Apr 2020 20:55:30 +0000	[thread overview]
Message-ID: <20200430205530.GA13902@tarantool.org> (raw)
In-Reply-To: <20200430201519.GG6499@atlas>

On 30 Apr 23:15, Konstantin Osipov wrote:
> * Nikita Pettik <korablev@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

  reply	other threads:[~2020-04-30 20:55 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 19:27 [Tarantool-patches] [PATCH 0/2] Fix crash in case of lack of FDs during recovery Nikita Pettik
2020-04-30 19:27 ` [Tarantool-patches] [PATCH 1/2] errinj: introduce delayed injection Nikita Pettik
2020-04-30 20:15   ` Konstantin Osipov
2020-04-30 20:55     ` Nikita Pettik [this message]
2020-05-01 19:15       ` Konstantin Osipov
2020-05-03 19:20   ` Vladislav Shpilevoy
2020-05-07 13:50     ` Nikita Pettik
2020-05-07 21:47       ` Vladislav Shpilevoy
2020-05-07 22:41         ` Nikita Pettik
2020-04-30 19:27 ` [Tarantool-patches] [PATCH 2/2] vinyl: drop wasted runs in case range recovery fails Nikita Pettik
2020-05-03 19:21   ` Vladislav Shpilevoy
2020-05-07 13:02     ` Nikita Pettik
2020-05-07 14:16       ` Konstantin Osipov
2020-05-07 21:47         ` Vladislav Shpilevoy
2020-05-07 22:37           ` Nikita Pettik
2020-05-07 21:47       ` Vladislav Shpilevoy
2020-05-07 22:36         ` Nikita Pettik
2020-05-10 19:59           ` Vladislav Shpilevoy
2020-05-12  1:16             ` Nikita Pettik
2020-05-03 19:20 ` [Tarantool-patches] [PATCH 0/2] Fix crash in case of lack of FDs during recovery Vladislav Shpilevoy
2020-05-07 14:11   ` Nikita Pettik
2020-05-12 20:53 ` Vladislav Shpilevoy
2020-05-12 20:56   ` Vladislav Shpilevoy
2020-05-12 22:45     ` Nikita Pettik
2020-05-13 20:19       ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200430205530.GA13902@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=alyapunov@tarantool.org \
    --cc=kostja.osipov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/2] errinj: introduce delayed injection' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox