1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00
Commit Graph

1418 Commits

Author SHA1 Message Date
David Steele
8800f32ad9 Remove exclusions once they have been tested in mock/all.
The exclusions no longer have any effect after a restore and just add noise to the expect log.
2019-11-25 08:35:26 -05:00
David Steele
9856fef586 Update integration tests in mock/all that use test points.
Test points will not be available in the C code so update these tests as best as possible without using them.

This represents a loss of coverage for the Perl code (soon to be removed) which will be made up in the C code with unit tests.
2019-11-25 07:48:52 -05:00
David Steele
3cd45a7411 Remove start/stop --force integration tests in mock/all.
These tests require test points which are not being implemented in the C code.

This functionality is fully tested in the command/control unit tests so integration tests are no longer required.
2019-11-25 07:45:58 -05:00
David Steele
01aefc563d Update Perl page checksum expression.
This expression determines which files contain page checksums but it was also including the directory above the relation directories.  In a real PostgreSQL installation this not a problem because these directories don't contain any files.

However, our tests place a file in `base` which the Perl code thought should have page checksums while the new C code says no.

Update the expression to document the change and avoid churn in the expect logs later.
2019-11-25 07:37:09 -05:00
David Steele
cace54151f Add hostId to protocolLocalGet().
Previously this function was only creating locals that talked to the repository.  Backup will need to be able to talk to multiple PostgreSQL hosts.
2019-11-23 10:32:57 -05:00
David Steele
ab65ffdfac Add protocolStorageType*() to manage protocol storage types.
Abstract the string representation of storage types that are passed over the protocol layer.
2019-11-23 10:22:11 -05:00
David Steele
a4b9440d35 Only install specific lcov version when required.
Installing lcov 1.14 everywhere turned out to be a problem just as using 1.13 on Ubuntu 19.04 was.

Since we primarily use Ubuntu 18.04 for coverage testing and reporting, we definitely want to make sure that works.  So, revert to using the default packaged lcov except when specified otherwise in VmTest.pm.

PostgreSQL minor version releases are also included since all containers have been rebuilt.
2019-11-22 19:25:49 -05:00
David Steele
52a3ba6b6f Revert "Forbid % character in parameters."
The issue "fixed" in f01aa586 was caused by treating all strings as format strings while logging, which was fixed in 0c05df45.

Revert because there no longer seems a reason for the extra logic, and it was only partially applied, i.e. not to env vars, command-line options, or config options.
2019-11-22 15:18:56 -05:00
David Steele
381aecae4e Fix walPath() when CWD is / and path is relative.
The function would return a // prefix in this case, which works fine but looks odd while debugging.
2019-11-22 14:30:56 -05:00
David Steele
0c05df4582 Add _FMT() logging macro variants.
Using the same macros for formatted and unformatted logging had several disadvantages.

First, the compiler was unable to verify the format string against the parameters.

Second, legitimate % characters in messages were being interpreted as format characters with garbage output ensuing.

Add _FMT() variants and update all call sites to use the correct variant.
2019-11-22 13:33:26 -05:00
David Steele
f01aa5861d Forbid % character in parameters.
This character causes problems in C and in the shell if we try to output it in an error message.

Forbid it completely and spell it out in error messages to avoid strange effects.

There is likely a better way deal with the issue but this will do for now.
2019-11-21 17:28:03 -05:00
David Steele
c524ec4f95 Remove obsolete integration tests from mock/all.
The protocol timeout tests have been superceded by unit tests.

The TEST_BACKUP_RESUME test point was incorrectly included into a number of tests, probably a copy pasto.  It didn't hurt anything but it did add 200ms to each test where it appeared.

Catalog and control version tests were redundant.  The database version and system id tests covered the important code paths and the C code gets these values from a lookup table.

Finally, fix an incomplete update to the backup.info file while munging for tests.
2019-11-21 16:06:27 -05:00
David Steele
270f9496e4 Add manifestMove(). 2019-11-21 12:08:32 -05:00
David Steele
c5a6631d27 Rearrange manifest module.
Put functions with related functions, move getters above the helper functions, and rename manifestPgPath() to manifestPathPg().
2019-11-21 11:44:40 -05:00
David Steele
9f71a019c8 Allow storageInfo() to operate outside the base storage path.
It is occasionally useful to get information about a file outside of the base storage path.  storageLocal() can be used in some cases but when the storage is remote is doesn't seem worth creating a separate storage object for adhoc info requests.

storageInfo() is a read-only operation so this seems pretty safe.  The noPathEnforce parameter will make auditing exceptions easy.
2019-11-21 10:55:03 -05:00
David Steele
d3b1897625 Allow adhoc enforcement in storagePath().
The ability to disable enforcement (i.e., the requested absolute path is within the storage path) globally will be removed after the Perl migration.

The feature will still be needed occasionally so allow it in an adhoc fashion.
2019-11-21 10:34:32 -05:00
David Steele
e1dad720a1 Rename storagePath() to storageP() in places where it was missed.
Correct this since it will be enforced in a subsequent patch.
2019-11-21 10:21:35 -05:00
David Steele
cef9f0f37f Process . in strPathAbsolute().
A . in a link will always lead to an error since the destination will be inside PGDATA.  However, it is accepted symlink syntax so it's better to resolve it and get the correct error message.

Also, we may have other uses for this function in the future.
2019-11-21 09:40:15 -05:00
David Steele
63c4c14836 Fix lcov build in Vagrantfile.
-q was being instead of -s for silent mode which caused the build to fail.
2019-11-19 20:52:01 -05:00
David Steele
1db9e3b144 Remove *MP() macros variants.
Adding a dummy column which is always set by the P() macro allows a single macro to be used for parameters or no parameters without violating C's prohibition on the {} initializer.

-Wmissing-field-initializers remains disabled because it still gives wildly different results between versions of gcc.
2019-11-17 15:10:40 -05:00
David Steele
09e129886e Add storageInfoList() support to remote storage driver. 2019-11-16 17:47:42 -05:00
David Steele
26e1da82e7 Allow zero-length substrings to be extracted from the end of a string.
The previous assert was a bit overzealous and did not allow this case.  It's not very common but still occasionally useful.
2019-11-16 17:32:49 -05:00
David Steele
8a3de1e05a Add storageInfo() support to remote storage driver. 2019-11-16 17:30:08 -05:00
David Steele
8d6a8c3bf0 Store base path for remote storage locally.
It wasn't practical for the main process to be ignorant of the remote path, and in any case knowing the path makes debugging easier.

Pull the remote path when connecting and pass the result of local storagePath() to the remote when making calls.
2019-11-16 17:12:16 -05:00
David Steele
6827a13f3a Add facility for reading and writing adhoc protocol output.
Pushing output through a JSON blob is not practical if the output is extremely large, e.g. a backup manifest with 100K+ files.

Add read/write routines so that output can be returned in chunks but errors will still be detected.
2019-11-16 17:05:34 -05:00
David Steele
c8db11e65b Add user-id/group-id to hrnReplaceKey(). 2019-11-15 17:50:12 -05:00
David Steele
53a2d04ab0 Allow "null" in jsonToStr(). 2019-11-15 17:48:25 -05:00
David Steele
48e8942e86 Allow trailing / for relative paths in strPathAbsolute().
The trailing / does nothing but is nevertheless valid syntax.
2019-11-15 08:53:15 -05:00
David Steele
3b879c2cb3 Filter logged command options based on the command definition.
Previously, options were being filtered based on what was currently valid.  For chained commands (e.g. backup then expire) some options may be valid for the first command but not the second.

Filter based on the command definition rather than what is currently valid to avoid logging options that are not valid for subsequent commands.  This reduces the number of options logged and will hopefully help avoid confusion and expect log churn.
2019-11-14 16:48:41 -05:00
David Steele
2d10293d04 v2.19: C Migrations and Bug Fixes
Bug Fixes:

* Fix remote timeout in delta restore. When performing a delta restore on a largely unchanged cluster the remote could timeout if no files were fetched from the repository within protocol-timeout. Add keep-alives to prevent remote timeout. (Reported by James Sewell, Jens Wilke.)
* Fix handling of repeated HTTP headers. When HTTP headers are repeated they should be considered equivalent to a single comma-separated header rather than generating an error, which was the prior behavior. (Reported by donicrosby.)

Improvements:

* JSON output from the info command is no longer pretty-printed. Monitoring systems can more easily ingest the JSON without linefeeds. External tools such as jq can be used to pretty-print if desired. (Contributed by Cynthia Shang.)
* The check command is implemented entirely in C. (Contributed by Cynthia Shang.)

Documentation Improvements:

* Document how to contribute to pgBackRest. (Contributed by Cynthia Shang.)
* Document maximum version for auto-stop option. (Contributed by Brad Nicholson.)

Test Suite Improvements:

