[关闭]
@aloxc 2017-12-05T06:37:18.000000Z 字数 24097 阅读 501

ignite中部署模式配置调整对官方的测试类CacheQueryExample.java的影响

ignite


如题,使用官方的示例代码来测试ignite的时候,如果不配置部署模式deploymentMode,也就是默认的配置SHARED,测试该类,一切正常,当调整为PRIVATE的时候(服务器端的配置同步调整为PRIVATE),如下

  1. <property name="deploymentMode" value="PRIVATE"/>

第二天补充下

部署模式测试了一下几种都会发生这个异常

  • PRIVATE
  • ISOLATED

SHAREDCONTINUOUS没问题,难道是bug还是?


这时候执行该类,会发生异常,异常堆栈如下:

  1. Exception in thread "main" javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: Query execution failed: GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, filter=com.github.aloxc.ignite.datagrid.CacheQueryExample$1@10c8f62, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=0, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=true, subjId=9d99e4dc-7040-4670-a190-4bdb10f92dcf, taskHash=0], rdc=null, trans=null]
  2. at org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1502)
  3. at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.next(GridCacheQueryFutureAdapter.java:176)
  4. at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager$5.onHasNext(GridCacheDistributedQueryManager.java:634)
  5. at org.apache.ignite.internal.util.GridCloseableIteratorAdapter.hasNextX(GridCloseableIteratorAdapter.java:53)
  6. at org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2$1.onHasNext(IgniteCacheProxy.java:501)
  7. at org.apache.ignite.internal.util.GridCloseableIteratorAdapter.hasNextX(GridCloseableIteratorAdapter.java:53)
  8. at org.apache.ignite.internal.util.lang.GridIteratorAdapter.hasNext(GridIteratorAdapter.java:45)
  9. at org.apache.ignite.internal.processors.cache.QueryCursorImpl.getAll(QueryCursorImpl.java:73)
  10. at com.github.aloxc.ignite.datagrid.CacheQueryExample.scanQueryx(CacheQueryExample.java:177)
  11. at com.github.aloxc.ignite.datagrid.CacheQueryExample.main(CacheQueryExample.java:111)
  12. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  13. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  14. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  15. at java.lang.reflect.Method.invoke(Method.java:498)
  16. at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  17. Caused by: class org.apache.ignite.IgniteCheckedException: Query execution failed: GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, filter=com.github.aloxc.ignite.datagrid.CacheQueryExample$1@10c8f62, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=0, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=true, subjId=9d99e4dc-7040-4670-a190-4bdb10f92dcf, taskHash=0], rdc=null, trans=null]
  18. at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.checkError(GridCacheQueryFutureAdapter.java:262)
  19. at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.internalIterator(GridCacheQueryFutureAdapter.java:320)
  20. at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.next(GridCacheQueryFutureAdapter.java:166)
  21. ... 13 more
  22. Caused by: class org.apache.ignite.IgniteCheckedException: Failed to execute query on node [query=GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, filter=com.github.aloxc.ignite.datagrid.CacheQueryExample$1@10c8f62, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=0, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=true, subjId=9d99e4dc-7040-4670-a190-4bdb10f92dcf, taskHash=0], rdc=null, trans=null], nodeId=a71b03a7-311c-41d6-9b9d-e381adfca013]
  23. at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.onPage(GridCacheQueryFutureAdapter.java:385)
  24. at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager.processQueryResponse(GridCacheDistributedQueryManager.java:398)
  25. at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager.access$000(GridCacheDistributedQueryManager.java:63)
  26. at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager$1.apply(GridCacheDistributedQueryManager.java:93)
  27. at org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager$1.apply(GridCacheDistributedQueryManager.java:91)
  28. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.processMessage(GridCacheIoManager.java:748)
  29. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.onMessage0(GridCacheIoManager.java:353)
  30. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.access$400(GridCacheIoManager.java:88)
  31. at org.apache.ignite.internal.processors.cache.GridCacheIoManager$OrderedMessageListener.onMessage(GridCacheIoManager.java:1262)
  32. at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1238)
  33. at org.apache.ignite.internal.managers.communication.GridIoManager.access$1600(GridIoManager.java:106)
  34. at org.apache.ignite.internal.managers.communication.GridIoManager$GridCommunicationMessageSet.unwind(GridIoManager.java:2488)
  35. at org.apache.ignite.internal.managers.communication.GridIoManager.unwindMessageSet(GridIoManager.java:1198)
  36. at org.apache.ignite.internal.managers.communication.GridIoManager.access$1900(GridIoManager.java:106)
  37. at org.apache.ignite.internal.managers.communication.GridIoManager$6.run(GridIoManager.java:1167)
  38. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  39. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  40. at java.lang.Thread.run(Thread.java:745)
  41. Caused by: class org.apache.ignite.IgniteCheckedException: com.github.aloxc.ignite.datagrid.CacheQueryExample$1
  42. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.unmarshall(GridCacheIoManager.java:1221)
  43. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.onMessage0(GridCacheIoManager.java:348)
  44. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.handleMessage(GridCacheIoManager.java:277)
  45. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.access$000(GridCacheIoManager.java:88)
  46. at org.apache.ignite.internal.processors.cache.GridCacheIoManager$1.onMessage(GridCacheIoManager.java:231)
  47. at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1238)
  48. at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:866)
  49. at org.apache.ignite.internal.managers.communication.GridIoManager.access$1700(GridIoManager.java:106)
  50. at org.apache.ignite.internal.managers.communication.GridIoManager$5.run(GridIoManager.java:829)
  51. ... 3 more
  52. Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: com.github.aloxc.ignite.datagrid.CacheQueryExample$1
  53. at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:671)
  54. at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:668)
  55. at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1474)
  56. at org.apache.ignite.internal.binary.GridBinaryMarshaller.deserialize(GridBinaryMarshaller.java:298)
  57. at org.apache.ignite.internal.binary.BinaryMarshaller.unmarshal(BinaryMarshaller.java:109)
  58. at org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest.finishUnmarshal(GridCacheQueryRequest.java:322)
  59. at org.apache.ignite.internal.processors.cache.GridCacheIoManager.unmarshall(GridCacheIoManager.java:1215)
  60. ... 11 more
  61. Caused by: java.lang.ClassNotFoundException: com.github.aloxc.ignite.datagrid.CacheQueryExample$1
  62. at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  63. at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  64. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  65. at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  66. at java.lang.Class.forName0(Native Method)
  67. at java.lang.Class.forName(Class.java:348)
  68. at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8350)
  69. at org.apache.ignite.internal.MarshallerContextAdapter.getClass(MarshallerContextAdapter.java:185)
  70. at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:662)
  71. ... 17 more

