Ignite实战( 三 )

  • 不允许并发还原操作 。因此,如果一个操作已经开始 , 则只有在第一个操作完成后才能启动另一个操作 。
  • 以下代码片段演示了如何从快照恢复单个缓存组 。
    // Restore cache named "snapshot-cache" from the snapshot "snapshot_02092020".ignite.snapshot().restoreSnapshot("snapshot_02092020", Collections.singleton("snapshot-cache")).get();3.使用 CLI 控制还原操作该control.sh|bat脚本提供了启动和停止恢复操作的能力 。
    # Start restoring all user-created cache groups from the snapshot "snapshot_09062021" in the background.control.(sh|bat) --snapshot restore snapshot_09062021 --start# Start restoring all user-created cache groups from the snapshot "snapshot_09062021" and wait for the entire operation to complete.control.(sh|bat) --snapshot restore snapshot_09062021 --start --sync# Start restoring all user-created cache groups from the snapshot "snapshot_09062021" located in the "/tmp/ignite/snapshots" folder (the full path to the snapshot files should be /tmp/ignite/snapshots/snapshot_09062021):control.(sh|bat) --snapshot restore snapshot_09062021 --src /tmp/ignite/snapshots# Start restoring only "cache-group1" and "cache-group2" from the snapshot "snapshot_09062021" in the background.control.(sh|bat) --snapshot restore snapshot_09062021 --start --groups cache-group1,cache-group2# Cancel the restore operation for "snapshot_09062021".control.(sh|bat) --snapshot restore snapshot_09062021 --cancel2.4.5 一致性保证在集群范围内的并发操作以及与 Ignite 的持续更改方面,所有快照都是完全一致的 。持久化数据、索引、模式、二进制元数据、编组器和节点上的其他文件 。
    集群范围的快照一致性是通过触发Partition-Map-Exchange 过程来实现的 。通过这样做,集群最终将到达所有先前启动的事务都完成并暂停新事务的时间点 。一旦发生这种情况 , 集群将启动快照创建过程 。PME 过程确保快照包括处于一致状态的主备份和备份 。
    Ignite Persistence 文件与其快照副本之间的一致性是通过将原始文件复制到目标快照目录并跟踪所有并发正在进行的更改来实现的 。跟踪更改可能需要 Ignite Persistence 存储介质上的额外空间(最多为存储介质的 1 倍大?。?。
    2.5 分布式计算Ignite 提供了一个 API,用于以平衡和容错的方式在集群节点之间分配计算 。您可以提交单个任务以供执行,也可以通过自动任务拆分来实现 MapReduce 模式 。API 提供对作业分配策略的细粒度控制 。
    2.5.1 获取计算接口运行分布式计算的主要入口点是计算接口,它可以从Ignite.
    Ignite ignite = Ignition.start();IgniteCompute compute = ignite.compute();2.5.2 指定计算的节点集计算接口的每个实例都与执行任务的一组节点相关联 。不带参数调用时,ignite.compute()返回与所有服务器节点关联的计算接口 。要获取特定节点子集的实例,请使用Ignite.compute(ClusterGroup group). 在以下示例中 , 计算接口仅绑定到远程节点,即除运行此代码的节点之外的所有节点 。
    Ignite ignite = Ignition.start();IgniteCompute compute = ignite.compute(ignite.cluster().forRemotes());2.5.3 执行任务Ignite 提供了三个接口,可以实现代表一个任务并通过计算接口执行:
    • IgniteRunnable— 其扩展java.lang.Runnable可用于实现没有输入参数且不返回结果的计算 。
    • IgniteCallablejava.util.concurrent.Callable—返回特定值的扩展 。
    • IgniteClosure— 接受参数并返回值的功能接口 。
    您可以执行一次任务(在其中一个节点上)或将其广播到所有节点 。
    2.5.4 执行一个可运行的任务要执行可运行的任务,请使用run(…?)计算接口的方法 。任务被发送到与计算实例关联的节点之一 。
    IgniteCompute compute = ignite.compute();// Iterate through all words and print// each word on a different cluster node.for (String word : "Print words on different cluster nodes".split(" ")) {compute.run(() -> System.out.println(word));}2.5.5 执行可调用任务要执行可调用任务,请使用call(…?)计算接口的方法 。
    Collection<IgniteCallable<Integer>> calls = new ArrayList<>();// Iterate through all words in the sentence and create callable jobs.for (String word : "How many characters".split(" "))calls.add(word::length);// Execute the collection of callables on the cluster.Collection<Integer> res = ignite.compute().call(calls);// Add all the word lengths received from cluster nodes.int total = res.stream().mapToInt(Integer::intValue).sum();2.5.6 执行IgniteClosure要执行IgniteClosure,请使用apply(…?)计算接口的方法 。该方法接受任务和任务的输入参数 。IgniteClosure参数在执行时传递给给定的 。
    IgniteCompute compute = ignite.compute();// Execute closure on all cluster nodes.Collection<Integer> res = compute.apply(String::length, Arrays.asList("How many characters".split(" ")));// Add all the word lengths received from cluster nodes.int total = res.stream().mapToInt(Integer::intValue).sum();

    推荐阅读