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();

    推薦閱讀