Skip to content

[#538] add --sort asc|desc option to list-backup command - #554

Merged
jesperpedersen merged 1 commit into
pgmoneta:mainfrom
dancingactor:test2
Apr 1, 2025
Merged

jesperpedersen merged 1 commit into
pgmoneta:mainfrom
dancingactor:test2

Conversation

@dancingactor

Copy link
Copy Markdown
Contributor

implement #538

This PR adds a --sort option to the list-backup CLI command, allowing users to sort backups by time in either ascending (asc) or descending (desc) order. This enhancement improves usability by enabling easier inspection of backup history in the desired order.

Example Output

Input: pgmoneta-cli list-backup primary --sort desc

Output:

  ClientVersion: 0.16.0
  Command: list-backup
  ...
Response:
  Backups:
    - Backup: 20250330135708
      BackupSize: 3.98MB
      ...
    - Backup: 20250330105024
      BackupSize: 3.98MB
      ...
    - Backup: 20250330102835
      BackupSize: 6.44MB
      ...
  NumberOfBackups: 3

Input: pgmoneta-cli list-backup primary --sort asc

Output:

Header:
  ClientVersion: 0.16.0
  Command: list-backup
  ...
Response:
  Backups:
    - Backup: 20250330102835
      BackupSize: 6.44MB
      ...
    - Backup: 20250330105024
      BackupSize: 3.98MB
      ...
    - Backup: 20250330135708
      BackupSize: 3.98MB
      ...
  NumberOfBackups: 3

Details

  • Updated the list_backup function to accept a sort_order parameter
  • Modified pgmoneta_management_request_list_backup to pass sort_order to the server
  • Implemented sorting logic in the server's pgmoneta_list_backup function
  • Updated help and usage documentation to include the new option
  • Updated user guide and manual documenting the new feature

@jesperpedersen

Copy link
Copy Markdown
Member

You need to add yourself to https://github.com/pgmoneta/pgmoneta/blob/main/doc/DEVELOPERS.md#authors

You need to reference the issue number in the commit subject

@dancingactor

Copy link
Copy Markdown
Contributor Author

Got it, do I need to close this one and create a new one

Comment thread src/cli.c Outdated
}
};

static char* global_sort_option = NULL;

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.

Use a variable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which one needs to use a variable?

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.

set it in main, and use it in list-backup

Comment thread src/include/backup.h
* @return 0 upon success, otherwise 1
*/
int
pgmoneta_extract_backup_file(int server, char* label, char* relative_file_path, char* target_directory, char** target_file);

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.

Where is this coming from ?

Comment thread src/include/management.h Outdated
#define MANAGEMENT_ARGUMENT_SERVERS "Servers"
#define MANAGEMENT_ARGUMENT_SERVER_SIZE "ServerSize"
#define MANAGEMENT_ARGUMENT_SERVER_VERSION "ServerVersion"
#define MANAGEMENT_ARGUMENT_SORT "Sort"

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.

Indentation

Comment thread src/libpgmoneta/backup.c
struct main_configuration* config;
struct json* request = NULL;
char* sort_order = NULL;
bool sort_desc = false;

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.

true in cli, and false here - why ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could you specify what you mean, the sort_desc variable is initialized to false here so that if the user doesn't specify a sort order, the backups will be sorted in ascending order by default.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry I still don't get it. Do you mean global_sort_option? But it's either "asc" or "desc"

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.

global_sort_option should be a local variable to main - so sort_option instead.

Do git grep sort and make sure that the bools are initialized in the same way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, I will fix it tomorrow

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ran git grep sort and didn't find any other booleans related to 'asc' and 'desc', so everything is consistent now

Comment thread src/libpgmoneta/backup.c

goto error;
}

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.

There are some extra spaces - did you run ./uncrustify.sh ?

Comment thread src/libpgmoneta/backup.c Outdated
}

// Check if sorting is requested
if (payload != NULL)

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.

This should always be true

Comment thread src/libpgmoneta/backup.c Outdated

int
pgmoneta_extract_backup_file(int server, char* label, char* relative_file_path, char* target_directory, char** target_file)
pgmoneta_extract_backup_file(int server, char* label, char* file, char* target_directory, char** target_file)

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.

Bad rebase ?

@jesperpedersen

Copy link
Copy Markdown
Member

@dancingactor No, you force push

@jesperpedersen

Copy link
Copy Markdown
Member

@dancingactor

Copy link
Copy Markdown
Contributor Author

sorry for lots of mistakes, this is my first PR. I will do my best to avoid them in the future

@jesperpedersen

Copy link
Copy Markdown
Member

@dancingactor It is ok - we will get there

@jesperpedersen

Copy link
Copy Markdown
Member

You need to squash

@dancingactor
dancingactor force-pushed the test2 branch 2 times, most recently from 63bf305 to e3d73f9 Compare April 1, 2025 02:21
@dancingactor

dancingactor commented Apr 1, 2025 •

Copy link
Copy Markdown
Contributor Author

@jesperpedersen , I've updated all the problematic code, please take another look. Thanks for your time

Comment thread src/libpgmoneta/management.c Outdated

pgmoneta_json_put(request, MANAGEMENT_ARGUMENT_SERVER, (uintptr_t)server, ValueString);

if (sort_order != NULL)

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.

We should always add the argument, so if NULL then default should be _put

@dancingactor dancingactor Apr 1, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it, I've set the default value to "asc", is it ok?

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.

yes

@jesperpedersen

Copy link
Copy Markdown
Member

Merged.

Thanks for your contribution !

@dancingactor

Copy link
Copy Markdown
Contributor Author

Thanks so much for your valuable feedback and time! Are there any other issues to contribute? I am eager to contirbute!

@jesperpedersen

Copy link
Copy Markdown
Member

@dancingactor You can comment on #557 and take that one

@dancingactor
dancingactor deleted the test2 branch April 3, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants