You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ignite.apache.org by Vladimir Ozerov <vo...@gridgain.com> on 2016/02/29 14:32:50 UTC

Re: Semaphore waiting for permit even if node is shut down

Hi,

I tested your code in multi-node scenario, and semaphore is released fine
when node owning a permit has been closed. In your code sample there is
only one node, and in this case semaphore is not released. I think that
"acquire" method should throw an exception in this case (say,
InterruptedException) as semaphore is no longer accessible when node is
stopped.

Vladislav,
I know you worked on distributed semaphore. Could you please share your
thoughts on the matter? And would you mind fixing that for a single-node
scenario?

Vladimir.

On Sun, Feb 28, 2016 at 11:14 PM, nyname00 <ma...@panagenda.com>
wrote:

> Hi Igniters,
>
> I've got a problem with a semaphore that seems to wait for a permit even if
> the node is already shut down. This behavior appears in a multi-node setup
> where i try to shut down all nodes at the same time (using a poison-pill).
> The code below can be used to reproduce the behavior. You will notice that
> there is no call on sem1#release() - this is because in my poison-pill
> scenario there seems to be no way to get a handle to sem1. And since I was
> under the impression that any semaphore gets released by Ignite when the
> node crashes/is shut down, I was expecting an exception on sem2#acquire().
>
> Any ideas? Best regards,
> Mario
>
> public static void main(String[] args) {
>         Ignite i1 = Ignition.start(new
> IgniteConfiguration().setGridName("1"));
>
>         System.out.println(">>> I1 STARTED");
>         IgniteSemaphore sem1 = i1.semaphore("sem1", 1, true, true);
>         System.out.println(">>> S1 READ");
>         sem1.acquire();
>         System.out.println(">>> S1 ACQUIRED");
>
>         new Thread(() -> {
>             IgniteSemaphore sem2 = i1.semaphore("sem1", 1, true, true);
>             System.out.println(">>> S1 READ 2");
>             sem2.acquire();
>             try {
>                 System.out.println(">>> S1 ACQUIRED 2");
>             } finally {
>                 sem2.release();
>             }
>         }).start();
>
>         try {
>             TimeUnit.SECONDS.sleep(2);
>         } catch (InterruptedException e) {
>             e.printStackTrace();
>         }
>
>         System.out.println(">>> I1 CLOSING");
>         i1.close();
>         System.out.println(">>> I1 CLOSED");
>     }
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/Semaphore-waiting-for-permit-even-if-node-is-shut-down-tp3232.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Semaphore waiting for permit even if node is shut down

Posted by Valentin Kulichenko <va...@gmail.com>.
Vladislav,

I provided my thoughts in the ticket. Please take a look.

-Val

On Mon, Feb 29, 2016 at 8:46 AM, Vladisav Jelisavcic <vl...@gmail.com>
wrote:

> Sure, no problem.
>
> I created a ticket:
> https://issues.apache.org/jira/browse/IGNITE-2735
>
> and a PR to resolve this problem.
> I think this should also fix:  IGNITE-1977
> but the non-failover test scenario is not good anymore;
>
> Best regards,
> Vladisav
>
>
>
>
> On Mon, Feb 29, 2016 at 2:32 PM, Vladimir Ozerov <vo...@gridgain.com>
> wrote:
>
> > Hi,
> >
> > I tested your code in multi-node scenario, and semaphore is released fine
> > when node owning a permit has been closed. In your code sample there is
> > only one node, and in this case semaphore is not released. I think that
> > "acquire" method should throw an exception in this case (say,
> > InterruptedException) as semaphore is no longer accessible when node is
> > stopped.
> >
> > Vladislav,
> > I know you worked on distributed semaphore. Could you please share your
> > thoughts on the matter? And would you mind fixing that for a single-node
> > scenario?
> >
> > Vladimir.
> >
> > On Sun, Feb 28, 2016 at 11:14 PM, nyname00 <ma...@panagenda.com>
> > wrote:
> >
> > > Hi Igniters,
> > >
> > > I've got a problem with a semaphore that seems to wait for a permit
> even
> > if
> > > the node is already shut down. This behavior appears in a multi-node
> > setup
> > > where i try to shut down all nodes at the same time (using a
> > poison-pill).
> > > The code below can be used to reproduce the behavior. You will notice
> > that
> > > there is no call on sem1#release() - this is because in my poison-pill
> > > scenario there seems to be no way to get a handle to sem1. And since I
> > was
> > > under the impression that any semaphore gets released by Ignite when
> the
> > > node crashes/is shut down, I was expecting an exception on
> > sem2#acquire().
> > >
> > > Any ideas? Best regards,
> > > Mario
> > >
> > > public static void main(String[] args) {
> > >         Ignite i1 = Ignition.start(new
> > > IgniteConfiguration().setGridName("1"));
> > >
> > >         System.out.println(">>> I1 STARTED");
> > >         IgniteSemaphore sem1 = i1.semaphore("sem1", 1, true, true);
> > >         System.out.println(">>> S1 READ");
> > >         sem1.acquire();
> > >         System.out.println(">>> S1 ACQUIRED");
> > >
> > >         new Thread(() -> {
> > >             IgniteSemaphore sem2 = i1.semaphore("sem1", 1, true, true);
> > >             System.out.println(">>> S1 READ 2");
> > >             sem2.acquire();
> > >             try {
> > >                 System.out.println(">>> S1 ACQUIRED 2");
> > >             } finally {
> > >                 sem2.release();
> > >             }
> > >         }).start();
> > >
> > >         try {
> > >             TimeUnit.SECONDS.sleep(2);
> > >         } catch (InterruptedException e) {
> > >             e.printStackTrace();
> > >         }
> > >
> > >         System.out.println(">>> I1 CLOSING");
> > >         i1.close();
> > >         System.out.println(">>> I1 CLOSED");
> > >     }
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://apache-ignite-users.70518.x6.nabble.com/Semaphore-waiting-for-permit-even-if-node-is-shut-down-tp3232.html
> > > Sent from the Apache Ignite Users mailing list archive at Nabble.com.
> > >
> >
>

