Search code examples
javacachingignite

Cannot create cache in existing Apache Ignite single node cluster


I am running two Apache Ignite instances (version 2.2.0) in my single host pc, and they discover each other with no issues. What I want to do now, is to simply create an IgniteCache in this existing "pseudo cluster", preferably without starting a new instance to do so. This is the code I have right now:

public class Create_Ignite_Cache {

public static void main(String[] args){

    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    TcpDiscoveryVmIpFinder ipFinder=new TcpDiscoveryMulticastIpFinder();
    List<String> adresses=new ArrayList<String>();
    adresses.add("127.0.0.1");
    ipFinder.setAddresses(adresses);
    spi.setIpFinder(ipFinder);

    IgniteConfiguration cfg=new IgniteConfiguration()
.setDiscoverySpi(spi).setClientMode(true);

    CacheConfiguration cache_conf=new CacheConfiguration<String,String>().setCacheMode(CacheMode.PARTITIONED).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setBackups(1).
            setGroupName("Test_group").setIndexedTypes(String.class,String.class).setName("Test_Cache");

    Ignite ignite=Ignition.getOrStart(cfg);

    ignite.getOrCreateCache(cache_conf);

    System.out.print("[INFO] CACHE CREATED");
    ignite.close();
}
 }

When I run this code, an Ignite client instance is created, tries to create a cache, and then closes the client instance. If I check the logs from the Ignite server instance, it detects the client instance when it is created:

[10:36:57] Topology snapshot [ver=1, servers=1, clients=0, CPUs=12, heap=1.0GB]
[10:41:07] Topology snapshot [ver=2, servers=1, clients=1, CPUs=12, heap=4.6GB]
[10:41:07] Topology snapshot [ver=3, servers=1, clients=0, CPUs=12, heap=1.0GB]

However, when I run the ignitevisor to check the cache list, it doesn't have any cache present:

visor> cache
(wrn) <visor>: No caches found.

My questions are:
What am I doing wrong by using this approach? Is there a way to create a cache in an existing cluster without having to create a client instance to do so? With a JDBC connection for example?


Solution

  • I tried your code, and Visor showed the created cache.

    Topology snapshot says, that you have only one server node. Is it possible, that server nodes didn't discover each other and formed two different clusters? You could create a cache in one of them and connect via Visor to another one. Try node Visor command and check whether you see all the server nodes.

    To avoid starting an additional node for cache creation, you can configure caches right in the node XML configuration. Take a look at the example: https://apacheignite.readme.io/docs/cache-modes#section-configuration

    If you want to use JDBC connection to create a cache, you can use a CREATE TABLE DDL command. Documentation: https://apacheignite-sql.readme.io/docs/create-table