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

add scripts to backfill undelegated fields in db #833

Merged
merged 12 commits into from
Sep 8, 2021

Conversation

hannaeko
Copy link
Member

@hannaeko hannaeko commented Jul 28, 2021

Purpose

Update the old 'undelegated' values in the database.

  • PostgreSQL tested with ~1% of the records of the zonemaster.net database on Postgres 9.3 and 13.3
  • SQLite
  • MySQL tested with ~1% of the records of the zonemaster.net database on MariaDB 10.3

Context

Fixes #829

Changes

Add patch scripts.

How to test this PR

Postgres

  • Check the value of delegated vs undelegated tests (all test are delegated, so the second query should return nothing except if you have the patch for undelegated tests in which case there can be a few).

    select DISTINCT params->>'ds_info' as ds_info, params->>'nameservers'  as nameservers from test_results where undelegated = 0 ;
    
    select DISTINCT params->>'ds_info' as ds_info, params->>'nameservers' as nameservers from test_results where undelegated = 1 ;
  • Apply update script perl zonemaster-backend/share/patch_postgresql_db_zonemaster_backend_ver_7.0.0.pl (ignore error if the table has already been changed, "if not exists" is not compatible with PG 9.3)

  • Repeat the first step to verify that all tests has been classified correctly.

MySQL

  • Check the value of delegated vs undelegated tests (all test are delegated, so the second query should return nothing except if you have the patch for undelegated tests in which case there can be a few).

     select distinct json_extract(params, '$.nameservers'), json_extract(params, '$.ds_info') from test_results where undelegated = 0;
    
     select distinct json_extract(params, '$.nameservers'), json_extract(params, '$.ds_info') from test_results where undelegated = 1;
  • Apply update script perl zonemaster-backend/share/patch_mysql_db_zonemaster_backend_ver_7.0.0.pl

  • Repeat the first step to verify that all tests has been classified correctly.

@hannaeko hannaeko requested review from matsduf and a user July 28, 2021 13:20
Copy link
Contributor

@matsduf matsduf left a comment

Choose a reason for hiding this comment

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

$ make distcheck
"/usr/local/bin/perl" "-Iinc" "-MExtUtils::Manifest=fullcheck" -e fullcheck
Not in MANIFEST: share/patch_mysql_db_zonemaster_backend_ver_7.0.0.pl
Not in MANIFEST: share/patch_sqlite_db_zonemaster_backend_ver_7.0.0.pl

@matsduf
Copy link
Contributor

matsduf commented Jul 29, 2021

I have tested SQLite where some delegated were reported as undelegated and vice versa. After running the script all were in the correct category.

In the instructions there is an extra step for FreeBSD (export ZONEMASTER_BACKEND_CONFIG_FILE="/usr/local/etc/zonemaster/backend_config.ini") which is easy to forget and could be removed by an update in the scripts.

Replace

use Zonemaster::Backend::Config;
use Zonemaster::Backend::DB::SQLite;

with

BEGIN {
    if ($^O eq "freebsd") {
        unless ($ENV{ZONEMASTER_BACKEND_CONFIG_FILE}) {
            $ENV{ZONEMASTER_BACKEND_CONFIG_FILE} = "/usr/local/etc/zonemaster/backend_config.ini"
        }
    }
    require Zonemaster::Backend::Config;
}
use Zonemaster::Backend::DB::SQLite;

I have tested this with SQLite, but it should work the same way in the other scripts.

Copy link
Contributor

@matsduf matsduf left a comment

Choose a reason for hiding this comment

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

The following files must also be update: README.md and docs/upgrade_db_zonemaster_backend_ver_7.0.0.md

@hannaeko
Copy link
Member Author

In the instructions there is an extra step for FreeBSD (export ZONEMASTER_BACKEND_CONFIG_FILE="/usr/local/etc/zonemaster/backend_config.ini") which is easy to forget and could be removed by an update in the scripts.

