From 11ef10332ef8491b4b81e161808fe07f179202b5 Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Mon, 2 Dec 2019 16:29:26 +0300 Subject: [PATCH] Add number of compressed hypertables to stat This change includes telemetry fixes which extends HypertablesStat with num_hypertables_compressed. It also updates the way how the number of regular hypertables is calculated, which is now treated as a non-compressed and not related to continuous aggregates. --- src/hypertable.c | 51 ++++++++++++--------------------------- src/hypertable.h | 7 ++---- src/telemetry/telemetry.c | 16 ++++++------ 3 files changed, 26 insertions(+), 48 deletions(-) diff --git a/src/hypertable.c b/src/hypertable.c index 555da4b0e..51fbea491 100644 --- a/src/hypertable.c +++ b/src/hypertable.c @@ -391,49 +391,20 @@ hypertable_scan_limit_internal(ScanKeyData *scankey, int num_scankeys, int index return ts_scanner_scan(&scanctx); } -/* Number of user-created hypertables (doesn't count internal hypertables for compression or - * continuous aggs) */ -int -ts_number_of_user_hypertables() +/* Is a user hypertable without compression or continuous aggs */ +static bool +hypertable_is_user_table(Hypertable *ht) { - int count = 0; - ScanIterator iterator = - ts_scan_iterator_create(HYPERTABLE, AccessExclusiveLock, CurrentMemoryContext); + ContinuousAggHypertableStatus status = ts_continuous_agg_hypertable_status(ht->fd.id); - ts_scanner_foreach(&iterator) - { - TupleInfo *ti = ts_scan_iterator_tuple_info(&iterator); - Hypertable *ht = ts_hypertable_from_tupleinfo(ti); - - if (!hypertable_is_compressed_or_materialization(ht)) - count++; - } - return count; -} - -/* Number of hypertables with compression enabled */ -int -ts_number_compressed_hypertables() -{ - int count = 0; - ScanIterator iterator = - ts_scan_iterator_create(HYPERTABLE, AccessExclusiveLock, CurrentMemoryContext); - - ts_scanner_foreach(&iterator) - { - TupleInfo *ti = ts_scan_iterator_tuple_info(&iterator); - Hypertable *ht = ts_hypertable_from_tupleinfo(ti); - - if (ht->fd.compressed_hypertable_id != INVALID_HYPERTABLE_ID) - count++; - } - return count; + return !ht->fd.compressed && status != HypertableIsMaterialization; } static ScanTupleResult hypertable_tuple_add_stat(TupleInfo *ti, void *data) { HypertablesStat *stat = data; + Hypertable *ht = ts_hypertable_from_tupleinfo(ti); bool isnull; Datum datum; @@ -453,6 +424,7 @@ hypertable_tuple_add_stat(TupleInfo *ti, void *data) break; default: Assert(replication_factor >= 1); + Assert(!ht->fd.compressed); stat->num_hypertables_distributed++; if (replication_factor > 1) stat->num_hypertables_distributed_and_replicated++; @@ -461,9 +433,16 @@ hypertable_tuple_add_stat(TupleInfo *ti, void *data) } else { - stat->num_hypertables_regular++; + /* Number of user-created hypertables (doesn't count internal hypertables + * for compression or continuous aggs) */ + if (hypertable_is_user_table(ht)) + stat->num_hypertables_user++; } + /* Number of hypertables with compression enabled */ + if (TS_HYPERTABLE_HAS_COMPRESSION(ht)) + stat->num_hypertables_compressed++; + return SCAN_CONTINUE; } diff --git a/src/hypertable.h b/src/hypertable.h index 3408d0489..4297c9a8d 100644 --- a/src/hypertable.h +++ b/src/hypertable.h @@ -63,13 +63,10 @@ enum Anum_create_hypertable #define Natts_create_hypertable (_Anum_create_hypertable_max - 1) -extern int ts_number_of_user_hypertables(void); - -extern int ts_number_compressed_hypertables(void); - typedef struct HypertablesStat { - int num_hypertables_regular; + int num_hypertables_user; + int num_hypertables_compressed; int num_hypertables_distributed_members; int num_hypertables_distributed; int num_hypertables_distributed_and_replicated; diff --git a/src/telemetry/telemetry.c b/src/telemetry/telemetry.c index 0084fe087..920088924 100644 --- a/src/telemetry/telemetry.c +++ b/src/telemetry/telemetry.c @@ -185,24 +185,26 @@ get_size(int64 size) static char * get_num_hypertables() { - // HypertablesStat stat; + HypertablesStat stat; StringInfo buf = makeStringInfo(); - // memset(&stat, 0, sizeof(stat)); - // ts_number_of_hypertables(&stat); - // - // appendStringInfo(buf, "%d", stat.num_hypertables_total); + memset(&stat, 0, sizeof(stat)); + ts_number_of_hypertables(&stat); - appendStringInfo(buf, "%d", ts_number_of_user_hypertables()); + appendStringInfo(buf, "%d", stat.num_hypertables_user); return buf->data; } static char * get_num_compressed_hypertables() { + HypertablesStat stat; StringInfo buf = makeStringInfo(); - appendStringInfo(buf, "%d", ts_number_compressed_hypertables()); + memset(&stat, 0, sizeof(stat)); + ts_number_of_hypertables(&stat); + + appendStringInfo(buf, "%d", stat.num_hypertables_compressed); return buf->data; }