Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] box: fix assertion with duplication in repl. source
@ 2018-08-28 16:22 Olga Arkhangelskaia
  2018-08-29  9:03 ` Vladimir Davydov
  0 siblings, 1 reply; 4+ messages in thread
From: Olga Arkhangelskaia @ 2018-08-28 16:22 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Olga Arkhangelskaia

When we try to connect one master more than once we used to have
assertion instead of error.

Closes #3610
---
https://github.com/tarantool/tarantool/issues/3610
https://github.com/tarantool/tarantool/tree/OKriw/assert_fail_when_connect_master_twice

 src/box/box.cc            | 14 ++++++++++++++
 test/box-tap/cfg.test.lua |  8 +++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index 8d7454d1f..3a571ae3c 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -369,9 +369,23 @@ static void
 box_check_replication(void)
 {
 	int count = cfg_getarr_size("replication");
+	char *repl[count-1];
 	for (int i = 0; i < count; i++) {
 		const char *source = cfg_getarr_elem("replication", i);
 		box_check_uri(source, "replication");
+		repl[i] = strdup(source);
+		if (repl[i] == NULL) {
+			tnt_raise(OutOfMemory, sizeof(*source), "source", "malloc");
+		}
+		for (int j = i; j >= 1; j--) {
+			if (strcmp(repl[i], repl[j-1]) == 0) {
+				tnt_raise(ClientError, ER_CFG, "replication",
+					  "duplication of replication source");
+			}
+		}
+	}
+	for (int i = 0; i < count; i++) {
+		free(repl[i]);
 	}
 }
 
diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
index 5e72004ca..b227c5edb 100755
--- a/test/box-tap/cfg.test.lua
+++ b/test/box-tap/cfg.test.lua
@@ -6,7 +6,7 @@ local socket = require('socket')
 local fio = require('fio')
 local uuid = require('uuid')
 local msgpack = require('msgpack')
-test:plan(90)
+test:plan(91)
 
 --------------------------------------------------------------------------------
 -- Invalid values
@@ -446,5 +446,11 @@ code = string.format(code_fmt, dir, instance_uuid, uuid.new())
 test:is(run_script(code), PANIC, "replicaset_uuid mismatch")
 fio.rmdir(dir)
 
+--
+--gh-3610: assertion failure when trying to connect to the same master more than once
+--
+status, reason = pcall(box.cfg, {listen = 3303, replication={3303,3303}})
+test:ok(not status and reason:match("Incorrect"), "Duplication of replication source")
+
 test:check()
 os.exit(0)
-- 
2.14.3 (Apple Git-98)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [tarantool-patches] [PATCH] box: fix assertion with duplication in repl. source
  2018-08-28 16:22 [tarantool-patches] [PATCH] box: fix assertion with duplication in repl. source Olga Arkhangelskaia
@ 2018-08-29  9:03 ` Vladimir Davydov
  2018-08-29  9:36   ` Olga Krishtal
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Davydov @ 2018-08-29  9:03 UTC (permalink / raw)
  To: Olga Arkhangelskaia; +Cc: tarantool-patches

On Tue, Aug 28, 2018 at 07:22:26PM +0300, Olga Arkhangelskaia wrote:
> When we try to connect one master more than once we used to have
> assertion instead of error.
> 
> Closes #3610
> ---
> https://github.com/tarantool/tarantool/issues/3610
> https://github.com/tarantool/tarantool/tree/OKriw/assert_fail_when_connect_master_twice

Broken link.

> 
>  src/box/box.cc            | 14 ++++++++++++++
>  test/box-tap/cfg.test.lua |  8 +++++++-
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/src/box/box.cc b/src/box/box.cc
> index 8d7454d1f..3a571ae3c 100644
> --- a/src/box/box.cc
> +++ b/src/box/box.cc
> @@ -369,9 +369,23 @@ static void
>  box_check_replication(void)
>  {
>  	int count = cfg_getarr_size("replication");
> +	char *repl[count-1];
>  	for (int i = 0; i < count; i++) {
>  		const char *source = cfg_getarr_elem("replication", i);
>  		box_check_uri(source, "replication");
> +		repl[i] = strdup(source);
> +		if (repl[i] == NULL) {
> +			tnt_raise(OutOfMemory, sizeof(*source), "source", "malloc");
> +		}
> +		for (int j = i; j >= 1; j--) {
> +			if (strcmp(repl[i], repl[j-1]) == 0) {
> +				tnt_raise(ClientError, ER_CFG, "replication",
> +					  "duplication of replication source");
> +			}
> +		}
> +	}
> +	for (int i = 0; i < count; i++) {
> +		free(repl[i]);

This is totally wrong, because different URLs can point to the same
instance, e.g.

Instance 1: box.cfg{listen = 12345}

Instance 2: box.cfg{replication = {12345, 'localhost:12345'}}

Crash.

All you're supposed to do is fix the checks in replication.cc

>  	}
>  }
>  
> diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
> index 5e72004ca..b227c5edb 100755
> --- a/test/box-tap/cfg.test.lua
> +++ b/test/box-tap/cfg.test.lua
> @@ -6,7 +6,7 @@ local socket = require('socket')
>  local fio = require('fio')
>  local uuid = require('uuid')
>  local msgpack = require('msgpack')
> -test:plan(90)
> +test:plan(91)
>  
>  --------------------------------------------------------------------------------
>  -- Invalid values
> @@ -446,5 +446,11 @@ code = string.format(code_fmt, dir, instance_uuid, uuid.new())
>  test:is(run_script(code), PANIC, "replicaset_uuid mismatch")
>  fio.rmdir(dir)
>  
> +--
> +--gh-3610: assertion failure when trying to connect to the same master more than once
> +--
> +status, reason = pcall(box.cfg, {listen = 3303, replication={3303,3303}})
> +test:ok(not status and reason:match("Incorrect"), "Duplication of replication source")
> +

The test passes with and without your patch, i.e. useless.

Besides, it doesn't test all cases described in the issue.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [tarantool-patches] [PATCH] box: fix assertion with duplication in repl. source
  2018-08-29  9:03 ` Vladimir Davydov
