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

1417 Commits

Author SHA1 Message Date
David Steele
efc62c9057 Begin v2.17 development. 2019-08-05 12:32:06 -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
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
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
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
David Steele
a22a6dc08c Update contributor name. 2019-07-10 06:06:07 -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
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
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
fc21013522 Fix scoping violations exposed by optimizations in gcc 9.
gcc < 9 makes all compound literals function scope, even though the C spec requires them to be invalid outside the current scope.  Since the compiler and valgrind were not enforcing this we had a few violations which caused problems in gcc >= 9.

Even though we are not quite ready to support gcc 9 officially, fix the scoping violations that currently exist in the codebase.

Reported by chrlange, Ned T. Crigler.
2019-07-05 16:25:28 -04:00
David Steele
c55009d0f9 Community yum package can be installed with --var=package=yum.
Like apt, the community yum package can now be installed instead of a user-specified package.
2019-06-27 14:39:11 -04:00
David Steele
020101b30b Update release notes to explicitly select release commit when tagging. 2019-06-27 09:38:40 -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
bd6c0941e9 Fix missing dash in site name.
Without this the project name and tagline just run together.
2019-06-25 17:27:19 -04:00
David Steele
466602387b Begin v2.16 development. 2019-06-25 08:42:20 -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
51fcaee43e Add host-repo-path variable internal replacement.
This variable needs to be replaced right before being used without being added to the cache since the host repo path will vary from system to system.

This is frankly a bit of a hack to get the documentation to build in the Debian packages for the upcoming release.  We'll need to come up with something more flexible going forward.
2019-06-25 07:58:38 -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
62715ebf2d Fix archive retention expiring too aggressively.
The problem expressed when repo1-archive-retention-type was set to diff.  In this case repo1-archive-retention ended up being effectively equal to one, which meant PITR recovery was only possible from the last backup.  WAL required for consistency was still preserved for all backups.

This issue is not present in the C migration committed at 434cd832, which was written before this bug was reported.  Even so, we wanted to note this issue in the release notes in case any other users have been affected.

Fixed by Cynthia Shang.
Reported by Mohamad El-Rifai.
2019-06-19 17:49:38 -04:00
David Steele
a7d64bab7a Add FAQ on where to find old Debian/Ubuntu packages. 2019-06-18 19:02:09 -04:00
Cynthia Shang
e2d791394a Add FAQ to the documentation.
Contributed by Cynthia Shang.
2019-06-18 18:42: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
0efdf2576f Remove hard-coded PostgreSQL user so $PGUSER works.
The PostgreSQL user was hard-coded to the OS user which libpq will automatically use if $PGUSER is not set, so this code was redundant and prevented $PGUSER from working when set.

Suggested by Julian Zhang, Janis Puris.
2019-06-18 07:35:34 -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
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
6e809e578f Add tag to specify minio version to use for documentation build.
The new minio major release broke the build.  We'll need to figure that out but for now use the last major version, which is known to work.
2019-06-11 10:34:42 -04:00
David Steele
d7bd0c58cd Use wal_level=replica in the documentation for PostgreSQL >= 9.6.
The documentation was using wal_level=hot_standby which is a deprecated setting.

Also remove the reference to wal_level=archive since it is no longer supported and is not recommended for older versions.

Suggested by Patrick McLaughlin.
2019-06-05 07:27:24 -04:00
David Steele
64260b2e98 Build all docs with S3 using --var=s3-all=y
Force repo-type=s3 for all tests.  This is not currently the default for any OS builds.
2019-05-29 08:38:45 -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
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
39cb624831 Add missing menus to the new user guides.
Since the CentOS 6/7 user guides were generated as a single page they did not get menus.  Generate the entire site for each user guide so menus are included.
2019-05-24 07:45:03 -04:00
David Steele
04f8b4ea52 Use git url for website clone. 2019-05-24 07:41:55 -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
936b8a289c Allow separate paragraphs in release items.
The first paragraph should match the first line of the commit message as closely as possible.  The following paragraphs add more information.

Release items have been updated back to 2.01.
2019-05-21 10:37:30 -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
a9f589b87a Begin v2.15 development. 2019-05-20 12:23:40 -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
David Steele
51d67ce1ba Update contributor name. 2019-05-16 09:59:34 -04:00
Cynthia Shang
19d8358cba Update mock/expire module test matrix so expect tests output.
Also add an error message to prevent regression.

