You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by David Li <da...@gmail.com> on 2017/05/15 08:44:55 UTC

Cannot create cache in EVT_CLIENT_NODE_RECONNECTED event

Hi guys,

In the code snippet below, I am trying to re-create a cache after the
client node has disconnected and reconnected to the server node, somehow
the line of creating the cache cannot be executed, the program just hangs
there.

public static class Predicate implements IgnitePredicate<DiscoveryEvent> {

    private Ignite ignite;
    private IgniteCache<Integer, String> cache;

    public Predicate(Ignite ignite, IgniteCache<Integer, String> cache) {
        this.ignite = ignite;
        this.cache = cache;
    }

    @Override
    public boolean apply(DiscoveryEvent evt) {
        // see this line in output
        System.out.println("Received event [evt=" + evt.name() + ",
type=" + evt.type());
        if (evt.type() == EventType.EVT_CLIENT_NODE_RECONNECTED) {
            // reinitialize all the caches
            cache = ignite.getOrCreateCache(CACHE_NAME);  // if debug,
program hangs here
            System.out.println("Initialised cache: " + CACHE_NAME);
// never see this in output
        }
        return true;
    }
}

Appreciate any ideas. Thanks.

BRs,

David

Re: Cannot create cache in EVT_CLIENT_NODE_RECONNECTED event

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi David,

Seems, this predicate called from sensitive code and cache creation end up
with deadlock.
Try to move cache creation to separate thread.

On Mon, May 15, 2017 at 11:44 AM, David Li <da...@gmail.com> wrote:

> Hi guys,
>
> In the code snippet below, I am trying to re-create a cache after the
> client node has disconnected and reconnected to the server node, somehow
> the line of creating the cache cannot be executed, the program just hangs
> there.
>
> public static class Predicate implements IgnitePredicate<DiscoveryEvent> {
>
>     private Ignite ignite;
>     private IgniteCache<Integer, String> cache;
>
>     public Predicate(Ignite ignite, IgniteCache<Integer, String> cache) {
>         this.ignite = ignite;
>         this.cache = cache;
>     }
>
>     @Override
>     public boolean apply(DiscoveryEvent evt) {
>         // see this line in output
>         System.out.println("Received event [evt=" + evt.name() + ", type=" + evt.type());
>         if (evt.type() == EventType.EVT_CLIENT_NODE_RECONNECTED) {
>             // reinitialize all the caches
>             cache = ignite.getOrCreateCache(CACHE_NAME);  // if debug, program hangs here
>             System.out.println("Initialised cache: " + CACHE_NAME);  // never see this in output
>         }
>         return true;
>     }
> }
>
> Appreciate any ideas. Thanks.
>
> BRs,
>
> David
>
>
>


-- 
Best regards,
Andrey V. Mashenkov