Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

ADBDEV-5169: Add the ability to backup partitions whose parent is in the extension#74

Merged
andr-sokolov merged 27 commits intomasterfrom
ADBDEV-5169
Jun 3, 2024
Merged

ADBDEV-5169: Add the ability to backup partitions whose parent is in the extension#74
andr-sokolov merged 27 commits intomasterfrom
ADBDEV-5169

Conversation

@KnightMurloc
Copy link

@KnightMurloc KnightMurloc commented Mar 28, 2024

Add the ability to backup partitions whose parent is in the extension

In 7X, if there was a partition in the database whose parent was in the
extension, then the backup attempt would have ended in panic. This was due to
the fact that when receiving the names of the parent tables, the tables in the
extension were filtered out, which led to a reference to nil when creating DDL
for ATTACH PARTITION.

This patch fixes the panic by removing the filtering of tables in the extension
for 7X.

This patch also adds the ability to backup such partitions in 7X. For 6X and
earlier, the old behavior was left in order not to violate the established
behavior.

There is a situation when, after a backup of the database with such partitions,
an error may appear when restoring. This can happen if data is added to the
default partition in the extension creation script. Then, during the restore,
when creating a new partition, the default partition constraints will change,
and if the data in the default partition does not meet the new constraints, an
error will appear. If such a situation occurs, problematic partitions should be
excluded using --exclude-table, where a root partition is specified. There is a
test for this case: "allows the user to exclude partitions that hinder restore
if the default partition in the extension contains data".

In 7X, if you add a partition to the partitioned table created by the extension,
the backup attempt would fail. The reason was that when receiving information
about table inheritance, tables related to extensions were filtered out, and
therefore the added partitions did not have a link to the parent partition.