Contributed by Cynthia Shang.
2019-05-16 09:53:55 -04:00
David Steele
c51274d1b6 Add user guides for CentOS/RHEL 6/7.
It would be better if the documentation could be generated on multiple operating systems all in one go, but the doc system currently does not allow vars to be changed once they are set.

The solution is to run the docs for each required OS and stitch the documentation together.  It's not pretty but it works and the automation in release.pl should at least make it easy to use.
2019-05-16 08:32:02 -04:00
David Steele
bc7b42e718 Restore index menu url default lost in b85e51d6.
The url for the menu item referring to the index (i.e. site root page) should use {[project-url-root]}.

This allows the url to be set to different values depending on the location of the index.
2019-05-16 07:35:45 -04:00
David Steele
a4561dc087 Add --out-preserve to preserve contents of output path.
Useful for building a single set of documentation over multiple doc.pl runs.
2019-05-16 07:29:17 -04:00
David Steele
bc30027d73 Fix typo in doc.pl command-line help. 2019-05-16 07:04:28 -04:00
Cynthia Shang
18d4cb5741 Bypass database checks when stanza-delete issued with force.
Previously it was not possible to delete a stanza if the PostgreSQL server could not be contacted.

Contributed by Cynthia Shang.
Suggested by Roman.
2019-05-15 13:14:58 -04:00
David Steele
5c1d4bcd0d Automate coverage summary report generation.
This report replaces the lcov report that was generated manually for each release.

The lcov report was overly verbose just to say that we have virtually 100% coverage.
2019-05-15 13:04:56 -04:00
David Steele
5bba72b874 Remove -Wswitch-enum compiler option.
The -Wswitch option included in -Wall provides the same level of coverage and allows enum options to be grouped into default.
2019-05-15 12:55:08 -04:00
David Steele
53f6232264 Improve coverage in config/parse module. 2019-05-14 10:35:39 -04:00
David Steele
1e5ab69cad Improve coverage in config/config module. 2019-05-13 19:10:24 -04:00
David Steele
15a33bf74b Error on multiple option alternate names and simplify help command.
There are currently no options with multiple alternate (deprecated) names so the code to render them in the help command could not be covered.

Remove the uncovered code and add an error when multiple alternate names are configured.  It's not clear that the current code was handling this correctly, so it will need to be reviewed if it comes up again.
2019-05-13 17:10:41 -04:00
David Steele
2d2bec842a Improve coverage in perl/exec module. 2019-05-13 13:36:24 -04:00
David Steele
431532574b Add testUser() and testGroup().
Retrieve the name of the current user/group used for testing.
2019-05-13 07:51:11 -04:00
David Steele
31d0fe5f50 Improve log performance, simplify macros, rename logWill() to logAny().
Pre-calculate the value used by logAny() to improve performance and make it more likely to be inlined.

Move IF_LOG_ANY() into LOG_INTERNAL() to simplify the macros and improve performance of LOG() and LOG_PID().  If the message has no chance of being logged there's no reason to call logInternal().

Rename logWill() to logAny() because it seems more intuitive.
2019-05-11 18:20:57 -04:00
David Steele
87f36e814e Improve macros and coverage rules that were hiding missing coverage.
The branch coverage exclusion rules were overly broad and included functions that ended in a capital letter, which disabled all coverage for the statement.  Improve matching so that all characters in the name must be upper-case for a match.

Some macros with internal branches accepted parameters that might contain conditionals.  This made it impossible to tell which branches belonged to which, and in any case an overzealous exclusion rule was ignoring all branches in such cases.  Add the DEBUG_COVERAGE flag to build a modified version of the macros without any internal branches to be used for coverage testing.  In most cases, the branches were optimizations (like checking logWill()) that improve production performance but are not needed for testing.  In other cases, a parameter needed to be added to the underlying function to handle the branch during coverage testing.

Also tweak the coverage rules so that macros without conditionals are automatically excluded from branch coverage as long as they are not themselves a parameter.

Finally, update tests and code where missing coverage was exposed by these changes.  Some code was updated to remove existing coverage exclusions when it was a simple change.
2019-05-11 14:51:51 -04:00
David Steele
f819a32cdf Improve efficiency of FUNCTION_LOG*() macros.
Call stackTraceTestStop()/stackTraceTestStart() once per block instead of with every param call.  This was done to be cautious but is not necessary and slows down development.

