Skip to content

Commit 8387a99

Browse files
committed
[pgmoneta#1089] fix the integration testing
Signed-off-by: Amr-Shams <amr.shams2015.as@gmail.com>
1 parent 34d7e97 commit 8387a99

3 files changed

Lines changed: 118 additions & 15 deletions

File tree

src/include/workflow.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ struct workflow
123123
struct workflow*
124124
pgmoneta_workflow_create(int workflow_type, struct backup* backup);
125125

126+
/**
127+
* Create a verify chain: decrypt -> decompress -> verify
128+
* @param backup The backup
129+
* @return The workflow chain
130+
*/
131+
struct workflow*
132+
pgmoneta_workflow_create_verify_chain(struct backup* backup);
133+
126134
/**
127135
* Create standard workflow nodes
128136
* @param server The server

src/libpgmoneta/s3.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
366366
goto error;
367367
}
368368

369+
if (pgmoneta_art_insert(nodes, USER_IDENTIFIER, (uintptr_t)prefix, ValueString))
370+
{
371+
ec = MANAGEMENT_ERROR_RESTORE_S3_WORKFLOW;
372+
goto error;
373+
}
374+
369375
workflow = pgmoneta_workflow_create(WORKFLOW_TYPE_S3_RESTORE, NULL);
370376

371377
if (workflow == NULL)
@@ -381,16 +387,26 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
381387
goto error;
382388
}
383389
pgmoneta_workflow_destroy(workflow);
390+
workflow = NULL;
391+
384392
base_dir = pgmoneta_get_server_backup(server);
385393
local_root = pgmoneta_get_server_backup_identifier(server, prefix);
394+
386395
if (pgmoneta_art_insert(nodes, NODE_TARGET_BASE, (uintptr_t)local_root, ValueString))
387396
{
388397
pgmoneta_log_error("S3 restore: could not add backup dir to art");
389398
goto error;
390399
}
400+
401+
if (pgmoneta_art_insert(nodes, NODE_TARGET_ROOT, (uintptr_t)local_root, ValueString))
402+
{
403+
pgmoneta_log_error("S3 restore: could not add target root to art");
404+
goto error;
405+
}
406+
391407
if (pgmoneta_art_insert(nodes, USER_FILES, (uintptr_t)NODE_ALL, ValueString))
392408
{
393-
pgmoneta_log_error("S3 restore: could not add base dir to art");
409+
pgmoneta_log_error("S3 restore: could not add user files to art");
394410
goto error;
395411
}
396412

@@ -399,7 +415,8 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
399415
pgmoneta_log_error("S3 restore: could not load info for %s", config->common.servers[server].name);
400416
goto error;
401417
}
402-
workflow = pgmoneta_workflow_create(WORKFLOW_TYPE_VERIFY, backup);
418+
419+
workflow = pgmoneta_workflow_create_verify_chain(backup);
403420
if (pgmoneta_workflow_execute(workflow, nodes, &en, &ec))
404421
{
405422
pgmoneta_log_error("S3 restore: workflow failed for %s", config->common.servers[server].name);
@@ -444,8 +461,8 @@ pgmoneta_restore_s3_objects(int client_fd, int server, char* prefix, uint8_t com
444461
pgmoneta_art_destroy(nodes);
445462
pgmoneta_workflow_destroy(workflow);
446463
free(elapsed);
447-
free(base_dir);
448464
free(backup);
465+
free(base_dir);
449466
if (local_root != NULL)
450467
{
451468
pgmoneta_delete_directory(local_root);

src/libpgmoneta/workflow.c

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,96 @@ wf_incremental_backup(void)
808808
return head;
809809
}
810810

811+
struct workflow*
812+
pgmoneta_workflow_create_verify_chain(struct backup* backup)
813+
{
814+
struct workflow* head = NULL;
815+
struct workflow* current = NULL;
816+
817+
if (backup->encryption != ENCRYPTION_NONE)
818+
{
819+
head = pgmoneta_encryption(false);
820+
current = head;
821+
}
822+
823+
switch (COMPRESSION_ALGORITHM(backup->compression))
824+
{
825+
case COMPRESSION_ALG_GZIP:
826+
if (head == NULL)
827+
{
828+
head = pgmoneta_create_gzip(false);
829+
current = head;
830+
}
831+
else
832+
{
833+
current->next = pgmoneta_create_gzip(false);
834+
current = current->next;
835+
}
836+
break;
837+
case COMPRESSION_ALG_ZSTD:
838+
if (head == NULL)
839+
{
840+
head = pgmoneta_create_zstd(false);
841+
current = head;
842+
}
843+
else
844+
{
845+
current->next = pgmoneta_create_zstd(false);
846+
current = current->next;
847+
}
848+
break;
849+
case COMPRESSION_ALG_LZ4:
850+
if (head == NULL)
851+
{
852+
head = pgmoneta_create_lz4(false);
853+
current = head;
854+
}
855+
else
856+
{
857+
current->next = pgmoneta_create_lz4(false);
858+
current = current->next;
859+
}
860+
break;
861+
case COMPRESSION_ALG_BZIP2:
862+
if (head == NULL)
863+
{
864+
head = pgmoneta_create_bzip2(false);
865+
current = head;
866+
}
867+
else
868+
{
869+
current->next = pgmoneta_create_bzip2(false);
870+
current = current->next;
871+
}
872+
break;
873+
}
874+
875+
if (head == NULL)
876+
{
877+
head = pgmoneta_create_verify();
878+
current = head;
879+
}
880+
else
881+
{
882+
current->next = pgmoneta_create_verify();
883+
current = current->next;
884+
}
885+
886+
#ifdef DEBUG
887+
current = head;
888+
while (current != NULL)
889+
{
890+
assert(current->name != NULL);
891+
assert(current->setup != NULL);
892+
assert(current->execute != NULL);
893+
assert(current->teardown != NULL);
894+
current = current->next;
895+
}
896+
#endif
897+
898+
return head;
899+
}
900+
811901
static struct workflow*
812902
wf_verify(struct backup* backup)
813903
{
@@ -852,18 +942,6 @@ wf_verify(struct backup* backup)
852942
current->next = pgmoneta_create_verify();
853943
current = current->next;
854944

855-
#ifdef DEBUG
856-
current = head;
857-
while (current != NULL)
858-
{
859-
assert(current->name != NULL);
860-
assert(current->setup != NULL);
861-
assert(current->execute != NULL);
862-
assert(current->teardown != NULL);
863-
current = current->next;
864-
}
865-
#endif
866-
867945
return head;
868946
}
869947

0 commit comments

Comments
 (0)