* Fix container test path being used when --vm=none. (Suggested by Stephen Frost.)
* Fix mismatched timezone in expect test. (Suggested by Stephen Frost.)
* Don't autogenerate embedded libc code by default. (Suggested by Stephen Frost.)
2019-11-12 15:51:28 -05:00
David Steele
a44c5d0315 Add Strings for STORAGE_REPO_ARCHIVE and STORAGE_REPO_BACKUP.
These constants are used often enough that they deserve to have String constants rather than repeatedly calling STRDEF().
2019-11-12 13:12:07 -05:00
David Steele
10c8eeaf6c Fix handling of repeated HTTP headers.
When HTTP headers are repeated they should be considered equivalent to a single comma-separated header rather than generating an error, which was the prior behavior.

Reported by donicrosby.
2019-11-08 18:58:45 -05:00
David Steele
4317178633 Update MinIO to newest release.
We had some problems with newer versions so had held off on updating.  Those problems appear to have been resolved.

In addition, the --compat flag is no longer required.  Prior versions of MinIO required all parts of a multi-part upload (except the last) to be of equal size.  The --compat flag was introduced to restore the default S3 behavior.  Now --compat is only required when ETag is being used for MD5 verification, which we don't do.
2019-11-08 17:56:34 -05:00
David Steele
edcc7306a3 Add TIME parameter debug type.
Previously we were using int64_t to debug time_t but this may not be right depending on how the compiler represents time_t, e.g. it could be a float.

Since a mismatch would have caused a compiler error we are not worried that this has actually happened, and anyway the worst case is that the debug log would be wonky.

The primary benefit, aside from correctness, is that it makes choosing a parameter debug type for time_t obvious.
2019-11-08 09:46:00 -05:00
David Steele
8b682b75d2 Allow mock integration tests for all VM types.
Previously the mock integration tests would be skipped for VMs other than the standard four used in CI.  Now VMs outside the standard four will run the same tests as VM4 (currently U18).
2019-11-02 10:35:48 +01:00
David Steele
7168e07440 Use getcwd() to construct path when WAL path is relative.
Using pg1-path, as we were doing previously, could lead to WAL being copied to/from unexpected places.  PostgreSQL sets the current working directory to PGDATA so we can use that to resolve relative paths.
2019-10-30 14:55:25 +01:00
David Steele
e06db21e35 Error when specified vm is invalid. 2019-10-17 14:00:18 +02:00
David Steele
a52faf83a5 Disable code generation on dry-run. 2019-10-17 11:56:45 +02:00
David Steele
fa6a54bb45 Update last tests that required sudo.
All tests should now run in a sudo-less environment.
2019-10-16 17:05:24 +02:00
David Steele
48bd9e22f1 C test harness refactor.
Consolidate setting configuration into hrnInit() and rename other functions for consistency.

Split out internal functions into a new header.
2019-10-16 15:48:33 +02:00
David Steele
b4aeb217e6 Allow parameters to be passed to travis.pl.
This makes configuring tests easier.

Also add a parameter for tests that require sudo.  This should be retired at some point but some tests still require it.
2019-10-15 17:19:42 +02:00
David Steele
f3b2189659 Remove package build sudo into the container.
By running this in the container we no longer need sudo on the host system for package builds.
2019-10-15 13:27:03 +02:00
David Steele
67dde73727 Run tests in tmpfs.
This will likely improve performance, but it also makes the filesystem consistent between platforms.

A number of tests were failing on shiftfs, which was the default for arm64 on Travis.
2019-10-14 11:51:14 +02:00
David Steele
64c6102a15 Update packages required for Travis-CI builds.
These packages are expected on the arm64 build even though we are using the same os image as amd64.  It appears the arm64 image is slimmer.
2019-10-12 14:47:01 -04:00
David Steele
35eef2b867 Use a lower user id for posix storage tests.
arm64 was not happy with the old user id, so use something smaller.
2019-10-12 14:16:22 -04:00
David Steele
827e95944a Use < 0 and > 0 for strCmp() tests.
Using -1 and 1 was a bit sloppy since the spec only guarantees that the values will be < 0 and > 0.

Found on arm64 where the values were -64 and 64.
2019-10-12 13:52:45 -04:00
David Steele
a2fa1d04b0 Update container images to PostgreSQL 12 GA. 2019-10-12 11:26:13 -04:00
David Steele
397a41e0f9 Add Ubuntu 19.04 container definition. 2019-10-12 11:24:55 -04:00
David Steele
93656db186 Update lcov to 1.14.
1.13 is not compatible with gcc 8 which is what ships with newer distributions.  Build from source to get a more recent version.

1.13 is not compatible with gcc 9 so we'll need to address that at a later date.
2019-10-12 11:24:21 -04:00
David Steele
11c7c8fabb Remove pgbackrest test user.
This user was created before we tested in containers to ensure isolation between the pg and repo hosts which were then just directories.  The downside is that this resulted in a lot of sudos to set the pgbackrest user and to remove files which did not belong to the main test user.

Containers provide isolation without needing separate users so we can now safely remove the pgbackrest user.  This allows us to remove most sudos, except where they are explicitly needed in tests.

While we're at it, remove the code that installed the Perl C library (which also required sudo) and simply add the build path to @INC instead.
2019-10-12 09:45:18 -04:00
David Steele
6f0e7f00af Fix recovery test failing in PostgreSQL 12.0.
This test was not creating recovery.signal when testing with --type=preserve.  The preserve recovery type only keeps existing files and does not create any.

RC1 was just ignoring recovery.signal and going right into recovery.  Weirdly, 12.0 used restore_command to do crash recovery which made the problem harder to diagnose, but this has now been fixed in PostgreSQL and should be released in 12.1.
2019-10-12 09:26:19 -04:00
Cynthia Shang
db1dc4f275 Remove pretty-printing from jsonFromKv() and jsonFromVar().
Now that pretty-printing has been removed from the info command it no longer has a purpose, so remove it.
2019-10-11 13:03:52 -04:00
Cynthia Shang
d90b2724f8 JSON output from the info command is no longer pretty-printed.
Monitoring systems can more easily ingest the JSON without linefeeds.

External tools such as jq can be used to pretty-print if desired.
2019-10-11 12:56:03 -04:00
Cynthia Shang
2972580566 Remove info expect tests from mock/all and mock/stanza.
These tests are redundant now that we have full coverage in the unit tests are are not worth maintaining anymore.
2019-10-11 12:38:03 -04:00
David Steele
642ce003c8 Don't autogenerate embedded libc code by default.
This is only needed when new code is added to the Perl C library, which is becoming rare as the migration progresses.

Also, the code will vary slightly based on the Perl version used for generation so for normal users it is just noise.

Suggested by Stephen Frost.
2019-10-11 11:32:51 -04:00
David Steele
bcd3e4953a Make perl/exec test container required.
This test fails in some cases when --vm=none but it's not worth investigating since this code will be going away soon.
2019-10-10 22:10:20 -04:00
David Steele
e3d87ebace Fix mismatched timezone in expect test.
Also run the --vm-none tests in a non-UTC timezone to prevent regressions.

Suggested by Stephen Frost.
2019-10-10 19:43:42 -04:00
David Steele
6db4e59a66 Allow tests that use ports to run in parallel.
Set the test index in the C unit test code so it can assign port numbers that won't conflict between tests.
2019-10-10 16:13:43 -04:00
David Steele
13fcbb24e9 Fix container test path being used when --vm=none.
Suggested by Stephen Frost.
2019-10-10 15:09:11 -04:00
David Steele
9a3ba649e1 Remove code to generate .travis.yml.
Most of the logic has been moved to test/travis.pl so there wasn't much purpose to this code anymore.
2019-10-10 11:25:59 -04:00
David Steele
696e6a7c44 Don't require sudo to run tests with --vm=none.
Run these tests without sudo privileges on Travis to prevent regressions.
2019-10-10 11:21:09 -04:00
David Steele
7f369006b5 Add gcc 9 support.
A number of tests have been updated and Fedora 30 has been added to the test suite so the unit tests can run on gcc 9.

Stop running unit tests on co6/7 since we appear to have ample unit test coverage.
2019-10-09 15:03:03 -04:00
David Steele
528f4c4347 Remove dependency on aws cli for testing.
This tool was only being used it a few places but was a pretty large dependency.

Rework the forceStorageMove() code using our storage layer and replace one aws cli cp with a storage put.

Also, remove the Dockerfile that was once used to build the Scality S3 test container.
2019-10-09 14:38:24 -04:00
David Steele
61c4f64895 Be smarter about which packages are loaded for testing.
Now that our tests are more diversified it makes sense to load only the packages that are needed for each test.

Move the package loads from .travis.yaml to test/travis.pl where we have more control over what is loaded.
2019-10-08 18:56:55 -04:00
Cynthia Shang
a1c13a50dd The check command is implemented entirely in C.
Note that building the manifest on each host has been temporarily removed.

This feature will likely be brought back as a non-default option (after the manifest code has been fully migrated to C) since it can be fairly expensive.
2019-10-08 18:04:09 -04:00
Cynthia Shang
ecae5e34e5 Update expire command to use C backup.info reconstruct.
This was still being done in Perl until the C Manifest object was available.
2019-10-08 17:30:33 -04:00
Cynthia Shang
4e4d1f414a Add infoBackupLoadFileReconstruct() to InfoBackup object.
Check the backup.info file against the backup path.  Add any backups that are missing and remove any backups that no longer exist.

