leveldb
Classes | Functions
leveldb::anonymous_namespace{dumpfile.cc} Namespace Reference

Classes

class  CorruptionReporter
 
class  WriteBatchItemPrinter
 

Functions

bool GuessType (const std::string &fname, FileType *type)
 
Status PrintLogContents (Env *env, const std::string &fname, void(*func)(uint64_t, Slice, WritableFile *), WritableFile *dst)
 
static void WriteBatchPrinter (uint64_t pos, Slice record, WritableFile *dst)
 
Status DumpLog (Env *env, const std::string &fname, WritableFile *dst)
 
static void VersionEditPrinter (uint64_t pos, Slice record, WritableFile *dst)
 
Status DumpDescriptor (Env *env, const std::string &fname, WritableFile *dst)
 
Status DumpTable (Env *env, const std::string &fname, WritableFile *dst)
 

Function Documentation

§ DumpDescriptor()

Status leveldb::anonymous_namespace{dumpfile.cc}::DumpDescriptor ( Env env,
const std::string &  fname,
WritableFile dst 
)

Definition at line 139 of file dumpfile.cc.

139  {
140  return PrintLogContents(env, fname, VersionEditPrinter, dst);
141 }
Status PrintLogContents(Env *env, const std::string &fname, void(*func)(uint64_t, Slice, WritableFile *), WritableFile *dst)
Definition: dumpfile.cc:50
static void VersionEditPrinter(uint64_t pos, Slice record, WritableFile *dst)
Definition: dumpfile.cc:124
Here is the call graph for this function:
Here is the caller graph for this function:

§ DumpLog()

Status leveldb::anonymous_namespace{dumpfile.cc}::DumpLog ( Env env,
const std::string &  fname,
WritableFile dst 
)

Definition at line 118 of file dumpfile.cc.

118  {
119  return PrintLogContents(env, fname, WriteBatchPrinter, dst);
120 }
static void WriteBatchPrinter(uint64_t pos, Slice record, WritableFile *dst)
Definition: dumpfile.cc:93
Status PrintLogContents(Env *env, const std::string &fname, void(*func)(uint64_t, Slice, WritableFile *), WritableFile *dst)
Definition: dumpfile.cc:50
Here is the call graph for this function:
Here is the caller graph for this function:

§ DumpTable()

Status leveldb::anonymous_namespace{dumpfile.cc}::DumpTable ( Env env,
const std::string &  fname,
WritableFile dst 
)

Definition at line 143 of file dumpfile.cc.

143  {
144  uint64_t file_size;
145  RandomAccessFile* file = NULL;
146  Table* table = NULL;
147  Status s = env->GetFileSize(fname, &file_size);
148  if (s.ok()) {
149  s = env->NewRandomAccessFile(fname, &file);
150  }
151  if (s.ok()) {
152  // We use the default comparator, which may or may not match the
153  // comparator used in this database. However this should not cause
154  // problems since we only use Table operations that do not require
155  // any comparisons. In particular, we do not call Seek or Prev.
156  s = Table::Open(Options(), file, file_size, &table);
157  }
158  if (!s.ok()) {
159  delete table;
160  delete file;
161  return s;
162  }
163 
164  ReadOptions ro;
165  ro.fill_cache = false;
166  Iterator* iter = table->NewIterator(ro);
167  std::string r;
168  for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
169  r.clear();
170  ParsedInternalKey key;
171  if (!ParseInternalKey(iter->key(), &key)) {
172  r = "badkey '";
173  AppendEscapedStringTo(&r, iter->key());
174  r += "' => '";
175  AppendEscapedStringTo(&r, iter->value());
176  r += "'\n";
177  dst->Append(r);
178  } else {
179  r = "'";
180  AppendEscapedStringTo(&r, key.user_key);
181  r += "' @ ";
182  AppendNumberTo(&r, key.sequence);
183  r += " : ";
184  if (key.type == kTypeDeletion) {
185  r += "del";
186  } else if (key.type == kTypeValue) {
187  r += "val";
188  } else {
189  AppendNumberTo(&r, key.type);
190  }
191  r += " => '";
192  AppendEscapedStringTo(&r, iter->value());
193  r += "'\n";
194  dst->Append(r);
195  }
196  }
197  s = iter->status();
198  if (!s.ok()) {
199  dst->Append("iterator error: " + s.ToString() + "\n");
200  }
201 
202  delete iter;
203  delete table;
204  delete file;
205  return Status::OK();
206 }
bool ParseInternalKey(const Slice &internal_key, ParsedInternalKey *result)
Definition: dbformat.h:176
void AppendNumberTo(std::string *str, uint64_t num)
Definition: logging.cc:16
void AppendEscapedStringTo(std::string *str, const Slice &value)
Definition: logging.cc:22
Here is the call graph for this function:
Here is the caller graph for this function:

