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_DISTRIBUTED_PERSISTENT_STORAGE_BLOCK_H_ 18 #define MINDSPORE_CCSRC_DISTRIBUTED_PERSISTENT_STORAGE_BLOCK_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "distributed/persistent/storage/json_utils.h" 24 #include "nlohmann/json.hpp" 25 26 namespace mindspore { 27 namespace distributed { 28 namespace storage { 29 // Using json to store and get meta info of a block, the content of meta info can be customized, 30 // such as shard shape, shard range, field length, etc. 31 using BlockMeta = JsonUtils; 32 33 // Class Block corresponds to the block file, saves the path of the block file, 34 // and provides block file integrity verification. 35 class Block { 36 public: Block(const std::string & block_name)37 explicit Block(const std::string &block_name) : block_file_name_(block_name) {} 38 ~Block() = default; 39 40 // The following two methods are used to file integrity check. 41 // Generate sha256 hash sequence. 42 void GenSha256Seq() const; 43 44 // Check sha256 hash sequence. 45 bool CheckSha256Seq() const; 46 47 // Set the block meta pointer associated with the block file. set_block_meta(const std::shared_ptr<BlockMeta> & block_meta)48 void set_block_meta(const std::shared_ptr<BlockMeta> &block_meta) { block_meta_ = block_meta; } 49 50 // Get block meta file path. block_file_name()51 const std::string &block_file_name() const { return block_file_name_; } 52 53 private: 54 // The block meta information corresponding to the block. 55 std::shared_ptr<BlockMeta> block_meta_; 56 // The block file path. 57 std::string block_file_name_; 58 }; 59 } // namespace storage 60 } // namespace distributed 61 } // namespace mindspore 62 63 #endif // MINDSPORE_CCSRC_DISTRIBUTED_PERSISTENT_STORAGE_BLOCK_H_ 64