Skip to content

[#524] Incremental backup restore size calculation - #590

Merged
Jubilee101 merged 1 commit into
pgmoneta:mainfrom
ashu3103:incr_restore
Apr 14, 2025
Merged

Jubilee101 merged 1 commit into
pgmoneta:mainfrom
ashu3103:incr_restore

Conversation

@ashu3103

@ashu3103 ashu3103 commented Apr 10, 2025 •

Copy link
Copy Markdown
Collaborator

Work in Progress

The objective is to calculate the approximate restoration size of incremental backup as per backup combine. The idea is to go through all the file entries in the manifest of the backup.

  • If the file is non incremental get the size from the manifest file itself (in bytes).
  • Else get the block_length using the function find_reconstructed_block_length -> which provides the total blocks in the actual restored file.

@Jubilee101, @jesperpedersen PTAL.

@ashu3103 ashu3103 self-assigned this Apr 10, 2025
Comment thread src/libpgmoneta/utils.c Resolved
Comment thread src/libpgmoneta/restore.c Resolved
Comment thread src/libpgmoneta/restore.c Resolved
Comment thread src/include/utils.h Resolved
Comment thread src/libpgmoneta/restore.c Resolved
Comment thread src/include/restore.h Resolved
@Jubilee101
Jubilee101 force-pushed the main branch 2 times, most recently from 0d2eb3a to 97d5199 Compare April 10, 2025 06:35
@ashu3103

Copy link
Copy Markdown
Collaborator Author

@Jubilee101, @jesperpedersen I have made the desired changes, PTAL

Thanks

Comment thread src/libpgmoneta/wf_backup.c Resolved
Comment thread src/include/restore.h Resolved
Comment thread src/libpgmoneta/restore.c Resolved
Comment thread src/libpgmoneta/wf_backup.c Resolved
@ashu3103

Copy link
Copy Markdown
Collaborator Author

@Jubilee101, Done

@Jubilee101

Copy link
Copy Markdown
Member

Looking good, can you restore an incremental backup and verify its size?

@ashu3103

Copy link
Copy Markdown
Collaborator Author

Encountering this error again and again

2025-04-11 01:42:23 ERROR restore.c:2620 restore_backup_incremental: could not rename file /tmp/restore/primary-20250411011348/postgresql.conf.tmp to /tmp/restore/primary-20250411011348/postgresql.conf

Don't think it has something to do with our backup size calculation infra

@Jubilee101

Copy link
Copy Markdown
Member

Can you log the errno message?

@ashu3103

ashu3103 commented Apr 10, 2025 •

Copy link
Copy Markdown
Collaborator Author

Can you log the errno message?

ENOENT

No such file or directory

@ashu3103

Copy link
Copy Markdown
Collaborator Author

Restore is working with base backups though

@Jubilee101

Copy link
Copy Markdown
Member

No such file or directory

Hmm, that is odd. And postgresql.conf is present in your backup 20250411011348?

@ashu3103

Copy link
Copy Markdown
Collaborator Author

No such file or directory

Hmm, that is odd. And postgresql.conf is present in your backup 20250411011348?

postgresql.auto.conf is present.

@Jubilee101

Copy link
Copy Markdown
Member

postgresql.auto.conf is present.

Does your postgres server have postgres.conf in the first place? This feels off, I'm not 100% sure, but postgres.conf seems to be a must-have. I'm curious why you don't have it.

@ashu3103

ashu3103 commented Apr 11, 2025 •

Copy link
Copy Markdown
Collaborator Author

postgresql.auto.conf is present.

Does your postgres server have postgres.conf in the first place? This feels off, I'm not 100% sure, but postgres.conf seems to be a must-have. I'm curious why you don't have it.

The postgres.conf is not directly under the data directory, its under /etc/postgresql directory. Let me create a new cluster using initdb.

@jesperpedersen

Copy link
Copy Markdown
Member

@ashu3103 How did you do the initdb ?

@ashu3103

Copy link
Copy Markdown
Collaborator Author

@ashu3103 How did you do the initdb ?

I really can't recall how I did it initially, I am initializing new cluster initdb -D </path/to/data/directory>.

@jesperpedersen

Copy link
Copy Markdown
Member

@ashu3103 You forgot -k

@ashu3103

Copy link
Copy Markdown
Collaborator Author

@ashu3103 You forgot -k

Thanks, I'll add that flag.
-k is for checksums right can't we skip it if we want a bare minimum setup?

@jesperpedersen

Copy link
Copy Markdown
Member

@ashu3103 No, we work towards production level installations - the documentation should reflect that as a minimum

@ashu3103

Copy link
Copy Markdown
Collaborator Author

ntation

Yeah, got your point!

@ashu3103

ashu3103 commented Apr 11, 2025 •

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen, @Jubilee101,

The calculated backup size: 50834256 bytes which is 48.4793 MB and the restore size is coming out to be RestoreSize: 48.48 MB.

Any more tests we have to run?

Comment thread src/libpgmoneta/restore.c Resolved
Comment thread src/libpgmoneta/restore.c Resolved
Comment thread src/libpgmoneta/restore.c Resolved
Comment thread src/libpgmoneta/restore.c Resolved
@jesperpedersen

Copy link
Copy Markdown
Member

Apart from split_file_path it looks ok

@ashu3103

Copy link
Copy Markdown
Collaborator Author

pgmoneta_file_finalname() can just be in utils.c,

Okay!

as for pgmoneta_extract_backup_file(), this is more of a restore thing... @jesperpedersen thoughts?

If we place pgmoneta_extract_backup_file in restore.h info.h will now have dependency on restore.h. Can't we also move this in utils, or in info.h itself?

@jesperpedersen

Copy link
Copy Markdown
Member

pgmoneta_file_finalname - what is that ? It sound static to me. I don't like the name.

pgmoneta_extract_backup_file sounds like restore.h.

We have to break it down, and maybe the higher level API is just a wrapper for a lower level one.

What are the core functions ? And, move them down, so we don't have dependencies in both directions

Jubilee101 added a commit that referenced this pull request Apr 12, 2025
@Jubilee101

Copy link
Copy Markdown
Member

pgmoneta_file_finalname - what is that ? It sound static to me. I don't like the name.

And it shall be. @ashu3103 Can you rebase? Sorry for the mess.

Can't we also move this in utils, or in info.h itself?

Yes, let's keep it as a static function inside info.c at the moment. It's not used elsewhere anyway. Jesper and I will sort out this circular dependency nightmare in another issue.

@ashu3103

Copy link
Copy Markdown
Collaborator Author

pgmoneta_file_finalname - what is that ? It sound static to me. I don't like the name.

And it shall be. @ashu3103 Can you rebase? Sorry for the mess.

Sure

Can't we also move this in utils, or in info.h itself?

Yes, let's keep it as a static function inside info.c at the moment. It's not used elsewhere anyway. Jesper and I will sort out this circular dependency nightmare in another issue.

I think it will still pose some issues (if you define pgmoneta_extract_backup_file static) because this function is alos used in restore.c in function copy_backup_file. So defining it static may not be a good idea we have to expose it in info.c

@Jubilee101

Copy link
Copy Markdown
Member

I think it will still pose some issues (if you define pgmoneta_extract_backup_file static) because this function is alos used in restore.c in function copy_backup_file. So defining it static may not be a good idea we have to expose it in info.c

Do what you must. We can do bigger refactoring work later.

@ashu3103

ashu3103 commented Apr 12, 2025 •

Copy link
Copy Markdown
Collaborator Author

I think it will still pose some issues (if you define pgmoneta_extract_backup_file static) because this function is alos used in restore.c in function copy_backup_file. So defining it static may not be a good idea we have to expose it in info.c

Do what you must. We can do bigger refactoring work later.

Okk

Also I had one doubt regarding your latest commit, you have made the functions pgmoneta_file_finalname (now file_final_name) static to restore.c but if we were anyways shifting rfile_create() in info.c, so shall I change that too.

Or Shall I leave the refactoring work for later

@Jubilee101

Copy link
Copy Markdown
Member

Also I had one doubt regarding your latest commit, you have made the functions pgmoneta_file_finalname (now file_final_name) static to restore.c but if we were anyways shifting rfile_create() in info.c, so shall I change that too.

Ok, what about moving it to a static function in info?

@ashu3103

Copy link
Copy Markdown
Collaborator Author

Also I had one doubt regarding your latest commit, you have made the functions pgmoneta_file_finalname (now file_final_name) static to restore.c but if we were anyways shifting rfile_create() in info.c, so shall I change that too.

Ok, what about moving it to a static function in info?

Yeah that would be fine, since its only used in rfile_create and we are moving that to info.c

@ashu3103
ashu3103 force-pushed the incr_restore branch 2 times, most recently from 3a8e53b to 5aae8d3 Compare April 12, 2025 03:48
@ashu3103

Copy link
Copy Markdown
Collaborator Author

@Jubilee101 @jesperpedersen PTAL

@jesperpedersen jesperpedersen added the enhancement Improvement to an existing feature label Apr 12, 2025
Comment thread src/include/info.h Resolved
Comment thread src/libpgmoneta/info.c Resolved
Comment thread src/libpgmoneta/info.c Resolved
Comment thread src/include/info.h Resolved
Comment thread src/include/info.h Resolved
Comment thread src/include/info.h Resolved
@ashu3103
ashu3103 force-pushed the incr_restore branch 6 times, most recently from c140239 to 36de5da Compare April 13, 2025 11:52
@ashu3103

Copy link
Copy Markdown
Collaborator Author

@Jubilee101, @jesperpedersen PTAL

Comment thread src/include/info.h
* @return 0 on success, 1 if otherwise
*/
int
pgmoneta_backup_size(int server, char* label, unsigned long* size, uint64_t* biggest_file_size);

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 be the only change in info.h - so you have to use static for the rest, or a lower level .h

@ashu3103 ashu3103 Apr 13, 2025 •

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.

We discussed about exposing rfile and corresponding APIs in info.h right, please tell me if I am missing something.

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.

info.h is about the struct backup - so if you can't use rfile as static only, then you need to create a rfile.h file and we can take it from there

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 doesn't change the fact that extract_backup belongs to restore.h. And if you don't want info to include restore, it's a dilemma. The patch looks good enough for me. And I don't see why rfile can't belong to info. It's still header metadata about backup file. Even if you put rfile in rfile.h, you'd still have extract_backup_file that belongs to nowhere. I'd like to merge this patch, and think about how we can rewire things in #592.

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.

Ok, go ahead then

@Jubilee101

Jubilee101 commented Apr 13, 2025 •

Copy link
Copy Markdown
Member

@ashu3103 It doesn't work when hotstandby is enabled. Free space check is checking the temp directory in workspace that has not been created yet. We use it to store the restored backup temporarily. Make a backup with hotstandby enabled and you'll see.

@Jubilee101

Copy link
Copy Markdown
Member

As a matter of fact, restore could always work on root that hasn't been created. You should check the space after the directory is created.

Comment thread src/include/info.h Resolved
@Jubilee101
Jubilee101 merged commit 9137666 into pgmoneta:main Apr 14, 2025
@Jubilee101

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.

3 participants