On 2024/11/25 8:31, Tatsuo Ishii wrote:
Now that two minor releases are out, are you going to commit and
back-patch this?

Yes, I will.

But, the patch didn't apply cleanly to some back branches, so I've created
and attached updated patches for them. Could you review these?
If they look good, I'll proceed with pushing them.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
From 4e542d9a070943c634c8f64f5619545c90d1c0e4 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Tue, 26 Nov 2024 01:01:14 +0900
Subject: [PATCH v4] pgbench: Ensure previous progress message is fully cleared
 when updating.

During pgbench's table initialization, progress updates could display
leftover characters from the previous message if the new message
was shorter. This commit resolves the issue by appending spaces to
the current message to fully overwrite any remaining characters from
the previous line.

Back-patch to all the supported versions.

Author: Yushi Ogiwara, Tatsuo Ishii, Fujii Masao
Reviewed-by: Tatsuo Ishii, Fujii Masao
Discussion: https://postgr.es/m/9a9b8b95b6a709877ae48ad5b0c59...@oss.nttdata.com
---
 src/bin/pgbench/pgbench.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index c1d577a959..c7f8431841 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -4222,6 +4222,8 @@ initGenerateDataClientSide(PGconn *con)
        PGresult   *res;
        int                     i;
        int64           k;
+       int                     chars = 0;
+       int                     prev_chars = 0;
 
        /* used to track elapsed time and estimate of the remaining time */
        pg_time_usec_t start;
@@ -4304,10 +4306,10 @@ initGenerateDataClientSide(PGconn *con)
                        double          elapsed_sec = 
PG_TIME_GET_DOUBLE(pg_time_now() - start);
                        double          remaining_sec = ((double) scale * 
naccounts - j) * elapsed_sec / j;
 
-                       fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " 
tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
-                                       j, (int64) naccounts * scale,
-                                       (int) (((int64) j * 100) / (naccounts * 
(int64) scale)),
-                                       elapsed_sec, remaining_sec, eol);
+                       chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
+                                                       j, (int64) naccounts * 
scale,
+                                                       (int) (((int64) j * 
100) / (naccounts * (int64) scale)),
+                                                       elapsed_sec, 
remaining_sec);
                }
                /* let's not call the timing for each row, but only each 100 
rows */
                else if (use_quiet && (j % 100 == 0))
@@ -4318,14 +4320,24 @@ initGenerateDataClientSide(PGconn *con)
                        /* have we reached the next interval (or end)? */
                        if ((j == scale * naccounts) || (elapsed_sec >= 
log_interval * LOG_STEP_SECONDS))
                        {
-                               fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
-                                               j, (int64) naccounts * scale,
-                                               (int) (((int64) j * 100) / 
(naccounts * (int64) scale)), elapsed_sec, remaining_sec, eol);
+                               chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
+                                                               j, (int64) 
naccounts * scale,
+                                                               (int) (((int64) 
j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
 
                                /* skip to the next interval */
                                log_interval = (int) ceil(elapsed_sec / 
LOG_STEP_SECONDS);
                        }
                }
+
+               /*
+                * If the previous progress message is longer than the current 
one,
+                * add spaces to the current line to fully overwrite any 
remaining
+                * characters from the previous message.
+                */
+               if (prev_chars > chars)
+                       fprintf(stderr, "%*c", prev_chars - chars, ' ');
+               fputc(eol, stderr);
+               prev_chars = chars;
        }
 
        if (eol != '\n')
-- 
2.47.0

From 24531a50a286005f4409e0b856fbd8204d00ebd0 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Tue, 26 Nov 2024 00:47:27 +0900
Subject: [PATCH v5] pgbench: Ensure previous progress message is fully cleared
 when updating.

During pgbench's table initialization, progress updates could display
leftover characters from the previous message if the new message
was shorter. This commit resolves the issue by appending spaces to
the current message to fully overwrite any remaining characters from
the previous line.

Back-patch to all the supported versions.

Author: Yushi Ogiwara, Tatsuo Ishii, Fujii Masao
Reviewed-by: Tatsuo Ishii, Fujii Masao
Discussion: https://postgr.es/m/9a9b8b95b6a709877ae48ad5b0c59...@oss.nttdata.com
---
 src/bin/pgbench/pgbench.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index c1134eae5b..fd2c8f42c5 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -4890,6 +4890,8 @@ initGenerateDataClientSide(PGconn *con)
        PGresult   *res;
        int                     i;
        int64           k;
+       int                     chars = 0;
+       int                     prev_chars = 0;
        char       *copy_statement;
 
        /* used to track elapsed time and estimate of the remaining time */
@@ -4975,10 +4977,10 @@ initGenerateDataClientSide(PGconn *con)
                        double          elapsed_sec = 
PG_TIME_GET_DOUBLE(pg_time_now() - start);
                        double          remaining_sec = ((double) scale * 
naccounts - j) * elapsed_sec / j;
 
