10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

203 lignes
6.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_OPTIONS_H_
  5. #define STORAGE_LEVELDB_INCLUDE_OPTIONS_H_
  6. #include <stddef.h>
  7. namespace leveldb {
  8. class Cache;
  9. class Comparator;
  10. class Env;
  11. class Snapshot;
  12. class WritableFile;
  13. // DB contents are stored in a set of blocks, each of which holds a
  14. // sequence of key,value pairs. Each block may be compressed before
  15. // being stored in a file. The following enum describes which
  16. // compression method (if any) is used to compress a block.
  17. enum CompressionType {
  18. // NOTE: do not change the values of existing entries, as these are
  19. // part of the persistent format on disk.
  20. kNoCompression = 0x0,
  21. kLightweightCompression = 0x1,
  22. };
  23. // Options to control the behavior of a database (passed to DB::Open)
  24. struct Options {
  25. // -------------------
  26. // Parameters that affect behavior
  27. // Comparator used to define the order of keys in the table.
  28. // Default: a comparator that uses lexicographic byte-wise ordering
  29. //
  30. // REQUIRES: The client must ensure that the comparator supplied
  31. // here has the same name and orders keys *exactly* the same as the
  32. // comparator provided to previous open calls on the same DB.
  33. const Comparator* comparator;
  34. // If true, the database will be created if it is missing.
  35. // Default: false
  36. bool create_if_missing;
  37. // If true, an error is raised if the database already exists.
  38. // Default: false
  39. bool error_if_exists;
  40. // If true, the implementation will do aggressive checking of the
  41. // data it is processing and will stop early if it detects any
  42. // errors. This may have unforeseen ramifications: for example, a
  43. // corruption of one DB entry may cause a large number of entries to
  44. // become unreadable or for the entire DB to become unopenable.
  45. // Default: false
  46. bool paranoid_checks;
  47. // Use the specified object to interact with the environment,
  48. // e.g. to read/write files, schedule background work, etc.
  49. // Default: Env::Default()
  50. Env* env;
  51. // Any internal progress/error information generated by the db will
  52. // be to written to info_log if it is non-NULL, or to a file stored
  53. // in the same directory as the DB contents if info_log is NULL.
  54. // Default: NULL
  55. WritableFile* info_log;
  56. // -------------------
  57. // Parameters that affect performance
  58. // Amount of data to build up in memory before converting to an
  59. // on-disk file.
  60. //
  61. // Some DB operations may encounter a delay proportional to the size
  62. // of this parameter. Therefore we recommend against increasing
  63. // this parameter unless you are willing to live with an occasional
  64. // slow operation in exchange for faster bulk loading throughput.
  65. //
  66. // Default: 1MB
  67. size_t write_buffer_size;
  68. // Number of open files that can be used by the DB. You may need to
  69. // increase this if your database has a large working set (budget
  70. // one open file per 2MB of working set).
  71. //
  72. // Default: 1000
  73. int max_open_files;
  74. // Handle values larger than "large_value_threshold" bytes
  75. // specially, by writing them into their own files (to avoid
  76. // compaction overhead) and doing content-based elimination of
  77. // duplicate values to save space.
  78. //
  79. // We recommend against changing this value.
  80. //
  81. // Default: 64K
  82. size_t large_value_threshold;
  83. // Control over blocks (user data is stored in a set of blocks, and
  84. // a block is the unit of reading from disk).
  85. // Use the specified cache for blocks (if non-NULL).
  86. // Default: NULL
  87. Cache* block_cache;
  88. // Approximate size of user data packed per block. Note that the
  89. // block size specified here corresponds to uncompressed data. The
  90. // actual size of the unit read from disk may be smaller if
  91. // compression is enabled. This parameter can be changed dynamically.
  92. //
  93. // Default: 8K
  94. int block_size;
  95. // Number of keys between restart points for delta encoding of keys.
  96. // This parameter can be changed dynamically. Most clients should
  97. // leave this parameter alone.
  98. //
  99. // Default: 16
  100. int block_restart_interval;
  101. // Compress blocks using the specified compression algorithm. This
  102. // parameter can be changed dynamically.
  103. //
  104. // Default: kLightweightCompression, which gives lightweight but fast
  105. // compression.
  106. //
  107. // Typical speeds of kLightweightCompression on an Intel(R) Core(TM)2 2.4GHz:
  108. // ~200-500MB/s compression
  109. // ~400-800MB/s decompression
  110. // Note that these speeds are significantly faster than most
  111. // persistent storage speeds, and therefore it is typically never
  112. // worth switching to kNoCompression. Even if the input data is
  113. // incompressible, the kLightweightCompression implementation will
  114. // efficiently detect that and will switch to uncompressed mode.
  115. CompressionType compression;
  116. // Create an Options object with default values for all fields.
  117. Options();
  118. };
  119. // Options that control read operations
  120. struct ReadOptions {
  121. // If true, all data read from underlying storage will be
  122. // verified against corresponding checksums.
  123. // Default: false
  124. bool verify_checksums;
  125. // Should the data read for this iteration be cached in memory?
  126. // Callers may wish to set this field to false for bulk scans.
  127. // Default: true
  128. bool fill_cache;
  129. // If "snapshot" is non-NULL, read as of the supplied snapshot
  130. // (which must belong to the DB that is being read and which must
  131. // not have been released). If "snapshot" is NULL, use an impliicit
  132. // snapshot of the state at the beginning of this read operation.
  133. // Default: NULL
  134. const Snapshot* snapshot;
  135. ReadOptions()
  136. : verify_checksums(false),
  137. fill_cache(true),
  138. snapshot(NULL) {
  139. }
  140. };
  141. // Options that control write operations
  142. struct WriteOptions {
  143. // If true, the write will be flushed from the operating system
  144. // buffer cache (by calling WritableFile::Sync()) before the write
  145. // is considered complete. If this flag is true, writes will be
  146. // slower.
  147. //
  148. // If this flag is false, and the machine crashes, some recent
  149. // writes may be lost. Note that if it is just the process that
  150. // crashes (i.e., the machine does not reboot), no writes will be
  151. // lost even if sync==false.
  152. //
  153. // Default: true
  154. bool sync;
  155. // If "post_write_snapshot" is non-NULL, and the write succeeds,
  156. // *post_write_snapshot will be modified to point to a snapshot of
  157. // the DB state immediately after this write. The caller must call
  158. // DB::ReleaseSnapshot(*post_write_snapshotsnapshot) when the
  159. // snapshot is no longer needed.
  160. //
  161. // If "post_write_snapshot" is non-NULL, and the write fails,
  162. // *post_write_snapshot will be set to NULL.
  163. //
  164. // Default: NULL
  165. const Snapshot** post_write_snapshot;
  166. WriteOptions()
  167. : sync(true),
  168. post_write_snapshot(NULL) {
  169. }
  170. };
  171. }
  172. #endif // STORAGE_LEVELDB_INCLUDE_OPTIONS_H_