From 1ac6041a15a82274d6443fb2354087fc17b1015f Mon Sep 17 00:00:00 2001 From: yaojun Date: Tue, 28 Nov 2023 16:44:57 +0800 Subject: [PATCH] fix dss_io_stat appear negative result Signed-off-by: yaojun --- src/common/backend/utils/adt/pgstatfuncs.cpp | 7 +++++-- src/include/storage/file/fio_device.h | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common/backend/utils/adt/pgstatfuncs.cpp b/src/common/backend/utils/adt/pgstatfuncs.cpp index 079737954..e842e20a6 100644 --- a/src/common/backend/utils/adt/pgstatfuncs.cpp +++ b/src/common/backend/utils/adt/pgstatfuncs.cpp @@ -14747,10 +14747,13 @@ Datum dss_io_stat(PG_FUNCTION_ARGS) if (duration > MAX_DURATION_TIME) { ereport(ERROR, (errmsg("The duration is too long, and it must be less than 60s."))); } + if (duration <= 0) { + ereport(ERROR, (errmsg("The duration must be greater than zero."))); + } init_dss_io_stat(); unsigned long long read_bytes = 0; unsigned long long write_bytes = 0; - int io_count = 0; + unsigned int io_count = 0; get_dss_io_stat(duration, &read_bytes, &write_bytes, &io_count); // tuple header int i = 1; @@ -14765,7 +14768,7 @@ Datum dss_io_stat(PG_FUNCTION_ARGS) i = 0; values[i++] = UInt64GetDatum(read_bytes); values[i++] = UInt64GetDatum(write_bytes); - values[i] = Int32GetDatum(io_count); + values[i] = UInt32GetDatum(io_count); HeapTuple heap_tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(heap_tuple); diff --git a/src/include/storage/file/fio_device.h b/src/include/storage/file/fio_device.h index b8ae4613c..a1ef8884c 100644 --- a/src/include/storage/file/fio_device.h +++ b/src/include/storage/file/fio_device.h @@ -96,9 +96,9 @@ static inline int close_dev(int fd) } typedef struct g_dss_io_stat { - int read_bytes; + unsigned long long read_bytes; unsigned long long write_bytes; - unsigned long long read_write_count; + unsigned int read_write_count; bool is_ready_for_stat; pthread_mutex_t lock; g_dss_io_stat() { @@ -132,7 +132,7 @@ static inline void init_dss_io_stat() * kB_write: total write kilobyte during the time * io_count: total read and write count */ -static inline void get_dss_io_stat(int duration, unsigned long long *kB_read, unsigned long long *kB_write, int *io_count) +static inline void get_dss_io_stat(int duration, unsigned long long *kB_read, unsigned long long *kB_write, unsigned int *io_count) { sleep(duration); if (kB_read) {