Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9aaf4f2

Browse files
committed
[#1119] Add test cases for tablespaces
1 parent a1ff2a8 commit 9aaf4f2

18 files changed

Lines changed: 790 additions & 22 deletions

File tree

src/include/achv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
9090
* @return 0 upon success, otherwise 1
9191
*/
9292
int
93-
pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art* file_checksums, struct art* file_sizes);
93+
pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art* file_checksums, struct art* file_sizes, char* manifest_prefix);
9494

9595
#ifdef __cplusplus
9696
}

src/libpgmoneta/aes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,11 @@ decrypt_data(char* d, struct workers* workers, struct deque* excludes)
535535

536536
while ((entry = readdir(dir)) != NULL)
537537
{
538-
if (entry->d_type == DT_DIR || entry->d_type == DT_LNK)
538+
if (entry->d_type == DT_DIR)
539539
{
540540
char path[1024];
541541

542-
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
542+
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0 || strcmp(entry->d_name, "pg_tblspc") == 0)
543543
{
544544
continue;
545545
}

src/libpgmoneta/archive.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,11 @@ pgmoneta_receive_archive_files(int srv, SSL* ssl, int socket, struct stream_buff
294294
{
295295
char file_path[MAX_PATH];
296296
char directory[MAX_PATH];
297+
char manifest_prefix[MAX_PATH];
297298
const char* archive_ext = basebackup_archive_extension();
298299
memset(file_path, 0, sizeof(file_path));
299300
memset(directory, 0, sizeof(directory));
301+
memset(manifest_prefix, 0, sizeof(manifest_prefix));
300302
if (tup->data[1] == NULL)
301303
{
302304
// main data directory
@@ -320,6 +322,7 @@ pgmoneta_receive_archive_files(int srv, SSL* ssl, int socket, struct stream_buff
320322
if (pgmoneta_compare_string(tup->data[1], tblspc->path))
321323
{
322324
tblspc->oid = atoi(tup->data[0]);
325+
pgmoneta_snprintf(manifest_prefix, sizeof(manifest_prefix), "pg_tblspc/%d", tblspc->oid);
323326
break;
324327
}
325328
tblspc = tblspc->next;
@@ -394,7 +397,7 @@ pgmoneta_receive_archive_files(int srv, SSL* ssl, int socket, struct stream_buff
394397
fclose(file);
395398

396399
// extract the file
397-
if (pgmoneta_extract_backup_tar_file(file_path, directory, file_checksums, file_sizes))
400+
if (pgmoneta_extract_backup_tar_file(file_path, directory, file_checksums, file_sizes, manifest_prefix))
398401
{
399402
goto error;
400403
}
@@ -479,6 +482,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
479482
char file_path[MAX_PATH];
480483
char directory[MAX_PATH];
481484
char link_path[MAX_PATH];
485+
char manifest_prefix[MAX_PATH];
482486
char tmp_manifest_file_path[MAX_PATH];
483487
char manifest_file_path[MAX_PATH];
484488
struct art* file_sizes = NULL;
@@ -487,6 +491,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
487491
memset(file_path, 0, sizeof(file_path));
488492
memset(directory, 0, sizeof(directory));
489493
memset(link_path, 0, sizeof(link_path));
494+
memset(manifest_prefix, 0, sizeof(manifest_prefix));
490495
memset(manifest_file_path, 0, sizeof(manifest_file_path));
491496
memset(tmp_manifest_file_path, 0, sizeof(tmp_manifest_file_path));
492497
memset(null_buffer, 0, 2 * 512);
@@ -568,7 +573,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
568573
fflush(file);
569574
fclose(file);
570575
file = NULL;
571-
if (pgmoneta_extract_backup_tar_file(file_path, directory, file_checksums, file_sizes))
576+
if (pgmoneta_extract_backup_tar_file(file_path, directory, file_checksums, file_sizes, manifest_prefix))
572577
{
573578
goto error;
574579
}
@@ -580,6 +585,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
580585

581586
memset(file_path, 0, sizeof(file_path));
582587
memset(directory, 0, sizeof(directory));
588+
memset(manifest_prefix, 0, sizeof(manifest_prefix));
583589
const char* archive_ext = basebackup_archive_extension();
584590
// The tablespace order in the second result set is presumably the same as the order in which the server sends tablespaces
585591
tblspc = tablespaces;
@@ -614,6 +620,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
614620
if (pgmoneta_compare_string(tblspc->path, archive_path))
615621
{
616622
tblspc->oid = atoi(tup->data[0]);
623+
pgmoneta_snprintf(manifest_prefix, sizeof(manifest_prefix), "pg_tblspc/%d", tblspc->oid);
617624
break;
618625
}
619626
tblspc = tblspc->next;
@@ -655,7 +662,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
655662
fflush(file);
656663
fclose(file);
657664
file = NULL;
658-
if (pgmoneta_extract_backup_tar_file(file_path, directory, file_checksums, file_sizes))
665+
if (pgmoneta_extract_backup_tar_file(file_path, directory, file_checksums, file_sizes, manifest_prefix))
659666
{
660667
goto error;
661668
}
@@ -795,7 +802,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
795802
}
796803

797804
int
798-
pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art* file_checksums, struct art* file_sizes)
805+
pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art* file_checksums, struct art* file_sizes, char* manifest_prefix)
799806
{
800807
char* archive_name = NULL;
801808
struct archive* a;
@@ -905,6 +912,11 @@ pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art*
905912
pgmoneta_snprintf(dst_path, sizeof(dst_path), "%s/%s", destination, entry_path);
906913
}
907914

915+
if (type == AE_IFLNK && pgmoneta_ends_with(dst_path, "/"))
916+
{
917+
dst_path[strlen(dst_path) - 1] = '\0';
918+
}
919+
908920
if (type == AE_IFDIR)
909921
{
910922
if (pgmoneta_mkdir(dst_path))
@@ -987,6 +999,11 @@ pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art*
987999
}
9881000
while (asize > 0);
9891001

1002+
if (manifest_prefix != NULL && strlen(manifest_prefix) > 0)
1003+
{
1004+
entry_path_cpy = pgmoneta_append(entry_path_cpy, manifest_prefix);
1005+
entry_path_cpy = pgmoneta_append(entry_path_cpy, "/");
1006+
}
9901007
entry_path_cpy = pgmoneta_append(entry_path_cpy, entry_path);
9911008
pgmoneta_art_insert(file_sizes, entry_path_cpy, (uintptr_t)strm->written, ValueUInt64);
9921009
pgmoneta_art_insert(file_checksums, entry_path_cpy, (uintptr_t)hasher->hash, ValueString);

src/libpgmoneta/compression.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ process_directory_operation(int server, char* directory, int type, struct worker
431431

432432
pgmoneta_snprintf(full_path, sizeof(full_path), "%s/%s", directory, entry->d_name);
433433

434+
if (strcmp(entry->d_name, "pg_tblspc") == 0)
435+
{
436+
continue;
437+
}
438+
434439
if (is_directory_entry(entry, full_path))
435440
{
436441
if (process_directory_operation(server, full_path, type, workers, excludes, decompress))

test/check.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ detect_container_engine() {
8686
fi
8787
}
8888

89+
make_tablespace_cleanup_writable() {
90+
local tablespace_dir
91+
92+
for tablespace_dir in tblspc_test tblspc_tesths; do
93+
if [[ ! -d "$PGCONF_DIRECTORY/$tablespace_dir" ]]; then
94+
continue
95+
fi
96+
97+
if [[ $MODE != "ci" && -n "${CONTAINER_ENGINE:-}" ]]; then
98+
$CONTAINER_ENGINE exec $CONTAINER_NAME chmod -R 777 "/conf/$tablespace_dir" 2>/dev/null || true
99+
fi
100+
if ! chmod -R 777 "$PGCONF_DIRECTORY/$tablespace_dir" 2>/dev/null; then
101+
$SUDO chmod -R 777 "$PGCONF_DIRECTORY/$tablespace_dir" || true
102+
fi
103+
done
104+
}
105+
106+
remove_tablespace_cleanup_directory() {
107+
local tablespace_dir
108+
109+
make_tablespace_cleanup_writable
110+
for tablespace_dir in tblspc_test tblspc_tesths; do
111+
if [[ -d "$PGCONF_DIRECTORY/$tablespace_dir" ]]; then
112+
rm -Rf "$PGCONF_DIRECTORY/$tablespace_dir" 2>/dev/null || $SUDO rm -Rf "$PGCONF_DIRECTORY/$tablespace_dir"
113+
fi
114+
done
115+
}
116+
89117
if [ -n "$PGMONETA_TEST_PORT" ]; then
90118
PORT=$PGMONETA_TEST_PORT
91119
fi
@@ -110,6 +138,8 @@ cleanup() {
110138

111139
echo "Clean Test Resources"
112140
if [[ -d $PGMONETA_ROOT_DIR ]]; then
141+
remove_tablespace_cleanup_directory
142+
113143
if [[ -d $BASE_DIR ]]; then
114144
rm -Rf "$BASE_DIR"
115145
fi
@@ -382,6 +412,7 @@ do_setup() {
382412

383413
echo "Preparing the pgmoneta directory"
384414
export LLVM_PROFILE_FILE="$COVERAGE_DIR/coverage-%p-%m.profraw"
415+
remove_tablespace_cleanup_directory
385416
rm -Rf "$PGMONETA_ROOT_DIR"
386417
mkdir -p "$PGMONETA_ROOT_DIR"
387418
mkdir -p "$LOG_DIR" "$PG_LOG_DIR" "$COVERAGE_DIR" "$BASE_DIR" "$RETROSPECT_DIR" "$HOT_STANDBY_DIRECTORY"
@@ -617,4 +648,3 @@ fi
617648
detect_container_engine
618649
trap cleanup EXIT SIGINT
619650
run_tests
620-

test/include/tscommon.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ pgmoneta_test_config_restore(void);
129129
int
130130
pgmoneta_test_execute_query(int srv, SSL* ssl, int skt, char* query, struct query_response** qr);
131131

132+
/**
133+
* Free a query response and set the pointer to NULL.
134+
* @param qr The query response pointer
135+
*/
136+
void
137+
pgmoneta_test_cleanup_query_response(struct query_response** qr);
138+
132139
/**
133140
* Resolve an executable path under build/src from a test process.
134141
* Example: "pgmoneta-walinfo" -> ".../build/src/pgmoneta-walinfo"

test/libpgmonetatest/tscommon.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@ pgmoneta_test_execute_query(int srv, SSL* ssl, int skt, char* query, struct quer
351351
return 1;
352352
}
353353

354+
void
355+
pgmoneta_test_cleanup_query_response(struct query_response** qr)
356+
{
357+
if (qr != NULL && *qr != NULL)
358+
{
359+
pgmoneta_free_query_response(*qr);
360+
*qr = NULL;
361+
}
362+
}
363+
354364
int
355365
pgmoneta_test_resolve_binary_path(const char* binary_name, char* out)
356366
{

test/postgresql/src/postgresql14/conf/pg_hba.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local all all trust
22
local replication all trust
33
host PG_DATABASE PG_USER_NAME all trust
44
host all PG_USER_NAME all trust
5+
host postgres postgres all trust
56
local postgres PG_REPL_USER_NAME md5
67
host postgres PG_REPL_USER_NAME all md5
7-
host replication PG_REPL_USER_NAME all md5
8+
host replication PG_REPL_USER_NAME all md5

test/postgresql/src/postgresql14/root/usr/bin/run-postgresql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ sed -i "s/PG_REPL_PASSWORD/$PG_REPL_PASSWORD/g" /conf/setup.sql
7171
touch /pglog/logfile
7272
chmod 666 /pglog/logfile
7373

74+
mkdir -p /conf/tblspc_test
75+
7476
/usr/pgsql-14/bin/pg_ctl -D /pgdata/ start
7577
/usr/pgsql-14/bin/psql -q -h /tmp -f /conf/setup.sql postgres
7678
/usr/pgsql-14/bin/pg_ctl -D /pgdata/ stop

test/postgresql/src/postgresql14/root/usr/bin/run-postgresql-local

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ sed -i "s/PG_USER_PASSWORD/$PG_USER_PASSWORD/g" /conf/setup.sql
5656
sed -i "s/PG_REPL_USER_NAME/$PG_REPL_USER_NAME/g" /conf/setup.sql
5757
sed -i "s/PG_REPL_PASSWORD/$PG_REPL_PASSWORD/g" /conf/setup.sql
5858

59+
mkdir -p /conf/tblspc_test
60+
5961
/usr/pgsql-14/bin/pg_ctl -D /pgdata/ start
6062
/usr/pgsql-14/bin/psql -q -h /tmp -f /conf/setup.sql postgres

0 commit comments

Comments
 (0)