-
Notifications
You must be signed in to change notification settings - Fork 16
Resolve issues #5 and #1: reduce number of collisions in the ptrack map #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
dd6fdc0
829f96c
3026be9
cf8e309
fbfba8c
ab17447
9c132a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| .deps | ||
| *.so | ||
| *.o | ||
| ptrack--2.0.sql | ||
| Dockerfile | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* ptrack/ptrack--2.1--2.2.sql */ | ||
|
|
||
| -- Complain if script is sourced in psql, rather than via ALTER EXTENSION | ||
| \echo Use "ALTER EXTENSION ptrack UPDATE;" to load this file.\ quit | ||
|
|
||
| CREATE FUNCTION ptrack_get_change_stat(start_lsn pg_lsn) | ||
| RETURNS TABLE ( | ||
| files bigint, | ||
| pages bigint, | ||
| "size, MB" numeric | ||
| ) AS | ||
| $func$ | ||
| DECLARE | ||
| block_size bigint; | ||
| BEGIN | ||
| block_size := (SELECT setting FROM pg_settings WHERE name = 'block_size'); | ||
|
|
||
| RETURN QUERY | ||
| SELECT changed_files, | ||
| changed_pages, | ||
| block_size*changed_pages/(1024.0*1024) | ||
| FROM | ||
| (SELECT count(path) AS changed_files, | ||
| sum( | ||
| length(replace(right((pagemap)::text, -1)::varbit::text, '0', '')) | ||
|
||
| ) AS changed_pages | ||
| FROM ptrack_get_pagemapset(start_lsn)) s; | ||
| END | ||
| $func$ LANGUAGE plpgsql; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -420,10 +420,9 @@ PG_FUNCTION_INFO_V1(ptrack_get_pagemapset); | |
| Datum | ||
| ptrack_get_pagemapset(PG_FUNCTION_ARGS) | ||
| { | ||
| PtScanCtx *ctx; | ||
| FuncCallContext *funcctx; | ||
| PtScanCtx *ctx; | ||
| MemoryContext oldcontext; | ||
| XLogRecPtr update_lsn; | ||
| datapagemap_t pagemap; | ||
| char gather_path[MAXPGPATH]; | ||
|
|
||
|
|
@@ -486,6 +485,12 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS) | |
|
|
||
| while (true) | ||
| { | ||
| size_t hash; | ||
| size_t slot1; | ||
| size_t slot2; | ||
| XLogRecPtr update_lsn1; | ||
| XLogRecPtr update_lsn2; | ||
|
|
||
| /* Stop traversal if there are no more segments */ | ||
| if (ctx->bid.blocknum > ctx->relsize) | ||
| { | ||
|
|
@@ -525,15 +530,25 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS) | |
| } | ||
| } | ||
|
|
||
| update_lsn = pg_atomic_read_u64(&ptrack_map->entries[BID_HASH_FUNC(ctx->bid)]); | ||
| hash = BID_HASH_FUNC(ctx->bid); | ||
| slot1 = hash % PtrackContentNblocks; | ||
| slot2 = ((hash << 32) | (hash >> 32)) % PtrackContentNblocks; | ||
|
|
||
| update_lsn1 = pg_atomic_read_u64(&ptrack_map->entries[slot1]); | ||
| update_lsn2 = pg_atomic_read_u64(&ptrack_map->entries[slot2]); | ||
|
||
|
|
||
| if (update_lsn1 != InvalidXLogRecPtr) | ||
| elog(DEBUG3, "ptrack: update_lsn1 %X/%X of blckno %u of file %s", | ||
| (uint32) (update_lsn1 >> 32), (uint32) update_lsn1, | ||
| ctx->bid.blocknum, ctx->relpath); | ||
|
|
||
| if (update_lsn != InvalidXLogRecPtr) | ||
| elog(DEBUG3, "ptrack: update_lsn %X/%X of blckno %u of file %s", | ||
| (uint32) (update_lsn >> 32), (uint32) update_lsn, | ||
| if (update_lsn2 != InvalidXLogRecPtr) | ||
| elog(DEBUG3, "ptrack: update_lsn2 %X/%X of blckno %u of file %s", | ||
| (uint32) (update_lsn1 >> 32), (uint32) update_lsn2, | ||
| ctx->bid.blocknum, ctx->relpath); | ||
|
|
||
| /* Block has been changed since specified LSN. Mark it in the bitmap */ | ||
| if (update_lsn >= ctx->lsn) | ||
| /* Block has been changed since specified LSN. Mark it in the bitmap */ | ||
| if (update_lsn1 >= ctx->lsn && update_lsn2 >= ctx->lsn) | ||
| datapagemap_add(&pagemap, ctx->bid.blocknum % ((BlockNumber) RELSEG_SIZE)); | ||
|
|
||
| ctx->bid.blocknum += 1; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # ptrack extension | ||
| comment = 'block-level incremental backup engine' | ||
| default_version = '2.1' | ||
| default_version = '2.2' | ||
| module_pathname = '$libdir/ptrack' | ||
| relocatable = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не могу найти, где делается unmap в этом случае?
При этом сразу после метки
ptrack_map_reinitделаетсяdurable_unlink(ptrack_mmap_path).В итоге, этот файл повисает невидимкой в файловой системе, и в адрессном пространстве процесса повисает его mmap.
Наверное есть смысл позвать здесь
ptrackCleanFilesAndMap?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, похоже на то. Я сомневался в этом месте, но потом забыл и не разобрался до конца