-                       fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " 
tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
-                                       j, (int64) naccounts * scale,
-                                       (int) (((int64) j * 100) / (naccounts * 
(int64) scale)),
-                                       elapsed_sec, remaining_sec, eol);
+                       chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
+                                                       j, (int64) naccounts * 
scale,
+                                                       (int) (((int64) j * 
100) / (naccounts * (int64) scale)),
+                                                       elapsed_sec, 
remaining_sec);
                }
                /* let's not call the timing for each row, but only each 100 
rows */
                else if (use_quiet && (j % 100 == 0))
@@ -4989,14 +4991,24 @@ initGenerateDataClientSide(PGconn *con)
                        /* have we reached the next interval (or end)? */
                        if ((j == scale * naccounts) || (elapsed_sec >= 
log_interval * LOG_STEP_SECONDS))
                        {
-                               fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
-                                               j, (int64) naccounts * scale,
-                                               (int) (((int64) j * 100) / 
(naccounts * (int64) scale)), elapsed_sec, remaining_sec, eol);
+                               chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
+                                                               j, (int64) 
naccounts * scale,
+                                                               (int) (((int64) 
j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
 
                                /* skip to the next interval */
                                log_interval = (int) ceil(elapsed_sec / 
LOG_STEP_SECONDS);
                        }
                }
+
+               /*
+                * If the previous progress message is longer than the current 
one,
+                * add spaces to the current line to fully overwrite any 
remaining
+                * characters from the previous message.
+                */
+               if (prev_chars > chars)
+                       fprintf(stderr, "%*c", prev_chars - chars, ' ');
+               fputc(eol, stderr);
+               prev_chars = chars;
        }
 
        if (eol != '\n')
-- 
2.47.0

From b55547a5db704a24dd6d2f8d01918f420626705c Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Fri, 8 Nov 2024 00:34:55 +0900
Subject: [PATCH v4] pgbench: Ensure previous progress message is fully cleared
 when updating.

During pgbench's table initialization, progress updates could display
leftover characters from the previous message if the new message
was shorter. This commit resolves the issue by appending spaces to
the current message to fully overwrite any remaining characters from
the previous line.

Back-patch to all the supported versions.

Author: Yushi Ogiwara, Tatsuo Ishii, Fujii Masao
Reviewed-by: Tatsuo Ishii, Fujii Masao
Discussion: https://postgr.es/m/9a9b8b95b6a709877ae48ad5b0c59...@oss.nttdata.com
---
 src/bin/pgbench/pgbench.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index ba247f3f85..85e7b68baa 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -4944,6 +4944,7 @@ initPopulateTable(PGconn *con, const char *table, int64 
base,
        int                     n;
        int64           k;
        int                     chars = 0;
+       int                     prev_chars = 0;
        PGresult   *res;
        PQExpBufferData sql;
        char            copy_statement[256];
@@ -5004,10 +5005,10 @@ initPopulateTable(PGconn *con, const char *table, int64 
base,
                        double          elapsed_sec = 
PG_TIME_GET_DOUBLE(pg_time_now() - start);
                        double          remaining_sec = ((double) total - j) * 
elapsed_sec / j;
 
-                       chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c",
+                       chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)",
                                                        j, total,
                                                        (int) ((j * 100) / 
total),
-                                                       table, elapsed_sec, 
remaining_sec, eol);
+                                                       table, elapsed_sec, 
remaining_sec);
                }
                /* let's not call the timing for each row, but only each 100 
rows */
                else if (use_quiet && (j % 100 == 0))
@@ -5018,19 +5019,29 @@ initPopulateTable(PGconn *con, const char *table, int64 
base,
                        /* have we reached the next interval (or end)? */
                        if ((j == total) || (elapsed_sec >= log_interval * 
LOG_STEP_SECONDS))
                        {
-                               chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c",
+                               chars = fprintf(stderr, INT64_FORMAT " of " 
INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)",
                                                                j, total,
                                                                (int) ((j * 
100) / total),
-                                                               table, 
elapsed_sec, remaining_sec, eol);
+                                                               table, 
elapsed_sec, remaining_sec);
 
                                /* skip to the next interval */
                                log_interval = (int) ceil(elapsed_sec / 
LOG_STEP_SECONDS);
                        }
                }
+
+               /*
+                * If the previous progress message is longer than the current 
one,
+                * add spaces to the current line to fully overwrite any 
remaining
+                * characters from the previous message.
+                */
+               if (prev_chars > chars)
+                       fprintf(stderr, "%*c", prev_chars - chars, ' ');
+               fputc(eol, stderr);
+               prev_chars = chars;
        }
 
        if (chars != 0 && eol != '\n')
-               fprintf(stderr, "%*c\r", chars - 1, ' ');       /* Clear the 
current line */
+               fprintf(stderr, "%*c\r", chars, ' ');   /* Clear the current 
line */
 
        if (PQputline(con, "\\.\n"))
                pg_fatal("very last PQputline failed");
-- 
2.47.0

Reply via email to