LCOV - code coverage report
Current view: top level - gdk - gdk_delta.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 43 20.9 %
Date: 2020-06-29 20:00:14 Functions: 1 3 33.3 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * @a M. L. Kersten, P. Boncz, N. Nes
      11             :  * @* Delta management
      12             :  * The basis for transaction management is to keep track of elements
      13             :  * inserted, deleted, and replaced.  This information is stored within
      14             :  * the BAT structure using three delta markers.  Inserted denotes the
      15             :  * first added BUN since the last commit. Deleted points to the BUNs
      16             :  * removed.  The deletion list is terminated at @%first@, where space
      17             :  * is reserved for swapping BUNs upon deletion. Initialization of the
      18             :  * BAT is extended as follows:
      19             :  */
      20             : 
      21             : /*
      22             :  * Impact on hashing and indexing.  The hash structure is maintained
      23             :  * for all elements to be deleted ?.
      24             :  */
      25             : #include "monetdb_config.h"
      26             : #include "gdk.h"
      27             : #include "gdk_private.h"
      28             : 
      29             : /*
      30             :  * batcommit really forgets the atoms guarded for an undo; we just
      31             :  * need to free their heap space (only if necessary).
      32             :  */
      33             : void
      34      452725 : BATcommit(BAT *b)
      35             : {
      36      452725 :         if (b == NULL)
      37             :                 return;
      38      452725 :         TRC_DEBUG(DELTA, "BATcommit1 %s free %zu ins " BUNFMT " base %p\n",
      39             :                   BATgetId(b), b->theap.free, b->batInserted, b->theap.base);
      40      452725 :         if (!BATdirty(b)) {
      41       59105 :                 b->batDirtyflushed = false;
      42             :         }
      43      452725 :         if (DELTAdirty(b)) {
      44       84484 :                 b->batDirtydesc = true;
      45             :         }
      46      452725 :         b->batInserted = BUNlast(b);
      47      452725 :         TRC_DEBUG(DELTA, "BATcommit2 %s free %zu ins " BUNFMT " base %p\n",
      48             :                   BATgetId(b), b->theap.free, b->batInserted, b->theap.base);
      49             : }
      50             : 
      51             : /*
      52             :  * BATfakeCommit() flushed the delta info, but leaves the BAT marked
      53             :  * clean.
      54             :  */
      55             : void
      56           0 : BATfakeCommit(BAT *b)
      57             : {
      58           0 :         if (b) {
      59           0 :                 BATcommit(b);
      60           0 :                 b->batDirtydesc = b->theap.dirty = false;
      61           0 :                 if (b->tvheap)
      62           0 :                         b->tvheap->dirty = false;
      63             :         }
      64           0 : }
      65             : 
      66             : /*
      67             :  * The routine @%BATundo@ restores the BAT to the previous commit
      68             :  * point.  The inserted elements are removed from the accelerators,
      69             :  * deleted from the heap. The guarded elements from uncommitted
      70             :  * deletes are inserted into the accelerators.
      71             :  */
      72             : void
      73           0 : BATundo(BAT *b)
      74             : {
      75           0 :         BATiter bi = bat_iterator(b);
      76           0 :         BUN p, bunlast, bunfirst;
      77             : 
      78           0 :         if (b == NULL)
      79           0 :                 return;
      80           0 :         TRC_DEBUG(DELTA, "BATundo: %s \n", BATgetId(b));
      81           0 :         if (b->batDirtyflushed) {
      82           0 :                 b->batDirtydesc = b->theap.dirty = true;
      83             :         } else {
      84           0 :                 b->batDirtydesc = b->theap.dirty = false;
      85           0 :                 if (b->tvheap)
      86           0 :                         b->tvheap->dirty = false;
      87             :         }
      88           0 :         bunfirst = b->batInserted;
      89           0 :         bunlast = BUNlast(b) - 1;
      90           0 :         if (bunlast >= b->batInserted) {
      91           0 :                 BUN i = bunfirst;
      92           0 :                 gdk_return (*tunfix) (const void *) = BATatoms[b->ttype].atomUnfix;
      93           0 :                 void (*tatmdel) (Heap *, var_t *) = BATatoms[b->ttype].atomDel;
      94             : 
      95           0 :                 if (b->thash)
      96           0 :                         HASHdestroy(b);
      97           0 :                 if (tunfix || tatmdel) {
      98           0 :                         for (p = bunfirst; p <= bunlast; p++, i++) {
      99           0 :                                 if (tunfix)
     100           0 :                                         (void) (*tunfix) (BUNtail(bi, p));
     101           0 :                                 if (tatmdel)
     102           0 :                                         (*tatmdel) (b->tvheap, (var_t *) BUNtloc(bi, p));
     103             :                         }
     104             :                 }
     105             :         }
     106           0 :         b->theap.free = tailsize(b, b->batInserted);
     107             : 
     108           0 :         BATsetcount(b, b->batInserted);
     109             : }

Generated by: LCOV version 1.14