Mangled_Aura_Nada
Mangled_Aura_Nada

Reputation: 147

Apache Ignite: SQL API @QuerySqlField Annotation on Remote Node

I have run into some errors trying to use Apache Ignite's SQL API @QueryEntity Annotation.

Right now, I start a cluster remotely by passing an XML file to the scrip bash ignite.sh. Then, I start another node locally and programmatically with C# that connects to an underlying Oracle database in order to load the cache with data.

My objective is to be able to query the data in cache, where the key is an Object ID and the value is the entire Object object. The only steps I've done was to annotate the fields in the value class definition with the @QuerySqlField annotation in Object.cs and instantiate the QueryEntity in CacheConfiguration in Program.cs.

XML file passed to start remote cluster

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="cacheConfiguration">
            <list>
                <!-- Partitioned cache example configuration (Atomic mode). -->
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="default"/>
                    <property name="atomicityMode" value="ATOMIC"/>
                    <property name="backups" value="1"/>
                </bean>
            </list>
        </property>

        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <value>[host1]:47500..47509</value>
                                <value>[host2]:47500..47509</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean> </beans>

Program.cs

namespace IgniteTest
{
    class Program
    {   
        static void Main(string[] args)
        {
            // Create Connection
            OracleConnection con = new OracleConnection();

            // Create ConnectionString using Builder
            OracleConnectionStringBuilder ocsb = new OracleConnectionStringBuilder();
            ocsb.Password = "[Password]";
            ocsb.UserID = "[User]";
            ocsb.DataSource = "[URL]";

            // Connect 
            con.ConnectionString = ocsb.ConnectionString;
            con.Open();
            Console.WriteLine();
            Console.WriteLine(">>> Connection Established");

            // Execute a SQL SELECT
            OracleCommand cmd = con.CreateCommand();
            cmd.CommandText = "COMMAND";
            OracleDataReader reader = cmd.ExecuteReader();

            // Create node locally; connect with remote cluster
            var cfg = new IgniteConfiguration
            {
                DiscoverySpi = new TcpDiscoverySpi
                {
                    IpFinder = new TcpDiscoveryStaticIpFinder
                    {
                        Endpoints = new[] { "[host1]", "[host1]:47500..47509" }
                    }
                },

                CacheConfiguration = new[]
                {
                    new CacheConfiguration
                    {
                        Name = "default",
                        Backups = 1,
                        QueryEntities = new[]
                        {
                            new QueryEntity(typeof(int), typeof(Object))
                        }
                    }
                }
            };

            IIgnite ignite = Ignition.Start(cfg);

            ICache<int, Object> cache = ignite.GetOrCreateCache<int, Object>("default");

            while (reader.Read())
            {

                Object object= new Object
                {
                    ObjectID = reader.IsDBNull(0) ? 0 : reader.GetInt32(0),
                    LastName = reader.IsDBNull(1) ? ">>> LAST_NAME null" : reader.GetString(1),
                    FirstName = reader.IsDBNull(2) ? ">>> FIRST_NAME null" : reader.GetString(2),
                    MiddleName = reader.IsDBNull(3) ? ">>> MIDDLE_NAME null" : reader.GetString(3),
                    JobTitle = reader.IsDBNull(8) ? ">>> JOB_TITLE null" : reader.GetString(8)
                };

                if (cache.PutIfAbsent(reader.GetInt32(0), object))
                {
                    Console.WriteLine(">>> Object added to cache");
                }
                else
                {
                    Console.WriteLine(">>> Object ID: " + cache.Get(reader.GetInt32(0)).ObjectID+ ", Job Title: " + cache.Get(reader.GetInt32(0)).JobTitle);
                }
            }

            // Clean up
            reader.Dispose();
            cmd.Dispose();
            con.Dispose();

        }
    }
}

Object.cs

namespace IgniteTest
{
    class Obje
    {
        [QuerySqlField(IsIndexed = true)]
        public int ObjectID { get; set; }
        [QuerySqlField]
        public string LastName { get; set; }
        [QuerySqlField]
        public string FirstName { get; set; }
        [QuerySqlField]
        public string MiddleName { get; set; }
        public string JobTitle { get; set; }
    }
}

The errors I'm getting on my local console

