LCOV - code coverage report
Current view: top level - src/leveldb/db - builder.cc (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 41 48 85.4 %
Date: 2022-04-21 14:51:19 Functions: 1 1 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 11 20 55.0 %

           Branch data     Line data    Source code
#       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                 :            : #include "db/builder.h"
#       6                 :            : 
#       7                 :            : #include "db/dbformat.h"
#       8                 :            : #include "db/filename.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"
#      14                 :            : 
#      15                 :            : namespace leveldb {
#      16                 :            : 
#      17                 :            : Status BuildTable(const std::string& dbname, Env* env, const Options& options,
#      18                 :        969 :                   TableCache* table_cache, Iterator* iter, FileMetaData* meta) {
#      19                 :        969 :   Status s;
#      20                 :        969 :   meta->file_size = 0;
#      21                 :        969 :   iter->SeekToFirst();
#      22                 :            : 
#      23                 :        969 :   std::string fname = TableFileName(dbname, meta->number);
#      24         [ +  - ]:        969 :   if (iter->Valid()) {
#      25                 :        969 :     WritableFile* file;
#      26                 :        969 :     s = env->NewWritableFile(fname, &file);
#      27         [ -  + ]:        969 :     if (!s.ok()) {
#      28                 :          0 :       return s;
#      29                 :          0 :     }
#      30                 :            : 
#      31                 :        969 :     TableBuilder* builder = new TableBuilder(options, file);
#      32                 :        969 :     meta->smallest.DecodeFrom(iter->key());
#      33         [ +  + ]:     165407 :     for (; iter->Valid(); iter->Next()) {
#      34                 :     164438 :       Slice key = iter->key();
#      35                 :     164438 :       meta->largest.DecodeFrom(key);
#      36                 :     164438 :       builder->Add(key, iter->value());
#      37                 :     164438 :     }
#      38                 :            : 
#      39                 :            :     // Finish and check for builder errors
#      40                 :        969 :     s = builder->Finish();
#      41         [ +  - ]:        969 :     if (s.ok()) {
#      42                 :        969 :       meta->file_size = builder->FileSize();
#      43                 :        969 :       assert(meta->file_size > 0);
#      44                 :        969 :     }
#      45                 :          0 :     delete builder;
#      46                 :            : 
#      47                 :            :     // Finish and check for file errors
#      48         [ +  - ]:        969 :     if (s.ok()) {
#      49                 :        969 :       s = file->Sync();
#      50                 :        969 :     }
#      51         [ +  - ]:        969 :     if (s.ok()) {
#      52                 :        969 :       s = file->Close();
#      53                 :        969 :     }
#      54                 :        969 :     delete file;
#      55                 :        969 :     file = nullptr;
#      56                 :            : 
#      57         [ +  - ]:        969 :     if (s.ok()) {
#      58                 :            :       // Verify that the table is usable
#      59                 :        969 :       Iterator* it = table_cache->NewIterator(ReadOptions(), meta->number,
#      60                 :        969 :                                               meta->file_size);
#      61                 :        969 :       s = it->status();
#      62                 :        969 :       delete it;
#      63                 :        969 :     }
#      64                 :        969 :   }
#      65                 :            : 
#      66                 :            :   // Check for input iterator errors
#      67         [ -  + ]:        969 :   if (!iter->status().ok()) {
#      68                 :          0 :     s = iter->status();
#      69                 :          0 :   }
#      70                 :            : 
#      71 [ +  - ][ +  - ]:        969 :   if (s.ok() && meta->file_size > 0) {
#      72                 :            :     // Keep it
#      73                 :        969 :   } else {
#      74                 :          0 :     env->DeleteFile(fname);
#      75                 :          0 :   }
#      76                 :        969 :   return s;
#      77                 :        969 : }
#      78                 :            : 
#      79                 :            : }  // namespace leveldb

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a