roseaysina
roseaysina

Reputation: 165

How to set up Ignite node from Scala application for IgniteSet?

I want to set up IgniteSet and fill it in Scala application using standalone Ignite cluster.

What I am doing: I raise client\server node, connect it to cluster and use Ignite instance to set up Set as shown in docs above. Similar to what I do for usual Ignite caches.

What's the problem: node cannot connect to cluster :(

From application the error is:

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@32f308c6], reconCnt=10, reconDelay=2000, maxAckTimeout=600000, soLinger=0, forceSrvMode=false, clientReconnectDisabled=false, internalLsnr=null, skipAddrsRandomization=false]
...
Caused by: class org.apache.ignite.spi.IgniteSpiException: Failed to deserialize object with given class loader: jdk.internal.loader.ClassLoaders$AppClassLoader@2c13da15

From Ignite cluster the error is:

Caused by: java.io.InvalidClassException: javax.cache.configuration.MutableConfiguration; local class incompatible: stream classdesc serialVersionUID = 201405, local class serialVersionUID = 201306200821

javax.cache.configuration.MutableConfiguration is part of javax.cache.cache-api package and so the error says that there is some version mismatch. But I explicitly checked that my Ignite cluster uses 1.0.0 version - there is file apache-ignite-2.9.1-bin/libs/cache-api-1.0.0.jar in my IGNITE_HOME; and that my app uses the same version - in build.sbt I explicitly set (also tried to exclude this package at all):

libraryDependencies ++= Seq(
  ...,
  "javax.cache" % "cache-api" % "1.0.0"
)

Moreover I cannot find version of javax.cache.cache-api that uses such serialVersionUID: both 1.0.0 and 1.1.0 have public static final long serialVersionUID = 201306200821L;

What I do in Scala application:

# fails
# port == TcpDiscoverySpi port from cluster configuration
val host = "localhost:45900..46000" # also tried with single port and 

val tcpDiscoverySpi: TcpDiscoverySpi = new TcpDiscoverySpi
val ipFinder: TcpDiscoveryVmIpFinder = new TcpDiscoveryVmIpFinder
ipFinder.setAddresses(util.Arrays.asList(host.split(","): _*))
tcpDiscoverySpi.setIpFinder(ipFinder)

val igniteConfiguration: IgniteConfiguration = new IgniteConfiguration
igniteConfiguration.setDiscoverySpi(tcpDiscoverySpi)
igniteConfiguration.setClientMode(false) # also tried with true

val ignite: Ignite = Ignition.start(igniteConfiguration) # error raised here

Also code snippet above works as expected from Java Spring application where the node is raised to set up Spring Data caches.

What works as expected from Scala application is the connector node to Ignite cluster (for creating regular caches) but I cannot use it because it is not possible to set up IgniteSet with IgniteClient instance :(

# works as expected
val host = "localhost"
val connector_port = "10800" # == ClientConnectorConfiguration port from cluster configuration

val cfg = new ClientConfiguration()
      .setAddresses(host + ":" + connector_port)

val ignite: IgniteClient = Ignition.startClient(cfg)

val cache = ignite.getOrCreateCache(...)

What I do with Ignite cluster: it is raised locally with script bin/ignite.sh of 2.9.1 version and with the following configuration:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean class="org.apache.ignite.configuration.IgniteConfiguration">

        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="localPort" value="45900"/>
                <property name="localPortRange" value="100"/>

                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.sharedfs.TcpDiscoverySharedFsIpFinder">
                        <property name="path" value="/opt/storage/ignite"/>
                    </bean>
                </property>
            </bean>
        </property>


        <property name="communicationSpi">
            <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
                <property name="localPort" value="47100"/>
            </bean>
        </property>


        <property name="clientConnectorConfiguration">
            <bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
                <property name="port" value="10800"/>
                <property name="portRange" value="100"/>
            </bean>
        </property>


        <property name="dataStorageConfiguration">
            <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
                <property name="defaultDataRegionConfiguration">
                    <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                        <property name="maxSize" value="1073741824"/>
                        <property name="persistenceEnabled" value="true"/>
                    </bean>
                </property>

                <property name="storagePath" value="/opt/storage/ignite"/>
                <property name="walSegmentSize" value="134217728"/>

            </bean>
        </property>

    </bean>

</beans>

I am also able to connect to it by JDBC (jdbc:ignite:thin://localhost:10800), see it in DataGrip and store data both from Java app and Spark Streaming Dataframes.

So the questions are:

  1. How to fix the problem - raise node from Scala app? Or maybe there is another valid way to create IgniteSet?
  2. How to understand which type of nodes to raise for different tasks - access cache, create cache, create sets/queues, access sets/queues? There are thin nodes, thick nodes, among them client/server nodes...

Will be glad to any help!

UPD: found similar problem here - advice to exclude Geronimo JCache spec which MutableConfiguration has serial number of 201405L. I tried to exclude it but still have the same error:

excludeDependencies ++= Seq(
  ExclusionRule("org.apache.geronimo.specs"),
  ExclusionRule("org.apache.geronimo")
)

Upvotes: 0

Views: 193

Answers (1)

alamar
alamar

Reputation: 19321

Apache Ignite needs JCache 1.0 and ships with corresponding version JAR.

If you have a different JAR in your client app compared to your server nodes, you may see this (de)serialization problem. You may use 1.1 or 1.0 but it has to match.

Upvotes: 1

Related Questions