These functions were never built into production so had no impact there.
2019-05-11 07:57:49 -04:00
David Steele
f0f105ddec Improve filter's notion of "done" to optimize filter processing.
Filters had different ideas about what "done" meant and this added complication to the group filter processing.  For example, gzip decompression would detect end of stream and mark the filter as done before it had been flushed.

Improve the IoFilter interface to give a consistent definition of done across all filters, i.e. no filter can be done until it has started flushing no matter what the underlying driver reports.  This removes quite a bit of tricky logic in the processing loop which tried to determine when a filter was "really" done.

Also improve management of the input buffers by pointing directly to the prior output buffer (or the caller's input) to eliminate loops that set/cleared these buffers.
2019-05-09 12:10:46 -04:00
David Steele
d5fac35fe3 Improve zero-length content handling in HttpClient object.
If content was zero-length then the IO object was not created.  This put the burden on the caller to test that the IO object existed before checking eof.

Instead, create an IO object even if it will immediately return eof.  This has little cost and makes the calling code simpler.

Also add an explicit test for zero-length files in S3 and a few assertions.
2019-05-09 09:53:24 -04:00
David Steele
15531151d7 Add --c option to request a C remote.
The rules for when a C remote is required are getting complicated and will get worse when restoreFile() is migrated.

Instead, set the --c option when a C remote is required.  This option will be removed when the remote is entirely implemented in C.
2019-05-09 08:55:48 -04:00
David Steele
c99c7c458b Add pathExists() to Storage object.
The S3 driver did not get an implementation since S3 has a weak notion of paths, and it is not currently required.
2019-05-09 08:28:58 -04:00
David Steele
f1eea23121 Add macros for object free functions.
Most of the *Free() functions are pretty generic so add macros to make creating them as easy as possible.

Create a distinction between *Free() functions that the caller uses to free memory and callbacks that free third-party resources.  There are a number of cases where a driver needs to free resources but does not need a normal *Free() because it is handled by the interface.

Add common/object.h for macros that make object maintenance easier.  This pattern can also be used for many more object functions.
2019-05-03 18:52:54 -04:00
David Steele
7ae96949f1 Various MemContext callback improvements.
Rename memContextCallback() to memContextCallbackSet() to be more consistent with other parts of the code.

Free all context memory when an exception is thrown from a callback.  Previously only the child contexts would be freed and this resulted in some allocations being lost.  In practice this is probably not a big deal since the process will likely terminate shortly, but there may well be cases where that is not true.
2019-05-03 18:09:58 -04:00
David Steele
4a20d44c6b Add common/macro.h for general-purpose macros.
Add GLUE() macro which is useful for creating identifiers.

Move MACRO_TO_STR() here and rename it STRINGIFY().  This appears to be the standard name for this type of macro and it is also an awesome name.
2019-05-03 17:49:57 -04:00
David Steele
32ca27a20b Simplify storage object names.
Remove "File" and "Driver" from object names so they are shorter and easier to keep consistent.

Also remove the "driver" directory so storage implementations are visible directly under "storage".
2019-05-03 15:46:15 -04:00
David Steele
8c712d89eb Improve type safety of interfaces and drivers.
The function pointer casting used when creating drivers made changing interfaces difficult and led to slightly divergent driver implementations.  Unit testing caught production-level errors but there were a lot of small issues and the process was harder than it should have been.

Use void pointers instead so that no casts are required.  Introduce the THIS_VOID and THIS() macros to make dealing with void pointers a little safer.

Since we don't want to expose void pointers in header files, driver functions have been removed from the headers and the various driver objects return their interface type.  This cuts down on accessor methods and the vast majority of those functions were not being used.  Move functions that are still required to .intern.h.

Remove the special "C" crypto functions that were used in libc and instead use the standard interface.
2019-05-02 17:52:24 -04:00
David Steele
498017bcf0 Various Buffer improvements.
Add bufDup() and bufNewUsedC().

Arrange bufNewC() params to match bufNewUsedC() since they have always seemed backward.

Fix bufHex() to only render the used portion of the buffer and fix some places where used was not being set correctly.

Use a union to make macro assignments for all legal values without casting.  This is much more likely to catch bad assignments.
2019-05-02 12:43:09 -04:00
David Steele
59234f249e Use THROW_ON_SYS_ERROR*() to improve code coverage.
There is only one instance in the core code where this helps. It is mostly helpful in the tests.

There is an argument to be made that only THROW_SYS_ERROR*() variants should be used in the core code to improve test coverage.  If so, that will be the subject of a future commit.
2019-04-29 18:36:57 -04:00
David Steele
683b096e18 Don't append strerror() to error message when errno is 0.
Some functions (e.g. getpwnam()/getgrnam()) will return an error but not set errno.  In this case there's no use in appending strerror(), which will be "Success".  This is confusing since an error has just been reported.

At least in the examples above, an error with no errno set just means "missing" and our current error message already conveys that.
2019-04-29 18:03:32 -04:00
David Steele
6ad44db9a0 Merge duplicated contributor. 2019-04-29 17:30:06 -04:00
David Steele
af33126cb6 Allow StorageFileWrite to set user, group, and modification time.
The S3 driver will throw an error if these options are set since they are not supported.
2019-04-29 17:17:14 -04:00
David Steele
d0c296bd5b Fix segfault when process-max > 8 for archive-push/archive-get.
The remote list was at most 9 (based on pg[1-8]-* max index) so anything over 8 wrote into unallocated memory.

The remote for the main process is (currently) stored in position zero so do the same for remotes started from locals, since there should only be one.  The main process will need to start more remotes in the future which is why there is extra space.

Reported by Jens Wilke.
2019-04-29 16:10:27 -04:00
David Steele
c935b1c9e8 Add missing httpUriEncode() in S3 request.
This was not a live bug since the files currently handled by C can't have special characters in them.
2019-04-29 15:20:54 -04:00
David Steele
62b48d8a5a Allow storageInfo() to follow links.
This allows info to be retrieved from linked files/paths in a single step.
2019-04-29 15:14:10 -04:00
David Steele
60edadf71d Expose handle (file descriptor) from IoWrite when applicable.
This is a followup to dee90d3e which exposed file handles for IoRead.

Also expose handle for StorageDriverPosixFileRead missed in dee90d3e.
2019-04-29 14:54:49 -04:00
David Steele
027c263871 Add configure script for improved multi-platform support.
Use autoconf to provide a basic configure script. WITH_BACKTRACE is yet to be migrated to configure and the unit tests still use a custom Makefile.

Each C file must include "build.auto.conf" before all other includes and defines.  This is enforced by test.pl for includes, but it won't detect incorrect define ordering.

Update packages to call configure and use standard flags to pass options.
2019-04-26 08:08:23 -04:00
David Steele
3505559a80 Update test containers with PostgreSQL minor releases and liblz4.
Update RHEL repos that have changed upstream.  Remove PostgreSQL 9.3 since the RHEL6/7 packages have disappeared.

Remove PostgreSQL versions from U12 that are still getting minor updates so the container does not need to be rebuilt.

LZ4 is included for future development, but this seems like a good time to add it to the containers.
2019-04-24 13:23:32 -04:00
David Steele
1ae8a6a716 Add build-max option to set max build processes.
Currently this controls make processes via -j.
2019-04-23 20:52:03 -04:00
David Steele
c11c936366 Reduce ScalityS3 processes since only two are needed. 2019-04-23 20:19:31 -04:00
David Steele
52b0b81976 Add storageInfoList() to get detailed info about all entries in a path.
The function provides all the file/path/link information required to build a backup manifest.

Also update storageInfo() to provide the same information for a single file.
2019-04-23 19:33:55 -04:00
David Steele
f492f0571b Add *Save() functions to most Info objects.
At the same time change the way that load constructors work (and are named) so that Ini objects do not persist after the constructors complete.

infoArchiveSave() is excluded from this commit since it is just a trivial call to infoPgSave() and won't be required soon.
2019-04-23 17:08:34 -04:00
David Steele
f41112a463 Add harnessInfoChecksum/Z() to ease creation of test info files. 2019-04-23 14:02:30 -04:00
David Steele
aebac47cd5 Extern infoHash() so it can be used by other modules.
This is currently needed only for testing, but there's no reason not to expose the function to everyone.
2019-04-23 13:58:19 -04:00
David Steele
cddb0c05b4 Add iniSave() and iniMove() to Ini object.
iniSave() sorts alphabetically to maintain compatibility with the expect tests, but we plan to change this behavior when the migration is complete.
2019-04-23 13:03:22 -04:00
David Steele
c650134a04 Add ioWriteStr() and ioWriteStrLine().
These function names make it clearer what is being written.

The old ioWriteLine() has been repurposed to write buffers.
2019-04-22 18:46:29 -04:00
David Steele
81f652137c Add separate functions to encode/decode each JSON type.
In most cases the JSON type is known so this is more efficient than converting to Variant first, both in terms of memory and time.

Also rename some of the existing functions for consistency.
2019-04-22 18:41:01 -04:00
David Steele
f100ea0ff4 Add constant for maximum buffer sizes required by cvt*() functions.
Also update Variant to use cvt*() in all cases.  Variant was written before these functions were available and not all cases were updated.
2019-04-22 17:52:23 -04:00
David Steele
f5739051eb Add true and false String constants. 2019-04-22 17:17:56 -04:00
David Steele
47491e3c47 varNewKv() accepts a KeyValue object rather than creating one.
This allows for more flexibility about when the Variant is created.
2019-04-22 16:04:04 -04:00
David Steele
fdf19e5ab6 Refactor Ini interface to expose String values instead of Variant.
Variants were being used to expose String and StringList types but this can be done more simply with an additional method.

Using only strings also allows for a more efficient implementation down the road.
2019-04-22 09:00:50 -04:00
David Steele
cc39bddc15 Refactor main() as a switch() statement.
This makes it clearer what has been migrated and where the new C implementations should go.
2019-04-22 08:47:32 -04:00
David Steele
e7255be108 Only process next filter in IoFilterGroup when input buffer is full or flushing.
This greatly reduces calls to filter processing, which is a performance benefit, but also makes the trace logs smaller and easier to read.

However, this means that ioWriteFlush() will no longer work with filters since a full flush of IoFilterGroup would require an expensive reset.  Currently ioWriteFlush() is not used in this scenario so for now just add an assert to ensure it stays that way.
2019-04-20 11:25:04 -04:00
David Steele
e513c52c09 Add macros to create constant Buffer objects.
These are more efficient than creating buffers in place when needed.

After replacement discovered that bufNewStr() and BufNewZ() were not being used in the core code so removed them.  This required using the macros in tests which is not the usual pattern.
2019-04-20 08:16:17 -04:00
David Steele
c9168028c6 Improve performance of non-blocking reads by using maximum buffer size.
Since the introduction of blocking read drivers (e.g. IoHandleRead, TlsClient) the non-blocking drivers have used the same rules for determining maximum buffer size, i.e. read only as much as requested.  This is necessary so the blocking drivers don't get stuck waiting for data that might not be coming.

Instead mark blocking drivers so IoRead knows how much buffer to allow for the read.  The non-blocking drivers can now request the maximum number of bytes allowed by buffer-size.
2019-04-19 14:38:11 -04:00
David Steele
0c866f52c6 Update code to use new unsigned int Variant type and config methods. 2019-04-19 11:40:39 -04:00
David Steele
9f0829cbf2 Add cfgOptionUInt() and cfgOptionUInt64().
These are better than casting from cfgOptionInt() since bounds checking is performed.
2019-04-19 11:29:08 -04:00
David Steele
1adcbc5c91 Add unsigned int Variant type.
This is better than using (unsigned int)varUInt64() because bounds checking is performed.
2019-04-19 11:22:43 -04:00
David Steele
c45ae5f221 Begin v2.14 development. 2019-04-19 08:41:17 -04:00
David Steele
41f3874822 v2.13: Bug Fixes
Bug Fixes:

* Fix zero-length reads causing problems for IO filters that did not expect them. (Reported by brunre01, jwpit, Tomasz Kontusz, guruguruguru.)
* Fix reliability of error reporting from local/remote processes.
* Fix Posix/CIFS error messages reporting the wrong filename on write/sync/close.
2019-04-18 21:26:02 -04:00
David Steele
7390952d8e Harden IO filters against zero input and optimize zero output case.
Add production checks to ensure no filter gets a zero-size input buffer.

Also, optimize the case where a filter returns no output.  There's no sense in running downstream filters if they have no new input.
2019-04-18 21:24:10 -04:00
David Steele
2d73de1d36 Fix zero-length reads causing problems for IO filters that did not expect them.
The IoRead object was passing zero-length buffers into the filter processing code but not all the filters were happy about getting them.

In particular, the gzip compression filter failed if it was given no input directly after it had flushed all of its buffers.  This made the problem rather intermittent even though a zero-length buffer was being passed to the filter at the end of every file.  It also explains why tweaking compress-level or buffer-size allowed the file to go through.

Since this error was happening after all processing had completed, there does not appear to be any risk that successfully processed files were corrupted.

Reported by brunre01, jwpit, Tomasz Kontusz, guruguruguru.
2019-04-18 21:21:35 -04:00
David Steele
670fa88a98 Add CHECK() macro for production assertions.
CHECK() works just like ASSERT() but is kept in production builds.
2019-04-18 13:21:24 -04:00
David Steele
b258aec0ad Move lockRelease() to the end of exitSafe().
Releasing the lock too early was allowing other async processes to sneak in and start running before the current process was completely shut down.

The only symptom seems to have been mixed up log messages so not a very serious issue.
2019-04-18 13:19:05 -04:00
David Steele
b960919cf7 Fix reliability of error reporting from local/remote processes.
Asserts were only only reported on stderr rather than being returned through the protocol layer.  This did not appear to be very reliable.

Instead, report the assert through the protocol layer like any other error.  Add a stack trace if an assert error or debug logging is enabled.
2019-04-18 10:36:21 -04:00
David Steele
281d2848b9 Option to build documentation from current apt.postgres.org packages.
This is useful for testing any issue currently being seen in the field.

We'll also need to add a "yum" option at some point.
2019-04-17 18:39:35 -04:00
David Steele
0d4ba3a39f Fix Posix/CIFS error messages reporting the wrong filename on write/sync/close.
The reported file name was the destination file, not the temp file that is written to during atomic write operations.
2019-04-17 18:18:55 -04:00
David Steele
4c13955c05 Add macros to create constant Variant types.
These work almost exactly like the String constant macros. However, a struct per variant type was required which meant custom constructors and destructors for each type.

Propagate the variant constants out into the codebase wherever they are useful.
2019-04-17 08:04:22 -04:00
David Steele
2dac4b5986 Add STR() macro to create constant String objects from runtime strings.
The STRING_CONST() macro worked fine for constants but was not able to constify strings created at runtime.

Add the STR() macro to do this by using strlen() to get the size.

Also rename STRING_CONST() to STRDEF() for brevity and to match the other macro name.
2019-04-16 13:39:58 -04:00
David Steele
a029eba8d5 Use a macro instead of a nested struct to create common String variables.
This makes the code a bit less obfuscated while still ensuring that these variables will be common to both String structures.
2019-04-16 13:18:30 -04:00
Cynthia Shang
a7281878ac Migrate backupRegExp() to C.
Removed the "anchor" parameter because it was never used in any calls in the Perl code so it was just a dead parameter that always defaulted to true.

Contributed by Cynthia Shang.
2019-04-15 08:29:25 -04:00
David Steele
c5157c0334 Automatically generate constants for command and option names.
These constants are easier than using cfgOptionName() and cfgCommandName() and lead to cleaner code and simpler to construct messages.

String versions are provided. Eventually all the strings will be used in the config structures, but for now they are useful to avoid wrapping with strNew().
2019-04-12 09:03:34 -04:00
David Steele
867690c08d Begin v2.13 development.
Also update CentOS packages so documentation builds.
2019-04-12 08:33:10 -04:00
David Steele
4e57b68916 v2.12: C Implementation of Archive Push
IMPORTANT NOTE: The new TLS/SSL implementation forbids dots in S3 bucket names per RFC-2818. This security fix is required for compliant hostname verification.

Bug Fixes:

* Fix issues when a path option is / terminated. (Reported by Marc Cousin.)
* Fix issues when log-level-file=off is set for the archive-get command. (Reported by Brad Nicholson.)
* Fix C code to recognize host:port option format like Perl does. (Reported by Kyle Nevins.)
* Fix issues with remote/local command logging options.

Improvements:

* The archive-push command is implemented entirely in C.
* Increase process-max limit to 999. (Suggested by Rakshitha-BR.)
* Improve error message when an S3 bucket name contains dots.

Documentation Improvements:

* Clarify that S3-compatible object stores are supported. (Suggested by Magnus Hagander.)
2019-04-11 09:14:22 -04:00
David Steele
df12cbb162 Fix C code to recognize host:port format like Perl does.
This was not an intentional feature in Perl, but it works, so it makes sense to implement the same syntax in C.

This is a break from other places where a -port option is explicitly supplied, so it may make sense to support both styles going forward.  This commit does not address that, however.

Reported by Kyle Nevins.
2019-04-10 17:48:34 -04:00
David Steele
25cea0bd0a Add process id to C archive-get and archive-push logging.
This was missed in the original migration.  There was no functional issue, but logging the process ids is useful for debugging.
2019-04-09 11:08:27 -04:00
David Steele
8c202c77da Add process id to ProtocolParallelJob.
This exposes the process that performed to job to the caller for logging purposes.
2019-04-09 11:01:35 -04:00
David Steele
4ace7edbd9 Allow process id in C logging
The default process id in C logging has always been zero.  This should have been updated when multi-processing was introduced in C, but it was missed.
2019-04-09 10:54:36 -04:00
David Steele
6099729e92 Improve error message when an S3 bucket name contains dots.
The Perl lib we have been using for TLS allows dots in wildcards, but this is forbidden by RFC-2818.  The new TLS implementation in C forbids this pattern, just as PostgreSQL and curl do.

However, this does present a problem for users who have been using bucket names with dots in older versions of pgBackRest.  Since this limitation exists for security reasons there appears to be no option but to take a hard line and do our best to notify the user of the issue as clearly as possible.
2019-04-08 19:38:06 -04:00
David Steele
21c83eea59 Fix issue setting log-level-file=off for the archive-get command.
This problem was not specific to archive-get, but that was the only place it was expressing in the last release.  The new archive-push was also affected.

The issue was with daemon processes that had closed all their file descriptors.  When exec'ing and setting up pipes to communicate with a child process the dup2() function created file descriptors that overlapped with the first descriptor (stdout) that was being duped into.  This descriptor was subsequently closed and wackiness ensued.

If logging was enabled (the default) that increased all the file descriptors by one and everything worked.

Fix this by checking if the file descriptor to be closed is the same one being dup'd into.  This solution may not be generally applicable but it works fine in this case.

Reported by Brad Nicholson.
2019-04-08 17:21:20 -04:00
David Steele
8ac422dca9 Close log file before exec().
The log file should be closed before exec() so the child process does not retain a reference to it.
2019-04-07 21:09:29 -04:00
David Steele
9f3425f6dd Skip coverage for macros with numbers in their name.
This was an oversight in the old regular expression.
2019-04-07 18:47:04 -04:00
David Steele
c72a94cfec Increase process-max limit to 999.
Recent hardware has outstripped the old default so increase it to something that should last for a while.

Suggested by Rakshitha-BR.
2019-04-07 18:20:03 -04:00
David Steele
9a7eab9428 Allow three-digits process IDs in logging.
This is required to support process-max > 99 or else there will be formatting/alignment issues in the logs.
2019-04-07 18:12:07 -04:00
David Steele
e97b8241a5 Clarify that S3-compatible object stores are supported.
The documentation mentioned Amazon S3 frequently but failed to mention that other S3-compatible object stores are also supported.

Tone down the specific mentions of Amazon S3 and replace them with "S3-compatible object store" when appropriate.

Suggested by Magnus Hagander.
2019-04-03 11:40:12 +01:00
David Steele
4c63279a19 Add forkSafe() to handle fork errors.
fork() rarely fails but we should definitely detect when it does so.
2019-04-02 13:50:02 +01:00
David Steele
1b48684713 The archive-push command is implemented entirely in C.
This new implementation should behave exactly like the old Perl code with the exception of updated log messages.

Remove as much of the Perl code as possible without breaking other commands.
2019-03-29 13:26:33 +00:00
David Steele
251dbede8f Add locking capability to the remote command.
When a repository server is configured, commands that modify the repository acquire a remote lock as well as a local lock for extra protection against multiple writers.

Instead of the custom logic used in Perl, make remote locking part of the command configuration.

This also means that the C remote needs the stanza since it is used to construct the lock name.  We may need to revisit this at a later date.
2019-03-27 21:14:06 +00:00
David Steele
7db8cedd68 Add protocolKeepAlive() to send noops to all remotes.
While the local processes are doing their jobs the remote connection from the main process may timeout.

Send occasional noops to ensure that doesn't happen.
2019-03-27 20:59:28 +00:00
David Steele
f8cbf5d78c Add TEST_64BIT() macro to detect 64-bit platforms.
This may not be the best way to detect 64-bit platforms but it seems to be working fine so far.

Create a macro to make it clearer what is being done and to make it easier to change the implementation.
2019-03-27 20:52:23 +00:00
David Steele
5ee8388f48 Build test harness with the same warnings as code being tested.
The test harness was not being built with warnings which caused some wackiness with an improperly structured switch.  Just use the same warnings as the code being tested.

Also enable warnings on code that is not directly being tested since other code modules are frequently modified during testing.
2019-03-26 08:20:55 +02:00
David Steele
abba2bd132 Add strLstMergeAnti() for merge anti-joins.
We deal with some pretty big lists in archive-push so a nested-loop anti-join looked like it would not be efficient enough.

This merge anti-join should do the trick even though both lists must be sorted first.
2019-03-25 20:35:20 +04:00
David Steele
538e2c7474 Add storagePg()/storagePgWrite() to storage helper.
Add read/write storage helper functions for the PostgreSQL data directory.
2019-03-25 09:45:36 +04:00
David Steele
444b4f8640 Allow warnings to be written by archiveAsyncStatusOkWrite().
Migrate this feature to the C code since archive-push will need it.
2019-03-25 09:17:15 +04:00
David Steele
8820d69574 Use a single file to handle global errors in async archiving.
The prior behavior on a global error (i.e. not file specific) was to write an individual error file for each WAL file being processed.  On retry each of these error files would be removed, and if the error was persistent, they would then be recreated.  In a busy environment this could mean tens or hundreds of thousands of files.

Another issue was that the error files could not be written until a list of WAL files to process had been generated.  This was easy enough for archive-get but archive-push requires more processing and any errors that happened when generating the list would only be reported in the pgBackRest log rather than the PostgreSQL log.

Instead write a global.error file that applies to any WAL file that does not have an explicit ok or error file.  This reduces churn and allows more errors to be reported directly to PostgreSQL.
2019-03-25 08:12:38 +04:00
David Steele
1fff60ad2a Remove unused infoArchiveCheckPg() function.
The idea was to use this function for archive-push, but in the end archive-push required two very different versions of the function.
2019-03-24 14:34:45 +04:00
David Steele
8560db5c42 Add constants for .ok/.error status extensions. 2019-03-24 13:54:05 +04:00
David Steele
7cf7373761 Refactor PostgreSQL interface to remove most code duplication.
Having a copy per version worked well until it was time to add new features or modify existing functions.  Then it was necessary to modify every version and try to keep them all in sync.

Consolidate all the PostgreSQL types into a single file using #if for type versions.  Many types do not change or change infrequently so this cuts down on duplication.  In addition, it is far easier to see what has changed when a new version is added.

Use macros to write the interface functions.  There is still duplication here since some changes require a new copy of the macro, but it is far less than before.
2019-03-21 21:11:36 +04:00
David Steele
e938a89250 Add WAL info to PostgreSQL interface.
This allows the WAL header to be read for any supported version on PostgreSQL.
2019-03-19 19:44:06 +04:00
David Steele
5c732e9929 Remove redundant documentation from PostgreSQL interface files and clarify ambiguous function names.
Move the documentation to postgres/interface.c so it can be updated without having to update N source files.

The "is" function was not very specific so rename to "controlIs".
2019-03-18 22:10:25 +04:00
David Steele
e26d510d0c Use restore command for remote performances tests.
Since archive-push is being moved to C, the Perl remote will no longer work with that command.

Eventually this module will need to be rewritten in C, but for now just use the restore command which is planned to be migrated last.
2019-03-17 22:11:35 +04:00
David Steele
856a369b86 Add file write to the S3 storage driver.
Now that repositories are writable the storage drivers that don't yet support file writes need to be updated to do so.

Note that the part size for multi-part upload has not been defined as a proper constant.  This will become an option in the near future so it doesn't seem worth creating a constant that we might then forget to remove.
2019-03-17 22:00:54 +04:00
David Steele
7193738288 Add document creation to XML objects.
The xml objects only exposed read methods of the underlying libxml2.

This worked for S3 commands that only received data but to send data we need to be able to create XML documents from scratch.

Add the ability to create empty documents and add nodes and contents.
2019-03-17 21:38:07 +04:00
David Steele
8ebc6d6c34 Add file write to the remote storage driver.
Now that repositories are writable the storage drivers that don't yet support file writes need to be updated to do so.
2019-03-16 21:50:19 +04:00