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