PostgreSQL Source Code  git master
datapagemap.c File Reference
#include "postgres_fe.h"
#include "common/logging.h"
#include "datapagemap.h"
Include dependency graph for datapagemap.c:

Go to the source code of this file.

Data Structures

struct  datapagemap_iterator
 

Functions

void datapagemap_add (datapagemap_t *map, BlockNumber blkno)
 
datapagemap_iterator_tdatapagemap_iterate (datapagemap_t *map)
 
bool datapagemap_next (datapagemap_iterator_t *iter, BlockNumber *blkno)
 
void datapagemap_print (datapagemap_t *map)
 

Function Documentation

◆ datapagemap_add()

void datapagemap_add ( datapagemap_t map,
BlockNumber  blkno 
)

Definition at line 32 of file datapagemap.c.

33 {
34  int offset;
35  int bitno;
36 
37  offset = blkno / 8;
38  bitno = blkno % 8;
39 
40  /* enlarge or create bitmap if needed */
41  if (map->bitmapsize <= offset)
42  {
43  int oldsize = map->bitmapsize;
44  int newsize;
45 
46  /*
47  * The minimum to hold the new bit is offset + 1. But add some
48  * headroom, so that we don't need to repeatedly enlarge the bitmap in
49  * the common case that blocks are modified in order, from beginning
50  * of a relation to the end.
51  */
52  newsize = offset + 1;
53  newsize += 10;
54 
55  map->bitmap = pg_realloc(map->bitmap, newsize);
56 
57  /* zero out the newly allocated region */
58  memset(&map->bitmap[oldsize], 0, newsize - oldsize);
59 
60  map->bitmapsize = newsize;
61  }
62 
63  /* Set the bit */
64  map->bitmap[offset] |= (1 << bitno);
65 }
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
int bitmapsize
Definition: datapagemap.h:18
char * bitmap
Definition: datapagemap.h:17

References datapagemap::bitmap, datapagemap::bitmapsize, and pg_realloc().

Referenced by process_target_wal_block_change().

◆ datapagemap_iterate()

datapagemap_iterator_t* datapagemap_iterate ( datapagemap_t map)

Definition at line 75 of file datapagemap.c.

76 {
78 
79  iter = pg_malloc(sizeof(datapagemap_iterator_t));
80  iter->map = map;
81  iter->nextblkno = 0;
82 
83  return iter;
84 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
BlockNumber nextblkno
Definition: datapagemap.c:21
datapagemap_t * map
Definition: datapagemap.c:20

References datapagemap_iterator::map, datapagemap_iterator::nextblkno, and pg_malloc().

Referenced by calculate_totals(), datapagemap_print(), and perform_rewind().

◆ datapagemap_next()

bool datapagemap_next ( datapagemap_iterator_t iter,
BlockNumber blkno 
)

Definition at line 87 of file datapagemap.c.

88 {
89  datapagemap_t *map = iter->map;
90 
91  for (;;)
92  {
93  BlockNumber blk = iter->nextblkno;
94  int nextoff = blk / 8;
95  int bitno = blk % 8;
96 
97  if (nextoff >= map->bitmapsize)
98  break;
99 
100  iter->nextblkno++;
101 
102  if (map->bitmap[nextoff] & (1 << bitno))
103  {
104  *blkno = blk;
105  return true;
106  }
107  }
108 
109  /* no more set bits in this bitmap. */
110  return false;
111 }
uint32 BlockNumber
Definition: block.h:31

References datapagemap::bitmap, datapagemap::bitmapsize, datapagemap_iterator::map, and datapagemap_iterator::nextblkno.

Referenced by calculate_totals(), datapagemap_print(), and perform_rewind().

◆ datapagemap_print()

void datapagemap_print ( datapagemap_t map)

Definition at line 117 of file datapagemap.c.

118 {
120  BlockNumber blocknum;
121 
122  iter = datapagemap_iterate(map);
123  while (datapagemap_next(iter, &blocknum))
124  pg_log_debug("block %u", blocknum);
125 
126  pg_free(iter);
127 }
bool datapagemap_next(datapagemap_iterator_t *iter, BlockNumber *blkno)
Definition: datapagemap.c:87
datapagemap_iterator_t * datapagemap_iterate(datapagemap_t *map)
Definition: datapagemap.c:75
void pg_free(void *ptr)
Definition: fe_memutils.c:105
#define pg_log_debug(...)
Definition: logging.h:133

References datapagemap_iterate(), datapagemap_next(), pg_free(), and pg_log_debug.

Referenced by print_filemap().