write_buffer_mock.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #include <map>
  19. #include <mutex>
  20. #include <string>
  21. #include "codec_impl.h"
  22. #include "search_store.pb.h"
  23. #include "write_buffer.h"
  24. namespace wwsearch {
  25. class WriteBufferMock : public WriteBuffer {
  26. private:
  27. uint64_t kv_cnt_{0};
  28. uint32_t total_size_{0};
  29. using KvList =
  30. std::map<std::string, std::pair<std::string, lsmsearch::MockData_Type>>;
  31. std::map<StorageColumnType, KvList> cf_kv_list_;
  32. using DeleteKeyRangeList = std::set<std::pair<std::string, std::string>>;
  33. std::map<StorageColumnType, DeleteKeyRangeList> cf_delete_keyrange_list_;
  34. CodecImpl* codec_;
  35. std::string data_;
  36. std::mutex mut_;
  37. public:
  38. // constructor
  39. WriteBufferMock(CodecImpl* codec, const std::string& data);
  40. WriteBufferMock(CodecImpl* codec) : codec_(codec) {}
  41. virtual ~WriteBufferMock() {}
  42. // Put
  43. virtual SearchStatus Put(StorageColumnType column, const std::string& key,
  44. const std::string& value) override;
  45. // Delete
  46. virtual SearchStatus Delete(StorageColumnType column,
  47. const std::string& key) override;
  48. // DeleteRange in db
  49. virtual SearchStatus DeleteRange(StorageColumnType column,
  50. const std::string& begin_key,
  51. const std::string& end_key) override;
  52. // Merge
  53. virtual SearchStatus Merge(StorageColumnType column, const std::string& key,
  54. const std::string& value) override;
  55. // Append WriteBuffer to db
  56. virtual SearchStatus Append(
  57. WriteBuffer* prepare_append_write_buffer) override;
  58. // Return Current data
  59. virtual std::string Data() override;
  60. // Return byte size of used.
  61. virtual uint64_t DataSize() const override;
  62. // Return k/v number in db.
  63. virtual uint64_t KvCount() const override;
  64. private:
  65. // Inner serialize api
  66. SearchStatus SeriableData();
  67. SearchStatus DeSeriableData();
  68. };
  69. } // namespace wwsearch