Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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