"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.9.2/src/knot/journal/journal_metadata.h" (12 Dec 2019, 6622 Bytes) of package /linux/misc/dns/knot-2.9.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "journal_metadata.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.9.1_vs_2.9.2.

    1 /*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15  */
   16 
   17 #pragma once
   18 
   19 #include "knot/journal/journal_basic.h"
   20 
   21 typedef struct {
   22     uint32_t first_serial;
   23     uint32_t serial_to;
   24     uint32_t flushed_upto;
   25     uint32_t merged_serial;
   26     uint32_t changeset_count;
   27     uint32_t flags; // a bitmap of flags, see enum below
   28     bool _new_zone; // private: if there were no metadata at all previously
   29 } journal_metadata_t;
   30 
   31 enum journal_metadata_flags {
   32     JOURNAL_LAST_FLUSHED_VALID   = (1 << 0), // deprecated
   33     JOURNAL_SERIAL_TO_VALID      = (1 << 1),
   34     JOURNAL_MERGED_SERIAL_VALID  = (1 << 2),
   35 };
   36 
   37 typedef int (*journals_walk_cb_t)(const knot_dname_t *zone, void *ctx);
   38 
   39 /*!
   40  * \brief Update the computation of DB resources used by each zone.
   41  *
   42  * Because the amount of used space is bigger than sum of changesets' serialized_sizes,
   43  * journal uses a complicated way to compute each zone's used space: there is a metadata
   44  * showing always the previously-inserting zone. Before the next insert, it is computed
   45  * how the total usage of the DB changed during the previous insert (or delete), and the
   46  * usage increase (or decrease) is accounted on the bill of the previous inserter.
   47  *
   48  * \param txn            Journal DB transaction.
   49  * \param new_inserter   Name of the zone that is going to insert now. Might be NULL if no insert nor delete will be done.
   50  */
   51 void update_last_inserter(knot_lmdb_txn_t *txn, const knot_dname_t *new_inserter);
   52 
   53 /* \brief Return the journal database usage by given zone. */
   54 uint64_t journal_get_occupied(knot_lmdb_txn_t *txn, const knot_dname_t *zone);
   55 
   56 /*!
   57  * \brief Load the metadata from DB into structure.
   58  *
   59  * \param txn    Journal DB transaction.
   60  * \param zone   Zone name.
   61  * \param md     Output: metadata structure.
   62  */
   63 void journal_load_metadata(knot_lmdb_txn_t *txn, const knot_dname_t *zone, journal_metadata_t *md);
   64 
   65 /*!
   66  * \brief Store the metadata from structure into DB.
   67  *
   68  * \param txn    Journal DB transaction.
   69  * \param zone   Zone name.
   70  * \param md     Metadata structure.
   71  */
   72 void journal_store_metadata(knot_lmdb_txn_t *txn, const knot_dname_t *zone, const journal_metadata_t *md);
   73 
   74 /*!
   75  * \brief Update metadata according to what was deleted.
   76  *
   77  * \param md              Metadata structure to be updated.
   78  * \param deleted_upto    Serial-to of the last deleted changeset.
   79  * \param deleted_count   Number of deleted changesets.
   80  */
   81 void journal_metadata_after_delete(journal_metadata_t *md, uint32_t deleted_upto,
   82                                    size_t deleted_count);
   83 
   84 /*!
   85  * \brief Update metadata according to what was merged.
   86  *
   87  * \param md                   Metadata structure to be updated.
   88  * \param merged_zij           True if it was a merge into zone-in-journal.
   89  * \param merged_serial        Serial-from of the merged changeset (ignored if 'merged_zij').
   90  * \param merged_serial_to     Serial-to of the merged changeset.
   91  * \param original_serial_to   Previous serial-to of the merged changeset before the merge.
   92  */
   93 void journal_metadata_after_merge(journal_metadata_t *md, bool merged_zij, uint32_t merged_serial,
   94                                   uint32_t merged_serial_to, uint32_t original_serial_to);
   95 
   96 /*!
   97  * \brief Update metadata according to what was inserted.
   98  *
   99  * \param md          Metadata structure to be updated.
  100  * \param serial      Serial-from of the inserted changeset.
  101  * \param serial_to   Serial-to of the inserted changeset.
  102  */
  103 void journal_metadata_after_insert(journal_metadata_t *md, uint32_t serial, uint32_t serial_to);
  104 
  105 /*!
  106  * \brief Update metadata according to inserted extra changeset.
  107  *
  108  * \param md          Metadata structure to be updated.
  109  * \param serial      Serial-from of the inserted changeset.
  110  * \param serial_to   Serial-to of the inserted changeset.
  111  */
  112 void journal_metadata_after_extra(journal_metadata_t *md, uint32_t serial, uint32_t serial_to);
  113 
  114 /*!
  115  * \brief Completely delete all journal records belonging to this zone, including metadata.
  116  *
  117  * \param j   Journal to be scraped.
  118  *
  119  * \return KNOT_E*
  120  */
  121 int journal_scrape_with_md(zone_journal_t j);
  122 
  123 /*!
  124  * \brief Update the metadata stored in journal DB after a zone flush.
  125  *
  126  * \param j   Journal to be notified about flush.
  127  *
  128  * \return KNOT_E*
  129  */
  130 int journal_set_flushed(zone_journal_t j);
  131 
  132 /*!
  133  * \brief Obtain information about the zone's journal from the DB (mostly metadata).
  134  *
  135  * \param j                Zone journal.
  136  * \param exists           Output: bool if the zone exists in the journal.
  137  * \param first_serial     Optional output: serial-from of the first changeset in journal.
  138  * \param has_zij          Optional output: bool if there is zone-in-journal.
  139  * \param serial_to        Optional output: serial.to of the last changeset in journal.
  140  * \param has_merged       Optional output: bool if there is a special (non zone-in-journal) merged changeset.
  141  * \param merged_serial    Optional output: serial-from of the merged changeset.
  142  * \param occupied         Optional output: DB space occupied by this zones.
  143  * \param occupied_total   Optional output: DB space occupied in total by all zones.
  144  *
  145  * \return KNOT_E*
  146  */
  147 int journal_info(zone_journal_t j, bool *exists, uint32_t *first_serial, bool *has_zij,
  148                  uint32_t *serial_to, bool *has_merged, uint32_t *merged_serial,
  149                  uint64_t *occupied, uint64_t *occupied_total);
  150 
  151 /*! \brief Return true if this zone exists in journal DB. */
  152 inline static bool journal_is_existing(zone_journal_t j) {
  153     bool ex = false;
  154     (void)journal_info(j, &ex, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  155     return ex;
  156 }
  157 
  158 /*!
  159  * \brief Call a function for each zone being in the journal DB.
  160  *
  161  * \param db    Journal database.
  162  * \param cb    Callback to be called for each zone-name found.
  163  * \param ctx   Arbitrary context to be passed to the callback.
  164  *
  165  * \return An error code from either journal operations or from the callback.
  166  */
  167 int journals_walk(knot_lmdb_db_t *db, journals_walk_cb_t cb, void *ctx);