It's important to run this before backup or expire to be sure we are using the most up-to-date list of backups.
2019-10-08 16:04:27 -04:00
David Steele
b2825b82c7 Add missing header file. 2019-10-08 15:47:47 -04:00
Cynthia Shang
6d8d0eeba7 Add pgBackRest version to Info and Manifest objects.
This was not being exposed previously because it is primarily informational, but now it is needed to reconstruct the backup.info file.
2019-10-08 15:37:08 -04:00
Cynthia Shang
38b72eded4 Document how to contribute to pgBackRest.
There's a lot more to be done here, but this is a good start.
2019-10-08 15:27:17 -04:00
David Steele
45881c74ae Allow most unit tests to run outside of a container.
Three major changes were required to get this working:

1) Provide the path to pgbackrest in the build directory when running outside a container.  Tests in a container will continue to install and run against /usr/bin/pgbackrest.

1) Set a per-test lock path so tests don't conflict on the default /tmp/pgbackrest path.  Also set a per-test log-path while we are at it.

2) Use localhost instead of a custom host for TLS test connections.  Tests in containers will continue to update /etc/hosts and use the custom host.

Add infrastructure and update harnessCfgLoad*() to get the correct exe and paths loaded for testing.

Since new tests are required to verify that running outside a container works, also rework the tests in Travis CI to provide coverage within a reasonable amount of time.  Mainly, break up to doc tests by VM and run an abbreviated unit test suite on co6 and co7.
2019-10-08 12:06:30 -04:00
David Steele
5394893e33 Remove pgPath parameter from pgControlFromFile().
In practice this function is always used with storagePg*() so pgPath is known.
2019-10-03 11:14:22 -04:00
David Steele
29e132f5e9 PostgreSQL 12 support.
Recovery settings are now written into postgresql.auto.conf instead of recovery.conf.  Existing recovery_target* settings will be commented out to help avoid conflicts.

A comment is added before recovery settings to identify them as written by pgBackRest since it is unclear how, in general, old settings will be removed.

recovery.signal and standby.signal are automatically created based on the recovery settings.
2019-10-01 13:20:43 -04:00
Cynthia Shang
f96c54c4ba Add info command set option for detailed text output.
The additional details include databases that can be used for selective restore and a list of tablespaces and symlinks with their default destinations.

This information is not included in the JSON output because it requires reading the manifest which is too IO intensive to do for all manifests.  We plan to include this information for JSON in a future release.
2019-09-30 12:39:38 -04:00
David Steele
a58635ac02 Move C performance tests out of unit tests.
Performance tests were being done in unit tests until there was a better place to put them.

Now there is, so move them there.
2019-09-28 14:24:27 -04:00
David Steele
f1ba428fb0 Add performance test capability in C with scaling.
Scaling allows the starting values to be increased from the command-line without code changes.

Also suppress valgrind and assertions when running performance testing.  Optimization is left at -O0 because we should not be depending on compiler optimizations to make our code performant, and it makes profiling more informative.
2019-09-28 14:02:12 -04:00
David Steele
004ff99a2d Identify Perl performance test by appending -perl.
This is intended to differentiate the upcoming C performance tests from the Perl performance tests that will eventually be migrated.
2019-09-28 13:17:21 -04:00
David Steele
cb62bebadf Use bsearch() on sorted lists rather than an iterative method.
bsearch() is far more efficient than an iterative approach except in the most trivial cases.

For now insert will reset the sort order to none and the list will need to be resorted before bsearch() can be used.  This is necessary because item pointers are not stable after a sort, i.e. they can move around.  Until lists are stable it's not a good idea to surprise the caller by mixing up their pointers on insert.
2019-09-28 10:08:20 -04:00
David Steele
d3d2a7cd86 Add line number and fix spacing in TEST_LOG*() macros. 2019-09-28 09:57:06 -04:00
David Steele
afc483ef86 Clarify which timeline should be used for timeline integration test. 2019-09-27 13:37:59 -04:00
David Steele
d82102d6ef Add explicit promotes to recovery integration tests.
PostgreSQL 12 will shutdown in these cases which seems to be the correct action (according to the documentation) when hot_standby = off, but older versions are promoting instead.  Set target_action explicitly so all versions will behave the same way.

This does beg the question of whether the PostgreSQL 12 behavior is wrong (though it matches the docs) or the previous versions are.
2019-09-27 13:04:36 -04:00
David Steele
833d0da0d9 Store recovery file name in integration when testing preserve recovery.
This makes the test a little more maintainable and is friendly with the changes needed for PostgreSQL 12.
2019-09-27 12:29:33 -04:00
David Steele
80eb561caf Add missing PostgreSQL 11 control/WAL versions in Perl tests.
These values don't seem to be used for testing but better to be tidy.
2019-09-27 09:45:11 -04:00
David Steele
d6a6d93a04 Add PostgreSQL 12 to u18 container.
This does not add PostgresQL 12 support; it simply adds PostgreSQL 12 to the u18 container for development and testing.
2019-09-27 09:35:59 -04:00
David Steele
03a7bda511 Refactor recovery file generation.
Separate the generation of recovery values and formatting them into recovery.conf format.  This is generally a good idea, but also makes the code ready to deal with a different recovery file in PostgreSQL 12.

Also move the recovery file logic out of cmdRestore() into restoreRecoveryWrite().
2019-09-27 09:19:12 -04:00
David Steele
c41fb575fb Add standby restore type.
This restore type automatically adds standby_mode=on to recovery.conf.

This could be accomplished previously by setting --recovery-option=standby_mode=on but PostgreSQL 12 requires standby mode to be enabled by a special file named standby.signal.

The new restore type allows us to maintain a common interface between PostgreSQL versions.
2019-09-26 17:39:45 -04:00
David Steele
451ae397be The restore command is implemented entirely in C.
For the most part this is a direct migration of the Perl code into C.

There is one important behavioral change with regard to how file permissions are handled.  The Perl code tried to set ownership as it was in the manifest even when running as an unprivileged user.  This usually just led to errors and frustration.

The C code works like this:

If a restore is run as a non-root user (the typical scenario) then all files restored will belong to the user/group executing pgBackRest. If existing files are not owned by the executing user/group then an error will result if the ownership cannot be updated to the executing user/group. In that case the file ownership will need to be updated by a privileged user before the restore can be retried.

If a restore is run as the root user then pgBackRest will attempt to recreate the ownership recorded in the manifest when the backup was made. Only user/group names are stored in the manifest so the same names must exist on the restore host for this to work. If the user/group name cannot be found locally then the user/group of the PostgreSQL data directory will be used and finally root if the data directory user/group cannot be mapped to a name.

Reviewed by Cynthia Shang.
2019-09-26 07:52:02 -04:00
David Steele
e968acbdd7 Fix outdated comment.
This was probably missed when a new test was added and the timeline was updated.
2019-09-24 16:55:11 -04:00
David Steele
71349c89ae Add TEST_TITLE() macro.
This macro displays a title for each test.  A test frequently has multiple parts and it was hard to tell which subparts went together.  We used ad hoc indentation to do this.

Anything that is a not a title is automatically indented so manually indenting is not longer needed.  This should make the tests and the test output easier to read.
2019-09-23 17:56:17 -04:00
David Steele
2fd2fe509f Add TEST_RESULT_LOG*() and TEST_SYSTEM*() macros.
These macros encapsulate the functionality provided by direct calls to harnessLogResult() and system().  They both have _FMT() variants.

The primary advantage is that {[path]}, {[user]}, and {[group]} will be replaced with the test path, user, and group respectively.  This saves a log of strNewFmt() calls and makes the tests less noisy.
2019-09-23 17:20:47 -04:00
David Steele
d3a7055ee5 Only enable test.pl --debug-test-trace option when --debug also enabled.
The other way makes no sense and leads to compile errors since --debug-test-trace requires some code that is only enabled by --debug.
2019-09-23 15:15:04 -04:00
David Steele
072aeb8109 Add LFs to storage list tests.
This makes the diffs easier to read when testing.
2019-09-23 15:10:31 -04:00
David Steele
c969137021 Migrate backup manifest load/save to C.
The backup manifest stores a complete list of all files, links, and paths in a backup along with metadata such as checksums, sizes,
timestamps, etc.  A list of databases is also included for selective restore.

The purpose of the manifest is to allow the restore command to confidently reconstruct the PostgreSQL data directory and ensure that
nothing is missing or corrupt.  It is also useful for reporting, e.g. size of backup, backup time, etc.

For now, migrate enough functionality to implement the restore command.

Reviewed by Cynthia Shang.
2019-09-23 13:50:46 -04:00
David Steele
5b64c93e8b Add local option for cfgExecParam().
cfgExecParam() was originally written to provide options for remote processes.  Remotes processes do not have access to the local config so it was necessary to pass every non-default option.

Local processes on the other hand, e.g. archive-get, archive-get-async, archive-push-async, and local, do have access to the local config and therefore don't need every parameter to be passed on the command-line.  The previous way was not wrong, but it was overly verbose and did not align with the way Perl had worked.

