~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/leveldb/include/leveldb/db.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#ifndef STORAGE_LEVELDB_INCLUDE_DB_H_
6
 
#define STORAGE_LEVELDB_INCLUDE_DB_H_
7
 
 
8
 
#include <stdint.h>
9
 
#include <stdio.h>
10
 
#include "leveldb/iterator.h"
11
 
#include "leveldb/options.h"
12
 
 
13
 
namespace leveldb {
14
 
 
15
 
static const int kMajorVersion = 1;
16
 
static const int kMinorVersion = 2;
17
 
 
18
 
struct Options;
19
 
struct ReadOptions;
20
 
struct WriteOptions;
21
 
class WriteBatch;
22
 
 
23
 
// Abstract handle to particular state of a DB.
24
 
// A Snapshot is an immutable object and can therefore be safely
25
 
// accessed from multiple threads without any external synchronization.
26
 
class Snapshot {
27
 
 protected:
28
 
  virtual ~Snapshot();
29
 
};
30
 
 
31
 
// A range of keys
32
 
struct Range {
33
 
  Slice start;          // Included in the range
34
 
  Slice limit;          // Not included in the range
35
 
 
36
 
  Range() { }
37
 
  Range(const Slice& s, const Slice& l) : start(s), limit(l) { }
38
 
};
39
 
 
40
 
// A DB is a persistent ordered map from keys to values.
41
 
// A DB is safe for concurrent access from multiple threads without
42
 
// any external synchronization.
43
 
class DB {
44
 
 public:
45
 
  // Open the database with the specified "name".
46
 
  // Stores a pointer to a heap-allocated database in *dbptr and returns
47
 
  // OK on success.
48
 
  // Stores NULL in *dbptr and returns a non-OK status on error.
49
 
  // Caller should delete *dbptr when it is no longer needed.
50
 
  static Status Open(const Options& options,
51
 
                     const std::string& name,
52
 
                     DB** dbptr);
53
 
 
54
 
  DB() { }
55
 
  virtual ~DB();
56
 
 
57
 
  // Set the database entry for "key" to "value".  Returns OK on success,
58
 
  // and a non-OK status on error.
59
 
  // Note: consider setting options.sync = true.
60
 
  virtual Status Put(const WriteOptions& options,
61
 
                     const Slice& key,
62
 
                     const Slice& value) = 0;
63
 
 
64
 
  // Remove the database entry (if any) for "key".  Returns OK on
65
 
  // success, and a non-OK status on error.  It is not an error if "key"
66
 
  // did not exist in the database.
67
 
  // Note: consider setting options.sync = true.
68
 
  virtual Status Delete(const WriteOptions& options, const Slice& key) = 0;
69
 
 
70
 
  // Apply the specified updates to the database.
71
 
  // Returns OK on success, non-OK on failure.
72
 
  // Note: consider setting options.sync = true.
73
 
  virtual Status Write(const WriteOptions& options, WriteBatch* updates) = 0;
74
 
 
75
 
  // If the database contains an entry for "key" store the
76
 
  // corresponding value in *value and return OK.
77
 
  //
78
 
  // If there is no entry for "key" leave *value unchanged and return
79
 
  // a status for which Status::IsNotFound() returns true.
80
 
  //
81
 
  // May return some other Status on an error.
82
 
  virtual Status Get(const ReadOptions& options,
83
 
                     const Slice& key, std::string* value) = 0;
84
 
 
85
 
  // Return a heap-allocated iterator over the contents of the database.
86
 
  // The result of NewIterator() is initially invalid (caller must
87
 
  // call one of the Seek methods on the iterator before using it).
88
 
  //
89
 
  // Caller should delete the iterator when it is no longer needed.
90
 
  // The returned iterator should be deleted before this db is deleted.
91
 
  virtual Iterator* NewIterator(const ReadOptions& options) = 0;
92
 
 
93
 
  // Return a handle to the current DB state.  Iterators created with
94
 
  // this handle will all observe a stable snapshot of the current DB
95
 
  // state.  The caller must call ReleaseSnapshot(result) when the
96
 
  // snapshot is no longer needed.
97
 
  virtual const Snapshot* GetSnapshot() = 0;
98
 
 
99
 
  // Release a previously acquired snapshot.  The caller must not
100
 
  // use "snapshot" after this call.
101
 
  virtual void ReleaseSnapshot(const Snapshot* snapshot) = 0;
102
 
 
103
 
  // DB implementations can export properties about their state
104
 
  // via this method.  If "property" is a valid property understood by this
105
 
  // DB implementation, fills "*value" with its current value and returns
106
 
  // true.  Otherwise returns false.
107
 
  //
108
 
  //
109
 
  // Valid property names include:
110
 
  //
111
 
  //  "leveldb.num-files-at-level<N>" - return the number of files at level <N>,
112
 
  //     where <N> is an ASCII representation of a level number (e.g. "0").
113
 
  //  "leveldb.stats" - returns a multi-line string that describes statistics
114
 
  //     about the internal operation of the DB.
115
 
  //  "leveldb.sstables" - returns a multi-line string that describes all
116
 
  //     of the sstables that make up the db contents.
117
 
  virtual bool GetProperty(const Slice& property, std::string* value) = 0;
118
 
 
119
 
  // For each i in [0,n-1], store in "sizes[i]", the approximate
120
 
  // file system space used by keys in "[range[i].start .. range[i].limit)".
121
 
  //
122
 
  // Note that the returned sizes measure file system space usage, so
123
 
  // if the user data compresses by a factor of ten, the returned
124
 
  // sizes will be one-tenth the size of the corresponding user data size.
125
 
  //
126
 
  // The results may not include the sizes of recently written data.
127
 
  virtual void GetApproximateSizes(const Range* range, int n,
128
 
                                   uint64_t* sizes) = 0;
129
 
 
130
 
  // Compact the underlying storage for the key range [*begin,*end].
131
 
  // In particular, deleted and overwritten versions are discarded,
132
 
  // and the data is rearranged to reduce the cost of operations
133
 
  // needed to access the data.  This operation should typically only
134
 
  // be invoked by users who understand the underlying implementation.
135
 
  //
136
 
  // begin==NULL is treated as a key before all keys in the database.
137
 
  // end==NULL is treated as a key after all keys in the database.
138
 
  // Therefore the following call will compact the entire database:
139
 
  //    db->CompactRange(NULL, NULL);
140
 
  virtual void CompactRange(const Slice* begin, const Slice* end) = 0;
141
 
 
142
 
 private:
143
 
  // No copying allowed
144
 
  DB(const DB&);
145
 
  void operator=(const DB&);
146
 
};
147
 
 
148
 
// Destroy the contents of the specified database.
149
 
// Be very careful using this method.
150
 
Status DestroyDB(const std::string& name, const Options& options);
151
 
 
152
 
// If a DB cannot be opened, you may attempt to call this method to
153
 
// resurrect as much of the contents of the database as possible.
154
 
// Some data may be lost, so be careful when calling this function
155
 
// on a database that contains important information.
156
 
Status RepairDB(const std::string& dbname, const Options& options);
157
 
 
158
 
}  // namespace leveldb
159
 
 
160
 
#endif  // STORAGE_LEVELDB_INCLUDE_DB_H_