Skip to content
Snippets Groups Projects
Commit 9d4ac029 authored by Nikita Pettik's avatar Nikita Pettik
Browse files

errinj: introduce delayed injection


With new macro ERROR_INJECT_COUNTDOWN it is possible to delay error
injection by iparam value: injection will be set only after iparam
times the path is executed. For instance:

void
foo(int i)
{
	/* 2 is delay counter. */
	ERROR_INJECT_COUNTDOWN(ERRINJ_FOO, {
		 printf("Error injection on %d cycle!\n", i);
		});
}

void
boo(void)
{
	for (int i = 0; i < 10; ++i)
		foo(i);
}

box.error.injection.set('ERRINJ_FOO', 2)

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.

Reviewed-by: default avatarVladislav Shpilevoy <vshpilevoi@mail.ru>
parent cb062017
No related branches found
No related tags found
No related merge requests found
......@@ -166,6 +166,7 @@ errinj_foreach(errinj_cb cb, void *cb_ctx);
# define ERROR_INJECT(ID, CODE)
# define ERROR_INJECT_WHILE(ID, CODE)
# define errinj(ID, TYPE) ((struct errinj *) NULL)
# define ERROR_INJECT_COUNTDOWN(ID, CODE)
#else
# /* Returns the error injection by id */
# define errinj(ID, TYPE) \
......@@ -184,6 +185,12 @@ errinj_foreach(errinj_cb cb, void *cb_ctx);
while (errinj(ID, ERRINJ_BOOL)->bparam) \
CODE; \
} while (0)
# define ERROR_INJECT_COUNTDOWN(ID, CODE) \
do { \
if (errinj(ID, ERRINJ_INT)->iparam-- == 0) { \
CODE; \
} \
} while (0)
#endif
#define ERROR_INJECT_RETURN(ID) ERROR_INJECT(ID, return -1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment