You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

block.h 2.2 kB

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