我们把java代码中的方法scanQuery()中的代码注释掉以后又没问题了,这是为嘛?有谁知道
注意看异常堆栈信息提示
Caused by: java.lang.ClassNotFoundException: com.github.aloxc.ignite.datagrid.CacheQueryExample$1,这个提示就是找不到CacheQueryExample,这是本类啊;照说找不到的话我把scanQuery()方法中的代码注释掉后再运行也应该找不到啊


  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.github.aloxc.ignite.datagrid;
  18. import com.github.aloxc.ignite.Config;
  19. import org.apache.ignite.Ignite;
  20. import org.apache.ignite.IgniteCache;
  21. import org.apache.ignite.Ignition;
  22. import org.apache.ignite.binary.BinaryObject;
  23. import org.apache.ignite.cache.CacheMode;
  24. import org.apache.ignite.cache.affinity.AffinityKey;
  25. import org.apache.ignite.cache.query.*;
  26. import org.apache.ignite.configuration.CacheConfiguration;
  27. import org.apache.ignite.examples.ExampleNodeStartup;
  28. import org.apache.ignite.examples.model.Organization;
  29. import org.apache.ignite.examples.model.Person;
  30. import org.apache.ignite.lang.IgniteBiPredicate;
  31. import javax.cache.Cache;
  32. import java.util.List;
  33. /**
  34. * Cache queries example. This example demonstrates SQL, TEXT, and FULL SCAN
  35. * queries over cache.
  36. * <p>
  37. * Example also demonstrates usage of fields queries that return only required
  38. * fields instead of whole key-value pairs. When fields queries are distributed
  39. * across several nodes, they may not work as expected. Keep in mind following
  40. * limitations (not applied if data is queried from one node only):
  41. * <ul>
  42. * <li>
  43. * Non-distributed joins will work correctly only if joined objects are stored in
  44. * collocated mode. Refer to {@link AffinityKey} javadoc for more details.
  45. * <p>
  46. * To use distributed joins it is necessary to set query 'distributedJoin' flag using
  47. * {@link SqlFieldsQuery#setDistributedJoins(boolean)} or {@link SqlQuery#setDistributedJoins(boolean)}.
  48. * </li>
  49. * <li>
  50. * Note that if you created query on to replicated cache, all data will
  51. * be queried only on one node, not depending on what caches participate in
  52. * the query (some data from partitioned cache can be lost). And visa versa,
  53. * if you created it on partitioned cache, data from replicated caches
  54. * will be duplicated.
  55. * </li>
  56. * </ul>
  57. * <p>
  58. * Remote nodes should be started using {@link ExampleNodeStartup} which will
  59. * start node with {@code examples/config/example-ignite.xml} configuration.
  60. */
  61. public class CacheQueryExample {
  62. /** Organizations cache name. */
  63. private static final String ORG_CACHE = CacheQueryExample.class.getSimpleName() + "Organizations";
  64. /** Persons collocated with Organizations cache name. */
  65. private static final String COLLOCATED_PERSON_CACHE = CacheQueryExample.class.getSimpleName() + "CollocatedPersons";
  66. /** Persons cache name. */
  67. private static final String PERSON_CACHE = CacheQueryExample.class.getSimpleName() + "Persons";
  68. /**
  69. * Executes example.
  70. *
  71. * @param args Command line arguments, none required.
  72. * @throws Exception If example execution failed.
  73. */
  74. public static void main(String[] args) throws Exception {
  75. try (Ignite ignite = Ignition.start(Config.DEFAULT_CONFIG_PATH)) {
  76. System.out.println();
  77. System.out.println(">>> Cache query example started.");
  78. CacheConfiguration<Long, Organization> orgCacheCfg = new CacheConfiguration<>(ORG_CACHE);
  79. orgCacheCfg.setCacheMode(CacheMode.PARTITIONED); // Default.
  80. orgCacheCfg.setIndexedTypes(Long.class, Organization.class);
  81. CacheConfiguration<AffinityKey<Long>, Person> colPersonCacheCfg = new CacheConfiguration<>(COLLOCATED_PERSON_CACHE);
  82. colPersonCacheCfg.setCacheMode(CacheMode.PARTITIONED); // Default.
  83. colPersonCacheCfg.setIndexedTypes(AffinityKey.class, Person.class);
  84. CacheConfiguration<AffinityKey<Long>, Person> personCacheCfg = new CacheConfiguration<>(PERSON_CACHE);
  85. personCacheCfg.setCacheMode(CacheMode.PARTITIONED); // Default.
  86. personCacheCfg.setIndexedTypes(Long.class, Person.class);
  87. // Auto-close cache at the end of the example.
  88. try (
  89. IgniteCache<Long, Organization> orgCache = ignite.getOrCreateCache(orgCacheCfg);
  90. IgniteCache<AffinityKey<Long>, Person> colPersonCache = ignite.getOrCreateCache(colPersonCacheCfg);
  91. IgniteCache<AffinityKey<Long>, Person> personCache = ignite.getOrCreateCache(personCacheCfg)
  92. ) {
  93. // Populate cache.
  94. initialize();
  95. // Example for SCAN-based query based on a predicate.
  96. scanQuery();
  97. // Example for SQL-based querying employees based on salary ranges.
  98. sqlQuery();
  99. // Example for SQL-based querying employees for a given organization (includes SQL join for collocated objects).
  100. sqlQueryWithJoin();
  101. // Example for SQL-based querying employees for a given organization (includes distributed SQL join).
  102. sqlQueryWithDistributedJoin();
  103. // Example for TEXT-based querying for a given string in peoples resumes.
  104. textQuery();
  105. // Example for SQL-based querying to calculate average salary among all employees within a company.
  106. sqlQueryWithAggregation();
  107. // Example for SQL-based fields queries that return only required
  108. // fields instead of whole key-value pairs.
  109. sqlFieldsQuery();
  110. // Example for SQL-based fields queries that uses joins.
  111. sqlFieldsQueryWithJoin();
  112. }
  113. finally {
  114. // Distributed cache could be removed from cluster only by #destroyCache() call.
  115. ignite.destroyCache(COLLOCATED_PERSON_CACHE);
  116. ignite.destroyCache(PERSON_CACHE);
  117. ignite.destroyCache(ORG_CACHE);
  118. }
  119. print("Cache query example finished.");
  120. }
  121. }
  122. private static void scanQuery() {
  123. IgniteCache<BinaryObject, BinaryObject> cache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE).withKeepBinary();
  124. ScanQuery<BinaryObject, BinaryObject> scan = new ScanQuery<>(
  125. new IgniteBiPredicate<BinaryObject, BinaryObject>() {
  126. @Override public boolean apply(BinaryObject key, BinaryObject person) {
  127. return person.<Double>field("salary") <= 1000;
  128. }
  129. }
  130. );
  131. // Execute queries for salary ranges.
  132. print("People with salaries between 0 and 1000 (queried with SCAN query)[withKeepBinary]: ", cache.query(scan).getAll());
  133. }
  134. /**
  135. * Example for SQL queries based on salary ranges.
  136. */
  137. private static void sqlQuery() {
  138. IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
  139. // SQL clause which selects salaries based on range.
  140. String sql = "salary > ? and salary <= ?";
  141. // Execute queries for salary ranges.
  142. print("People with salaries between 0 and 1000 (queried with SQL query): ",
  143. cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, sql).
  144. setArgs(0, 1000)).getAll());
  145. print("People with salaries between 1000 and 2000 (queried with SQL query): ",
  146. cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, sql).
  147. setArgs(1000, 2000)).getAll());
  148. }
  149. /**
  150. * Example for SQL queries based on all employees working for a specific organization.
  151. */
  152. private static void sqlQueryWithJoin() {
  153. IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
  154. // SQL clause query which joins on 2 types to select people for a specific organization.
  155. String joinSql =
  156. "from Person, \"" + ORG_CACHE + "\".Organization as org " +
  157. "where Person.orgId = org.id " +
  158. "and lower(org.name) = lower(?)";
  159. // Execute queries for find employees for different organizations.
  160. print("Following people are 'ApacheIgnite' employees: ",
  161. cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, joinSql).
  162. setArgs("ApacheIgnite")).getAll());
  163. print("Following people are 'Other' employees: ",
  164. cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, joinSql).
  165. setArgs("Other")).getAll());
  166. }
  167. /**
  168. * Example for SQL queries based on all employees working for a specific organization (query uses distributed join).
  169. */
  170. private static void sqlQueryWithDistributedJoin() {
  171. IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
  172. // SQL clause query which joins on 2 types to select people for a specific organization.
  173. String joinSql =
  174. "from Person, \"" + ORG_CACHE + "\".Organization as org " +
  175. "where Person.orgId = org.id " +
  176. "and lower(org.name) = lower(?)";
  177. SqlQuery qry = new SqlQuery<AffinityKey<Long>, Person>(Person.class, joinSql).
  178. setArgs("ApacheIgnite");
  179. // Enable distributed joins for query.
  180. qry.setDistributedJoins(true);
  181. // Execute queries for find employees for different organizations.
  182. print("Following people are 'ApacheIgnite' employees (distributed join): ", cache.query(qry).getAll());
  183. qry.setArgs("Other");
  184. print("Following people are 'Other' employees (distributed join): ", cache.query(qry).getAll());
  185. }
  186. /**
  187. * Example for TEXT queries using LUCENE-based indexing of people's resumes.
  188. */
  189. private static void textQuery() {
  190. IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
  191. // Query for all people with "Master Degree" in their resumes.
  192. QueryCursor<Cache.Entry<AffinityKey<Long>, Person>> masters =
  193. cache.query(new TextQuery<AffinityKey<Long>, Person>(Person.class, "Master"));
  194. // Query for all people with "Bachelor Degree" in their resumes.
  195. QueryCursor<Cache.Entry<AffinityKey<Long>, Person>> bachelors =
  196. cache.query(new TextQuery<AffinityKey<Long>, Person>(Person.class, "Bachelor"));
  197. print("Following people have 'Master Degree' in their resumes: ", masters.getAll());
  198. print("Following people have 'Bachelor Degree' in their resumes: ", bachelors.getAll());
  199. }
  200. /**
  201. * Example for SQL queries to calculate average salary for a specific organization.
  202. */
  203. private static void sqlQueryWithAggregation() {
  204. IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
  205. // Calculate average of salary of all persons in ApacheIgnite.
  206. // Note that we also join on Organization cache as well.
  207. String sql =
  208. "select avg(salary) " +
  209. "from Person, \"" + ORG_CACHE + "\".Organization as org " +
  210. "where Person.orgId = org.id " +
  211. "and lower(org.name) = lower(?)";
  212. QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(sql).setArgs("ApacheIgnite"));
  213. // Calculate average salary for a specific organization.
  214. print("Average salary for 'ApacheIgnite' employees: ", cursor.getAll());
  215. }
  216. /**
  217. * Example for SQL-based fields queries that return only required
  218. * fields instead of whole key-value pairs.
  219. */
  220. private static void sqlFieldsQuery() {
  221. IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
  222. // Execute query to get names of all employees.
  223. QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(
  224. "select concat(firstName, ' ', lastName) from Person"));
  225. // In this particular case each row will have one element with full name of an employees.
  226. List<List<?>> res = cursor.getAll();
  227. // Print names.
  228. print("Names of all employees:", res);
  229. }
  230. /**
  231. * Example for SQL-based fields queries that return only required
  232. * fields instead of whole key-value pairs.
  233. */
  234. private static void sqlFieldsQueryWithJoin() {
  235. IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
  236. // Execute query to get names of all employees.
  237. String sql =
  238. "select concat(firstName, ' ', lastName), org.name " +
  239. "from Person, \"" + ORG_CACHE + "\".Organization as org " +
  240. "where Person.orgId = org.id";
  241. QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(sql));
  242. // In this particular case each row will have one element with full name of an employees.
  243. List<List<?>> res = cursor.getAll();
  244. // Print persons' names and organizations' names.
  245. print("Names of all employees and organizations they belong to: ", res);
  246. }
  247. /**
  248. * Populate cache with test data.
  249. */
  250. private static void initialize() {
  251. IgniteCache<Long, Organization> orgCache = Ignition.ignite().cache(ORG_CACHE);
  252. // Clear cache before running the example.
  253. orgCache.clear();
  254. // Organizations.
  255. Organization org1 = new Organization("ApacheIgnite");
  256. Organization org2 = new Organization("Other");
  257. orgCache.put(org1.id(), org1);
  258. orgCache.put(org2.id(), org2);
  259. IgniteCache<AffinityKey<Long>, Person> colPersonCache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
  260. IgniteCache<Long, Person> personCache = Ignition.ignite().cache(PERSON_CACHE);
  261. // Clear caches before running the example.
  262. colPersonCache.clear();
  263. personCache.clear();
  264. // People.
  265. Person p1 = new Person(org1, "John", "Doe", 2000, "John Doe has Master Degree.");
  266. Person p2 = new Person(org1, "Jane", "Doe", 800, "Jane Doe has Bachelor Degree.");
  267. Person p3 = new Person(org2, "John", "Smith", 900, "John Smith has Bachelor Degree.");
  268. Person p4 = new Person(org2, "Jane", "Smith", 2000, "Jane Smith has Master Degree.");
  269. // Note that in this example we use custom affinity key for Person objects
  270. // to ensure that all persons are collocated with their organizations.
  271. colPersonCache.put(p1.key(), p1);
  272. colPersonCache.put(p2.key(), p2);
  273. colPersonCache.put(p3.key(), p3);
  274. colPersonCache.put(p4.key(), p4);
  275. // These Person objects are not collocated with their organizations.
  276. personCache.put(p1.id, p1);
  277. personCache.put(p2.id, p2);
  278. personCache.put(p3.id, p3);
  279. personCache.put(p4.id, p4);
  280. }
  281. /**
  282. * Prints message and query results.
  283. *
  284. * @param msg Message to print before all objects are printed.
  285. * @param col Query results.
  286. */
  287. private static void print(String msg, Iterable<?> col) {
  288. print(msg);
  289. print(col);
  290. }
  291. /**
  292. * Prints message.
  293. *
  294. * @param msg Message to print before all objects are printed.
  295. */
  296. private static void print(String msg) {
  297. System.out.println();
  298. System.out.println(">>> " + msg);
  299. }
  300. /**
  301. * Prints query results.
  302. *
  303. * @param col Query results.
  304. */
  305. private static void print(Iterable<?> col) {
  306. for (Object next : col)
  307. System.out.println(">>> " + next);
  308. }
  309. }

