作者: 韩晨旭 10225101440 李畅 10225102463
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. //
  5. // WriteBatch holds a collection of updates to apply atomically to a DB.
  6. //
  7. // The updates are applied in the order in which they are added
  8. // to the WriteBatch. For example, the value of "key" will be "v3"
  9. // after the following batch is written:
  10. //
  11. // batch.Put("key", "v1");
  12. // batch.Delete("key");
  13. // batch.Put("key", "v2");
  14. // batch.Put("key", "v3");
  15. //
  16. // Multiple threads can invoke const methods on a WriteBatch without
  17. // external synchronization, but if any of the threads may call a
  18. // non-const method, all threads accessing the same WriteBatch must use
  19. // external synchronization.
  20. #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
  21. #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
  22. #include <string>
  23. #include "leveldb/export.h"
  24. #include "leveldb/status.h"
  25. namespace leveldb {
  26. class Slice;
  27. class LEVELDB_EXPORT WriteBatch {
  28. public:
  29. WriteBatch();
  30. ~WriteBatch();
  31. // Store the mapping "key->value" in the database.
  32. void Put(const Slice& key, const Slice& value);
  33. // If the database contains a mapping for "key", erase it. Else do nothing.
  34. void Delete(const Slice& key);
  35. // Clear all updates buffered in this batch.
  36. void Clear();
  37. // The size of the database changes caused by this batch.
  38. //
  39. // This number is tied to implementation details, and may change across
  40. // releases. It is intended for LevelDB usage metrics.
  41. size_t ApproximateSize();
  42. // Support for iterating over the contents of a batch.
  43. class Handler {
  44. public:
  45. virtual ~Handler();
  46. virtual void Put(const Slice& key, const Slice& value) = 0;
  47. virtual void Delete(const Slice& key) = 0;
  48. };
  49. Status Iterate(Handler* handler) const;
  50. private:
  51. friend class WriteBatchInternal;
  52. std::string rep_; // See comment in write_batch.cc for the format of rep_
  53. // Intentionally copyable
  54. };
  55. } // namespace leveldb
  56. #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_