Update cfgExecParam() to accept a local option which excludes options from the command line which can be read from local configs.
2019-09-20 17:50:49 -04:00
David Steele
3f18040aab Rename MANIFEST_FILE to BACKUP_MANIFEST_FILE.
This is a bit more descriptive and avoids a naming conflict in the new C manifest code.
2019-09-20 08:13:36 -04:00
David Steele
174cb7b3af Add strPathAbsolute() and strLstRemoveIdx().
strPathAbsolute() generates an absolute path from an absolute base path and an absolute/relative path.

strLstRemoveIdx() is a support function based on lstRemoveIdx().
2019-09-19 22:42:28 -04:00
David Steele
9421493d09 Allow resets when generating local/remote command options.
Somehow this was left out of the original implementation, but it is particularly important for certain types of restores.
2019-09-19 22:34:12 -04:00
David Steele
e24b2e3f4d Only test timestamps for files.
In general we don't care about path and link times since they are easily recreated when restoring.

So, outside of storageInfo() we don't need to bother testing them.
2019-09-18 22:23:04 -04:00
David Steele
54638e8704 Add strLstRemove().
Allow a string to be removed from a StringList using the underlying lstRemove().
2019-09-18 22:17:22 -04:00
David Steele
60d93df503 Use a callback to feed jobs to ProtocolParallel.
Loading jobs in advance uses a lot of memory in the case that there are millions of jobs to be performed.  We haven't seen this yet, but with backup and restore on the horizon it will become the norm.

Instead, use a callback so that jobs are only created as they are needed and can be freed as soon as they are completed.
2019-09-18 07:15:16 -04:00
Cynthia Shang
56bf9d0566 Update HINT messages to conform to new standard detailed in CODING.md. 2019-09-14 12:21:08 -04:00
Cynthia Shang
c5f496b903 Rename parameter processId to processIdx in harnessFork.h for clarity. 2019-09-14 11:56:29 -04:00
David Steele
15d04ca19c Add recursion and json output to the ls command.
These features finally make the ls command practical.

Currently the JSON contains only name, type, and size.  We may add more fields in the future, but these seem like the minimum needed to be useful.
2019-09-12 16:29:50 -04:00
David Steele
e45baa1830 Add sorting, filters, and recursion to storageInfoList().
These are needed for the ls command and are also useful for testing.
2019-09-12 16:03:05 -04:00
David Steele
92365fb801 Disable missing-field-initializers warnings in unit testing.
This warning gives very unpredictable results between compiler versions and seems unrealistic since most of our structs are zeroed for initialization.

This warning has been disabled in the Makefile for a long time.
2019-09-12 15:55:18 -04:00
David Steele
f809d2f008 Ignore apt-get update errors in Travis CI.
Broken vendor packages have been causing builds to break due to an error on apt-get update.

Ignore errors and proceed directory to apt-get install.  It's possible that we'll try to reference an expired package version and get an error anyway, but that seems better than a guaranteed hard error.
2019-09-12 15:16:42 -04:00
David Steele
506c10f7f2 Sort and find improvements to List and StringList objects.
Push the responsibility for sort and find down to the List object by introducing a general comparator function that can be used for both sorting and finding.

Update insert and add functions to return the item added rather than the list.  This is more useful in the core code, though numerous updates to the tests were required.
2019-09-12 12:04:25 -04:00
David Steele
dca5b63f97 Move documentation job first for Travis CI.
Since this job has been running long recently this should improved overall performance when multiple commits are queued up.
2019-09-10 13:06:44 -04:00
David Steele
f4f21d0df7 Add groupIdFromName() and userIdFromName() to user module.
Update StorageWritePosix to use the new functions.

A side effect is that storageWritePosixOpen() will no longer error when the user/group name does not exist.  It will simply retain the original user/group, i.e. the user that executed the restore.

In general this is a feature since completing a restore is more important than setting permissions exactly from the source host.  However, some notification of this omission to the user would be beneficial.
2019-09-10 13:02:05 -04:00
David Steele
f8d0574759 Increase process timeout and emit occasional warnings.
Travis will timeout after 10 minutes with no output.  Emit a warning every 5 minutes to keep Travis alive and increase the total timeout to 20 minutes.

Documentation builds have been timing out a lot recently so hopefully this will help.
2019-09-10 12:29:36 -04:00
David Steele
1049632873 Add user module for managing system users/groups.
Centralize the management of users and groups.

Also update Posix storage driver where users/groups were already in use.
2019-09-08 20:11:51 -04:00
David Steele
d957acb36b Add function to generate PostgreSQL tablespace identifier.
In PostgreSQL >= 9.0 each tablespace data is stored in a specially named directory so different major versions can share the same tablespace path.
2019-09-08 06:53:23 -04:00
David Steele
051128ed9e Add test macro for comparing String to zero-terminated strings.
This macro avoids the need to wrap the first parameter in strPtr() and should improve readability.
2019-09-08 06:47:52 -04:00
David Steele
0a96764cb8 Remove most references to PostgreSQL control and catalog versions.
The control and catalog versions were stored a variety of places in the optimistic hope that they would be useful.  In fact they never were.

We can't remove them from the backup.info and backup.manifest files due to backwards compatibility concerns, but we can at least avoid loading and storing them in C structures.

Add functions to the PostgreSQL interface which will return the control and catalog versions for any supported version of PostgreSQL to allow backwards compatibility for backup.info and backup.manifest.  These functions will be useful in other ways, e.g. generating the tablespace identifier in PostgreSQL >= 9.0.
2019-09-07 18:04:39 -04:00
David Steele
843a602080 Add user/group id to storageInfo().
This is required for some operations on Posix storage.
2019-09-07 15:41:55 -04:00
David Steele
2eb1d1fee3 Rename lstRemove() to lstRemoveIdx().
This works better with the names of upcoming functions and seems sensible even in isolation.
2019-09-06 16:50:57 -04:00
David Steele
dde0c2b0c9 Rename INFO_MANIFEST_FILE to MANIFEST_FILE.
This was missed in 5c314df0 when the module was renamed.
2019-09-06 16:43:53 -04:00
David Steele
4d84820021 Improve performance of info file load/save.
Info files required three copies in memory to be loaded (the original string, an ini representation, and the final info object). Not only was this memory inefficient but the Ini object does sequential scans when searching for keys making large files very slow to load.

This has not been an issue since archive.info and backup.info are very small, but it becomes a big deal when loading manifests with hundreds of thousands of files.

Instead of holding copies of the data in memory, use a callback to deliver the ini data directly to the object when loading. Use a similar method for save to avoid having an intermediate copy. Save is a bit complex because sections/keys must be written in alpha order or older versions of pgBackRest will not calculate the correct checksum.

Also move the load retry logic to helper functions rather than embedding it in the Info object. This allows for more flexibility in loading and ensures that stack traces will be available when developing unit tests.

Reviewed by Cynthia Shang.
2019-09-06 13:48:28 -04:00
David Steele
7334f30c35 Add helper function for adding CipherBlock filters to groups.
Reviewed by Cynthia Shang.
2019-09-06 13:35:28 -04:00
David Steele
5c314df098 Rename infoManifest module to manifest.
The manifest is not an info file so if anything it should be called backupManifest.  But that seems too long for such a commonly used object so manifest seems better.

Note that unlike Perl there is no storage manifest method so this stands as the only manifest in the C code, as befits its importance.
2019-09-05 19:53:00 -04:00
David Steele
ce2bf29998 v2.17: C Migrations and Bug Fixes
Bug Fixes:

* Improve slow manifest build for very large quantities of tables/segments. (Reported by Jens Wilke.)
* Fix exclusions for special files. (Reported by CluelessTechnologist, Janis Puris, Rachid Broum.)

Improvements:

* The stanza-create/update/delete commands are implemented entirely in C. (Contributed by Cynthia Shang.)
* The start/stop commands are implemented entirely in C. (Contributed by Cynthia Shang.)
* Create log directories/files with 0750/0640 mode. (Suggested by Damiano Albani.)

Documentation Bug Fixes:

* Fix yum.p.o package being installed when custom package specified. (Reported by Joe Ayers, John Harvey.)

Documentation Improvements:

* Build pgBackRest as an unprivileged user. (Suggested by Laurenz Albe.)
2019-09-03 16:39:32 -04:00
David Steele
3a28b68b8b Disable S3 and encryption on u18 integration tests for mock/all/1.
This test is commonly used for sanity checking but the combination of S3 and encryption makes it hard to use and encourages temporary changes to make it usable.

Acknowledge this and disable S3 and encryption for this test and move them to mock/all/2.
2019-09-02 19:06:12 -04:00
David Steele
05abab5e72 Add OBJECT_DEFINE_MOVE() macro.
The object *Move() functions are very repetitive so replace them with a macro that works similarly to OBJECT_DEFINE_FREE().
2019-08-30 14:36:02 -04:00
David Steele
d1675b7e91 Add ioReadLineParam() to allow return on eof.
ioReadLine() errors on eof because it has previously been used only for protocol reads.

