write_buffer_rocks.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #pragma once
  19. #include "write_buffer.h"
  20. #include "rocksdb/db.h"
  21. #include "rocksdb/options.h"
  22. #include "rocksdb/slice.h"
  23. #include "rocksdb/write_batch.h"
  24. namespace wwsearch {
  25. class WriteBufferRocksImpl : public WriteBuffer {
  26. private:
  27. rocksdb::WriteBatch* write_batch_;
  28. std::vector<rocksdb::ColumnFamilyHandle*>* column_family_;
  29. rocksdb::WriteOptions* write_options_;
  30. // std::atomic<uint64_t> kv_count_;
  31. public:
  32. WriteBufferRocksImpl(std::vector<rocksdb::ColumnFamilyHandle*>* column_family,
  33. rocksdb::WriteOptions* write_options,
  34. const std::string* write_buffer);
  35. WriteBufferRocksImpl(const WriteBufferRocksImpl& write_buffer_rocks_impl) {
  36. *this = write_buffer_rocks_impl;
  37. }
  38. WriteBufferRocksImpl& operator=(
  39. const WriteBufferRocksImpl& write_buffer_rocks_impl) {
  40. this->write_batch_ =
  41. new rocksdb::WriteBatch(*(write_buffer_rocks_impl.write_batch_));
  42. this->column_family_ = write_buffer_rocks_impl.column_family_;
  43. this->write_options_ = write_buffer_rocks_impl.write_options_;
  44. }
  45. virtual ~WriteBufferRocksImpl();
  46. virtual SearchStatus Put(StorageColumnType column, const std::string& key,
  47. const std::string& value) override;
  48. virtual SearchStatus Delete(StorageColumnType column,
  49. const std::string& key) override;
  50. virtual SearchStatus DeleteRange(StorageColumnType column,
  51. const std::string& begin_key,
  52. const std::string& end_key) override;
  53. virtual SearchStatus Merge(StorageColumnType column, const std::string& key,
  54. const std::string& value) override;
  55. virtual SearchStatus Append(WriteBuffer* prepare_append_write_buffer);
  56. virtual std::string Data() override;
  57. virtual uint64_t DataSize() const override;
  58. virtual uint64_t KvCount() const override;
  59. rocksdb::WriteBatch* GetWriteBatch();
  60. private:
  61. friend class VirtualDBRocksImpl;
  62. };
  63. } // namespace wwsearch