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

[DocDB] PITR: Disable restoring to before the sequence was dropped #11875

Closed
sanketkedia opened this issue Mar 24, 2022 · 0 comments
Closed

[DocDB] PITR: Disable restoring to before the sequence was dropped #11875

sanketkedia opened this issue Mar 24, 2022 · 0 comments
Assignees
Labels
area/docdb YugabyteDB core features

Comments

@sanketkedia
Copy link
Contributor

Description

  1. Consider a table that has the following schema:
CREATE TABLE orders(
   id INT NOT NULL,
   details VARCHAR NOT NULL
);

  1. Say we made the id column a sequence
CREATE SEQUENCE order_id_seq
START 10
INCREMENT 10
OWNED BY orders.id;
  1. Assume at time t1 we have the following data in the table:
    SELECT * FROM orders;

id details
10 Order of IPhone11

  1. Say at time t2 (> t1) we drop the sequence
    DROP SEQUENCE order_id_seq;

  2. Now say that we restore to time t1. After restoration, if we try to insert a row with the next id in the sequence (we should be able to since, after restoration, the sequence order_id_seq should be restored), it throws an error. We are not able to insert rows in the orders table using the sequence. Note that we are able to insert a row specifying an explicit value of the id column i.e.

INSERT INTO orders (id, name) values (2, 'Order of earphones’); → Works
INSERT INTO orders (id, name) values (nextval(‘order_id_seq’), 'Order of chocolates’); → throws an error ERROR:  relation "order_id_seq" does not exist

The fix for this is non-trivial. Until we add support for it, we should have a way to prevent restorations such as the above and propagate a suitable error all the way to the client. To detect such a condition, during the restoration of pg catalog tables, we could check the contents of the pg_sequence table for both the times and error out if there are differences.

@sanketkedia sanketkedia added the area/docdb YugabyteDB core features label Mar 24, 2022
lingamsandeep added a commit that referenced this issue Apr 5, 2022
…ore time

Summary:
Problem:
Short summary: If sequences are dropped or modified between the Restore time and the current time, the restore itself may complete successfully. However, the system does not behave in a consistent way as sequences dropped after the restore time may not be accessible despite restore completing successfully. To prevent this inconsistency post-restore, PITR is being disallowed if sequences were created, updated or modified since the Restore time.

Background: Sequences in PG are stored in 2 places - pg_catalog tables which reside in the syscatalog tablet, sequences_data table in the system_postgres database which resides on tservers. Additionally postgres processes maintain in-memory caches of sequences per session. Restore currently does not restore the sequences_data table as it is part of the system_postgres database and not the user database which is restored. As a result, operations of a restored user database that have a dependency on the presence/absence of the sequence at the restore time can fail due to corresponding entries being inconsistent in this sequences_data table.

Test Plan: **ybd  --cxx-test tools_yb-admin-snapshot-schedule-test  --gtest_filter YbAdminSnapshotScheduleTest.PgsqlSequenceCreateDropWithRestore**

Reviewers: bogdan, skedia

Reviewed By: skedia

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D16313
lingamsandeep added a commit that referenced this issue Apr 6, 2022
… since the restore time

Summary:
Problem:

Short summary: If sequences are dropped or modified between the Restore time and the current time, the restore itself may complete successfully. However, the system does not behave in a consistent way as sequences dropped after the restore time may not be accessible despite restore completing successfully. To prevent this inconsistency post-restore, PITR is being disallowed if sequences were created, updated or modified since the Restore time.

Background: Sequences in PG are stored in 2 places - pg_catalog tables which reside in the syscatalog tablet, sequences_data table in the system_postgres database which resides on tservers. Additionally postgres processes maintain in-memory caches of sequences per session. Restore currently does not restore the sequences_data table as it is part of the system_postgres database and not the user database which is restored. As a result, operations of a restored user database that have a dependency on the presence/absence of the sequence at the restore time can fail due to corresponding entries being inconsistent in this sequences_data table.

Original Commit:371b89ae13826e40d0c551931fac9e6c3895a65e

Original Differential Revision : https://phabricator.dev.yugabyte.com/D16313

Test Plan:  **ybd  --cxx-test tools_yb-admin-snapshot-schedule-test  --gtest_filter YbAdminSnapshotScheduleTest.PgsqlSequenceCreateDropWithRestore**

Reviewers: bogdan, skedia

Reviewed By: skedia

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D16405
lingamsandeep added a commit that referenced this issue Apr 7, 2022
…since the restore time

Summary:
Problem:

Short summary: If sequences are dropped or modified between the Restore time and the current time, the restore itself may complete successfully. However, the system does not behave in a consistent way as sequences dropped after the restore time may not be accessible despite restore completing successfully. To prevent this inconsistency post-restore, PITR is being disallowed if sequences were created, updated or modified since the Restore time.

Background: Sequences in PG are stored in 2 places - pg_catalog tables which reside in the syscatalog tablet, sequences_data table in the system_postgres database which resides on tservers. Additionally postgres processes maintain in-memory caches of sequences per session. Restore currently does not restore the sequences_data table as it is part of the system_postgres database and not the user database which is restored. As a result, operations of a restored user database that have a dependency on the presence/absence of the sequence at the restore time can fail due to corresponding entries being inconsistent in this sequences_data table.

Original Commit:371b89ae13826e40d0c551931fac9e6c3895a65e

Original Differential Revision : https://phabricator.dev.yugabyte.com/D16313

Test Plan: ybd --cxx-test tools_yb-admin-snapshot-schedule-test --gtest_filter YbAdminSnapshotScheduleTest.PgsqlSequenceCreateDropWithRestore

Reviewers: skedia, bogdan

Reviewed By: bogdan

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D16412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docdb YugabyteDB core features
Projects
None yet
Development

No branches or pull requests

3 participants