2012-08-17 19:48:40 +02:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#include "db/version_set.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "db/filename.h"
|
|
|
|
#include "db/log_reader.h"
|
|
|
|
#include "db/log_writer.h"
|
|
|
|
#include "db/memtable.h"
|
|
|
|
#include "db/table_cache.h"
|
|
|
|
#include "leveldb/env.h"
|
|
|
|
#include "leveldb/table_builder.h"
|
|
|
|
#include "table/merger.h"
|
|
|
|
#include "table/two_level_iterator.h"
|
|
|
|
#include "util/coding.h"
|
|
|
|
#include "util/logging.h"
|
2013-03-15 01:00:04 +01:00
|
|
|
#include "util/storage_options.h"
|
2012-08-17 19:48:40 +02:00
|
|
|
|
|
|
|
static int verbose = 0;
|
2012-12-21 08:12:29 +01:00
|
|
|
static int output_hex = 0;
|
2012-08-17 19:48:40 +02:00
|
|
|
|
|
|
|
using namespace leveldb;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Takes a manifest file and dumps out all metedata
|
|
|
|
//
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
// parse command line options
|
2012-08-29 21:29:43 +02:00
|
|
|
size_t n;
|
2012-08-17 19:48:40 +02:00
|
|
|
char junk;
|
2012-08-17 19:48:40 +02:00
|
|
|
int foundfile = 0;
|
|
|
|
std::string manifestfile;
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
std::string param(argv[i]);
|
|
|
|
if ((n = param.find("--file=")) != std::string::npos) {
|
|
|
|
manifestfile = param.substr(strlen("--file="));
|
|
|
|
foundfile = 1;
|
2012-09-12 18:54:22 +02:00
|
|
|
} else if (sscanf(argv[i], "--verbose=%ld%c", &n, &junk) == 1 &&
|
2012-08-17 19:48:40 +02:00
|
|
|
(n == 0 || n == 1)) {
|
|
|
|
verbose = n;
|
2012-12-21 08:12:29 +01:00
|
|
|
} else if (param == "--output_hex") {
|
|
|
|
output_hex = n;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown or badly-formatted option: %s\n",
|
|
|
|
argv[i]);
|
|
|
|
abort();
|
2012-08-17 19:48:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundfile) {
|
2012-12-21 08:12:29 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s [--verbose=0|1] [--output_hex] [--file=pathname of manifest file]\n",
|
|
|
|
argv[0]);
|
2012-08-17 19:48:40 +02:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
printf("Processing Manifest file %s\n", manifestfile.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
Options options;
|
2013-03-15 01:00:04 +01:00
|
|
|
StorageOptions sopt;
|
2012-08-17 19:48:40 +02:00
|
|
|
std::string file(manifestfile);
|
|
|
|
std::string dbname("dummy");
|
2013-03-15 01:00:04 +01:00
|
|
|
TableCache* tc = new TableCache(dbname, &options, sopt, 10);
|
2012-08-17 19:48:40 +02:00
|
|
|
const InternalKeyComparator* cmp = new InternalKeyComparator(options.comparator);
|
|
|
|
|
2013-03-15 01:00:04 +01:00
|
|
|
VersionSet* versions = new VersionSet(dbname, &options, sopt,
|
2012-08-17 19:48:40 +02:00
|
|
|
tc, cmp);
|
2012-12-21 08:12:29 +01:00
|
|
|
Status s = versions->DumpManifest(options, file, verbose, output_hex);
|
2012-08-17 19:48:40 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
printf("Error in processing file %s %s\n", manifestfile.c_str(),
|
|
|
|
s.ToString().c_str());
|
|
|
|
}
|
|
|
|
if (verbose) {
|
|
|
|
printf("Processing Manifest file %s done\n", manifestfile.c_str());
|
|
|
|
}
|
|
|
|
}
|