[11:43:34,607][INFO][tcp-disco-srvr-[:47500]-#3-#43][TcpDiscoverySpi] TCP discovery accepted incoming connection [rmtAddr=/[host1], rmtPort=35269]
[11:43:34,617][INFO][tcp-disco-srvr-[:47500]-#3-#43][TcpDiscoverySpi] TCP discovery spawning a new thread for connection [rmtAddr=/[host1], rmtPort=35269]
[11:43:34,617][INFO][tcp-disco-sock-reader-[]-#4-#44][TcpDiscoverySpi] Started serving remote node connection [rmtAddr=/[host1]:35269, rmtPort=35269]
[11:43:34,622][INFO][tcp-disco-sock-reader-[]-#4-#44][TcpDiscoverySpi] Received ping request from the remote node [rmtNodeId=973d6f42-df7c-4a73-b157-c6562ea8f7fe, rmtAddr=/[host1]:35269, rmtPort=35269]
[11:43:34,623][INFO][tcp-disco-sock-reader-[]-#4-#44][TcpDiscoverySpi] Finished writing ping response [rmtNodeId=973d6f42-df7c-4a73-b157-c6562ea8f7fe, rmtAddr=/[host1]:35269, rmtPort=35269]
[11:43:34,623][INFO][tcp-disco-sock-reader-[]-#4-#44][TcpDiscoverySpi] Finished serving remote node connection [rmtAddr=/[host1]:35269, rmtPort=35269
[11:43:34,674][INFO][tcp-disco-srvr-[:47500]-#3-#43][TcpDiscoverySpi] TCP discovery accepted incoming connection [rmtAddr=/[host1], rmtPort=51961]
[11:43:34,674][INFO][tcp-disco-srvr-[:47500]-#3-#43][TcpDiscoverySpi] TCP discovery spawning a new thread for connection [rmtAddr=/[host1], rmtPort=51961]
[11:43:34,679][INFO][tcp-disco-sock-reader-[]-#5-#45][TcpDiscoverySpi] Started serving remote node connection [rmtAddr=/[host1]:51961, rmtPort=51961]
[11:43:34,684][INFO][tcp-disco-sock-reader-[]-#5-#45][TcpDiscoverySpi] Received ping request from the remote node [rmtNodeId=973d6f42-df7c-4a73-b157-c6562ea8f7fe, rmtAddr=/[host1]:51961, rmtPort=51961]
[11:43:34,685][INFO][tcp-disco-sock-reader-[]-#5-#45][TcpDiscoverySpi] Finished writing ping response [rmtNodeId=973d6f42-df7c-4a73-b157-c6562ea8f7fe, rmtAddr=/[host1]:51961, rmtPort=51961]
[11:43:34,686][INFO][tcp-disco-sock-reader-[]-#5-#45][TcpDiscoverySpi] Finished serving remote node connection [rmtAddr=/[host1]:51961, rmtPort=51961
[11:43:34,732][INFO][tcp-disco-srvr-[:47500]-#3-#43][TcpDiscoverySpi] TCP discovery accepted incoming connection [rmtAddr=/[host1], rmtPort=54361]
[11:43:34,732][INFO][tcp-disco-srvr-[:47500]-#3-#43][TcpDiscoverySpi] TCP discovery spawning a new thread for connection [rmtAddr=/[host1], rmtPort=54361]
[11:43:34,737][INFO][tcp-disco-sock-reader-[]-#6-#46][TcpDiscoverySpi] Started serving remote node connection [rmtAddr=/[host1]:54361, rmtPort=54361]
[11:43:34,741][INFO][tcp-disco-sock-reader-[973d6f42 [host1]:54361]-#6-#46][TcpDiscoverySpi] Initialized connection with remote server node [nodeId=973d6f42-df7c-4a73-b157-c6562ea8f7fe, rmtAddr=/[host1]:54361]
[11:43:34,759][SEVERE][main][IgniteKernal] Failed to start manager: GridManagerAdapter [enabled=true, name=o.a.i.i.managers.discovery.GridDiscoveryManager]
class org.apache.ignite.IgniteCheckedException: Failed to start SPI: TcpDiscoverySpi [addrRslvr=null, sockTimeout=5000, ackTimeout=5000, marsh=JdkMarshaller [clsFilter=org.apache.ignite.marshaller.MarshallerUtils$1@53cdecf6], reconCnt=10, reconDelay=2000, maxAckTimeout=600000, soLinger=5, forceSrvMode=false, clientReconnectDisabled=false, internalLsnr=null, skipAddrsRandomization=false]
        at org.apache.ignite.internal.managers.GridManagerAdapter.startSpi(GridManagerAdapter.java:302)
        at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.start(GridDiscoveryManager.java:967)
        at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1935)
        at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:1298)
        at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:2046)
        at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1698)
        at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1114)
        at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:612)
        at org.apache.ignite.internal.processors.platform.PlatformAbstractBootstrap.start(PlatformAbstractBootstrap.java:43)
        at org.apache.ignite.internal.processors.platform.PlatformIgnition.start(PlatformIgnition.java:74)
Caused by: class org.apache.ignite.spi.IgniteSpiException: Failed to join node to the active cluster (the config of the cache 'default' has to be merged which is impossible on active grid). Deactivate grid and retry node join or clean the joining node.
        at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.checkFailedError(TcpDiscoverySpi.java:2018)
        at org.apache.ignite.spi.discovery.tcp.ServerImpl.joinTopology(ServerImpl.java:1189)
        at org.apache.ignite.spi.discovery.tcp.ServerImpl.spiStart(ServerImpl.java:462)
        at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.spiStart(TcpDiscoverySpi.java:2120)
        at org.apache.ignite.internal.managers.GridManagerAdapter.startSpi(GridManagerAdapter.java:299)
        ... 9 more
[11:43:34,767][SEVERE][main][IgniteKernal] Got exception while starting (will rollback startup routine).
class org.apache.ignite.IgniteCheckedException: Failed to start manager: GridManagerAdapter [enabled=true, name=org.apache.ignite.internal.managers.discovery.GridDiscoveryManager]
        at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1940)
        at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:1298)
        at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:2046)
        at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1698)
        at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1114)
        at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:612)
        at org.apache.ignite.internal.processors.platform.PlatformAbstractBootstrap.start(PlatformAbstractBootstrap.java:43)
        at org.apache.ignite.internal.processors.platform.PlatformIgnition.start(PlatformIgnition.java:74)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to start SPI: TcpDiscoverySpi [addrRslvr=null, sockTimeout=5000, ackTimeout=5000, marsh=JdkMarshaller [clsFilter=org.apache.ignite.marshaller.MarshallerUtils$1@53cdecf6], reconCnt=10, reconDelay=2000, maxAckTimeout=600000, soLinger=5, forceSrvMode=false, clientReconnectDisabled=false, internalLsnr=null, skipAddrsRandomization=false]
        at org.apache.ignite.internal.managers.GridManagerAdapter.startSpi(GridManagerAdapter.java:302)
        at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.start(GridDiscoveryManager.java:967)
        at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1935)
        ... 7 more
Caused by: class org.apache.ignite.spi.IgniteSpiException: Failed to join node to the active cluster (the config of the cache 'default' has to be merged which is impossible on active grid). Deactivate grid and retry node join or clean the joining node.
        at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.checkFailedError(TcpDiscoverySpi.java:2018)
        at org.apache.ignite.spi.discovery.tcp.ServerImpl.joinTopology(ServerImpl.java:1189)
        at org.apache.ignite.spi.discovery.tcp.ServerImpl.spiStart(ServerImpl.java:462)
        at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.spiStart(TcpDiscoverySpi.java:2120)
        at org.apache.ignite.internal.managers.GridManagerAdapter.startSpi(GridManagerAdapter.java:299)
        ... 9 more
[11:43:34,772][INFO][main][GridTcpRestProtocol] Command protocol successfully stopped: TCP binary
[11:43:34,774][INFO][tcp-disco-sock-reader-[973d6f42 [host1]:54361]-#6-#46][TcpDiscoverySpi] Finished serving remote node connection [rmtAddr=/[host1]:54361, rmtPort=54361
[11:43:39,781][INFO][main][TcpDiscoverySpi] No verification for local node leave has been received from coordinator (will stop node anyway).
[11:43:39,794][INFO][main][IgniteKernal]

Am I getting these errors because the cache configurations on the XML file does not match the cache configurations with C# in Program.cs? Would I have to add the query entities in the XML file as well? If so, how would I go about that?

Upvotes: 1

Views: 838

Answers (1)

Vladimir Pligin
Vladimir Pligin

Reputation: 1660

You're trying to set two mismatching cache configurations with the same name. Have a look at this message:

Caused by: class org.apache.ignite.spi.IgniteSpiException: Failed to join node to the active cluster (the config of the cache 'default' has to be merged which is impossible on active grid). Deactivate grid and retry node join or clean the joining node.

This particular error says that it's not possible to merge configurations if a cluster has been already activated. As far as I understand in your case it's just enough to remove default cache configuration from the xml configuration of your server node. You're using ignite.GetOrCreateCache to retrieve a cache proxy, it means that the default cache will be created when you call that.

Upvotes: 2

Related Questions