This patch fixes the getUserTableRelations function to ignore partitions whose
root is in the extension, as is done in 6X. The filtering of extension tables
from GetTableInheritance has also been removed in order to correctly handle
situations when the parent table is added to extensions.
@KnightMurloc KnightMurloc marked this pull request as ready for review March 29, 2024 07:36
JOIN pg_namespace n ON p.relnamespace = n.oid
WHERE %s%s
ORDER BY i.inhrelid, i.inhseqno`,
ExtensionFilterClause("p"), tableFilterStr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you removed ExtensionFilterClause for 5X and 6X?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in 6X, we can also lose inheritance during backup if the parent is in the extension.

// If we are filtering on tables, we only want to record dependencies on other tables in the list
if len(tableOidList) > 0 {
tableFilterStr = fmt.Sprintf("\nAND i.inhrelid IN (%s)", strings.Join(tableOidList, ","))
tableFilterStr = fmt.Sprintf("WHERE i.inhrelid IN (%s)", strings.Join(tableOidList, ","))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it is good idea to put where in condition variable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have no other conditions, WHERE is needed only in the case of this filter.

@Stolb27 Stolb27 requested review from dnskvlnk and red1452 April 3, 2024 12:02
@Stolb27 Stolb27 requested a review from InnerLife0 April 4, 2024 07:13
@KnightMurloc KnightMurloc marked this pull request as draft April 4, 2024 11:36
This reverts commit fd90de7.
This reverts commit fedc752.
This reverts commit 4561cc9.
This patch adds the ability to backup partitions of tables in the extension that
were added after the extension was created.

Several issues have also been fixed:
1. We no longer get panic when trying to backup a 7X cluster in which there are
partitioned tables in the extension, some partitions of which are outside the
extension. This was due to the fact that when we received the parent tables, we
filtered out the tables in the extension.
2. In 6X, if the table was inherited from a table in the extension, we we no
longer lost inheritance during backup.
3. When backing up a 6X cluster, we no longer ignore partitions not from the
extension of tables in the extension, but only if the '--leaf-partition-data'
flag is present, since the COPY command to the intermediate table in 6X does not
return anything.
@KnightMurloc KnightMurloc changed the title ADBDEV-5169: Handle tables whose parent is in the extension ADBDEV-5169: Add the ability to backup partitions whose parent is in the extension Apr 16, 2024
@KnightMurloc KnightMurloc marked this pull request as ready for review April 16, 2024 12:14
InnerLife0
InnerLife0 previously approved these changes Apr 18, 2024
@InnerLife0 InnerLife0 self-requested a review April 18, 2024 14:13
@InnerLife0 InnerLife0 dismissed their stale review April 18, 2024 14:14

Mistake

1. updated comments
2. Combined the PrintExchangeExternalPartitionStatements and PrintAlterExtensionTablesStatements functions
3. The old behavior for include-tables for 6X has been returned since the sibling backup is the expected behavior.
4. The tests use special functions to verify the correctness of the recovery.
@InnerLife0
Copy link

I have some new questions/comments.

  1. If I understand this right, the behavior of gpbackup in prism of default partition backup is different in 6x and 7x. I miss explanation of this difference in PR and commit description.

  2. Next, I have the following case.
    Extension script:

create schema if not exists test;
create table test.ao1 (a int, b int, c text) 
with (appendonly=true) 
distributed by (a)
partition by range (b) (start (1) end (10) every (5));
insert into test.ao1 select i,i,i from generate_series(1,9) i;

User script:

alter table test.ao1 add partition test_part start(10) end(15);
insert into test.ao1 select i,i,i from generate_series(10,14) i;

When I try to backup this using the latest version on 6x, the user partition is not backed up. It seems that previous version of patch backed up this partition. Is it an expected behavior?

  1. Some of my old review messages were not taken into account.

  2. It's better to answer to reviewer comments. Otherwise, I should check all the points by myself without understanding was my comment useful and taken into account.

Copy link
Author

@KnightMurloc KnightMurloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Actually, the difference is not that big between 6X and 7X. In 6X, we to do SPLIT the default partition in case it is in the table. In 7X, we need to do SPLIT only if the default partition contains data related to the new partition. Therefore, in 6X it is important for us to create a default partition the last ones, and in 7X the order is not important to us.
  2. Has the --leaf-partition-data flag been set? if not, then skipping such partitions is the expected behavior. I checked with me if the --leaf-partition-data flag is set, then the user partition will be backed up.

@InnerLife0
Copy link

  1. Actually, the difference is not that big between 6X and 7X. In 6X, we to do SPLIT the default partition in case it is in the table. In 7X, we need to do SPLIT only if the default partition contains data related to the new partition. Therefore, in 6X it is important for us to create a default partition the last ones, and in 7X the order is not important to us.
  2. Has the --leaf-partition-data flag been set? if not, then skipping such partitions is the expected behavior. I checked with me if the --leaf-partition-data flag is set, then the user partition will be backed up.
  1. You already have a good point in description about --leaf-partition-data in 6x. We should highlight all the differences between 6x and 7x in the same way. If we have some cases in which we can't create backup script properly (e.g. SPLIT except ADD to table with default partition) then we should highlight them too. Description should contain a full picture of our desired behavior.
  2. I can't restore my past test scripts, but it seems you are right. Sorry.

I also want to check how query plans were changed, but will do this later.

This patch adds the ability to backup partitions of partitioned tables whose
root is in the extension for gpdb 7.
We can backup partitions that are outside the extension if no data is added to
the default partition in the extension creation script, otherwise we will get an
error when restoring from the backup. Because when adding a new partition, the
constants on the default partition change, and if the data in the partition does
not meet the new constraints, we will get an error. If such a situation occurs
during restore, you should exclude problematic partitions using --exclude-table,
where you need to specify the name of the root partition.

Also fixed panic in 7X in case parent tables are in the extension.
@InnerLife0
Copy link

We can backup partitions that are outside the extension if no data is added to the default partition in the extension creation script, otherwise we will get an error when restoring from the backup. Because when adding a new partition, the constants on the default partition change, and if the data in the partition does not meet the new constraints, we will get an error. If such a situation occurs during restore, you should exclude problematic partitions using --exclude-table, where you need to specify the name of the root partition.

The updated explanation looks too informal and contains a lot of pronounces.
Some sentences can be changed. For example:
We can backup partitions -> partitions can be backed up
we will get an error -> the error occurs
you should exclude problematic partitions -> partitions should be excluded (or use a past tense if it was before the patch and describe how it works now)
the constants on the default partition change -> (here I just don't understand what you mean)

Please format PR message according to points in our wiki.

Copy link
Author

@KnightMurloc KnightMurloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the constants on the default partition change -> (here I just don't understand what you mean)

when we create a partitioned table with a default partition, a constraint is added to it:

Partition constraint: (NOT ((a IS NOT NULL) AND (((a >= 0) AND (a < 1)) OR ((a >= 1) AND (a < 2)) OR ((a >= 2) AND (a < 3)))))

simplified looks like this:

NOT ((a IS NOT NULL) AND (a = 0 OR a = 1 OR a = 2))

if we add a partition for a = 1. the constraint will change to:

NOT ((a IS NOT NULL) AND (a = 0 OR a = 2))

And if the default partition contains rows with a = 1, we will get an error.

@InnerLife0
Copy link

Overall ok, but the PR description should be updated to highlight current situation, what abilities current code missed and what was changed to achieve them (including difference in 6x and 7x behavior). Already explained case is just a special case, but it can be linked with existed test.

… that hinder restore if the default partition in the extension contains data' test
@InnerLife0 InnerLife0 self-requested a review May 31, 2024 06:57
InnerLife0
InnerLife0 previously approved these changes May 31, 2024
@andr-sokolov andr-sokolov merged commit 96aed47 into master Jun 3, 2024
@andr-sokolov andr-sokolov deleted the ADBDEV-5169 branch June 3, 2024 11:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants