LCOV - differential code coverage report
Current view: top level - src/bin/pg_upgrade - tablespace.c (source / functions) Coverage Total Hit UNC UBC GNC CBC DUB
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 60.0 % 35 21 1 13 21 1
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 3 3 1 2
Baseline: 16@8cea358b128 Branches: 21.4 % 14 3 11 3
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed [..60] days: 0.0 % 1 0 1
(240..) days: 61.8 % 34 21 13 21
Function coverage date bins:
(240..) days: 100.0 % 3 3 1 2
Branch coverage date bins:
(240..) days: 21.4 % 14 3 11 3

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  *  tablespace.c
                                  3                 :                :  *
                                  4                 :                :  *  tablespace functions
                                  5                 :                :  *
                                  6                 :                :  *  Copyright (c) 2010-2024, PostgreSQL Global Development Group
                                  7                 :                :  *  src/bin/pg_upgrade/tablespace.c
                                  8                 :                :  */
                                  9                 :                : 
                                 10                 :                : #include "postgres_fe.h"
                                 11                 :                : 
                                 12                 :                : #include "pg_upgrade.h"
                                 13                 :                : 
                                 14                 :                : static void get_tablespace_paths(void);
                                 15                 :                : static void set_tablespace_directory_suffix(ClusterInfo *cluster);
                                 16                 :                : 
                                 17                 :                : 
                                 18                 :                : void
 4926 bruce@momjian.us           19                 :CBC           8 : init_tablespaces(void)
                                 20                 :                : {
                                 21                 :              8 :     get_tablespace_paths();
                                 22                 :                : 
 4852                            23                 :              8 :     set_tablespace_directory_suffix(&old_cluster);
                                 24                 :              8 :     set_tablespace_directory_suffix(&new_cluster);
                                 25                 :                : 
 4113                            26         [ -  + ]:              8 :     if (os_info.num_old_tablespaces > 0 &&
 2489 tgl@sss.pgh.pa.us          27         [ #  # ]:UBC           0 :         strcmp(old_cluster.tablespace_suffix, new_cluster.tablespace_suffix) == 0)
 3848 peter_e@gmx.net            28                 :              0 :         pg_fatal("Cannot upgrade to/from the same system catalog version when\n"
                                 29                 :                :                  "using tablespaces.");
 5086 bruce@momjian.us           30                 :CBC           8 : }
                                 31                 :                : 
                                 32                 :                : 
                                 33                 :                : /*
                                 34                 :                :  * get_tablespace_paths()
                                 35                 :                :  *
                                 36                 :                :  * Scans pg_tablespace and returns a malloc'ed array of all tablespace
                                 37                 :                :  * paths. It's the caller's responsibility to free the array.
                                 38                 :                :  */
                                 39                 :                : static void
 4926                            40                 :              8 : get_tablespace_paths(void)
                                 41                 :                : {
 4852                            42                 :              8 :     PGconn     *conn = connectToServer(&old_cluster, "template1");
                                 43                 :                :     PGresult   *res;
                                 44                 :                :     int         tblnum;
                                 45                 :                :     int         i_spclocation;
                                 46                 :                :     char        query[QUERY_ALLOC];
                                 47                 :                : 
 4512 magnus@hagander.net        48                 :              8 :     snprintf(query, sizeof(query),
                                 49                 :                :              "SELECT pg_catalog.pg_tablespace_location(oid) AS spclocation "
                                 50                 :                :              "FROM pg_catalog.pg_tablespace "
                                 51                 :                :              "WHERE    spcname != 'pg_default' AND "
                                 52                 :                :              "     spcname != 'pg_global'");
                                 53                 :                : 
                                 54                 :              8 :     res = executeQueryOrDie(conn, "%s", query);
                                 55                 :                : 
 4113 bruce@momjian.us           56         [ -  + ]:              8 :     if ((os_info.num_old_tablespaces = PQntuples(res)) != 0)
 1536 alvherre@alvh.no-ip.       57                 :UBC           0 :         os_info.old_tablespaces =
                                 58                 :              0 :             (char **) pg_malloc(os_info.num_old_tablespaces * sizeof(char *));
                                 59                 :                :     else
 4113 bruce@momjian.us           60                 :CBC           8 :         os_info.old_tablespaces = NULL;
                                 61                 :                : 
 5086                            62                 :              8 :     i_spclocation = PQfnumber(res, "spclocation");
                                 63                 :                : 
 4113                            64         [ -  + ]:              8 :     for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
                                 65                 :                :     {
                                 66                 :                :         struct stat statBuf;
                                 67                 :                : 
 1536 alvherre@alvh.no-ip.       68                 :UBC           0 :         os_info.old_tablespaces[tblnum] = pg_strdup(PQgetvalue(res, tblnum, i_spclocation));
                                 69                 :                : 
                                 70                 :                :         /*
                                 71                 :                :          * Check that the tablespace path exists and is a directory.
                                 72                 :                :          * Effectively, this is checking only for tables/indexes in
                                 73                 :                :          * non-existent tablespace directories.  Databases located in
                                 74                 :                :          * non-existent tablespaces already throw a backend error.
                                 75                 :                :          * Non-existent tablespace directories can occur when a data directory
                                 76                 :                :          * that contains user tablespaces is moved as part of pg_upgrade
                                 77                 :                :          * preparation and the symbolic links are not updated.
                                 78                 :                :          */
 3650 bruce@momjian.us           79         [ #  # ]:              0 :         if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0)
                                 80                 :                :         {
                                 81         [ #  # ]:              0 :             if (errno == ENOENT)
                                 82                 :              0 :                 report_status(PG_FATAL,
                                 83                 :                :                               "tablespace directory \"%s\" does not exist",
                                 84                 :              0 :                               os_info.old_tablespaces[tblnum]);
                                 85                 :                :             else
                                 86                 :              0 :                 report_status(PG_FATAL,
                                 87                 :                :                               "could not stat tablespace directory \"%s\": %m",
   33 michael@paquier.xyz        88                 :UNC           0 :                               os_info.old_tablespaces[tblnum]);
                                 89                 :                :         }
 3650 bruce@momjian.us           90         [ #  # ]:UBC           0 :         if (!S_ISDIR(statBuf.st_mode))
 3631                            91                 :              0 :             report_status(PG_FATAL,
                                 92                 :                :                           "tablespace path \"%s\" is not a directory",
                                 93                 :              0 :                           os_info.old_tablespaces[tblnum]);
                                 94                 :                :     }
                                 95                 :                : 
 5086 bruce@momjian.us           96                 :CBC           8 :     PQclear(res);
                                 97                 :                : 
                                 98                 :              8 :     PQfinish(conn);
                                 99                 :              8 : }
                                100                 :                : 
                                101                 :                : 
                                102                 :                : static void
 4852                           103                 :             16 : set_tablespace_directory_suffix(ClusterInfo *cluster)
                                104                 :                : {
                                105                 :                :     /* This cluster has a version-specific subdirectory */
                                106                 :                : 
                                107                 :                :     /* The leading slash is needed to start a new directory. */
  852 tgl@sss.pgh.pa.us         108                 :             32 :     cluster->tablespace_suffix = psprintf("/PG_%s_%d",
                                109                 :             16 :                                           cluster->major_version_str,
                                110                 :                :                                           cluster->controldata.cat_ver);
 5086 bruce@momjian.us          111                 :             16 : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622