Re: Semaphore waiting for permit even if node is shut down

Posted by Vladisav Jelisavcic <vl...@gmail.com>.
Sure, no problem.

I created a ticket:
https://issues.apache.org/jira/browse/IGNITE-2735

and a PR to resolve this problem.
I think this should also fix:  IGNITE-1977
but the non-failover test scenario is not good anymore;

Best regards,
Vladisav




On Mon, Feb 29, 2016 at 2:32 PM, Vladimir Ozerov <vo...@gridgain.com>
wrote:

> Hi,
>
> I tested your code in multi-node scenario, and semaphore is released fine
> when node owning a permit has been closed. In your code sample there is
> only one node, and in this case semaphore is not released. I think that
> "acquire" method should throw an exception in this case (say,
> InterruptedException) as semaphore is no longer accessible when node is
> stopped.
>
> Vladislav,
> I know you worked on distributed semaphore. Could you please share your
> thoughts on the matter? And would you mind fixing that for a single-node
> scenario?
>
> Vladimir.
>
> On Sun, Feb 28, 2016 at 11:14 PM, nyname00 <ma...@panagenda.com>
> wrote:
>
> > Hi Igniters,
> >
> > I've got a problem with a semaphore that seems to wait for a permit even
> if
> > the node is already shut down. This behavior appears in a multi-node
> setup
> > where i try to shut down all nodes at the same time (using a
> poison-pill).
> > The code below can be used to reproduce the behavior. You will notice
> that
> > there is no call on sem1#release() - this is because in my poison-pill
> > scenario there seems to be no way to get a handle to sem1. And since I
> was
> > under the impression that any semaphore gets released by Ignite when the
> > node crashes/is shut down, I was expecting an exception on
> sem2#acquire().
> >
> > Any ideas? Best regards,
> > Mario
> >
> > public static void main(String[] args) {
> >         Ignite i1 = Ignition.start(new
> > IgniteConfiguration().setGridName("1"));
> >
> >         System.out.println(">>> I1 STARTED");
> >         IgniteSemaphore sem1 = i1.semaphore("sem1", 1, true, true);
> >         System.out.println(">>> S1 READ");
> >         sem1.acquire();
> >         System.out.println(">>> S1 ACQUIRED");
> >
> >         new Thread(() -> {
> >             IgniteSemaphore sem2 = i1.semaphore("sem1", 1, true, true);
> >             System.out.println(">>> S1 READ 2");
> >             sem2.acquire();
> >             try {
> >                 System.out.println(">>> S1 ACQUIRED 2");
> >             } finally {
> >                 sem2.release();
> >             }
> >         }).start();
> >
> >         try {
> >             TimeUnit.SECONDS.sleep(2);
> >         } catch (InterruptedException e) {
> >             e.printStackTrace();
> >         }
> >
> >         System.out.println(">>> I1 CLOSING");
> >         i1.close();
> >         System.out.println(">>> I1 CLOSED");
> >     }
> >
> >
> >
> > --
> > View this message in context:
> >
> http://apache-ignite-users.70518.x6.nabble.com/Semaphore-waiting-for-permit-even-if-node-is-shut-down-tp3232.html
> > Sent from the Apache Ignite Users mailing list archive at Nabble.com.
> >
>

Re: Semaphore waiting for permit even if node is shut down

Posted by nyname00 <ma...@panagenda.com>.
Vladimir,

in my original tests I used two nodes, one owning the permit and the second
one waiting in acqire(). I then used a poison-pill (using a client and from
a separate JVM) to shutdown both nodes at the same time (similar to the
solution posted here:
http://apache-ignite-users.70518.x6.nabble.com/How-shutdown-all-nodes-td1531.html).

So, when all nodes but the last one are closed - it's a single node scenario
:)
The source I provided produces the same effects I get in a multi-node setup,
I just thought it easier to reproduce. I could provide a more complex
multi-node (+client) example, if that is of any help.

Thanks,
Mario



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Semaphore-waiting-for-permit-even-if-node-is-shut-down-tp3232p3257.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.