2016-12-07补充下:今天为技术分享会做准备的时候,对一些参数进行测试,其中就有调整过部署模式,调整为PRIVATE,当时是测试分布式计算,计算字符串中所有单词的长度。当部署模式是SHARED的时候没问题,更改为PRIVATE的时候日志中有一行提示,
Deployment mode for cache is not CONTINUOUS or SHARED (it is recommended that you change deployment mode and restart): PRIVATE
意思是对于缓存来说,部署模式仅仅支持CONTINUOUS和SHARED.我当时的配置文件中的确有缓存相关的配置,虽然我测试中没有使用缓存,它还是依然给我提示了。如下为配置文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:util="http://www.springframework.org/schema/util"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xsi:schemaLocation="
  7. http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/util
  10. http://www.springframework.org/schema/util/spring-util.xsd
  11. http://www.springframework.org/schema/context
  12. http://www.springframework.org/schema/context/spring-context.xsd">
  13. <context:annotation-config/>
  14. <context:component-scan base-package="com.github.aloxc.ignite.datagrid.store"/>
  15. <!-- Datasource for sample in-memory H2 database. -->
  16. <bean id="h2-example-db" class="org.h2.jdbcx.JdbcDataSource">
  17. <property name="URL" value="jdbc:h2:tcp://localhost/mem:ExampleDb" />
  18. <property name="user" value="sa" />
  19. </bean>
  20. <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="tybbs_user_datasource">
  21. <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
  22. <property name="url" value="jdbc:mysql://192.168.20.185:3306/user"></property>
  23. <property name="username" value="testtyDB"></property>
  24. <property name="password" value="wfjmL2vF"></property>
  25. </bean>
  26. <bean id="cacheOnlyStoreFactoryExampleUsingMysql" class="com.github.aloxc.ignite.datagrid.store.CacheOnlyStoreFactoryExampleUsingMysql">
  27. <property name="dataSource" ref="tybbs_user_datasource"></property>
  28. </bean>
  29. <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
  30. <property name="peerClassLoadingEnabled" value="true"/>
  31. <property name="clientMode" value="false"/>
  32. <property name="deploymentMode" value="PRIVATE"/>
  33. <property name="marshaller">
  34. <bean class="org.apache.ignite.internal.binary.BinaryMarshaller"/>
  35. </property>
  36. <property name="cacheConfiguration" >
  37. <list>
  38. <bean class="org.apache.ignite.configuration.CacheConfiguration">
  39. <property name="cacheMode" value="PARTITIONED"/>
  40. <property name="writeThrough" value="true"/>
  41. <property name="readThrough" value="true" />
  42. <property name="name" value="cacheOnlyUsingMysql"/>
  43. <property name="backups" value="1"/>
  44. <property name="writeBehindEnabled" value="true" />
  45. <property name="writeBehindFlushSize" value="3" />
  46. <property name="writeBehindFlushFrequency" value="0" />
  47. <property name="writeBehindBatchSize" value="10" />
  48. <property name="cacheStoreFactory">
  49. <bean class="javax.cache.configuration.FactoryBuilder.SingletonFactory">
  50. <constructor-arg ref="cacheOnlyStoreFactoryExampleUsingMysql" />
  51. </bean>
  52. </property>
  53. <property name="queryEntities">
  54. <util:list>
  55. <bean class="org.apache.ignite.cache.QueryEntity">
  56. <property name="keyType" value="java.lang.Long"/>
  57. <property name="valueType" value="com.github.aloxc.ignite.model.Person"/>
  58. <property name="fields">
  59. <map>
  60. <entry key="id" value="java.lang.Long"/>
  61. <entry key="first_name" value="java.lang.String"/>
  62. <entry key="last_name" value="java.lang.String"/>
  63. </map>
  64. </property>
  65. <property name="indexes">
  66. <list>
  67. <bean class="org.apache.ignite.cache.QueryIndex">
  68. <constructor-arg name="field" value="id" />
  69. </bean>
  70. <bean class="org.apache.ignite.cache.QueryIndex">
  71. <constructor-arg name="field" value="first_name" />
  72. </bean>
  73. </list>
  74. </property>
  75. </bean>
  76. </util:list>
  77. </property>
  78. </bean>
  79. </list>
  80. </property>
  81. </bean>
  82. </beans>

作者[@aloxc]

x

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注