/**
   * 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);
  }
  /** {@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;
  }
  /**
   * Executes example.
   *
   * @param args Command line arguments, none required.
   */
  public static void main(String[] args) {
    try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
      System.out.println();
      System.out.println(">>> Portable objects cache put-get example started.");

      CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>();

      cfg.setCacheMode(CacheMode.PARTITIONED);
      cfg.setName(CACHE_NAME);
      cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);

      try (IgniteCache<Integer, Organization> cache = ignite.createCache(cfg)) {
        if (ignite.cluster().forDataNodes(cache.getName()).nodes().isEmpty()) {
          System.out.println();
          System.out.println(">>> This example requires remote cache node nodes to be started.");
          System.out.println(">>> Please start at least 1 remote cache node.");
          System.out.println(">>> Refer to example's javadoc for details on configuration.");
          System.out.println();

          return;
        }

        putGet(cache);
        putGetPortable(cache);
        putGetAll(cache);
        putGetAllPortable(cache);

        System.out.println();
      } finally {
        // Delete cache with its content completely.
        ignite.destroyCache(CACHE_NAME);
      }
    }
  }
  /** {@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;
  }
Пример #5
0
  /**
   * <code>initiate</code> starts the operations of this system handler. All excecution code for the
   * plugins is expected to begin at this point.
   *
   * @throws UnRetriableException
   */
  @Override
  public void initiate() throws UnRetriableException {

    // Initiate the session reset manager.
    SessionResetManager sessionResetManager = new SessionResetManager();
    sessionResetManager.setWorker(this);
    sessionResetManager.setDatastore(this.getDatastore());
    setSessionResetManager(sessionResetManager);

    String igniteCacheName = "dumbTester";

    CacheConfiguration clCfg = new CacheConfiguration();

    clCfg.setName(igniteCacheName);
    clCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    clCfg.setCacheMode(CacheMode.PARTITIONED);
    clCfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);

    LruEvictionPolicy lruEvictionPolicy = new LruEvictionPolicy(5170000);
    clCfg.setEvictionPolicy(lruEvictionPolicy);

    clCfg.setSwapEnabled(true);

    // if(subscriptions instanceof  IgniteCache) {
    // subscriptions = getIgnite().createCache(clCfg);
    // }

    // Initiate unirest properties.
    Unirest.setTimeouts(5000, 5000);
  }
  /** {@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;
  }
  /**
   * @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);

    CacheConfiguration atomicCacheCfg = cacheConfiguration0();

    atomicCacheCfg.setName(CACHE_ATOMIC);
    atomicCacheCfg.setAtomicityMode(ATOMIC);
    atomicCacheCfg.setAtomicWriteOrderMode(PRIMARY);

    CacheConfiguration atomicOffheapCacheCfg = offheapCacheConfiguration0();

    atomicOffheapCacheCfg.setName(CACHE_ATOMIC_OFFHEAP);
    atomicOffheapCacheCfg.setAtomicityMode(ATOMIC);
    atomicOffheapCacheCfg.setAtomicWriteOrderMode(PRIMARY);

    CacheConfiguration atomicOffheapTieredCacheCfg = offheapTieredCacheConfiguration();

    atomicOffheapTieredCacheCfg.setName(CACHE_ATOMIC_OFFHEAP_TIERED);
    atomicOffheapTieredCacheCfg.setAtomicityMode(ATOMIC);
    atomicOffheapTieredCacheCfg.setAtomicWriteOrderMode(PRIMARY);

    c.setCacheConfiguration(
        cacheConfiguration(),
        offheapCacheConfiguration(),
        offheapTieredCacheConfiguration(),
        atomicCacheCfg,
        atomicOffheapCacheCfg,
        atomicOffheapTieredCacheCfg);

    c.setSwapSpaceSpi(new FileSwapSpaceSpi());

    c.setPeerClassLoadingEnabled(peerClassLoading());

    return c;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    assert gridName != null;

    IgniteConfiguration cfg = super.getConfiguration(gridName);

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(discoSpi);

    if (gridName.contains("cache")) {
      String cacheName = "test-checkpoints";

      CacheConfiguration cacheCfg = defaultCacheConfiguration();

      cacheCfg.setName(cacheName);
      cacheCfg.setWriteSynchronizationMode(FULL_SYNC);

      CacheCheckpointSpi spi = new CacheCheckpointSpi();

      spi.setCacheName(cacheName);

      cfg.setCacheConfiguration(cacheCfg);

      cfg.setCheckpointSpi(spi);
    } else if (gridName.contains("jdbc")) {
      JdbcCheckpointSpi spi = new JdbcCheckpointSpi();

      jdbcDataSource ds = new jdbcDataSource();

      ds.setDatabase("jdbc:hsqldb:mem:gg_test_" + getClass().getSimpleName());
      ds.setUser("sa");
      ds.setPassword("");

      spi.setDataSource(ds);
      spi.setCheckpointTableName("test_checkpoints");
      spi.setKeyFieldName("key");
      spi.setValueFieldName("value");
      spi.setValueFieldType("longvarbinary");
      spi.setExpireDateFieldName("expire_date");

      cfg.setCheckpointSpi(spi);
    }

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

    TcpDiscoverySpi spi = new TcpDiscoverySpi();

    spi.setIpFinder(ipFinder);

    c.setDiscoverySpi(spi);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setName("test");
    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setNearConfiguration(null);

    c.setCacheConfiguration(cc);

    return c;
  }