You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by averri <al...@gmail.com> on 2015/10/31 20:51:28 UTC

Failed to find atomic long with given name

I am getting the following error when running a code with IgniteAtomicLong
counter:

Exception in thread "main" class org.apache.ignite.IgniteException: Failed
to find atomic long with given name: myCounter
	at
org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:881)
	at
org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongImpl.incrementAndGet(GridCacheAtomicLongImpl.java:254)
	at
com.sixbell.grid.CounterApplication.lambda$main$0(CounterApplication.java:29)
	at
java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
	at java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:557)
	at com.sixbell.grid.CounterApplication.main(CounterApplication.java:27)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to find
atomic long with given name: myCounter
	at
org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongImpl$3.call(GridCacheAtomicLongImpl.java:98)
	at
org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongImpl$3.call(GridCacheAtomicLongImpl.java:92)
	at
org.apache.ignite.internal.processors.cache.GridCacheUtils$25.call(GridCacheUtils.java:1782)
	at
org.apache.ignite.internal.processors.cache.GridCacheUtils.outTx(GridCacheUtils.java:970)
	at
org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongImpl.incrementAndGet(GridCacheAtomicLongImpl.java:251)
	... 9 more



The CounterApplication:

public class CounterApplication {

    public static void main(String[] args) throws InterruptedException {
        try (final Ignite ignite = Ignition.start()) {
            final IgniteAtomicLong counter = ignite.atomicLong("myCounter",
0, true);
            System.out.println("Waiting 5 seconds...");
            sleepMillis(5_000);
            System.out.println("Starting to count...");
            IntStream.range(0, 10_000).forEach(n -> {
                sleepMillis(1);
                counter.incrementAndGet();
            });
        }
    }

    private static void sleepMillis(final int millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}


In order to reproduce the problem, start two instances of
CounterApplication, and after the second instance join the grid, kill the
other.

Waiting 5 seconds...
[19:53:13] Topology snapshot [ver=2, servers=2, clients=0, CPUs=4,
heap=3.5GB]




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Failed-to-find-atomic-long-with-given-name-tp1800.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Failed to find atomic long with given name

Posted by Denis Magda <dm...@gridgain.com>.
Hi,

IgniteAtomicLong and other atomics or data structures are implemented using
caches in Ignite.

By default IgniteAtomicLong will be backed by a partitioned cache that
doesn't have a backup.
This should lead to the exception you see. So when you kill the first node
that held the atomic long there is no node left that has info on your atomic
long.

To fix this you should provide a special AtomicConfiguration like this

AtomicConfiguration atomicCfg = new AtomicConfiguration();
        
// Set at least one backup for partitioned cache
atomicCfg.setCacheMode(CacheMode.PARTITIONED);
atomicCfg.setBackups(1);
        
// or use the cache in the replicated mode.
// atomicCfg.setCacheMode(CacheMode.REPLICATED);
        
IgniteConfiguration cfg = new IgniteConfiguration();
        
cfg.setAtomicConfiguration(atomicCfg);
        
Ignition.start(cfg);


Please try to set a specific AtomicConfiguration and let us know about the
result.

Regards,
Denis



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Failed-to-find-atomic-long-with-given-name-tp1800p1806.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.