作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

85 rindas
2.9 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. #ifndef STORAGE_LEVELDB_INCLUDE_TABLE_H_
  5. #define STORAGE_LEVELDB_INCLUDE_TABLE_H_
  6. #include <stdint.h>
  7. #include "leveldb/export.h"
  8. #include "leveldb/iterator.h"
  9. namespace leveldb {
  10. class Block;
  11. class BlockHandle;
  12. class Footer;
  13. struct Options;
  14. class RandomAccessFile;
  15. struct ReadOptions;
  16. class TableCache;
  17. // A Table is a sorted map from strings to strings. Tables are
  18. // immutable and persistent. A Table may be safely accessed from
  19. // multiple threads without external synchronization.
  20. class LEVELDB_EXPORT Table {
  21. public:
  22. // Attempt to open the table that is stored in bytes [0..file_size)
  23. // of "file", and read the metadata entries necessary to allow
  24. // retrieving data from the table.
  25. //
  26. // If successful, returns ok and sets "*table" to the newly opened
  27. // table. The client should delete "*table" when no longer needed.
  28. // If there was an error while initializing the table, sets "*table"
  29. // to nullptr and returns a non-ok status. Does not take ownership of
  30. // "*source", but the client must ensure that "source" remains live
  31. // for the duration of the returned table's lifetime.
  32. //
  33. // *file must remain live while this Table is in use.
  34. static Status Open(const Options& options,
  35. RandomAccessFile* file,
  36. uint64_t file_size,
  37. Table** table);
  38. Table(const Table&) = delete;
  39. void operator=(const Table&) = delete;
  40. ~Table();
  41. // Returns a new iterator over the table contents.
  42. // The result of NewIterator() is initially invalid (caller must
  43. // call one of the Seek methods on the iterator before using it).
  44. Iterator* NewIterator(const ReadOptions&) const;
  45. // Given a key, return an approximate byte offset in the file where
  46. // the data for that key begins (or would begin if the key were
  47. // present in the file). The returned value is in terms of file
  48. // bytes, and so includes effects like compression of the underlying data.
  49. // E.g., the approximate offset of the last key in the table will
  50. // be close to the file length.
  51. uint64_t ApproximateOffsetOf(const Slice& key) const;
  52. private:
  53. struct Rep;
  54. Rep* rep_;
  55. explicit Table(Rep* rep) { rep_ = rep; }
  56. static Iterator* BlockReader(void*, const ReadOptions&, const Slice&);
  57. // Calls (*handle_result)(arg, ...) with the entry found after a call
  58. // to Seek(key). May not make such a call if filter policy says
  59. // that key is not present.
  60. friend class TableCache;
  61. Status InternalGet(
  62. const ReadOptions&, const Slice& key,
  63. void* arg,
  64. void (*handle_result)(void* arg, const Slice& k, const Slice& v));
  65. void ReadMeta(const Footer& footer);
  66. void ReadFilter(const Slice& filter_handle_value);
  67. };
  68. } // namespace leveldb
  69. #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_