You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dm...@apache.org on 2017/05/26 00:02:35 UTC
ignite git commit: Added an example for PersistentStore
Repository: ignite
Updated Branches:
refs/heads/ignite-5267 4608cc92b -> 11f7572cd
Added an example for PersistentStore
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/11f7572c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/11f7572c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/11f7572c
Branch: refs/heads/ignite-5267
Commit: 11f7572cdffb989cbb90eaa06f5999504c145aec
Parents: 4608cc9
Author: Denis Magda <dm...@gridgain.com>
Authored: Thu May 25 17:02:28 2017 -0700
Committer: Denis Magda <dm...@gridgain.com>
Committed: Thu May 25 17:02:28 2017 -0700
----------------------------------------------------------------------
.../example-persistent-store.xml | 71 ++++++++++++++++
examples/pom.xml | 7 ++
.../ignite/examples/model/Organization.java | 9 ++
.../persistentstore/PersistentStoreExample.java | 88 ++++++++++++++++++++
.../PersistentStoreExampleNodeStartup.java | 29 +++++++
5 files changed, 204 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7572c/examples/config/persistentstore/example-persistent-store.xml
----------------------------------------------------------------------
diff --git a/examples/config/persistentstore/example-persistent-store.xml b/examples/config/persistentstore/example-persistent-store.xml
new file mode 100644
index 0000000..955ef8c
--- /dev/null
+++ b/examples/config/persistentstore/example-persistent-store.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<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">
+
+
+ <!-- Enabling Apache Ignite Persistent Store. -->
+ <property name="persistentStoreConfiguration">
+ <bean class="org.apache.ignite.configuration.PersistentStoreConfiguration"/>
+ </property>
+
+ <!-- Setting up caches. -->
+ <property name="cacheConfiguration">
+ <list>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="organization"/>
+ <property name="backups" value="1"/>
+
+ <property name="atomicityMode" value="TRANSACTIONAL"/>
+
+ <property name="writeSynchronizationMode" value="FULL_SYNC"/>
+
+ <property name="indexedTypes">
+ <list>
+ <value>java.lang.Long</value>
+ <value>org.apache.ignite.examples.model.Organization</value>
+ </list>
+ </property>
+ </bean>
+ </list>
+ </property>
+
+ <!-- Explicitly configure TCP discovery SPI to provide a list of initial nodes. -->
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
+ <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
+ <property name="addresses">
+ <list>
+ <!-- In distributed environment, replace with actual host IP address. -->
+ <value>127.0.0.1:47500..47502</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7572c/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 790565b..4768270 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -68,6 +68,13 @@
</dependency>
<dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-pds</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ <dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>spymemcached</artifactId>
<version>2.7.3</version>
http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7572c/examples/src/main/java/org/apache/ignite/examples/model/Organization.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/Organization.java b/examples/src/main/java/org/apache/ignite/examples/model/Organization.java
index 70d4eee..fc90c07 100644
--- a/examples/src/main/java/org/apache/ignite/examples/model/Organization.java
+++ b/examples/src/main/java/org/apache/ignite/examples/model/Organization.java
@@ -62,6 +62,15 @@ public class Organization {
}
/**
+ * @param id Organization ID.
+ * @param name Organization name.
+ */
+ public Organization(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ /**
* @param name Name.
* @param addr Address.
* @param type Type.
http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7572c/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java
new file mode 100644
index 0000000..2e066ef
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExample.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.persistentstore;
+
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.examples.model.Organization;
+
+/**
+ * This example demonstrates the usage of Apache Ignite Persistent Store.
+ * <p>
+ * To execute this example you should start an instance of {@link PersistentStoreExampleNodeStartup}
+ * class which will start up an Apache Ignite remote server node with a proper configuration.
+ * <p>
+ * When {@code UPDATE} parameter of this example is set to {@code true}, the example will populate
+ * the cache with some data and will then run a sample SQL query to fetch some results.
+ * <p>
+ * When {@code UPDATE} parameter of this example is set to {@code false}, the example will run
+ * the SQL query against the cache without the initial data pre-loading from the store.
+ * <p>
+ * You can populate the cache first with {@code UPDATE} set to {@code true}, then restart the nodes and
+ * run the example with {@code UPDATE} set to {@code false} to verify that Apache Ignite can work with the
+ * data that is in the persistence only.
+ */
+public class PersistentStoreExample {
+ /** */
+ private static final boolean UPDATE = true;
+
+ /**
+ * @param args Program arguments, ignored.
+ * @throws Exception If failed.
+ */
+ public static void main(String[] args) throws Exception {
+ Ignition.setClientMode(true);
+
+ try (Ignite ig = Ignition.start("examples/config/persistentstore/example-persistent-store.xml")) {
+
+ IgniteCache<Long, Organization> cache = ig.cache("organization");
+
+ if (UPDATE) {
+ System.out.println("Populating the cache...");
+
+ try (IgniteDataStreamer<Long, Organization> streamer = ig.dataStreamer("organization")) {
+ streamer.allowOverwrite(true);
+
+ for (long i = 0; i < 100_000; i++) {
+ streamer.addData(i, new Organization(i, "organization-" + i));
+
+ if (i > 0 && i % 10_000 == 0)
+ System.out.println("Done: " + i);
+ }
+ }
+ }
+
+ // Run SQL without explicitly calling to loadCache().
+ QueryCursor<List<?>> cur = cache.query(
+ new SqlFieldsQuery("select id, name from Organization where name like ?")
+ .setArgs("organization-54321"));
+
+ System.out.println("SQL Result: " + cur.getAll());
+
+ // Run get() without explicitly calling to loadCache().
+ Organization org = cache.get(54321l);
+
+ System.out.println("GET Result: " + org);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7572c/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java
new file mode 100644
index 0000000..ecada47
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/persistentstore/PersistentStoreExampleNodeStartup.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.persistentstore;
+
+import org.apache.ignite.Ignition;
+
+/**
+ * @see PersistentStoreExampleNodeStartup
+ */
+public class PersistentStoreExampleNodeStartup {
+ public static void main(String[] args) throws Exception {
+ Ignition.start("examples/config/persistentstore/example-persistent-store.xml");
+ }
+}