1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_PS_CORE_RECOVERY_BASE_H_ 18 #define MINDSPORE_CCSRC_PS_CORE_RECOVERY_BASE_H_ 19 20 #include <cstdlib> 21 #include <iostream> 22 #include <memory> 23 #include <string> 24 #include <vector> 25 #include <mutex> 26 #include "include/backend/distributed/ps/constants.h" 27 #include "utils/log_adapter.h" 28 #include "ps/core/file_configuration.h" 29 #include "include/backend/distributed/ps/ps_context.h" 30 31 namespace mindspore { 32 namespace ps { 33 namespace core { 34 enum class StorageType : int { kFileStorage = 1 }; 35 // RecoveryBase is used to parse configuration items related to recovery. 36 // It is the base class of SchedulerRecovery and NodeRecovery. 37 class RecoveryBase { 38 public: RecoveryBase()39 RecoveryBase() : recovery_storage_(nullptr), storage_type_(StorageType::kFileStorage) {} 40 41 virtual ~RecoveryBase() = default; 42 43 // Initialize the recovery configuration item and get the storage type of recovery. 44 virtual bool Initialize(const std::string &json_config); 45 46 // Initialize the recovery configuration item and get the storage type of recovery. 47 virtual bool InitializeNodes(const std::string &json_config); 48 49 // The node needs to recover metadata information when it starts. 50 virtual bool Recover() = 0; 51 52 // Persist metadata to storage. 53 virtual void Persist(const core::ClusterConfig &clusterConfig); 54 55 // Persist metadata to storage. 56 virtual void PersistNodesInfo(const core::ClusterConfig &clusterConfig); 57 58 protected: 59 // Persistent storage used to save metadata. 60 std::unique_ptr<Configuration> recovery_storage_; 61 62 // Persistent storage used to save server nodes metadata. 63 std::unique_ptr<Configuration> scheduler_recovery_storage_; 64 65 // Storage type for recovery,Currently only supports storage of file types 66 StorageType storage_type_; 67 68 std::mutex recovery_mtx_; 69 }; 70 } // namespace core 71 } // namespace ps 72 } // namespace mindspore 73 #endif // MINDSPORE_CCSRC_PS_CORE_RECOVERY_BASE_H_ 74