Skip to content

Commit 92c34f2

Browse files
committed
Toward the ptrack 2.1
1 parent d79447e commit 92c34f2

13 files changed

+1446
-1103
lines changed

Diff for: .travis.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ notifications:
2121
on_success: change
2222
on_failure: always
2323

24-
# Default MODE is basic, i.e. all tests with PG_PROBACKUP_TEST_BASIC=ON
2524
env:
2625
- PG_VERSION=12 PG_BRANCH=REL_12_STABLE
27-
28-
jobs:
29-
allow_failures:
30-
- if: env(MODE) IN (archive, backup, delta, locking, merge, replica, retention, restore)
26+
# - PG_VERSION=13 PG_BRANCH=master

Diff for: Makefile

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# contrib/ptrack/Makefile
22

33
MODULE_big = ptrack
4-
OBJS = ptrack.o $(WIN32RES)
4+
OBJS = ptrack.o datapagemap.o engine.o $(WIN32RES)
55
EXTENSION = ptrack
6-
EXTVERSION = 2.0
7-
DATA = ptrack.sql
6+
EXTVERSION = 2.1
7+
DATA = ptrack.sql ptrack--2.0--2.1.sql
88
DATA_built = $(EXTENSION)--$(EXTVERSION).sql
9-
PGFILEDESC = "ptrack - public API for internal ptrack engine"
9+
PGFILEDESC = "ptrack - block-level incremental backup engine"
1010

1111
EXTRA_CLEAN = $(EXTENSION)--$(EXTVERSION).sql
1212

@@ -24,4 +24,26 @@ endif
2424
$(EXTENSION)--$(EXTVERSION).sql: ptrack.sql
2525
cat $^ > $@
2626

27+
# check: isolationcheck
28+
29+
# ISOLATIONCHECKS=corner_cases
30+
31+
# submake-isolation:
32+
# $(MAKE) -C $(top_builddir)/src/test/isolation all
33+
34+
# isolationcheck: | submake-isolation temp-install
35+
# $(MKDIR_P) isolation_output
36+
# $(pg_isolation_regress_check) \
37+
# --temp-config $(top_srcdir)/contrib/pg_query_state/test.conf \
38+
# --outputdir=isolation_output \
39+
# $(ISOLATIONCHECKS)
40+
41+
# isolationcheck-install-force: all | submake-isolation temp-install
42+
# $(MKDIR_P) isolation_output
43+
# $(pg_isolation_regress_installcheck) \
44+
# --outputdir=isolation_output \
45+
# $(ISOLATIONCHECKS)
46+
47+
# .PHONY: isolationcheck isolationcheck-install-force check
48+
2749
temp-install: EXTRA_INSTALL=contrib/ptrack

Diff for: datapagemap.c

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* datapagemap.c
4+
* A data structure for keeping track of data pages that have changed.
5+
*
6+
* This is a fairly simple bitmap.
7+
*
8+
* Copyright (c) 2013-2020, PostgreSQL Global Development Group
9+
* Copyright (c) 2019-2020, Postgres Professional
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#include "postgres.h"
15+
16+
#include "datapagemap.h"
17+
18+
struct datapagemap_iterator
19+
{
20+
datapagemap_t *map;
21+
BlockNumber nextblkno;
22+
};
23+
24+
/*
25+
* Add a block to the bitmap.
26+
*/
27+
void
28+
datapagemap_add(datapagemap_t *map, BlockNumber blkno)
29+
{
30+
int offset;
31+
int bitno;
32+
33+
offset = blkno / 8;
34+
bitno = blkno % 8;
35+
36+
/* enlarge or create bitmap if needed */
37+
if (map->bitmapsize <= offset)
38+
{
39+
int oldsize = map->bitmapsize;
40+
int newsize;
41+
42+
/*
43+
* The minimum to hold the new bit is offset + 1. But add some
44+
* headroom, so that we don't need to repeatedly enlarge the bitmap in
45+
* the common case that blocks are modified in order, from beginning
46+
* of a relation to the end.
47+
*/
48+
newsize = offset + 1;
49+
newsize += 10;
50+
51+
if (map->bitmap != NULL)
52+
map->bitmap = repalloc(map->bitmap, newsize);
53+
else
54+
map->bitmap = palloc(newsize);
55+
56+
/* zero out the newly allocated region */
57+
memset(&map->bitmap[oldsize], 0, newsize - oldsize);
58+
59+
map->bitmapsize = newsize;
60+
}
61+
62+
/* Set the bit */
63+
map->bitmap[offset] |= (1 << bitno);
64+
}
65+
66+
/*
67+
* Start iterating through all entries in the page map.
68+
*
69+
* After datapagemap_iterate, call datapagemap_next to return the entries,
70+
* until it returns false. After you're done, use pg_free() to destroy the
71+
* iterator.
72+
*/
73+
datapagemap_iterator_t *
74+
datapagemap_iterate(datapagemap_t *map)
75+
{
76+
datapagemap_iterator_t *iter;
77+
78+
iter = palloc(sizeof(datapagemap_iterator_t));
79+
iter->map = map;
80+
iter->nextblkno = 0;
81+
82+
return iter;
83+
}
84+
85+
bool
86+
datapagemap_next(datapagemap_iterator_t *iter, BlockNumber *blkno)
87+
{
88+
datapagemap_t *map = iter->map;
89+
90+
for (;;)
91+
{
92+
BlockNumber blk = iter->nextblkno;
93+
int nextoff = blk / 8;
94+
int bitno = blk % 8;
95+
96+
if (nextoff >= map->bitmapsize)
97+
break;
98+
99+
iter->nextblkno++;
100+
101+
if (map->bitmap[nextoff] & (1 << bitno))
102+
{
103+
*blkno = blk;
104+
return true;
105+
}
106+
}
107+
108+
/* no more set bits in this bitmap. */
109+
return false;
110+
}
111+
112+
/*
113+
* A debugging aid. Prints out the contents of the page map.
114+
*/
115+
void
116+
datapagemap_print(datapagemap_t *map)
117+
{
118+
datapagemap_iterator_t *iter;
119+
BlockNumber blocknum;
120+
121+
iter = datapagemap_iterate(map);
122+
while (datapagemap_next(iter, &blocknum))
123+
elog(DEBUG3, "block %u", blocknum);
124+
125+
pfree(iter);
126+
}

Diff for: datapagemap.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* datapagemap.h
4+
*
5+
* Copyright (c) 2013-2019, PostgreSQL Global Development Group
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
9+
#ifndef DATAPAGEMAP_H
10+
#define DATAPAGEMAP_H
11+
12+
#include "storage/relfilenode.h"
13+
#include "storage/block.h"
14+
15+
struct datapagemap
16+
{
17+
char *bitmap;
18+
int bitmapsize;
19+
};
20+
21+
typedef struct datapagemap datapagemap_t;
22+
typedef struct datapagemap_iterator datapagemap_iterator_t;
23+
24+
extern void datapagemap_add(datapagemap_t *map, BlockNumber blkno);
25+
extern datapagemap_iterator_t *datapagemap_iterate(datapagemap_t *map);
26+
extern bool datapagemap_next(datapagemap_iterator_t *iter, BlockNumber *blkno);
27+
extern void datapagemap_print(datapagemap_t *map);
28+
29+
#endif /* DATAPAGEMAP_H */

0 commit comments

Comments
 (0)