§ GuessType()

bool leveldb::anonymous_namespace{dumpfile.cc}::GuessType ( const std::string &  fname,
FileType type 
)

Definition at line 23 of file dumpfile.cc.

23  {
24  size_t pos = fname.rfind('/');
25  std::string basename;
26  if (pos == std::string::npos) {
27  basename = fname;
28  } else {
29  basename = std::string(fname.data() + pos + 1, fname.size() - pos - 1);
30  }
31  uint64_t ignored;
32  return ParseFileName(basename, &ignored, type);
33 }
bool ParseFileName(const std::string &fname, uint64_t *number, FileType *type)
Definition: filename.cc:80
Here is the call graph for this function:
Here is the caller graph for this function:

§ PrintLogContents()

Status leveldb::anonymous_namespace{dumpfile.cc}::PrintLogContents ( Env env,
const std::string &  fname,
void(*)(uint64_t, Slice, WritableFile *)  func,
WritableFile dst 
)

Definition at line 50 of file dumpfile.cc.

52  {
53  SequentialFile* file;
54  Status s = env->NewSequentialFile(fname, &file);
55  if (!s.ok()) {
56  return s;
57  }
58  CorruptionReporter reporter;
59  reporter.dst_ = dst;
60  log::Reader reader(file, &reporter, true, 0);
61  Slice record;
62  std::string scratch;
63  while (reader.ReadRecord(&record, &scratch)) {
64  (*func)(reader.LastRecordOffset(), record, dst);
65  }
66  delete file;
67  return Status::OK();
68 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ VersionEditPrinter()

static void leveldb::anonymous_namespace{dumpfile.cc}::VersionEditPrinter ( uint64_t  pos,
Slice  record,
WritableFile dst 
)
static

Definition at line 124 of file dumpfile.cc.

124  {
125  std::string r = "--- offset ";
126  AppendNumberTo(&r, pos);
127  r += "; ";
128  VersionEdit edit;
129  Status s = edit.DecodeFrom(record);
130  if (!s.ok()) {
131  r += s.ToString();
132  r.push_back('\n');
133  } else {
134  r += edit.DebugString();
135  }
136  dst->Append(r);
137 }
void AppendNumberTo(std::string *str, uint64_t num)
Definition: logging.cc:16
Here is the call graph for this function:
Here is the caller graph for this function:

§ WriteBatchPrinter()

static void leveldb::anonymous_namespace{dumpfile.cc}::WriteBatchPrinter ( uint64_t  pos,
Slice  record,
WritableFile dst 
)
static

Definition at line 93 of file dumpfile.cc.

93  {
94  std::string r = "--- offset ";
95  AppendNumberTo(&r, pos);
96  r += "; ";
97  if (record.size() < 12) {
98  r += "log record length ";
99  AppendNumberTo(&r, record.size());
100  r += " is too small\n";
101  dst->Append(r);
102  return;
103  }
104  WriteBatch batch;
105  WriteBatchInternal::SetContents(&batch, record);
106  r += "sequence ";
107  AppendNumberTo(&r, WriteBatchInternal::Sequence(&batch));
108  r.push_back('\n');
109  dst->Append(r);
110  WriteBatchItemPrinter batch_item_printer;
111  batch_item_printer.dst_ = dst;
112  Status s = batch.Iterate(&batch_item_printer);
113  if (!s.ok()) {
114  dst->Append(" error: " + s.ToString() + "\n");
115  }
116 }
void AppendNumberTo(std::string *str, uint64_t num)
Definition: logging.cc:16
Here is the call graph for this function:
Here is the caller graph for this function: