作者: 韩晨旭 10225101440 李畅 10225102463
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

99 рядки
3.5 KiB

Release 1.18 Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue #143 * issue #198 * issue #249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue #243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue #166 * issue #241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue #201)
10 роки тому
  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. // A Cache is an interface that maps keys to values. It has internal
  6. // synchronization and may be safely accessed concurrently from
  7. // multiple threads. It may automatically evict entries to make room
  8. // for new entries. Values have a specified charge against the cache
  9. // capacity. For example, a cache where the values are variable
  10. // length strings, may use the length of the string as the charge for
  11. // the string.
  12. //
  13. // A builtin cache implementation with a least-recently-used eviction
  14. // policy is provided. Clients may use their own implementations if
  15. // they want something more sophisticated (like scan-resistance, a
  16. // custom eviction policy, variable cache sizing, etc.)
  17. #ifndef STORAGE_LEVELDB_INCLUDE_CACHE_H_
  18. #define STORAGE_LEVELDB_INCLUDE_CACHE_H_
  19. #include <stdint.h>
  20. #include "leveldb/slice.h"
  21. namespace leveldb {
  22. class Cache;
  23. // Create a new cache with a fixed size capacity. This implementation
  24. // of Cache uses a least-recently-used eviction policy.
  25. extern Cache* NewLRUCache(size_t capacity);
  26. class Cache {
  27. public:
  28. Cache() { }
  29. // Destroys all existing entries by calling the "deleter"
  30. // function that was passed to the constructor.
  31. virtual ~Cache();
  32. // Opaque handle to an entry stored in the cache.
  33. struct Handle { };
  34. // Insert a mapping from key->value into the cache and assign it
  35. // the specified charge against the total cache capacity.
  36. //
  37. // Returns a handle that corresponds to the mapping. The caller
  38. // must call this->Release(handle) when the returned mapping is no
  39. // longer needed.
  40. //
  41. // When the inserted entry is no longer needed, the key and
  42. // value will be passed to "deleter".
  43. virtual Handle* Insert(const Slice& key, void* value, size_t charge,
  44. void (*deleter)(const Slice& key, void* value)) = 0;
  45. // If the cache has no mapping for "key", returns NULL.
  46. //
  47. // Else return a handle that corresponds to the mapping. The caller
  48. // must call this->Release(handle) when the returned mapping is no
  49. // longer needed.
  50. virtual Handle* Lookup(const Slice& key) = 0;
  51. // Release a mapping returned by a previous Lookup().
  52. // REQUIRES: handle must not have been released yet.
  53. // REQUIRES: handle must have been returned by a method on *this.
  54. virtual void Release(Handle* handle) = 0;
  55. // Return the value encapsulated in a handle returned by a
  56. // successful Lookup().
  57. // REQUIRES: handle must not have been released yet.
  58. // REQUIRES: handle must have been returned by a method on *this.
  59. virtual void* Value(Handle* handle) = 0;
  60. // If the cache contains entry for key, erase it. Note that the
  61. // underlying entry will be kept around until all existing handles
  62. // to it have been released.
  63. virtual void Erase(const Slice& key) = 0;
  64. // Return a new numeric id. May be used by multiple clients who are
  65. // sharing the same cache to partition the key space. Typically the
  66. // client will allocate a new id at startup and prepend the id to
  67. // its cache keys.
  68. virtual uint64_t NewId() = 0;
  69. private:
  70. void LRU_Remove(Handle* e);
  71. void LRU_Append(Handle* e);
  72. void Unref(Handle* e);
  73. struct Rep;
  74. Rep* rep_;
  75. // No copying allowed
  76. Cache(const Cache&);
  77. void operator=(const Cache&);
  78. };
  79. } // namespace leveldb
  80. #endif // STORAGE_LEVELDB_INCLUDE_CACHE_H_