Skip to content
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

ADBDEV-6339 Implement files tracking for arenadata_toolkit #1079

Open
wants to merge 65 commits into
base: adb-6.x-dev
Choose a base branch
from

Conversation

bimboterminator1
Copy link
Member

@bimboterminator1 bimboterminator1 commented Oct 15, 2024

Implement relfilenode tracking for arenadata_toolkit

This patch introduces some enhancements to the arenadata_toolkit for the GPDB,
primarily focusing on tracking relfilenode changes. The key
components of this implementation include: tracking API, hooks processing and
background workers to facilitate initialization tasks on both the master and
segment levels. The main concept of implementation is in utilizing Bloom filters
to efficiently track relfilenode changes.

The main purpose of this code is achieving fast database size
calculation and tracking file changes at relation level. The extension
implements a probabilistic tracking system using Bloom filters to monitor file
changes across Greenplum segments. It utilizes shared memory for state
management and employs background workers to maintain consistency.

The original code of toolkit extension has been reorganized due to increased
logic complexity. Now extension is built from several units stored in
gpcontrib/arenadata_toolkit/src folder.

Previous code for calculation relation sizes is stored in dbsize.c. New api
functions related to tracking are in track_files.c. Other units are dedicated
to utility purposes providing sustainable infrastructure for extension.

Generally speaking, extension uses storage manager hooks which catch relations
files changes (create, extend, truncate, unlink) via Bloom filter. We use our own
implementation of bloom filter, which is stored in shared memory. Main hash
function used in Bloom filter is an adapted wyhash function for our specific case.

Transactional semantics works as follow. Each bloom filter is allocated with
double arenadata_toolkit.tracking_bloom_size in order to preserve filter state
in case of track acquisition rollback. Each bloom filter is also assigned a
"version" variable, which represents a simple counter. The main
tracking_get_track function takes a version value from master as an argument,
and after function is dispatched on segments, function compares filter version
on segment and incoming master's version. If they are equal track is acquired
normally, current active filter is copied to local memory and is then switched
to other filter (which is allocated near it in shared memory). Then new active
filter is cleared, and filter version is bumped. If transaction with track
acquisition is committed, master version is bumped as well leading to
consistency with segments. In case of abort, master version stays the same,
and on next tracking_get_track call there will be version conflict, which
indicates that function needs to use previously preserved filter in current
track acquisition.

Relation sizes are calculated via stat call for segment files. However, locks
for the relation are not acquired in order to avoid performance decrease.
If something happen with files, we will just ignore erroneous stat call
and return zero size.

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/83009

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/83030

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/83066

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/83098

@whitehawk

This comment was marked as outdated.

@whitehawk

This comment was marked as resolved.

@whitehawk

This comment was marked as resolved.

@whitehawk

This comment was marked as resolved.

gpcontrib/arenadata_toolkit/src/track_files.c Outdated Show resolved Hide resolved
gpcontrib/arenadata_toolkit/src/track_files.c Outdated Show resolved Hide resolved
gpcontrib/arenadata_toolkit/src/track_files.c Show resolved Hide resolved
gpcontrib/arenadata_toolkit/src/bloom_set.c Outdated Show resolved Hide resolved
gpcontrib/arenadata_toolkit/src/arenadata_toolkit_guc.c Outdated Show resolved Hide resolved
@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/86273

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/86294

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/86309

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/86353

KnightMurloc
KnightMurloc previously approved these changes Nov 20, 2024
whitehawk
whitehawk previously approved these changes Nov 21, 2024
@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/86430

KnightMurloc
KnightMurloc previously approved these changes Nov 21, 2024
@bimboterminator1
Copy link
Member Author

bimboterminator1 commented Nov 25, 2024

Last changes fixes the slow size calculation for AO tables.

drop table a;
drop table b;
drop table c;
drop table d;
drop table e;
drop table f;
drop table g;
drop table h;

create table a(c1 int, c2 text) with (appendoptimized=true); insert into a select generate_series(1,1000), 'foo';
create table b(c1 int, c2 text) with (appendoptimized=true); insert into b select generate_series(1,1000), 'foo';
create table c(c1 int, c2 text) with (appendoptimized=true); insert into c select generate_series(1,1000), 'foo';
create table d(c1 int, c2 text) with (appendoptimized=true); insert into d select generate_series(1,1000), 'foo';
create table e(c1 int, c2 text) with (appendoptimized=true); insert into e select generate_series(1,1000), 'foo';
create table f(c1 int, c2 text) with (appendoptimized=true); insert into f select generate_series(1,1000), 'foo';
create table g(c1 int, c2 text) with (appendoptimized=true); insert into g select generate_series(1,1000), 'foo';
create table h(c1 int, c2 text) with (appendoptimized=true); insert into h select generate_series(1,1000), 'foo';

time -p psql -c 'begin; select * from arenadata_toolkit.tables_track order by relname, segid; rollback;'
ROLLBACK

real 6.94
user 0.00
sys 0.00


With changes
time -p psql -c 'begin; select * from arenadata_toolkit.tables_track order by relname, segid; rollback;'
ROLLBACK
real 1.11
user 0.00
sys 0.00

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/86831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants