• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 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_DISTRIBUTED_RECOVERY_CONFIGURATION_H_
18 #define MINDSPORE_CCSRC_DISTRIBUTED_RECOVERY_CONFIGURATION_H_
19 
20 #include <string>
21 
22 namespace mindspore {
23 namespace distributed {
24 namespace recovery {
25 // An abstract configuration class to store and recover key-value style metadata, which could be stored in a local file
26 // or other storages.
27 class Configuration {
28  public:
29   Configuration() = default;
30   virtual ~Configuration() = default;
31 
32   // These two methods should be implemented in sub-class to allocate and release resources owned by this configuration
33   // instance.
34   virtual bool Initialize() = 0;
Finalize()35   virtual bool Finalize() { return true; }
36 
37   // Get the configuration item value by the specified key, returns the default value if the key does not
38   // exist.
39   virtual std::string Get(const std::string &key, const std::string &defaultvalue) const = 0;
40 
41   // Persist the key-value pair metadata.
42   virtual void Put(const std::string &key, const std::string &value) = 0;
43 
44   // Check whether the specified configuration key exists.
45   virtual bool Exists(const std::string &key) const = 0;
46 
47   // Check whether the configuration contains any key-value pairs.
48   virtual bool Empty() const = 0;
49 
50   // Flush all the key-value pairs in memory into the specific sub-class's storage.
51   virtual bool Flush() = 0;
52 };
53 }  // namespace recovery
54 }  // namespace distributed
55 }  // namespace mindspore
56 #endif  // MINDSPORE_CCSRC_DISTRIBUTED_RECOVERY_CONFIGURATION_H_
57