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

* 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?

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:15 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 [this message]
2020-04-30 20:55     ` Nikita Pettik
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=20200430201519.GG6499@atlas \
    --to=kostja.osipov@gmail.com \
    --cc=korablev@tarantool.org \
    --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