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.
5 #ifndef STORAGE_LEVELDB_INCLUDE_OPTIONS_H_
6 #define STORAGE_LEVELDB_INCLUDE_OPTIONS_H_
19 // DB contents are stored in a set of blocks, each of which holds a
20 // sequence of key,value pairs. Each block may be compressed before
21 // being stored in a file. The following enum describes which
22 // compression method (if any) is used to compress a block.
23 enum CompressionType
{
24 // NOTE: do not change the values of existing entries, as these are
25 // part of the persistent format on disk.
27 kSnappyCompression
= 0x1
30 // Options to control the behavior of a database (passed to DB::Open)
32 // -------------------
33 // Parameters that affect behavior
35 // Comparator used to define the order of keys in the table.
36 // Default: a comparator that uses lexicographic byte-wise ordering
38 // REQUIRES: The client must ensure that the comparator supplied
39 // here has the same name and orders keys *exactly* the same as the
40 // comparator provided to previous open calls on the same DB.
41 const Comparator
* comparator
;
43 // If true, the database will be created if it is missing.
45 bool create_if_missing
;
47 // If true, an error is raised if the database already exists.
51 // If true, the implementation will do aggressive checking of the
52 // data it is processing and will stop early if it detects any
53 // errors. This may have unforeseen ramifications: for example, a
54 // corruption of one DB entry may cause a large number of entries to
55 // become unreadable or for the entire DB to become unopenable.
59 // Use the specified object to interact with the environment,
60 // e.g. to read/write files, schedule background work, etc.
61 // Default: Env::Default()
64 // Any internal progress/error information generated by the db will
65 // be written to info_log if it is non-NULL, or to a file stored
66 // in the same directory as the DB contents if info_log is NULL.
70 // -------------------
71 // Parameters that affect performance
73 // Amount of data to build up in memory (backed by an unsorted log
74 // on disk) before converting to a sorted on-disk file.
76 // Larger values increase performance, especially during bulk loads.
77 // Up to two write buffers may be held in memory at the same time,
78 // so you may wish to adjust this parameter to control memory usage.
79 // Also, a larger write buffer will result in a longer recovery time
80 // the next time the database is opened.
83 size_t write_buffer_size
;
85 // Number of open files that can be used by the DB. You may need to
86 // increase this if your database has a large working set (budget
87 // one open file per 2MB of working set).
92 // Control over blocks (user data is stored in a set of blocks, and
93 // a block is the unit of reading from disk).
95 // If non-NULL, use the specified cache for blocks.
96 // If NULL, leveldb will automatically create and use an 8MB internal cache.
100 // Approximate size of user data packed per block. Note that the
101 // block size specified here corresponds to uncompressed data. The
102 // actual size of the unit read from disk may be smaller if
103 // compression is enabled. This parameter can be changed dynamically.
108 // Number of keys between restart points for delta encoding of keys.
109 // This parameter can be changed dynamically. Most clients should
110 // leave this parameter alone.
113 int block_restart_interval
;
115 // Leveldb will write up to this amount of bytes to a file before
116 // switching to a new one.
117 // Most clients should leave this parameter alone. However if your
118 // filesystem is more efficient with larger files, you could
119 // consider increasing the value. The downside will be longer
120 // compactions and hence longer latency/performance hiccups.
121 // Another reason to increase this parameter might be when you are
122 // initially populating a large database.
125 size_t max_file_size
;
127 // Compress blocks using the specified compression algorithm. This
128 // parameter can be changed dynamically.
130 // Default: kSnappyCompression, which gives lightweight but fast
133 // Typical speeds of kSnappyCompression on an Intel(R) Core(TM)2 2.4GHz:
134 // ~200-500MB/s compression
135 // ~400-800MB/s decompression
136 // Note that these speeds are significantly faster than most
137 // persistent storage speeds, and therefore it is typically never
138 // worth switching to kNoCompression. Even if the input data is
139 // incompressible, the kSnappyCompression implementation will
140 // efficiently detect that and will switch to uncompressed mode.
141 CompressionType compression
;
143 // EXPERIMENTAL: If true, append to existing MANIFEST and log files
144 // when a database is opened. This can significantly speed up open.
146 // Default: currently false, but may become true later.
149 // If non-NULL, use the specified filter policy to reduce disk reads.
150 // Many applications will benefit from passing the result of
151 // NewBloomFilterPolicy() here.
154 const FilterPolicy
* filter_policy
;
156 // Create an Options object with default values for all fields.
160 // Options that control read operations
162 // If true, all data read from underlying storage will be
163 // verified against corresponding checksums.
165 bool verify_checksums
;
167 // Should the data read for this iteration be cached in memory?
168 // Callers may wish to set this field to false for bulk scans.
172 // If "snapshot" is non-NULL, read as of the supplied snapshot
173 // (which must belong to the DB that is being read and which must
174 // not have been released). If "snapshot" is NULL, use an implicit
175 // snapshot of the state at the beginning of this read operation.
177 const Snapshot
* snapshot
;
180 : verify_checksums(false),
186 // Options that control write operations
187 struct WriteOptions
{
188 // If true, the write will be flushed from the operating system
189 // buffer cache (by calling WritableFile::Sync()) before the write
190 // is considered complete. If this flag is true, writes will be
193 // If this flag is false, and the machine crashes, some recent
194 // writes may be lost. Note that if it is just the process that
195 // crashes (i.e., the machine does not reboot), no writes will be
196 // lost even if sync==false.
198 // In other words, a DB write with sync==false has similar
199 // crash semantics as the "write()" system call. A DB write
200 // with sync==true has similar crash semantics to a "write()"
201 // system call followed by "fsync()".
211 } // namespace leveldb
213 #endif // STORAGE_LEVELDB_INCLUDE_OPTIONS_H_