Returning on eof is handy for reading lines from files where eof is not considered an error.
2019-08-28 10:46:54 -04:00
Josh Soref
545ccfa878 Fix typos in the documentation.
Contributed by Josh Soref.
2019-08-26 12:26:00 -04:00
Josh Soref
08bac74d38 Fix typo in stack trace message.
Contributed by Josh Soref.
2019-08-26 12:20:51 -04:00
Josh Soref
c2771e5469 Fix comment typos.
This includes some variable names in tests which don't seem important enough for their own commits.

Contributed by Josh Soref.
2019-08-26 12:05:36 -04:00
David Steele
22aa532be1 Add storage tests for files beginning with dots.
Prevent a regression of the issue fixed in f88012ce by adding some tests.
2019-08-26 11:37:21 -04:00
Josh Soref
8c9df8c290 Fix typo in httpClientReponseHeader() function name.
Contributed by Josh Soref.
2019-08-26 11:35:35 -04:00
David Steele
01c2669b97 Fix exclusions for special files.
Prior to 2.16 the Perl manifest code would skip any file that began with a dot.  This was not intentional but it allowed PostgreSQL socket files to be located in the data directory.  The new C code in 2.16 did not have this unintentional exclusion so socket files in the data directory caused errors.

Worse, the file type error was being thrown before the exclusion check so there was really no way around the issue except to move the socket files out of the data directory.

Special file types (e.g. socket, pipe) will now be automatically skipped and a warning logged to notify the user of the exclusion.  The warning can be suppressed with an explicit --exclude.

Reported by CluelessTechnologist, Janis Puris, Rachid Broum.
2019-08-23 07:47:54 -04:00
David Steele
2862f480cd Add special file type to storageInfo().
There's not much we can do with special files, but higher level logic can at least exclude them gracefully rather than throwing a hard error.
2019-08-23 07:24:25 -04:00
David Steele
f88012cef3 Fix regexp to ignore ./.. directories in the Posix driver.
In versions <= 2.15 the old regexp caused any file or directory beginning with . to be ignored during a backup.  This has caused behavioral differences in 2.16 because the new C code correctly excludes ./.. directories.

This Perl code is only used for testing now, but it should still match the output of the C functions.
2019-08-22 10:18:34 -04:00
David Steele
c002a2ce2f Move info file checksum to the end of the file.
Putting the checksum at the beginning of the file made it impossible to stream the file out when saving.  The entire file had to be held in memory while it was checksummed so the checksum could be written at the beginning.

Instead place the checksum at the end.  This does not break the existing Perl or C code since the read is not order dependent.

There are no plans to improve the Perl code to take advantage of this change, but it will make the C implementation more efficient.

Reviewed by Cynthia Shang.
2019-08-21 19:45:48 -04:00
Cynthia Shang
c733319063 The stanza-create/update/delete commands are implemented entirely in C.
Contributed by Cynthia Shang.
2019-08-21 16:26:28 -04:00
Cynthia Shang
53f27da3a6 Add checkDbConfig() to compare pgBackRest/PostgreSQL configs.
Checking the PostgreSQL-reported path and version against the pgBackRest configuration helps ensure that pgBackRest is operating against the correct cluster.

In Perl this functionality was in the Db object, but check seems like a better place for it in C.

Contributed by Cynthia Shang.
2019-08-21 15:41:52 -04:00
David Steele
8b93fdf349 Add storagePg*() variants to get storage for a specified host id.
Previously the host id to use was pulled from the host-id option or defaulted to 1.

The stanza, check, and backup commands will all need the ability to address a specified pg host, so add functions to make that possible.
2019-08-21 15:26:52 -04:00
Cynthia Shang
fa640f22ad Allow Info* objects to be created from scratch in C.
Previously, info files (e.g. archive.info, backup.info) were created in Perl and only loaded in C.

The upcoming stanza commands in C need to create these files so refactor the Info* objects to allow new, empty objects to be created.  Also, add functions needed to initialize each Info* object to a valid state.

Contributed by Cynthia Shang.
2019-08-21 15:12:00 -04:00
Cynthia Shang
71d96531f8 Fix comment typo.
Contributed by Cynthia Shang.
2019-08-21 12:10:09 -04:00
Cynthia Shang
c4533765fb Add Db object getters missed in e4901d50.
dbOpen() loaded the version and data directory but there was no way to get the data externally.

Contributed by Cynthia Shang.
2019-08-21 11:59:51 -04:00
Cynthia Shang
27e8235812 Add repoIsLocalVerify() to verify repository locality.
Some commands can only be run on a host where the repository is local.  This function centralizes the check and error.

Contributed by Cynthia Shang.
2019-08-21 11:41:36 -04:00
Cynthia Shang
6a09d9294d Require storage when calling pgControlFromFile().
Previously storageLocal() was being used internally but loading pg_control from remote storage is often required.

Also, storagePg() is more appropriate than storageLocal() for all current usage.

Contributed by Cynthia Shang.
2019-08-21 11:29:30 -04:00
David Steele
f6aef6e466 Properly reset conflicting pg-* options for the remote protocol.
The pg1-socket-path and pg1-port options were not being reset when options from a higher index were being pushed down for processing by a remote.  Since remotes only talk to one cluster they always use the options in index 1.  This requires moving options from the original index to 1 before starting the remote.  All options already set on index 1 must be removed if they are not being overwritten.
2019-08-19 21:45:54 -04:00
David Steele
d411321d28 Add reset to temp memory contexts to save memory and processing time.
Processing large datasets in a memory context can lead to high memory usage and long allocation times.  Add a new MEM_CONTEXT_TEMP_RESET_BEGIN() macro that allows temp allocations to be automatically freed after N iterations.
2019-08-19 21:16:10 -04:00
David Steele
7d97d49f41 Add MostCommonValue object.
Calculate the most common value in a list of variants.  If there is a tie then the first value passed to mcvUpdate() wins.

mcvResult() can be called multiple times because it does not end processing, but there is a cost to calculating the result each time
since it is not stored.
2019-08-18 20:46:34 -04:00
David Steele
8aa1e552b0 Add backup type conversion functions.
Convert back and forth between the string and enum representations of backup types.
2019-08-18 20:09:44 -04:00
David Steele
3df075bf40 Fix test writing "null" into manifest files.
"null" is not allowed in the manifest format (null values should be missing instead) but Perl was treating the invalid values written by this test as if they were missing.

Update the test code to remove the values rather than setting them to "null".
2019-08-18 15:29:18 -04:00
David Steele
8edc57b581 Remove RHEL package patch merged to upstream. 2019-08-18 15:19:10 -04:00
David Steele
d0dee2e260 Add bool rendering to jsonFromVar(). 2019-08-17 17:47:13 -04:00
David Steele
8fc1d3883b Fix expire not immediately writing into separate file after backup.
Logging stayed in the backup log until the Perl code started.  Fix this so it logs to the correct file and will still work after the Perl code is removed.
2019-08-17 17:43:56 -04:00
David Steele
bc5385142c Change comment for searchability. 2019-08-09 15:18:42 -04:00
Cynthia Shang
382ed92825 The start/stop commands are implemented entirely in C.
The Perl versions remain because they are still being used by the Perl stanza commands.  Once the stanza commands are migrated they can be removed.

Contributed by Cynthia Shang.
2019-08-09 15:17:18 -04:00
David Steele
fe196cb0df Update RHEL patch for upstream changes.
This isn't correct, but we can't test anything else if the package doesn't build.
2019-08-09 14:52:26 -04:00
David Steele
e9517dcec0 Add hash constants for zero-length data.
No need to calculate a hash when the data length is known to be zero.  Use one of these constants instead.
2019-08-08 18:47:02 -04:00
David Steele
1076b142e3 Remove Debian package patch merged to upstream. 2019-08-08 16:15:42 -04:00
David Steele
969e5817c5 Add cvtZToMode().
The companion function to cvtModeToZ().
2019-08-08 11:59:39 -04:00
David Steele
1f93e147fa Add kvGetDefault() to KeyValue object.
Return the default only if the key is not found, not when the value is NULL.
2019-08-08 11:41:49 -04:00
David Steele
289b47902b Allow NULLs in strEq().
Bring this function more in line with the way varEq() works.  NULL == NULL but NULL != NOT NULL.
2019-08-08 10:50:25 -04:00
Cynthia Shang
feec674b6f Add constant for lock file extension.
Contributed by Cynthia Shang.
2019-08-08 06:48:25 -04:00
David Steele
9e730c1bd6 v2.16: C Migrations and Bug Fixes
Bug Fixes:

* Retry S3 RequestTimeTooSkewed errors instead of immediately terminating. (Reported by sean0101n, Tim Garton, Jesper St John, Aleš Zelený.)
* Fix incorrect handling of transfer-encoding response to HEAD request. (Reported by Pavel Suderevsky.)
* Fix scoping violations exposed by optimizations in gcc 9. (Reported by Christian Lange, Ned T. Crigler.)

Features:

* Add repo-s3-port option for setting a non-standard S3 service port.

Improvements:

