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.cc 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "distributed/persistent/storage/block.h"
  17. #include "utils/system/sha256.h"
  18. #include "utils/log_adapter.h"
  19. #include "utils/utils.h"
  20. namespace mindspore {
  21. namespace distributed {
  22. namespace storage {
  23. void Block::GenSha256Seq() const {
  24. std::string sha256_cal = system::sha256::GetHashFromFile(block_file_name_);
  25. MS_EXCEPTION_IF_NULL(block_meta_);
  26. block_meta_->Insert(kHashSeq, sha256_cal);
  27. }
  28. bool Block::CheckSha256Seq() const {
  29. MS_EXCEPTION_IF_NULL(block_meta_);
  30. std::string sha256_gen = block_meta_->Get<std::string>(kHashSeq);
  31. if (sha256_gen != system::sha256::GetHashFromFile(block_file_name_)) {
  32. MS_LOG(ERROR) << "The block file has been modified, file name: " << block_file_name_;
  33. return false;
  34. }
  35. return true;
  36. }
  37. } // namespace storage
  38. } // namespace distributed
  39. } // namespace mindspore