/** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration iCfg = super.getConfiguration(gridName);

    ((TcpDiscoverySpi) iCfg.getDiscoverySpi()).setIpFinder(ipFinder);
    ((TcpDiscoverySpi) iCfg.getDiscoverySpi()).setForceServerMode(true);

    if (getTestGridName(10).equals(gridName)) iCfg.setClientMode(true);

    CacheConfiguration<Integer, Integer> cachePCfg = new CacheConfiguration<>();

    cachePCfg.setName(CACHE_NAME_DHT_PARTITIONED);
    cachePCfg.setCacheMode(CacheMode.PARTITIONED);
    cachePCfg.setRebalanceMode(CacheRebalanceMode.SYNC);
    cachePCfg.setBackups(1);
    cachePCfg.setRebalanceBatchSize(1);
    cachePCfg.setRebalanceBatchesPrefetchCount(1);
    cachePCfg.setRebalanceOrder(2);

    CacheConfiguration<Integer, Integer> cachePCfg2 = new CacheConfiguration<>();

    cachePCfg2.setName(CACHE_NAME_DHT_PARTITIONED_2);
    cachePCfg2.setCacheMode(CacheMode.PARTITIONED);
    cachePCfg2.setRebalanceMode(CacheRebalanceMode.SYNC);
    cachePCfg2.setBackups(1);
    cachePCfg2.setRebalanceOrder(2);
    // cachePCfg2.setRebalanceDelay(5000);//Known issue, possible deadlock in case of low priority
    // cache rebalancing delayed.

    CacheConfiguration<Integer, Integer> cacheRCfg = new CacheConfiguration<>();

    cacheRCfg.setName(CACHE_NAME_DHT_REPLICATED);
    cacheRCfg.setCacheMode(CacheMode.REPLICATED);
    cacheRCfg.setRebalanceMode(CacheRebalanceMode.SYNC);
    cacheRCfg.setRebalanceBatchSize(1);
    cacheRCfg.setRebalanceBatchesPrefetchCount(Integer.MAX_VALUE);
    ((TcpCommunicationSpi) iCfg.getCommunicationSpi())
        .setSharedMemoryPort(-1); // Shmem fail fix for Integer.MAX_VALUE.

    CacheConfiguration<Integer, Integer> cacheRCfg2 = new CacheConfiguration<>();

    cacheRCfg2.setName(CACHE_NAME_DHT_REPLICATED_2);
    cacheRCfg2.setCacheMode(CacheMode.REPLICATED);
    cacheRCfg2.setRebalanceMode(CacheRebalanceMode.SYNC);
    cacheRCfg2.setRebalanceOrder(4);

    iCfg.setCacheConfiguration(cachePCfg, cachePCfg2, cacheRCfg, cacheRCfg2);

    iCfg.setRebalanceThreadPoolSize(2);

    return iCfg;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    assertNotNull(clientNodes);

    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);

    boolean client = false;

    for (Integer clientIdx : clientNodes) {
      if (getTestGridName(clientIdx).equals(gridName)) {
        client = true;

        break;
      }
    }

    cfg.setClientMode(client);

    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setBackups(0);
    ccfg.setRebalanceMode(SYNC);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
  }
  /** @throws Exception If failed. */
  public void testClientNodeNotInAffinity() throws Exception {
    checkCache(CACHE1, 2);

    checkCache(CACHE2, 2);

    checkCache(CACHE3, 2);

    checkCache(CACHE4, 3);

    checkCache(CACHE5, 2);

    Ignite client = ignite(NODE_CNT - 1);

    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setBackups(0);

    ccfg.setNodeFilter(new TestNodesFilter());

    IgniteCache<Integer, Integer> cache = client.createCache(ccfg);

    try {
      checkCache(null, 1);
    } finally {
      cache.destroy();
    }

    cache = client.createCache(ccfg, new NearCacheConfiguration());

    try {
      checkCache(null, 1);
    } finally {
      cache.destroy();
    }
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.getTransactionConfiguration().setTxSerializableEnabled(true);

    cfg.setDiscoverySpi(disco);

    BasicWarmupClosure warmupClosure = new BasicWarmupClosure();

    warmupClosure.setGridCount(2);
    warmupClosure.setIterationCount(10);
    warmupClosure.setKeyRange(10);

    cfg.setWarmupClosure(warmupClosure);

    CacheConfiguration<Integer, Integer> cacheCfg = new CacheConfiguration<>();

    cacheCfg.setCacheMode(CacheMode.PARTITIONED);
    cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    cacheCfg.setBackups(1);
    cacheCfg.setName("test");

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
  }
  /**
   * @param gridName Grid name.
   * @return Cache configuration.
   * @throws Exception In case of error.
   */
  @SuppressWarnings("unchecked")
  protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    CacheStore<?, ?> store = cacheStore();

    if (store != null) {
      cfg.setCacheStoreFactory(new TestStoreFactory());
      cfg.setReadThrough(true);
      cfg.setWriteThrough(true);
      cfg.setLoadPreviousValue(true);
    }

    cfg.setSwapEnabled(swapEnabled());
    cfg.setCacheMode(cacheMode());
    cfg.setAtomicityMode(atomicityMode());
    cfg.setWriteSynchronizationMode(writeSynchronization());
    cfg.setNearConfiguration(nearConfiguration());

    Class<?>[] idxTypes = indexedTypes();

    if (!F.isEmpty(idxTypes)) cfg.setIndexedTypes(idxTypes);

    if (cacheMode() == PARTITIONED) cfg.setBackups(1);

    return cfg;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);

    CacheConfiguration ccfg1 = new CacheConfiguration();

    ccfg1.setBackups(1);
    ccfg1.setName(CACHE1);
    ccfg1.setAffinity(new RendezvousAffinityFunction());
    ccfg1.setNodeFilter(new TestNodesFilter());

    CacheConfiguration ccfg2 = new CacheConfiguration();

    ccfg2.setBackups(1);
    ccfg2.setName(CACHE2);
    ccfg2.setAffinity(new RendezvousAffinityFunction());

    CacheConfiguration ccfg3 = new CacheConfiguration();

    ccfg3.setBackups(1);
    ccfg3.setName(CACHE3);
    ccfg3.setAffinity(new FairAffinityFunction());
    ccfg3.setNodeFilter(new TestNodesFilter());

    CacheConfiguration ccfg4 = new CacheConfiguration();

    ccfg4.setCacheMode(REPLICATED);
    ccfg4.setName(CACHE4);
    ccfg4.setNodeFilter(new TestNodesFilter());

    CacheConfiguration ccfg5 = new CacheConfiguration();

    ccfg5.setBackups(1);
    ccfg5.setName(CACHE5);

    if (gridName.equals(getTestGridName(NODE_CNT - 1))) {
      cfg.setClientMode(true);

      cfg.setCacheConfiguration(ccfg5);
    } else cfg.setCacheConfiguration(ccfg1, ccfg2, ccfg3, ccfg4);

    return cfg;
  }