* The local command for backup is implemented entirely in C. (Contributed by David Steele, Cynthia Shang.)
* The check command is implemented partly in C. (Reviewed by Cynthia Shang.)
2019-08-05 12:03:04 -04:00
David Steele
3d3003e9ca The check command is implemented partly in C.
Implement switch WAL and archive check in C but leave the rest in Perl for now.

The main idea was to have some real integration tests for the new database code so the rest of the migration can wait.

Reviewed by Cynthia Shang.
2019-08-01 20:35:01 -04:00
David Steele
e4901d50d5 Add Db object to encapsulate PostgreSQL queries and commands.
Migrate functionality from the Perl Db module to C. For now this is just enough to implement the WAL switch check.

Add the dbGet() helper function to get Db objects easily.

Create macros in harnessPq to make writing pq scripts easier by grouping commonly used functions together.

Reviewed by Cynthia Shang.
2019-08-01 15:38:27 -04:00
David Steele
f9e1f3a798 Retry S3 RequestTimeTooSkewed errors instead of immediately terminating.
The cause of this error seems to be that a failed request takes so long that a subsequent retry at the http level uses outdated headers.

We're not sure if pgBackRest it to blame here (in one case a kernel downgrade fixed it, in another case an incorrect network driver was the problem) so add retries to hopefully deal with the issue if it is not too persistent.  If SSL_write() has long delays before reporting an error then this will obviously affect backup performance.

Reported by sean0101n, Tim Garton, Jesper St John, Aleš Zelený.
2019-08-01 14:28:30 -04:00
David Steele
2eb3c9f95f Improve error handling for SSL_write().
Error codes were not being caught for SSL_write() so it was hard to see exactly what was happening in error cases.  Report errors to aid in debugging.

Also add a retry for SSL_ERROR_WANT_READ.  Even though we have not been able to reproduce this case it is required by SSL_write() so go ahead and implement it.
2019-08-01 09:58:24 -04:00
David Steele
89c67287bc Improve multi-host handling in protocol helper.
Multiple PostgreSQL hosts were supported via the host-id option but there are cases where it is useful to be able to directly specify the host id required, e.g. to iterate through pg* hosts when looking for candidate primaries and standbys during backup.
2019-07-31 20:44:49 -04:00
David Steele
893ae24284 Add timeout to walSegmentFind().
Keep trying to locate the WAL segment until timeout.  This is useful for the check and backup commands which must wait for segments to arrive in the archive.
2019-07-31 19:58:57 -04:00
Cynthia Shang
03b28da1ca Rename control/control module to control/common.
This is more consistent with how other common modules are named.

Contributed by Cynthia Shang.
2019-07-31 11:35:58 -04:00
David Steele
88c1929ec5 Don't pass local config* options to the remote.
The remotes have their own config options (repo-host-config, etc.) so don't pass the local config* options.

This was a regression from the behavior of the Perl code and while there have been no field reports it caused breakage on test systems with multiple configurations.
2019-07-26 08:37:58 -04:00
David Steele
f8b0676fd6 Allow modules to be included for testing without requiring coverage.
Sometimes it is useful to get at the internals of a module that is not being tested for coverage in order to provide coverage for another module that is being tested.  The include directive allows this.

Update modules that had previously been added to coverage that only need to be included.
2019-07-25 20:15:06 -04:00
David Steele
554d98746a Add repo-s3-port option for setting a non-standard S3 service port.
If this option is set then ports appended to repo-s3-endpoint or repo-s3-host will be ignored.

Setting this option explicitly may be the only way to use a bare ipv6 address with S3 (since multiple colons confuse the parser) but we plan to improve this in the future.
2019-07-25 17:36:51 -04:00
David Steele
d8ca0e5c5b Add Perl interface to C PgQuery object.
This validates that all current queries work with the new interface and removes the dependency on DBD::Pg.
2019-07-25 17:05:39 -04:00
David Steele
415542b4a3 Add PostgreSQL query client.
This direct interface to libpq allows simple queries to be run against PostgreSQL and supports timeouts.

Testing is performed using a shim that can use scripted responses to test all aspects of the client code.  The shim will be very useful for testing backup scenarios on complex topologies.

Reviewed by Cynthia Shang.
2019-07-25 14:50:02 -04:00
David Steele
59f135340d The local command for backup is implemented entirely in C.
The local process is now entirely migrated to C.  Since all major I/O operations are performed in the local process, the vast majority of I/O is now performed in C.

Contributed by David Steele, Cynthia Shang.
2019-07-25 14:34:16 -04:00
David Steele
54ec8f151e Add int rendering to jsonFromVar(). 2019-07-24 19:45:35 -04:00
David Steele
615735e7ee Add new types to JSON render.
Add bool, array, and int64 as valid array subtypes.

Pretty print for the array subtype is not correct but is currently not in use (this can be seen at line 328 in typeJsonTest.c).
2019-07-24 06:52:49 -04:00
David Steele
38ba458616 Add IoSink filter.
Discard all data passed to the filter.  Useful for calculating size/checksum on a remote system when no data needs to be returned.

Update ioReadDrain() to automatically use the IoSink filter.
2019-07-18 08:42:42 -04:00
Cynthia Shang
d1dd6add48 Remove never-used infoBackupCheckPg() function.
Contributed by Cynthia Shang.
2019-07-17 16:55:21 -04:00
David Steele
3bdba4933d Fix incorrect handling of transfer-encoding response to HEAD request.
The HTTP server can use either content-length or transfer-encoding to indicate that there is content in the response.  HEAD requests do not include content but return all the same headers as GET.  In the HEAD case we were ignoring content-length but not transfer-encoding which led to unexpected eof errors on AWS S3.  Our test server, minio, uses content-length so this was not caught in integration testing.

Ignore all content for HEAD requests (no matter how it is reported) and add a unit test for transfer-encoding to prevent a regression.

Found by Pavel Suderevsky.
2019-07-17 16:49:42 -04:00
Cynthia Shang
6f981c53bb Remove obsolete ignoreMissing parameter.
Contributed by Cynthia Shang.
2019-07-17 15:44:55 -04:00
David Steele
7662d32e60 Fix comment typos and clarify HEAD response behavior. 2019-07-17 15:42:37 -04:00
David Steele
eee67db4d6 Allow pg storage to be remote.
None of the currently migrated commands needed remote pg storage but now backup, check, stanza-* will need it.
2019-07-17 14:09:50 -04:00
David Steele
30f55a3c2a Add compressed storage feature.
This feature denotes storage that can compress files so that they take up less space than what was written.  Currently this includes the Posix and CIFS drivers.  The stored size of the file will be rechecked after write to determine if the reported size is different.  This check would be wasted on object stores such as S3, and they might not report the file as existing immediately after write.

Also add tests to each storage driver to check features.
2019-07-15 17:36:24 -04:00
David Steele
3e1062825d Allow multiple filters to be pushed to the remote and return results.
Previously only a single filter could be pushed to the remote since order was not being maintained.  Now the filters are strictly ordered.

Results are returned from the remote and set in the local IoFilterGroup so they can be retrieved.

Expand remote filter support to include all filters.
2019-07-15 16:49:46 -04:00
David Steele
d5654375a5 Add ioReadDrain().
Read all data from an IoRead object and discard it.  This is handy for calculating size, hash, etc. when the output is not needed.

Update code where a loop was used before.
2019-07-15 08:44:41 -04:00
David Steele
ede7df9fb1 Allow NULL in JSON list. 2019-07-14 15:53:31 -04:00
David Steele
c836c483dc Add lstClear() to List object. 2019-07-14 15:42:55 -04:00
David Steele
e10577d0b0 Fix incorrect offline upper bound for ignoring page checksum errors.
For offline backups the upper bound was being set to 0x0000FFFF0000FFFF rather than UINT64_MAX.  This meant that page checksum errors might be ignored for databases with a lot of past WAL in offline mode.

Online mode is not affected since the upper bound is retrieved from pg_start_backup().
2019-07-11 09:13:56 -04:00
Cynthia Shang
6a89c1526e Revert a2dcdc07.
It is simpler to implement the required logic in stanza-delete rather than add complexity to this function.

Contributed by Cynthia Shang.
2019-07-10 12:04:25 -04:00
Cynthia Shang
a2dcdc0711 Update lockStopTest() to optionally return a result rather than error.
Some commands (e.g. stanza-delete) would prefer to throw a customized error.

Contributed by Cynthia Shang.
2019-07-09 16:41:58 -04:00
David Steele
27b3246e85 Exclude more build files from rsync between tests.
Files (especially build.auto.h) were being removed and forcing a full build between separate invocations of test.pl.

This affected ad-hoc testing at the command-line, not a full test run in CI.
2019-07-08 08:29:25 -04:00
David Steele
5e1ed2e8a5 Remove clang static analysis.
This analysis never produced anything but false positives (var might be NULL) but took over a minute per test run and added 600MB to the test container.
2019-07-05 18:34:15 -04:00
David Steele
488fb67294 Force PostgreSQL versions to string for newer versions of JSON:PP.
Since 2.91 JSON::PP has a bias for saving variables that look like numbers as numbers even if they were declared as strings.