@ 2018-08-29  9:36   ` Olga Krishtal
  2018-08-29 10:00     ` Vladimir Davydov
  0 siblings, 1 reply; 4+ messages in thread
From: Olga Krishtal @ 2018-08-29  9:36 UTC (permalink / raw)
  To: Vladimir Davydov; +Cc: tarantool-patches

[-- Attachment #1: Type: text/plain, Size: 3314 bytes --]

Thanks!

ср, 29 авг. 2018 г. в 12:03, Vladimir Davydov <vdavydov.dev@gmail.com>:

> On Tue, Aug 28, 2018 at 07:22:26PM +0300, Olga Arkhangelskaia wrote:
> > When we try to connect one master more than once we used to have
> > assertion instead of error.
> >
> > Closes #3610
> > ---
> > https://github.com/tarantool/tarantool/issues/3610
> >
> https://github.com/tarantool/tarantool/tree/OKriw/assert_fail_when_connect_master_twice
>
> Broken link.
>
> >
> >  src/box/box.cc            | 14 ++++++++++++++
> >  test/box-tap/cfg.test.lua |  8 +++++++-
> >  2 files changed, 21 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/box/box.cc b/src/box/box.cc
> > index 8d7454d1f..3a571ae3c 100644
> > --- a/src/box/box.cc
> > +++ b/src/box/box.cc
> > @@ -369,9 +369,23 @@ static void
> >  box_check_replication(void)
> >  {
> >       int count = cfg_getarr_size("replication");
> > +     char *repl[count-1];
> >       for (int i = 0; i < count; i++) {
> >               const char *source = cfg_getarr_elem("replication", i);
> >               box_check_uri(source, "replication");
> > +             repl[i] = strdup(source);
> > +             if (repl[i] == NULL) {
> > +                     tnt_raise(OutOfMemory, sizeof(*source), "source",
> "malloc");
> > +             }
> > +             for (int j = i; j >= 1; j--) {
> > +                     if (strcmp(repl[i], repl[j-1]) == 0) {
> > +                             tnt_raise(ClientError, ER_CFG,
> "replication",
> > +                                       "duplication of replication
> source");
> > +                     }
> > +             }
> > +     }
> > +     for (int i = 0; i < count; i++) {
> > +             free(repl[i]);
>
> This is totally wrong, because different URLs can point to the same
> instance, e.g.
>
> Instance 1: box.cfg{listen = 12345}
>
> Instance 2: box.cfg{replication = {12345, 'localhost:12345'}}
>
> Crash.
>
> All you're supposed to do is fix the checks in replication.cc
>


I am a bit lost. We have to raise an exception when have duplication uri,
or or just skip duplication?



>
> >       }
> >  }
> >
> > diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
> > index 5e72004ca..b227c5edb 100755
> > --- a/test/box-tap/cfg.test.lua
> > +++ b/test/box-tap/cfg.test.lua
> > @@ -6,7 +6,7 @@ local socket = require('socket')
> >  local fio = require('fio')
> >  local uuid = require('uuid')
> >  local msgpack = require('msgpack')
> > -test:plan(90)
> > +test:plan(91)
> >
> >
> --------------------------------------------------------------------------------
> >  -- Invalid values
> > @@ -446,5 +446,11 @@ code = string.format(code_fmt, dir, instance_uuid,
> uuid.new())
> >  test:is(run_script(code), PANIC, "replicaset_uuid mismatch")
> >  fio.rmdir(dir)
> >
> > +--
> > +--gh-3610: assertion failure when trying to connect to the same master
> more than once
> > +--
> > +status, reason = pcall(box.cfg, {listen = 3303,
> replication={3303,3303}})
> > +test:ok(not status and reason:match("Incorrect"), "Duplication of
> replication source")
> > +
>
> The test passes with and without your patch, i.e. useless.
>
> Besides, it doesn't test all cases described in the issue.
>

will fix

[-- Attachment #2: Type: text/html, Size: 4653 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [tarantool-patches] [PATCH] box: fix assertion with duplication in repl. source
  2018-08-29  9:36   ` Olga Krishtal
@ 2018-08-29 10:00     ` Vladimir Davydov
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir Davydov @ 2018-08-29 10:00 UTC (permalink / raw)
  To: Olga Krishtal; +Cc: tarantool-patches

On Wed, Aug 29, 2018 at 12:36:33PM +0300, Olga Krishtal wrote:
> > > diff --git a/src/box/box.cc b/src/box/box.cc
> > > index 8d7454d1f..3a571ae3c 100644
> > > --- a/src/box/box.cc
> > > +++ b/src/box/box.cc
> > > @@ -369,9 +369,23 @@ static void
> > >  box_check_replication(void)
> > >  {
> > >       int count = cfg_getarr_size("replication");
> > > +     char *repl[count-1];
> > >       for (int i = 0; i < count; i++) {
> > >               const char *source = cfg_getarr_elem("replication", i);
> > >               box_check_uri(source, "replication");
> > > +             repl[i] = strdup(source);
> > > +             if (repl[i] == NULL) {
> > > +                     tnt_raise(OutOfMemory, sizeof(*source), "source",
> > "malloc");
> > > +             }
> > > +             for (int j = i; j >= 1; j--) {
> > > +                     if (strcmp(repl[i], repl[j-1]) == 0) {
> > > +                             tnt_raise(ClientError, ER_CFG,
> > "replication",
> > > +                                       "duplication of replication
> > source");
> > > +                     }
> > > +             }
> > > +     }
> > > +     for (int i = 0; i < count; i++) {
> > > +             free(repl[i]);
> >
> > This is totally wrong, because different URLs can point to the same
> > instance, e.g.
> >
> > Instance 1: box.cfg{listen = 12345}
> >
> > Instance 2: box.cfg{replication = {12345, 'localhost:12345'}}
> >
> > Crash.
> >
> > All you're supposed to do is fix the checks in replication.cc
> >
> 
> 
> I am a bit lost. We have to raise an exception when have duplication uri,
> or or just skip duplication?

Before replication_connect_quorum was introduced, we checked for
duplicate connections when configuring replication and raised exception
on error (see replicaset_update).

Now, due to replication_connect_quorum, we may be unable to detect
duplicate connections, because we can fail to connect to some masters
within replication_connect_timeout, before box.cfg{} returns. So we
allow the configuration anyway and print a warning if later on, when a
master is connected, we find it to be a duplicate.

I guess we should preserve this behavior and just fix the crash.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-29 10:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28 16:22 [tarantool-patches] [PATCH] box: fix assertion with duplication in repl. source Olga Arkhangelskaia
2018-08-29  9:03 ` Vladimir Davydov
2018-08-29  9:36   ` Olga Krishtal
2018-08-29 10:00     ` Vladimir Davydov

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