LevelDB project 1 10225501460 林子骥 10211900416 郭夏辉
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 line
2.0 KiB

1 月之前
  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. // Thread-safe (provides internal synchronization)
  6. #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_
  7. #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_
  8. #include <cstdint>
  9. #include <string>
  10. #include "db/dbformat.h"
  11. #include "leveldb/cache.h"
  12. #include "leveldb/table.h"
  13. #include "port/port.h"
  14. namespace leveldb {
  15. class Env;
  16. class TableCache {
  17. public:
  18. TableCache(const std::string& dbname, const Options& options, int entries);
  19. TableCache(const TableCache&) = delete;
  20. TableCache& operator=(const TableCache&) = delete;
  21. ~TableCache();
  22. // Return an iterator for the specified file number (the corresponding
  23. // file length must be exactly "file_size" bytes). If "tableptr" is
  24. // non-null, also sets "*tableptr" to point to the Table object
  25. // underlying the returned iterator, or to nullptr if no Table object
  26. // underlies the returned iterator. The returned "*tableptr" object is owned
  27. // by the cache and should not be deleted, and is valid for as long as the
  28. // returned iterator is live.
  29. Iterator* NewIterator(const ReadOptions& options, uint64_t file_number,
  30. uint64_t file_size, Table** tableptr = nullptr);
  31. // If a seek to internal key "k" in specified file finds an entry,
  32. // call (*handle_result)(arg, found_key, found_value).
  33. Status Get(const ReadOptions& options, uint64_t file_number,
  34. uint64_t file_size, const Slice& k, void* arg,
  35. void (*handle_result)(void*, const Slice&, const Slice&));
  36. // Evict any entry for the specified file number
  37. void Evict(uint64_t file_number);
  38. private:
  39. Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**);
  40. Env* const env_;
  41. const std::string dbname_;
  42. const Options& options_;
  43. Cache* cache_;
  44. };
  45. } // namespace leveldb
  46. #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_