Force versions to strings where needed by appending ''.

Update the json-pp-perl package on Ubuntu 18.04 to 2.97 to provide test coverage.
2019-07-05 17:25:01 -04:00
David Steele
9836578520 Remove perl critic and coverage.
No new Perl code is being developed, so these tools are just taking up time and making migrations to newer platforms harder.  There are only a few Perl tests remaining with full coverage so the coverage tool does not warn of loss of coverage in most cases.

Remove both tools and associated libraries.
2019-07-05 16:55:17 -04:00
David Steele
1708f1d151 Use minio for integration testing.
ScalityS3 has not received any maintenance in years and is slow to start which is bad for testing.  Replace it with minio which starts quickly and ships as a single executable or a tiny container.

Minio has stricter limits on allowable characters but should still provide enough coverage to show that our encoding is working correctly.

This commit also includes the upgrade to openssl 1.1.1 in the Ubuntu 18.04 container.
2019-07-02 22:20:35 -04:00
David Steele
b9b21315ea Updates for openssl 1.1.1.
Some HTTP error tests were failing after the upgrade to openssl 1.1.1, though the rest of the unit and integration tests worked fine.  This seemed to be related to the very small messages used in the error testing, but it pointed to an issue with the code not being fully compliant, made worse by auto-retry being enabled by default.

Disable auto-retry and implement better error handling to bring the code in line with openssl recommendations.

There's no evidence this is a problem in the field, but having all the tests pass seems like a good idea and the new code is certainly more robust.

Coverage will be complete in the next commit when openssl 1.1.1 is introduced.
2019-07-02 22:09:12 -04:00
David Steele
b0728c33db Remove Debian package patch merged to upstream. 2019-06-27 14:30:20 -04:00
Cynthia Shang
33e3d316d6 Reverse loop in infoPgSave() to be consistent with infoPgNewLoad().
Contributed by Cynthia Shang.
2019-06-26 19:52:04 -04:00
David Steele
4bffa0c5bb Add test function to create the S3 bucket instead of using aws cli.
Eventually the idea is to remove the dependency on aws cli since Python is a big install.
2019-06-26 15:02:30 -04:00
David Steele
4815752ccc Add Perl interface to C storage layer.
Maintaining the storage layer/drivers in two languages is burdensome.  Since the integration tests require the Perl storage layer/drivers we'll need them even after the core code is migrated to C.  Create an interface layer so the Perl code can be removed and new storage drivers/features introduced without adding Perl equivalents.

The goal is to move the integration tests to C so this interface will eventually be removed.  That being the case, the interface was designed for maximum compatibility to ease the transition.  The result looks a bit hacky but we'll improve it as needed until it can be retired.
2019-06-26 08:24:58 -04:00
David Steele
6650d8144c v2.15: C Implementation of Expire
Bug Fixes:

* Fix archive retention expiring too aggressively. (Fixed by Cynthia Shang. Reported by Mohamad El-Rifai.)

Improvements:

* The expire command is implemented entirely in C. (Contributed by Cynthia Shang.)
* The local command for restore is implemented entirely in C.
* Remove hard-coded PostgreSQL user so $PGUSER works. (Suggested by Julian Zhang, Janis Puris.)
* Honor configure --prefix option. (Suggested by Daniel Westermann.)
* Rename repo-s3-verify-ssl option to repo-s3-verify-tls. The new name is preferred because pgBackRest does not support any SSL protocol versions (they are all considered to be insecure). The old name will continue to be accepted.

Documentation Improvements:

* Add FAQ to the documentation. (Contributed by Cynthia Shang.)
* Use wal_level=replica in the documentation for PostgreSQL ≥ 9.6. (Suggested by Patrick McLaughlin.)
2019-06-25 08:29:06 -04:00
David Steele
d7f12f268a Redact secure options in the help command.
Secure options could show up in the help as "current".  While the user must have permissions to see the source of the options (e.g. environment, config file) it's still not a good idea to display them in an unexpected context.

Instead show secure options as <redacted> in the help command.
2019-06-24 19:27:13 -04:00
David Steele
c22e10e4a9 Honor configure --prefix option.
The --prefix option was entirely ignored and DESTDIR was a combination of DESTDIR and bindir.

Bring both in line with recommendations for autoconf and make as specified in https://www.gnu.org/software/make/manual/html_node/Directory-Variables.html and https://www.gnu.org/prep/standards/html_node/DESTDIR.html.

Suggested by Daniel Westermann.
2019-06-24 15:42:33 -04:00
Cynthia Shang
b498188f01 Error on db history mismatch when expiring.
Amend commit 434cd832 to error when the db history in archive.info and backup.info do not match.

The Perl code would attempt to reconcile the history by matching on system id and version but we are not planning to migrate that code to C.  It's possible that there are users with mismatches but if so they should have been getting errors from info for the last six months.  It's easy enough to manually fix these files if there are any mismatches in the field.

Contributed by Cynthia Shang.
2019-06-24 11:59:44 -04:00
David Steele
039e515a31 Allow protocol compression when read/writing remote files.
If the file is compressible (i.e. not encrypted or already compressed) it can be marked as such in storageNewRead()/storageNewWrite().  If the file is being read from/written to a remote it will be compressed in transit using gzip.

Simplify filter group handling by having the IoRead/IoWrite objects create the filter group automatically.  This removes the need for a lot of NULL checking and has a negligible effect on performance since a filter group needs to be created eventually unless the source file is missing.

Allow filters to be created using a VariantList so filter parameters can be passed to the remote.
2019-06-24 10:20:47 -04:00
David Steele
434cd83285 The expire command is implemented entirely in C.
This implementation duplicates the functionality of the Perl code but does so with different logic and includes full unit tests.

Along the way at least one bug was fixed, see issue #748.

Contributed by Cynthia Shang.
2019-06-18 15:19:20 -04:00
David Steele
f88bee7b33 TLS/HTTP statistics log replacements.
These statistics can change with any code update so they cause a lot of churn in the expect logs.
2019-06-18 10:13:28 -04:00
David Steele
593446718a Add S3 info type missed in 7f2f5354.
File is the only type possible in S3.
2019-06-18 06:45:47 -04:00
David Steele
0a96a2895d Add storage layer for tests and documentation.
The tests and documentation have been using the core storage layer but soon that will depend entirely on the C library, creating a bootstrap problem (i.e. the storage layer will be needed to build the C library).

Create a simplified Posix storage layer to be used by documentation and the parts of the test code that build and execute the actual tests.  The actual tests will still use the core storage driver so they can interact with any type of storage.
2019-06-17 09:16:44 -04:00
David Steele
ceafd8e19d Migrate page checksum filter to C.
This filter exactly mimics the behavior of the Perl filter so is a drop-in replacement.

The filter is not integrated yet since it requires the Perl-to-C storage layer interface coming in a future commit.
2019-06-17 07:52:03 -04:00
David Steele
892f35a728 Add new types to JSON render.
Still not a complete list, but we are getting there.
2019-06-17 07:42:12 -04:00
Cynthia Shang
c64c9c0590 Add backup management functions to InfoBackup.
Allow current backups to be listed and deleted.

Also expose some constants required by expire and stanza-* commands.

Contributed by Cynthia Shang.
2019-06-17 06:59:06 -04:00
Cynthia Shang
44bafc127d Rename info*New() functions to info*NewLoad().
These names more accurately reflect what the functions do and follow the convention started in Info and InfoPg.

Also remove the ignoreMissing parameter since it was never used.

Contributed by Cynthia Shang.
2019-06-17 06:47:15 -04:00
David Steele
f05fbc54a8 Fix filters not processing when there is no input.
Some filters (e.g. encryption and compression) produce output even if there is no input.  Since the filter group was marked as "done" initially, processing would not run when there was zero input and that resulted in zero output.

All filters start not done so start the filter group the same way.
2019-06-14 08:04:28 -04:00
David Steele
9ba95e993b Use retries to wait for test S3 server to start.
The prior method of tailing the docker log no longer seems reliable.  Instead, keep retrying the make bucket command until it works and show the error if it times out.
2019-06-13 17:58:33 -04:00
David Steele
fdd375b63d Integrate S3 storage driver with HTTP client cache.
This allows copying from one S3 object to another.  We generally try to avoid doing this but there are a few cases where it is needed and the tests do it quite a bit.

One thing to look out for here is that reads require the http client to be explicitly released by calling httpClientDone().  This means than clients could grow if they are not released properly.  The http statistics will hopefully alert us if this is happening.
2019-06-11 16:26:32 -04:00
David Steele
ced42d6511 Add HTTP client cache.
This cache manages multiple http clients and returns one to the caller that is not busy.  It is the responsibility of the caller to indicate when they are done with a client. If returnContent is set then the client will automatically be marked done.

