Skip to content

[#1018] Refactored utils aes & compression - #1038

Merged
jesperpedersen merged 1 commit into
pgmoneta:mainfrom
sommye-ctr:issue_1018
Apr 2, 2026
Merged

jesperpedersen merged 1 commit into
pgmoneta:mainfrom
sommye-ctr:issue_1018

Conversation

@sommye-ctr

Copy link
Copy Markdown
Collaborator

Resolves #1018

Changes

  • Standardised compression/decompression flow. Removed duplicated codec specific directory/tablespace wrappers and updated callers to use the unified path in compression.c
  • Moved functions related to file type detections from utils.h to extraction.h
  • Moved compression and encryption related functions to their respective files
  • Moved compression/extraction/AES tests to dedicated files

@sommye-ctr

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen I am unable to reproduce the CI error on my local machine...

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr Are you fully rebased ?

@jesperpedersen
jesperpedersen self-requested a review March 19, 2026 13:25
@jesperpedersen jesperpedersen added the enhancement Improvement to an existing feature label Mar 19, 2026
@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr Rebase

Comment thread src/include/extraction.h Outdated
* @return Normalized file type bitmask
*/
uint32_t
pgmoneta_normalize_file_type(uint32_t type);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do we need this for ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was already being used, it is shifted from utils to extraction and now made into static (since it is only being used in extraction.c)

Comment thread src/include/extraction.h Resolved
Comment thread src/include/extraction.h Resolved
Comment thread src/include/pgmoneta.h Resolved
Comment thread src/include/compression.h Resolved
Comment thread src/include/workflow.h Resolved
Comment thread src/include/workflow.h Outdated
*/
int
pgmoneta_workflow_compress_tablespaces(char* root, int compression_type, struct workers* workers);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need one for encryption as well ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

pgmoneta_encrypt_tablespaces exists in aes.c

Comment thread src/libpgmoneta/walfile/wal_reader.c Resolved
Comment thread src/libpgmoneta/walfile/wal_reader.c Resolved
Comment thread src/libpgmoneta/aes.c Resolved
@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr Try and take these comments through the entire patch. PTAL me once it is sorted

@sommye-ctr
sommye-ctr force-pushed the issue_1018 branch 2 times, most recently from 09233b5 to fd16bc0 Compare March 24, 2026 05:08
@sommye-ctr

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen PTAL

@jesperpedersen

jesperpedersen commented Mar 24, 2026 •

Copy link
Copy Markdown
Member

@sommye-ctr We are moving in right direction.

The important part is that

  • Compress
  • Decompress
  • Encrypt
  • Decrypt

all take a struct workers* as their last parameter.

You also have to look at - f.ex. what is the difference between pgmoneta_bzip2_wal_file and pgmoneta_bzip2_file. We need as few public functions as possible.

So, compression.h, aes.h and extraction.h provides a simple API that other components can use.

   struct workers* workers = NULL;
   if (config->workers > 0)
   {
      /* Setup workers */
   }

   /* Do compression */
   if (workers != NULL)
   {
       /* Workers.wait */
   }

   /* Do encryption */
   if (workers != NULL)
   {
       /* Workers.wait */
   }

Yes, in order for this to work in certain cases we have to pass in file extensions that should be skipped - could be a struct deque* or a string array...

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr We should expand the DEBUG logging around main.c:926 with all vault sizes, and the number of workers

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr During development set workers to > 0, and make sure that all code paths are using the workers

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr Are you ok on this ? Its a high-priority PR

@sommye-ctr

Copy link
Copy Markdown
Collaborator Author

@sommye-ctr Are you ok on this ? Its a high-priority PR

Yes, I'll push changes till tomorrow

@sommye-ctr

Copy link
Copy Markdown
Collaborator Author

I have removed the codec specific wal functions and rather used the generic functions from aes & compression. Also added workers in all functions & cleaned up the public functions.

Comment thread src/include/workflow.h Resolved
@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr Look into if we actually need tablespace specific functions now - is _directory enough ? Maybe we need an iterator on top...

@sommye-ctr

Copy link
Copy Markdown
Collaborator Author

@sommye-ctr Look into if we actually need tablespace specific functions now - is _directory enough ? Maybe we need an iterator on top...

We could do that, currently we have pgmoneta_encrypt_data which is called by pgmoneta_encrypt_directory and pgmoneta_encrypt_tablespaces. So the callers of tablespace function would need to pass in excludes list.

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr We should see if we can get to

  • _encrypt_file
  • _encrypt_directory
  • _decrypt_file
  • _decrypt_directory
  • _compress_file
  • _compress_directory
  • _decompress_file
  • _decompress_directory

as the core API

@sommye-ctr

Copy link
Copy Markdown
Collaborator Author

Removed both the encrypt and compress tablespaces function.

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr CI

@sommye-ctr

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen I think the issue is caused by that I had replaced pgmoneta_compress_tablespace(backup_base...) and pgmoneta_compress_directory(backup_data....) with a single call of pgmoneta_compress_directory(backup_base...).

Now there are some exclusions of metadata files by default in directory function but some are missed which cause them to be compressed and then later on the workflow tries to read one of the files (which are compressed) and is unable to read.

So to solve this we can pass in the exclude list with a set of meta files in the backup_base, here is the list of files I think that need to be skipped:

backup.manifest
backup.info
backup.sha*
backup_label (already does)
backup_manifest (already does)

Are there any other files I am missing that needs to be skipped for compressing/encryption?

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr That should be it

Comment thread src/include/aes.h Resolved
Comment thread src/include/workflow.h Resolved
@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr We are getting really close now - then I'll do the .c files but they should be ok, if the .h's are

@jesperpedersen

Copy link
Copy Markdown
Member

@sommye-ctr So, we need to move some call-sites, like

   if (workers != NULL)
   {
      pgmoneta_workers_wait(workers);
   }

from aes.c and compression.c.

The wait / outcome checking has to be done in the clients of those APIs - see restore.c as a workers example

@jesperpedersen
jesperpedersen merged commit c49a128 into pgmoneta:main Apr 2, 2026
9 checks passed
@jesperpedersen

Copy link
Copy Markdown
Member

Merged.

Thanks for your contribution !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compression: Workers

2 participants