]> granicus.if.org Git - postgresql/commitdiff
Fix some issues in pg_rewind.
authorFujii Masao <fujii@postgresql.org>
Thu, 11 Jun 2015 13:31:18 +0000 (22:31 +0900)
committerFujii Masao <fujii@postgresql.org>
Thu, 11 Jun 2015 13:31:18 +0000 (22:31 +0900)
* Remove invalid option character "N" from the third argument (valid option
string) of getopt_long().

* Use pg_free() or pfree() to free the memory allocated by pg_malloc() or
palloc() instead of always using free().

* Assume problem is no disk space if write() fails but doesn't set errno.

* Fix several typos.

Patch by me. Review by Michael Paquier.

src/bin/pg_rewind/copy_fetch.c
src/bin/pg_rewind/datapagemap.c
src/bin/pg_rewind/file_ops.c
src/bin/pg_rewind/filemap.c
src/bin/pg_rewind/libpq_fetch.c
src/bin/pg_rewind/logging.h
src/bin/pg_rewind/pg_rewind.c

index 1ca00d12adfb2f49c15f74ccfd12c6783eef2cef..991e34867065803648a7e982e053bfbc859ef492 100644 (file)
@@ -43,7 +43,7 @@ traverse_datadir(const char *datadir, process_file_callback_t callback)
 /*
  * recursive part of traverse_datadir
  *
- * parent_path is the current subdirectory's path relative to datadir,
+ * parentpath is the current subdirectory's path relative to datadir,
  * or NULL at the top level.
  */
 static void
@@ -262,5 +262,5 @@ execute_pagemap(datapagemap_t *pagemap, const char *path)
                copy_file_range(path, offset, offset + BLCKSZ, false);
                /* Ok, this block has now been copied from new data dir to old */
        }
-       free(iter);
+       pg_free(iter);
 }
index 3477366af9ce4a2805b9044aac19f5a55061ab68..ff10bc9653b1377b1cfffc2801138d81d4927613 100644 (file)
@@ -67,7 +67,7 @@ datapagemap_add(datapagemap_t *map, BlockNumber blkno)
  * Start iterating through all entries in the page map.
  *
  * After datapagemap_iterate, call datapagemap_next to return the entries,
- * until it returns NULL. After you're done, use free() to destroy the
+ * until it returns false. After you're done, use pg_free() to destroy the
  * iterator.
  */
 datapagemap_iterator_t *
@@ -122,5 +122,5 @@ datapagemap_print(datapagemap_t *map)
        while (datapagemap_next(iter, &blocknum))
                printf("  blk %u\n", blocknum);
 
-       free(iter);
+       pg_free(iter);
 }
index 589a01a43407d20c7543c0dabe492946cf50a97e..d6a743f7884f137acccfcc622fff3a5e5bdce1e5 100644 (file)
@@ -105,10 +105,16 @@ write_target_range(char *buf, off_t begin, size_t size)
        {
                int                     writelen;
 
+               errno = 0;
                writelen = write(dstfd, p, writeleft);
                if (writelen < 0)
+               {
+                       /* if write didn't set errno, assume problem is no disk space */
+                       if (errno == 0)
+                               errno = ENOSPC;
                        pg_fatal("could not write file \"%s\": %s\n",
                                         dstpath, strerror(errno));
+               }
 
                p += writelen;
                writeleft -= writelen;
index cb2bf4d1a0ec3e149690544cd69ab621a2ce1fc7..3821e9c84652b70235768aca77f31e721b0b118f 100644 (file)
@@ -114,7 +114,7 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
                case FILE_TYPE_DIRECTORY:
                        if (exists && !S_ISDIR(statbuf.st_mode))
                        {
-                               /* it's a directory in target, but not in source. Strange.. */
+                               /* it's a directory in source, but not in target. Strange.. */
                                pg_fatal("\"%s\" is not a directory\n", localpath);
                        }
 
@@ -135,7 +135,7 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
                                )
                        {
                                /*
-                                * It's a symbolic link in target, but not in source.
+                                * It's a symbolic link in source, but not in target.
                                 * Strange..
                                 */
                                pg_fatal("\"%s\" is not a symbolic link\n", localpath);
@@ -354,7 +354,7 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
                entry = *e;
        else
                entry = NULL;
-       free(path);
+       pfree(path);
 
        if (entry)
        {
@@ -530,7 +530,7 @@ print_filemap(void)
  * Does it look like a relation data file?
  *
  * For our purposes, only files belonging to the main fork are considered
- * relation files. Other forks are alwayes copied in toto, because we cannot
+ * relation files. Other forks are always copied in toto, because we cannot
  * reliably track changes to them, because WAL only contains block references
  * for the main fork.
  */
index 14a861006dac523b8cc03cb27a1754ec4fbc7bbf..6ffd24e9f194172d526c2d47d012da3f86bfe791 100644 (file)
@@ -69,7 +69,7 @@ libpqConnect(const char *connstr)
        pg_free(str);
 
        /*
-        * Also check that full_page-writes are enabled. We can get torn pages if
+        * Also check that full_page_writes is enabled. We can get torn pages if
         * a page is modified while we read it with pg_read_binary_file(), and we
         * rely on full page images to fix them.
         */
@@ -465,5 +465,5 @@ execute_pagemap(datapagemap_t *pagemap, const char *path)
 
                fetch_file_range(path, offset, offset + BLCKSZ);
        }
-       free(iter);
+       pg_free(iter);
 }
index 0272a22039de2827cdb3389bb86c17ce1b2d046d..efbc9b7bb9475d5f0918c59149255a852b76b581 100644 (file)
@@ -32,4 +32,4 @@ extern void pg_fatal(const char *fmt,...) pg_attribute_printf(1, 2) pg_attribute
 
 extern void progress_report(bool force);
 
-#endif
+#endif   /* PG_REWIND_LOGGING_H */
index 8088be4fab652b725736c9b47560f7ffe406b335..7e54ac55fc4ee17f0a2f15946c995a7285eb8582 100644 (file)
@@ -121,7 +121,7 @@ main(int argc, char **argv)
                }
        }
 
-       while ((c = getopt_long(argc, argv, "D:NnP", long_options, &option_index)) != -1)
+       while ((c = getopt_long(argc, argv, "D:nP", long_options, &option_index)) != -1)
        {
                switch (c)
                {
@@ -370,7 +370,7 @@ sanityChecks(void)
        if (ControlFile_target.data_checksum_version != PG_DATA_CHECKSUM_VERSION &&
                !ControlFile_target.wal_log_hints)
        {
-               pg_fatal("target server need to use either data checksums or \"wal_log_hints = on\"\n");
+               pg_fatal("target server needs to use either data checksums or \"wal_log_hints = on\"\n");
        }
 
        /*
@@ -450,7 +450,7 @@ findCommonAncestorTimeline(XLogRecPtr *recptr, TimeLineID *tli)
                        *recptr = entry->end;
                        *tli = entry->tli;
 
-                       free(sourceHistory);
+                       pg_free(sourceHistory);
                        return;
                }
        }