LCOV - code coverage report
Current view: top level - home/snapwebsites/snapcpp/snapwebsites/snapdatabase/snapdatabase/file - file_snap_database_table.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 25 72.0 %
Date: 2019-12-15 17:13:15 Functions: 8 11 72.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2019  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snapdatabase
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software; you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation; either version 2 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License along
      17             : // with this program; if not, write to the Free Software Foundation, Inc.,
      18             : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             : 
      20             : 
      21             : /** \file
      22             :  * \brief Database file implementation.
      23             :  *
      24             :  * Each table uses one or more files. Each file is handled by a dbfile
      25             :  * object and a corresponding set of blocks.
      26             :  */
      27             : 
      28             : // self
      29             : //
      30             : #include    "snapdatabase/file/file_snap_database_table.h"
      31             : 
      32             : #include    "snapdatabase/block/block_header.h"
      33             : 
      34             : 
      35             : // C++ lib
      36             : //
      37             : #include    <iostream>
      38             : 
      39             : 
      40             : // last include
      41             : //
      42             : #include    <snapdev/poison.h>
      43             : 
      44             : 
      45             : 
      46             : namespace snapdatabase
      47             : {
      48             : 
      49             : 
      50             : 
      51             : namespace detail
      52             : {
      53             : }
      54             : 
      55             : 
      56             : 
      57             : namespace
      58             : {
      59             : 
      60             : 
      61             : 
      62             : // 'SDBT' -- snapdatabase file
      63             : constexpr struct_description_t g_description[] =
      64             : {
      65             :     define_description(
      66             :           FieldName("header")
      67             :         , FieldType(struct_type_t::STRUCT_TYPE_STRUCTURE)
      68             :         , FieldSubDescription(detail::g_block_header)
      69             :     ),
      70             :     define_description(
      71             :           FieldName("file_version")
      72             :         , FieldType(struct_type_t::STRUCT_TYPE_VERSION)
      73             :     ),
      74             :     define_description(
      75             :           FieldName("block_size")
      76             :         , FieldType(struct_type_t::STRUCT_TYPE_UINT32)
      77             :     ),
      78             :     define_description(
      79             :           FieldName("table_definition") // this is the schema
      80             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
      81             :     ),
      82             :     define_description(
      83             :           FieldName("first_free_block")
      84             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
      85             :     ),
      86             :     // at this time we do not allow dynamically created/dropped tables
      87             :     //define_description(
      88             :     //      FieldName("table_expiration_date")
      89             :     //    , FieldType(struct_type_t::STRUCT_TYPE_TIME)
      90             :     //),
      91             :     define_description(
      92             :           FieldName("indirect_index")
      93             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
      94             :     ),
      95             :     define_description(
      96             :           FieldName("last_oid")
      97             :         , FieldType(struct_type_t::STRUCT_TYPE_OID)
      98             :     ),
      99             :     define_description(
     100             :           FieldName("first_free_oid")
     101             :         , FieldType(struct_type_t::STRUCT_TYPE_OID)
     102             :     ),
     103             :     define_description(
     104             :           FieldName("first_compactable_block")
     105             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
     106             :     ),
     107             :     define_description(
     108             :           FieldName("top_key_index_block")
     109             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
     110             :     ),
     111             :     define_description(
     112             :           FieldName("expiration_index_block")
     113             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
     114             :     ),
     115             :     define_description(
     116             :           FieldName("secondary_index_block")
     117             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
     118             :     ),
     119             :     define_description(
     120             :           FieldName("tree_index_block")
     121             :         , FieldType(struct_type_t::STRUCT_TYPE_REFERENCE)
     122             :     ),
     123             :     define_description(
     124             :           FieldName("deleted_rows")
     125             :         , FieldType(struct_type_t::STRUCT_TYPE_UINT64)
     126             :     ),
     127             :     define_description( // bloom filters use separate files
     128             :           FieldName("bloom_filter_flags=algorithm:4/renewing")
     129             :         , FieldType(struct_type_t::STRUCT_TYPE_BITS32)
     130             :     ),
     131             :     end_descriptions()
     132             : };
     133             : 
     134             : 
     135             : constexpr descriptions_by_version_t const g_descriptions_by_version[] =
     136             : {
     137             :     define_description_by_version(
     138             :         DescriptionVersion(0, 1),
     139             :         DescriptionDescription(g_description)
     140             :     ),
     141             :     end_descriptions_by_version()
     142             : };
     143             : 
     144             : 
     145             : 
     146             : }
     147             : // no name namespace
     148             : 
     149             : 
     150             : 
     151             : 
     152             : 
     153             : 
     154             : 
     155             : 
     156             : 
     157           1 : file_snap_database_table::file_snap_database_table(dbfile::pointer_t f, reference_t offset)
     158           1 :     : block(g_descriptions_by_version, f, offset)
     159             : {
     160           1 : std::cerr << "--- the file_snap_database_table offset = " << offset << "\n";
     161           1 : }
     162             : 
     163             : 
     164           0 : version_t file_snap_database_table::get_file_version() const
     165             : {
     166           0 :     return static_cast<version_t>(static_cast<uint32_t>(f_structure->get_uinteger("file_version")));
     167             : }
     168             : 
     169             : 
     170           1 : void file_snap_database_table::set_file_version(version_t v)
     171             : {
     172           1 :     f_structure->set_uinteger("file_version", v.to_binary());
     173           1 : }
     174             : 
     175             : 
     176           0 : uint32_t file_snap_database_table::get_block_size() const
     177             : {
     178           0 :     return static_cast<reference_t>(f_structure->get_uinteger("block_size"));
     179             : }
     180             : 
     181             : 
     182           1 : void file_snap_database_table::set_block_size(uint32_t offset)
     183             : {
     184           1 :     f_structure->set_uinteger("block_size", offset);
     185           1 : }
     186             : 
     187             : 
     188           1 : reference_t file_snap_database_table::get_table_definition() const
     189             : {
     190           1 :     return static_cast<reference_t>(f_structure->get_uinteger("table_definition"));
     191             : }
     192             : 
     193             : 
     194           0 : void file_snap_database_table::set_table_definition(reference_t offset)
     195             : {
     196           0 :     f_structure->set_uinteger("table_definition", offset);
     197           0 : }
     198             : 
     199             : 
     200           1 : reference_t file_snap_database_table::get_first_free_block() const
     201             : {
     202           1 :     return static_cast<reference_t>(f_structure->get_uinteger("first_free_block"));
     203             : }
     204             : 
     205             : 
     206           2 : void file_snap_database_table::set_first_free_block(reference_t offset)
     207             : {
     208           2 :     f_structure->set_uinteger("first_free_block", offset);
     209           2 : }
     210             : 
     211             : 
     212             : 
     213           6 : } // namespace snapdatabase
     214             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13