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.

storage_manager.h 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright 2019 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 DATASET_UTIL_STORAGE_MANAGER_H_
  17. #define DATASET_UTIL_STORAGE_MANAGER_H_
  18. #include <unistd.h>
  19. #include <memory>
  20. #include <string>
  21. #include <utility>
  22. #include <vector>
  23. #include "dataset/util/allocator.h"
  24. #include "dataset/util/auto_index.h"
  25. #include "dataset/util/lock.h"
  26. #include "dataset/util/memory_pool.h"
  27. #include "dataset/util/path.h"
  28. #include "dataset/util/service.h"
  29. #include "dataset/util/slice.h"
  30. #include "dataset/util/storage_container.h"
  31. using ListOfContainers = std::vector<std::shared_ptr<mindspore::dataset::StorageContainer>>;
  32. namespace mindspore {
  33. namespace dataset {
  34. class StorageManager : public Service {
  35. public:
  36. using storage_index = AutoIndexObj<std::pair<int, std::pair<off_t, size_t>>>;
  37. using key_type = storage_index::key_type;
  38. using value_type = storage_index::value_type;
  39. explicit StorageManager(const Path &);
  40. ~StorageManager() override;
  41. StorageManager(const StorageManager &) = delete;
  42. StorageManager &operator=(const StorageManager &) = delete;
  43. Status Write(key_type *out_key, const std::vector<ReadableSlice> &buf);
  44. Status Read(key_type key, WritableSlice *dest, size_t *bytesRead) const;
  45. Status DoServiceStart() override;
  46. Status DoServiceStop() noexcept override;
  47. friend std::ostream &operator<<(std::ostream &os, const StorageManager &s);
  48. private:
  49. Path root_;
  50. ListOfContainers containers_;
  51. int file_id_;
  52. RWLock rw_lock_;
  53. storage_index index_;
  54. std::string GetBaseName(const std::string &prefix, int32_t file_id);
  55. std::string ConstructFileName(const std::string &prefix, int32_t file_id, const std::string &suffix);
  56. Status AddOneContainer();
  57. };
  58. } // namespace dataset
  59. } // namespace mindspore
  60. #endif // DATASET_UTIL_STORAGE_MANAGER_H_