Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 06/10] box: introduce stacked diagnostic area
Date: Tue, 31 Mar 2020 17:44:07 +0000	[thread overview]
Message-ID: <20200331174407.GA22927@tarantool.org> (raw)
In-Reply-To: <8620360c-c99d-f9ea-e7f4-25c97c00c0f1@tarantool.org>

On 28 Mar 19:59, Vladislav Shpilevoy wrote:
> Two more comments.
> 
> > diff --git a/test/box/error.test.lua b/test/box/error.test.lua
> > index a0b7d3e78..1fdd6ed98 100644
> > --- a/test/box/error.test.lua
> > +++ b/test/box/error.test.lua
> > @@ -108,4 +108,109 @@ box.error.new(err)
> > +
> >  space:drop()
> 
> 1. You probably need to keep this 'space:drop()' after
> the test related to it.

Isn't it too late?:) I mean test it is related to is finished at
line 20, meanwhile space:drop() is already at line 111 (box/error.test.lua
is already pushed).

> 2. Also I did some double checking if there are no leaks. And came
> up with that test:
> ====================
> diff --git a/extra/exports b/extra/exports
> index 9323996c1..f581026fb 100644
> --- a/extra/exports
> +++ b/extra/exports
> @@ -43,6 +43,7 @@ tnt_iconv_close
>  tnt_iconv
>  exception_get_string
>  exception_get_int
> +get_error_count
>  
>  tarantool_lua_ibuf
>  uuid_nil
> diff --git a/src/lib/core/diag.c b/src/lib/core/diag.c
> index 57da5da44..f5d3c8a18 100644
> --- a/src/lib/core/diag.c
> +++ b/src/lib/core/diag.c
> @@ -31,6 +31,14 @@
>  #include "diag.h"
>  #include "fiber.h"
>  
> +int diag_error_count = 0;
> +
> +int
> +get_error_count(void)
> +{
> +	return __atomic_load_n(&diag_error_count, __ATOMIC_SEQ_CST);
> +}
> +
>  /* Must be set by the library user */
>  struct error_factory *error_factory = NULL;
>  
> @@ -76,6 +84,7 @@ error_create(struct error *e,
>  	     error_f destroy, error_f raise, error_f log,
>  	     const struct type_info *type, const char *file, unsigned line)
>  {
> +	__atomic_add_fetch(&diag_error_count, 1, __ATOMIC_SEQ_CST);
>  	e->destroy = destroy;
>  	e->raise = raise;
>  	e->log = log;
> @@ -92,6 +101,7 @@ error_create(struct error *e,
>  	e->errmsg[0] = '\0';
>  	e->cause = NULL;
>  	e->effect = NULL;
> +
>  }
>  
>  struct diag *
> diff --git a/src/lib/core/diag.h b/src/lib/core/diag.h
> index 665f492fa..bd4ddcf3e 100644
> --- a/src/lib/core/diag.h
> +++ b/src/lib/core/diag.h
> @@ -47,11 +47,16 @@ enum {
>  	DIAG_FILENAME_MAX = 256
>  };
>  
> +extern int diag_error_count;
> +
>  struct type_info;
>  struct error;
>  
>  typedef void (*error_f)(struct error *e);
>  
> +int
> +get_error_count(void);
> +
>  /**
>   * Error diagnostics needs to be equally usable in C and C++
>   * code. This is why there is a common infrastructure for errors.
> @@ -136,6 +141,7 @@ error_unref(struct error *e)
>  		if (cause == NULL)
>  			return;
>  		to_delete = cause;
> +		__atomic_add_fetch(&diag_error_count, -1, __ATOMIC_SEQ_CST);
>  	}
>  }
>  
> diff --git a/test/box/error.test.lua b/test/box/error.test.lua
> index 1fdd6ed98..8f884c372 100644
> --- a/test/box/error.test.lua
> +++ b/test/box/error.test.lua
> @@ -78,6 +78,25 @@ t;
>  
>  test_run:cmd("setopt delimiter ''");
>  
> +ffi = require('ffi')
> +
> +ffi.cdef[[						\
> +	int 						\
> +	get_error_count(void); 				\
> +]]
> +
> +e1 = nil
> +e2 = nil
> +e3 = nil
> +e4 = nil
> +e5 = nil
> +err = nil
> +box.error.clear()
> +collectgarbage('collect')
> +collectgarbage('collect')
> +
> +errcount = ffi.C.get_error_count()
> +
>  -- gh-4778: don't add created via box.error.new() errors to
>  -- Tarantool's diagnostic area.
>  --
> @@ -213,4 +232,20 @@ box.error.set(e1)
>  box.error.clear()
>  assert(e1.prev == e2)
>  
> +e1 = nil
> +e2 = nil
> +e3 = nil
> +e4 = nil
> +e5 = nil
> +err = nil
> +box.error.clear()
> +
> +collectgarbage('collect')
> +collectgarbage('collect')
> +
> +errcount2 = ffi.C.get_error_count()
> +
> +errcount
> +errcount2
> +
>  space:drop()
> ====================
> 
> errcount is 13, errcount2 is 17. Something is probably wrong.
> I thought these were errors created before line

Apllied your diff with one change and every launch I get:

[001] +errcount
[001] + | ---
[001] + | - 1
[001] + | ...
[001] +errcount2
[001] + | ---
[001] + | - 1
[001] + | ...
[001] +

One error I guess is that which gets stuck in diag. The change is:

@@ -124,6 +129,7 @@ error_unref(struct error *e)
                to_delete->cause = NULL;
                to_delete->effect = NULL;
                to_delete->destroy(to_delete);
+               __atomic_add_fetch(&diag_error_count, -1, __ATOMIC_SEQ_CST);
                if (cause == NULL)
                        return;
                to_delete = cause;
 
I.e. we should accout destroy before checking cause since for
the last error in the list it is NULL, ergo it won't be accounted.

Nit: could you please send diff as a separate mail attachment next time?
The thing is I have to manually extract it to a separate file
instead of being capable of applying it as a patch via git am/apply.
Thanks.

>     gh-4778: don't add created via box.error.new() errors to
> 
> But the difference still should be 0. Because I nullified and
> cleared all variables you use before and after the test. I tried
> commenting out all the code before this line, and still get a
> not 0 difference. I ask you to check why some errors are not
> deleted.

  reply	other threads:[~2020-03-31 17:44 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25  1:42 [Tarantool-patches] [PATCH v2 00/10] Stacked diagnostics Nikita Pettik
2020-03-25  1:42 ` [Tarantool-patches] [PATCH v2 01/10] box: rfc for stacked diagnostic area Nikita Pettik
2020-03-25  8:27   ` Konstantin Osipov
2020-03-25 14:08     ` Nikita Pettik
2020-03-25  1:42 ` [Tarantool-patches] [PATCH v2 02/10] box: rename diag_add_error to diag_set_error Nikita Pettik
2020-03-25  8:27   ` Konstantin Osipov
2020-03-26  0:22   ` Vladislav Shpilevoy
2020-03-26 12:31     ` Nikita Pettik
2020-03-25  1:42 ` [Tarantool-patches] [PATCH v2 03/10] test: move box.error tests to box/error.test.lua Nikita Pettik
2020-03-25  8:28   ` Konstantin Osipov
2020-03-26  0:22   ` Vladislav Shpilevoy
2020-03-26 12:31     ` Nikita Pettik
2020-03-25  1:43 ` [Tarantool-patches] [PATCH v2 04/10] box/error: introduce box.error.set() method Nikita Pettik
2020-03-25  8:33   ` Konstantin Osipov
2020-03-25 17:41     ` Nikita Pettik
2020-03-26  0:22   ` Vladislav Shpilevoy
2020-03-26 12:31     ` Nikita Pettik
2020-03-25  1:43 ` [Tarantool-patches] [PATCH v2 05/10] box/error: don't set error created via box.error.new to diag Nikita Pettik
2020-03-26 16:50   ` Konstantin Osipov
2020-03-26 17:59     ` Nikita Pettik
2020-03-26 18:06       ` Nikita Pettik
2020-03-26 18:07       ` Alexander Turenko
2020-03-27  0:19   ` Vladislav Shpilevoy
2020-03-27 13:09     ` Nikita Pettik
2020-03-25  1:43 ` [Tarantool-patches] [PATCH v2 06/10] box: introduce stacked diagnostic area Nikita Pettik
2020-03-26 16:54   ` Konstantin Osipov
2020-03-26 18:03     ` Nikita Pettik
2020-03-26 18:08       ` Konstantin Osipov
2020-03-28 18:40   ` Vladislav Shpilevoy
2020-04-01 16:09     ` Nikita Pettik
2020-04-02  0:29       ` Vladislav Shpilevoy
2020-04-02 17:42         ` Nikita Pettik
2020-04-02 22:20           ` Vladislav Shpilevoy
2020-04-03  1:54             ` Nikita Pettik
2020-04-03 23:17               ` Vladislav Shpilevoy
2020-03-28 18:59   ` Vladislav Shpilevoy
2020-03-31 17:44     ` Nikita Pettik [this message]
2020-04-02  0:29       ` Vladislav Shpilevoy
2020-04-02 14:16         ` Nikita Pettik
2020-03-25  1:43 ` [Tarantool-patches] [PATCH v2 07/10] box: use stacked diagnostic area for functional indexes Nikita Pettik
2020-03-30 23:24   ` Vladislav Shpilevoy
2020-04-01 15:53     ` Nikita Pettik
2020-03-25  1:43 ` [Tarantool-patches] [PATCH v2 08/10] box/error: clarify purpose of reference counting in struct error Nikita Pettik
2020-03-30 23:24   ` Vladislav Shpilevoy
2020-03-25  1:43 ` [Tarantool-patches] [PATCH v2 09/10] iproto: refactor error encoding with mpstream Nikita Pettik
2020-03-30 23:24   ` Vladislav Shpilevoy
2020-04-01 15:54     ` Nikita Pettik
2020-03-25  1:43 ` [Tarantool-patches] [PATCH v2 10/10] iproto: support error stacked diagnostic area Nikita Pettik
2020-03-30 23:24   ` Vladislav Shpilevoy
2020-04-01 16:26     ` Nikita Pettik
2020-04-01 22:24       ` Nikita Pettik
2020-04-02  0:29         ` Vladislav Shpilevoy
2020-04-02 14:01           ` Nikita Pettik
2020-04-02 22:20             ` Vladislav Shpilevoy
2020-04-03  2:16               ` Nikita Pettik
2020-04-03 23:17                 ` Vladislav Shpilevoy
2020-04-06 11:07                   ` Nikita Pettik

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=20200331174407.GA22927@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 06/10] box: introduce stacked diagnostic area' \
    /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