Exemple #7
0
  /** Configure cacheEmployee. */
  private static <K, V> CacheConfiguration<K, V> cacheEmployee() {
    CacheConfiguration<K, V> ccfg = cacheConfiguration(EMPLOYEE_CACHE_NAME);

    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setBackups(1);

    // Configure cacheEmployee types.
    Collection<QueryEntity> qryEntities = new ArrayList<>();

    // EMPLOYEE.
    QueryEntity type = new QueryEntity();

    qryEntities.add(type);

    type.setKeyType(Integer.class.getName());
    type.setValueType(Employee.class.getName());

    // Query fields for EMPLOYEE.
    LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>();

    qryFlds.put("id", "java.lang.Integer");
    qryFlds.put("departmentId", "java.lang.Integer");
    qryFlds.put("managerId", "java.lang.Integer");
    qryFlds.put("firstName", "java.lang.String");
    qryFlds.put("lastName", "java.lang.String");
    qryFlds.put("email", "java.lang.String");
    qryFlds.put("phoneNumber", "java.lang.String");
    qryFlds.put("hireDate", "java.sql.Date");
    qryFlds.put("job", "java.lang.String");
    qryFlds.put("salary", "java.lang.Double");

    type.setFields(qryFlds);

    // Indexes for EMPLOYEE.
    Collection<QueryIndex> indexes = new ArrayList<>();

    QueryIndex idx = new QueryIndex();

    idx.setName("EMP_NAMES");
    idx.setIndexType(QueryIndexType.SORTED);
    LinkedHashMap<String, Boolean> indFlds = new LinkedHashMap<>();

    indFlds.put("firstName", Boolean.FALSE);
    indFlds.put("lastName", Boolean.FALSE);

    idx.setFields(indFlds);

    indexes.add(idx);
    indexes.add(new QueryIndex("salary", QueryIndexType.SORTED, false, "EMP_SALARY"));

    type.setIndexes(indexes);

    ccfg.setQueryEntities(qryEntities);

    return ccfg;
  }
  /**
   * @return Cache configuration.
   * @throws Exception In case of error.
   */
  protected CacheConfiguration cacheConfiguration() throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(PARTITIONED);
    cfg.setBackups(1);
    cfg.setWriteSynchronizationMode(FULL_SYNC);
    cfg.setRebalanceMode(SYNC);

    return cfg;
  }
  /**
   * Gets cache configuration.
   *
   * @return Cache configuration.
   */
  private CacheConfiguration cacheConfiguration() {
    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setBackups(1);
    cacheCfg.setWriteSynchronizationMode(FULL_SYNC);

    if (noNodesFilter) cacheCfg.setNodeFilter(F.alwaysFalse());

    return cacheCfg;
  }
  /**
   * Start grid with IGFS.
   *
   * @param gridName Grid name.
   * @param igfsName IGFS name
   * @param mode IGFS mode.
   * @param secondaryFs Secondary file system (optional).
   * @param restCfg Rest configuration string (optional).
   * @return Started grid instance.
   * @throws Exception If failed.
   */
  protected Ignite startGridWithIgfs(
      String gridName,
      String igfsName,
      IgfsMode mode,
      @Nullable IgfsSecondaryFileSystem secondaryFs,
      @Nullable IgfsIpcEndpointConfiguration restCfg)
      throws Exception {
    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setDataCacheName("dataCache");
    igfsCfg.setMetaCacheName("metaCache");
    igfsCfg.setName(igfsName);
    igfsCfg.setBlockSize(IGFS_BLOCK_SIZE);
    igfsCfg.setDefaultMode(mode);
    igfsCfg.setIpcEndpointConfiguration(restCfg);
    igfsCfg.setSecondaryFileSystem(secondaryFs);
    igfsCfg.setPrefetchBlocks(PREFETCH_BLOCKS);
    igfsCfg.setSequentialReadsBeforePrefetch(SEQ_READS_BEFORE_PREFETCH);

    CacheConfiguration dataCacheCfg = defaultCacheConfiguration();

    dataCacheCfg.setName("dataCache");
    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setNearConfiguration(null);
    dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(2));
    dataCacheCfg.setBackups(0);
    dataCacheCfg.setAtomicityMode(TRANSACTIONAL);
    dataCacheCfg.setOffHeapMaxMemory(0);

    CacheConfiguration metaCacheCfg = defaultCacheConfiguration();

    metaCacheCfg.setName("metaCache");
    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setGridName(gridName);

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);
    cfg.setCacheConfiguration(dataCacheCfg, metaCacheCfg);
    cfg.setFileSystemConfiguration(igfsCfg);

    cfg.setLocalHost("127.0.0.1");
    cfg.setConnectorConfiguration(null);

    return G.start(cfg);
  }
  /** @return Cache configuration. */
  protected CacheConfiguration cacheConfiguration() {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(PARTITIONED);
    cfg.setBackups(1);
    cfg.setNearConfiguration(nearConfiguration());
    cfg.setWriteSynchronizationMode(FULL_SYNC);
    cfg.setAtomicityMode(atomicityMode);

    return cfg;
  }
  /**
   * @param name Cache name.
   * @param cacheMode Cache mode.
   * @param parts Number of partitions.
   * @return Cache configuration.
   */
  private CacheConfiguration cacheConfiguration(String name, CacheMode cacheMode, int parts) {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName(name);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    if (cacheMode == PARTITIONED) ccfg.setBackups(1);

    ccfg.setAffinity(new RendezvousAffinityFunction(false, parts));

    return ccfg;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(gridName);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(ipFinder);

    c.setDiscoverySpi(disco);

    CacheConfiguration<?, ?> cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setBackups(1);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setIndexedTypes(Integer.class, Integer.class);

    c.setCacheConfiguration(cc);

    return c;
  }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    ((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);

    OptimizedMarshaller marsh = new OptimizedMarshaller();
    marsh.setRequireSerializable(false);

    cfg.setMarshaller(marsh);

    CacheConfiguration ccfg = defaultCacheConfiguration();
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
    ccfg.setNearConfiguration(null);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    CacheConfiguration<?, ?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setIndexedTypes(Integer.class, TestObject.class);

    cfg.setCacheConfiguration(cache);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(disco);

    cfg.setConnectorConfiguration(new ConnectorConfiguration());

    return cfg;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    TcpDiscoverySpi spi = new TcpDiscoverySpi();

    spi.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(spi);

    cfg.setIncludeProperties();

    cfg.setIncludeEventTypes(EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);

    cfg.setConnectorConfiguration(null);

    cfg.setPeerClassLoadingEnabled(true);

    if (useCache) {
      CacheConfiguration cc = defaultCacheConfiguration();

      cc.setCacheMode(PARTITIONED);

      cc.setNearConfiguration(null);
      cc.setWriteSynchronizationMode(FULL_SYNC);
      cc.setStartSize(ENTRY_CNT / GRID_CNT);
      cc.setSwapEnabled(false);

      cc.setBackups(1);

      cfg.setCacheSanityCheckEnabled(false);
      cfg.setCacheConfiguration(cc);
    } else cfg.setCacheConfiguration();

    return cfg;
  }