For this issue I suggest a small change in configuration loading, see #835

@hannaeko
Copy link
Member Author

The following files must also be update: README.md and docs/upgrade_db_zonemaster_backend_ver_7.0.0.md

Those files have been updated.

@matsduf
Copy link
Contributor

matsduf commented Jul 29, 2021

In the instructions there is an extra step for FreeBSD (export ZONEMASTER_BACKEND_CONFIG_FILE="/usr/local/etc/zonemaster/backend_config.ini") which is easy to forget and could be removed by an update in the scripts.

For this issue I suggest a small change in configuration loading, see #835

I guess there are pros and cons with both solutions. A "local" solution in the patch scripts make sure that the change will not affect anything else. Also see my comment in #835.

README.md Outdated
@@ -40,7 +40,7 @@ Older than 1.0.3 | [Upgrade to 1.0.3] |
At least 1.0.3 but older than 1.1.0 | [Upgrade to 1.1.0] |
At least 1.1.0 but older than 5.0.0 | [Upgrade to 5.0.0] |
At least 5.0.0 but older than 5.0.2 | [Upgrade to 5.0.2] | For MySQL/MariaDB only
At least 5.0.2 but older than 7.0.0 | [Upgrade to 7.0.0] | For PostgreSQL only
At least 5.0.2 but older than 7.0.0 | [Upgrade to 7.0.0] | For all database types
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest that the comment is empty when all database engines are affected.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@matsduf
Copy link
Contributor

matsduf commented Jul 29, 2021

If #835 is accepted, then that should be merged first, and then the special instructions for FreeBSD in the upgrade instructions can be removed.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Looks good. A small comment though and I commented #835 as well.

eval {
$dbh->do( 'ALTER TABLE test_results ADD COLUMN undelegated integer NOT NULL DEFAULT 0' );
};
print "Error while changing DB schema: " . $@;
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be printed only if there are errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes indeed, fixed.

ghost
ghost previously approved these changes Aug 5, 2021
@matsduf
Copy link
Contributor

matsduf commented Aug 12, 2021

Merge #835, rebase this and remove the special setting for FreeBSD.

ghost
ghost previously approved these changes Aug 16, 2021
@hannaeko
Copy link
Member Author

Merge #835, rebase this and remove the special setting for FreeBSD.

This is now done.

share/patch_mysql_db_zonemaster_backend_ver_7.0.0.pl Outdated Show resolved Hide resolved
print "Error while changing DB schema: " . $@;
}

$dbh->do( qq[
Copy link
Member

Choose a reason for hiding this comment

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

Could this be done using the much simpler for-loop from the MySQL and SQLite implementations?

Copy link
Member Author

Choose a reason for hiding this comment

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

It could but it has a impact on the performance. Processing 13K rows (about 1% of the zonemaster.net database) with the sql statement takes around 1 second and doing it with the while loop takes 17 seconds.

Copy link
Member

Choose a reason for hiding this comment

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

That's an impressive difference. But this is a one-time task.
And the SQL statement is quite complex. What are the chances that a bug has snuck into it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough, I can can change it to the other implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

@blacksponge, have you addressed the comment from @mattias-p?

Copy link
Member Author

Choose a reason for hiding this comment

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

It has now been addressed.

ghost
ghost previously approved these changes Aug 24, 2021
@matsduf
Copy link
Contributor

matsduf commented Sep 1, 2021

When @blacksponge and @mattias-p agree on share/patch_postgresql_db_zonemaster_backend_ver_7.0.0.pl then I am ready to approve.

@hannaeko hannaeko merged commit 86ae65a into zonemaster:develop Sep 8, 2021
@hannaeko hannaeko self-assigned this Nov 17, 2021
@hannaeko hannaeko added the S-ReleaseTested Status: The PR has been successfully tested in release testing label Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-ReleaseTested Status: The PR has been successfully tested in release testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants