56
56
#include <signal.h>
57
57
#include <time.h>
58
58
59
+ #include "common/relpath.h"
59
60
#include "mb/pg_wchar.h"
60
61
#include "getaddrinfo.h"
61
62
#include "getopt_long.h"
@@ -210,6 +211,7 @@ static char **filter_lines_with_token(char **lines, const char *token);
210
211
static char * * readfile (const char * path );
211
212
static void writefile (char * path , char * * lines );
212
213
static void walkdir (char * path , void (* action ) (char * fname , bool isdir ));
214
+ static void walktblspc_links (char * path , void (* action ) (char * fname , bool isdir ));
213
215
static void pre_sync_fname (char * fname , bool isdir );
214
216
static void fsync_fname (char * fname , bool isdir );
215
217
static FILE * popen_check (const char * command , const char * mode );
@@ -585,6 +587,55 @@ walkdir(char *path, void (*action) (char *fname, bool isdir))
585
587
(* action ) (path , true);
586
588
}
587
589
590
+ /*
591
+ * walktblspc_links: call walkdir on each entry under the given
592
+ * pg_tblspc directory, or do nothing if pg_tblspc doesn't exist.
593
+ */
594
+ static void
595
+ walktblspc_links (char * path , void (* action ) (char * fname , bool isdir ))
596
+ {
597
+ DIR * dir ;
598
+ struct dirent * direntry ;
599
+ char subpath [MAXPGPATH ];
600
+
601
+ dir = opendir (path );
602
+ if (dir == NULL )
603
+ {
604
+ if (errno == ENOENT )
605
+ return ;
606
+ fprintf (stderr , _ ("%s: could not open directory \"%s\": %s\n" ),
607
+ progname , path , strerror (errno ));
608
+ exit_nicely ();
609
+ }
610
+
611
+ while (errno = 0 , (direntry = readdir (dir )) != NULL )
612
+ {
613
+ if (strcmp (direntry -> d_name , "." ) == 0 ||
614
+ strcmp (direntry -> d_name , ".." ) == 0 )
615
+ continue ;
616
+
617
+ /* fsync the version specific tablespace subdirectory */
618
+ snprintf (subpath , sizeof (subpath ), "%s/%s/%s" ,
619
+ path , direntry -> d_name , TABLESPACE_VERSION_DIRECTORY );
620
+
621
+ walkdir (subpath , action );
622
+ }
623
+
624
+ if (errno )
625
+ {
626
+ fprintf (stderr , _ ("%s: could not read directory \"%s\": %s\n" ),
627
+ progname , path , strerror (errno ));
628
+ exit_nicely ();
629
+ }
630
+
631
+ if (closedir (dir ))
632
+ {
633
+ fprintf (stderr , _ ("%s: could not close directory \"%s\": %s\n" ),
634
+ progname , path , strerror (errno ));
635
+ exit_nicely ();
636
+ }
637
+ }
638
+
588
639
/*
589
640
* Hint to the OS that it should get ready to fsync() this file.
590
641
*/
@@ -2311,6 +2362,7 @@ static void
2311
2362
perform_fsync (void )
2312
2363
{
2313
2364
char pdir [MAXPGPATH ];
2365
+ char pg_tblspc [MAXPGPATH ];
2314
2366
2315
2367
fputs (_ ("syncing data to disk ... " ), stdout );
2316
2368
fflush (stdout );
@@ -2329,19 +2381,26 @@ perform_fsync(void)
2329
2381
/* first the parent of the PGDATA directory */
2330
2382
pre_sync_fname (pdir , true);
2331
2383
2332
- /* then recursively through the directory */
2384
+ /* then recursively through the data directory */
2333
2385
walkdir (pg_data , pre_sync_fname );
2334
2386
2387
+ /* now do the same thing for everything under pg_tblspc */
2388
+ snprintf (pg_tblspc , MAXPGPATH , "%s/pg_tblspc" , pg_data );
2389
+ walktblspc_links (pg_tblspc , pre_sync_fname );
2390
+
2335
2391
/*
2336
2392
* Now, do the fsync()s in the same order.
2337
2393
*/
2338
2394
2339
2395
/* first the parent of the PGDATA directory */
2340
2396
fsync_fname (pdir , true);
2341
2397
2342
- /* then recursively through the directory */
2398
+ /* then recursively through the data directory */
2343
2399
walkdir (pg_data , fsync_fname );
2344
2400
2401
+ /* and now the same for all tablespaces */
2402
+ walktblspc_links (pg_tblspc , fsync_fname );
2403
+
2345
2404
check_ok ();
2346
2405
}
2347
2406
0 commit comments