Also add special handing for HEAD requests to recognize that content-length is informational only and no content is expected.
2019-06-11 10:48:22 -04:00
David Steele
7f2f535460 Add info() and infoList() to S3 driver.
These should be the last functions required to complete the implementation of the S3 driver.
2019-06-10 16:09:38 -04:00
David Steele
9d1b03781f Revert removal of aws cli in 3e1b06ac.
This is required for integration tests to create buckets.
2019-06-10 15:52:51 -04:00
David Steele
456391f67c Create general-purpose S3 list function.
There are already two functions which need file lists and more on the way, so create a general-purpose function to reduce code duplication.
2019-06-10 12:23:04 -04:00
David Steele
e701e8fd84 Expose storage type.
Code calling the storage should be driver agnostic but knowing the storage type can be useful for debugging and error reporting.
2019-06-05 11:50:49 -04:00
David Steele
6ff3325c77 Enforce requiring repo-cipher-pass at config parse time.
This was not enforced at parse time because repo1-cipher-type could be passed on the command-line even in cases where encryption was not needed by the subprocess.

Filter repo-cipher-type so it is never passed on the command line.  If the subprocess does not have access to the passphrase then knowing the encryption type is useless anyway.
2019-06-05 11:43:17 -04:00
David Steele
aca11b2fa1 Add String to types supported by JSON list render.
All types should be supported eventually but for now this answers the need.
2019-06-04 17:40:27 -04:00
David Steele
0ab6f3bb87 Fix incorrect error type on missing path. 2019-06-04 13:38:05 -04:00
David Steele
4b91259de8 Make working with filter groups less restrictive.
Filter groups could not be manipulated once they had been assigned to an IO object.  Now they can be freely manipulated up to the time the IO object is opened.

Also, move the filter group into the IO object's context so they don't need to be tracked separately.
2019-06-04 12:56:04 -04:00
David Steele
92e04ea9f4 Remove per-stanza repo cache clear during testing.
This was not being used and is not supported by the equivalent C code.
2019-06-04 10:34:19 -04:00
David Steele
44eb21ea93 Use HEAD to check if a file exists on S3.
The previous implementation searched for the file in a list which worked but was not optimal.  For arbitrary bucket structures it would also produce a false negative if a match was not found in the first 1000 entries.  This was not an issue for our repo structure since the max hits on exists calls is two but it seems worth fixing to avoid future complications.
2019-06-04 10:05:27 -04:00
David Steele
15b8e3b6af Make C S3 requests use the same host logic as Perl.
The C code was passing the host (if specified) with the request which could force the server into path-style URLs, which are not supported.

Instead, use the Perl logic of always passing bucket.endpoint in the request no matter what host is used for the HTTPS connection.

It's an open question whether we should support path-style URLs but since we don't it's useless to tell the server otherwise.  Note that Amazon S3 has deprecated path-style URLs and they are no longer supported on newly created buckets.
2019-06-04 09:39:08 -04:00
David Steele
12bca3c43e Add CPPFLAGS to compile rules.
This should silence the last of the Debian package warnings.
2019-06-01 09:28:31 -04:00
David Steele
388ba0458c Fix build.flags being removed on each build.
This was being removed by rsync which forced a full build even when a partial should have been fine.  Rewrite the file after the rsync so it is preserved.
2019-05-31 18:37:31 -04:00
David Steele
6cba50c3f2 Remove Debian package patch merged to upstream. 2019-05-31 18:32:40 -04:00
David Steele
a2ec1253e9 Add code classification exclusion missed in 3e1b06ac. 2019-05-30 10:44:35 -04:00
David Steele
404284b90f Add internal flag for commands.
Allow commands to be skipped by default in the command help but still work if help is requested for the command directly.  There may be other uses for the flag in the future.

Update help for ls now that it is exposed.
2019-05-28 12:18:05 -04:00
David Steele
20e5b92f36 Add ls command.
Allows listing repo paths/files from the command-line, to be used primarily for testing and debugging.

This command is internal-only so the interface may change at any time without notice.
2019-05-28 10:03:48 -04:00
David Steele
3b3327eae6 Move tls/http statistics output to command/command.
This module already has the filtering required to keep these messages from being displayed by default for commands that output to stdout (e.g. info).
2019-05-28 09:50:59 -04:00
David Steele
3e1b06acaa Use minio as local S3 emulator in documentation.
The documentation was relying on a ScalityS3 container built for testing which wasn't very transparent.  Instead, use the stock minio container and configure it in the documentation.

Also, install certificates and CA so that TLS verification can be enabled.
2019-05-27 07:37:20 -04:00
David Steele
a474ba54c5 Refactoring path support in the storage module.
Not all storage types support paths as a physical thing that must be created/destroyed.  Add a feature to determine which drivers use paths and simplify the driver API as much as possible given that knowledge and by implementing as much path logic as possible in the Storage object.

Remove the ignoreMissing parameter from pathSync() since it is not used and makes little sense.

Create a standard list of error messages for the drivers to use and apply them where the code was modified -- there is plenty of work still to be done here.
2019-05-26 12:41:15 -04:00
David Steele
38f28bd520 Log TLS and HTTP statistics on exit.
These stats measure how efficiently TLS and HTTP are reusing connections (i.e. pipelining).
2019-05-26 12:32:49 -04:00
David Steele
d12d94c53c Make info(), pathCreate() and pathSync() optional for storage drivers.
These functions are not required for repository storage so make them optional and error if they are not implemented for non-repository storage, .e.g. pg or spool.

The goal is to simplify the drivers (e.g. S3) that are intended only for repository storage.
2019-05-24 18:09:16 -04:00
David Steele
39645fc1a9 Add pathRemove() and remove() to S3 storage.
These functions will be needed for the expire command.
2019-05-24 14:33:47 -04:00
David Steele
96770c529b storageList() returns an empty list by default for missing paths.
The prior behavior was to return NULL so the caller would know the path was missing, but this is rarely useful, complicates the calling code, and increases the chance of segfaults.

The .nullOnMissing param has been added to enable the prior behavior.
2019-05-24 13:12:56 -04:00
David Steele
ec9622cde8 Use the git log to ease release note management.
The release notes are generally a direct reflection of the git log.  So, ease the burden of maintaining the release notes by using the git log to determine what needs to be added.

Currently only non-dev items are required to be matched to a git commit but the goal is to account for all commits.

The git history cache is generated from the git log but can be modified to correct typos and match the release notes as they evolve.  The commit hash is used to identify commits that have already been added to the cache.

There's plenty more to do here.  For instance, links to the commits for each release item should be added to the release notes.
2019-05-22 18:54:49 -04:00
David Steele
86482c7db9 Reduce log level for all expect tests to detail.
The C code is designed to be efficient rather than deterministic at the debug log level.  As we move more testing from integration to unit tests it makes less sense to try and maintain the expect logs at this log level.

Most of the expect logs have already been moved to detail level but mock/all still had tests at debug level.  Change the logging defaults in the config file and remove as many references to log-level-console as possible.
2019-05-22 18:23:44 -04:00
David Steele
e4cc008b98 Remove duplicated hint.
At some point this hint got added to the underlying code so it is no longer needed here.
2019-05-22 11:31:38 -04:00
David Steele
ff9c1bed5d Save cipher-pass key/value missed in f492f057.
This value is required when encryption is enabled.

In passing simplify the expression used to skip the checksum when calculating the checksum.
2019-05-22 11:24:18 -04:00
David Steele
3da60f4b5e Don't escape / when rendering JSON.
/ is escaped in the spec but the Perl renderer we use does not escape it which leads to checksum mismatches between the two sets of code.

This particular escape seems to be a more recent addition to the spec and is targeted toward embedding JSON in JavaScript.

\/ is still allowed when parsing JSON.
2019-05-22 11:10:43 -04:00
David Steele
664054fea9 Remove RHEL package patch merged to upstream. 2019-05-22 06:55:31 -04:00
David Steele
e3fe3434b4 Rename repo-s3-verify-ssl option to repo-s3-verify-tls.
The new name is preferred because pgBackRest does not support any SSL protocol versions (they are all considered to be insecure).

The old name will continue to be accepted.
2019-05-21 10:14:41 -04:00
David Steele
1bc84c6474 The local command for restore is implemented entirely in C.
This is just the part of restore run by the local helper processes, not the entire command.

Even so, various optimizations in the code (like pipelining and optimizations for zero-length files) should make the restore command faster on object stores.
2019-05-20 17:07:37 -04:00
Cynthia Shang
a839830333 Add most unimplemented functions to the remote storage driver.
Add pathCreate(), pathRemove(), pathSync(), and remove() to the driver.

Contributed by Cynthia Shang.
2019-05-20 16:19:14 -04:00
David Steele
0f685a33a0 v2.14: Bug Fix and Improvements
Bug Fixes:

* Fix segfault when process-max > 8 for archive-push/archive-get. (Reported by Jens Wilke.)

Improvements:

* Bypass database checks when stanza-delete issued with force. (Contributed by Cynthia Shang. Suggested by hatifnatt.)
* Add configure script for improved multi-platform support.

Documentation Features:

* Add user guides for CentOS/RHEL 6/7.
2019-05-20 11:51:58 -04:00
Cynthia Shang
2b75f57232 Add linefeeds for clarity. 2019-05-16 09:56:48 -04:00