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
#include "db/builder.h"
7
#include "db/filename.h"
8
#include "db/dbformat.h"
9
#include "db/table_cache.h"
10
#include "db/version_edit.h"
11
#include "leveldb/db.h"
12
#include "leveldb/env.h"
13
#include "leveldb/iterator.h"
17
Status BuildTable(const std::string& dbname,
19
const Options& options,
20
TableCache* table_cache,
27
std::string fname = TableFileName(dbname, meta->number);
30
s = env->NewWritableFile(fname, &file);
35
TableBuilder* builder = new TableBuilder(options, file);
36
meta->smallest.DecodeFrom(iter->key());
37
for (; iter->Valid(); iter->Next()) {
38
Slice key = iter->key();
39
meta->largest.DecodeFrom(key);
40
builder->Add(key, iter->value());
43
// Finish and check for builder errors
45
s = builder->Finish();
47
meta->file_size = builder->FileSize();
48
assert(meta->file_size > 0);
55
// Finish and check for file errors
66
// Verify that the table is usable
67
Iterator* it = table_cache->NewIterator(ReadOptions(),
75
// Check for input iterator errors
76
if (!iter->status().ok()) {
80
if (s.ok() && meta->file_size > 0) {
83
env->DeleteFile(fname);
88
} // namespace leveldb