From 3089c92103607acb62cbb06f1944c5509c18d1eb Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Wed, 2 Sep 2020 11:41:01 -0700 Subject: [PATCH] header file and include cleanup --- cstore.c | 38 +++++++++++++- cstore.h | 7 +-- cstore_compression.c | 2 +- cstore_fdw.c | 92 ++++++++++++++++----------------- cstore_fdw.h | 44 +--------------- cstore_metadata_serialization.c | 7 +-- cstore_metadata_serialization.h | 6 --- cstore_reader.c | 12 ++--- cstore_version_compat.h | 2 +- cstore_writer.c | 18 ++----- mod.c | 2 + 11 files changed, 101 insertions(+), 129 deletions(-) diff --git a/cstore.c b/cstore.c index ccb59675f..e704bc31d 100644 --- a/cstore.c +++ b/cstore.c @@ -13,12 +13,14 @@ #include "postgres.h" +#include +#include + #include "miscadmin.h" +#include "utils/rel.h" #include "cstore.h" -#include - static void CreateDirectory(StringInfo directoryName); static bool DirectoryExists(StringInfo directoryName); @@ -168,3 +170,35 @@ CreateCStoreDatabaseDirectory(Oid databaseOid) } } + +/* + * DeleteCStoreTableFiles deletes the data and footer files for a cstore table + * whose data filename is given. + */ +void +DeleteCStoreTableFiles(char *filename) +{ + int dataFileRemoved = 0; + int footerFileRemoved = 0; + + StringInfo tableFooterFilename = makeStringInfo(); + appendStringInfo(tableFooterFilename, "%s%s", filename, CSTORE_FOOTER_FILE_SUFFIX); + + /* delete the footer file */ + footerFileRemoved = unlink(tableFooterFilename->data); + if (footerFileRemoved != 0) + { + ereport(WARNING, (errcode_for_file_access(), + errmsg("could not delete file \"%s\": %m", + tableFooterFilename->data))); + } + + /* delete the data file */ + dataFileRemoved = unlink(filename); + if (dataFileRemoved != 0) + { + ereport(WARNING, (errcode_for_file_access(), + errmsg("could not delete file \"%s\": %m", + filename))); + } +} diff --git a/cstore.h b/cstore.h index d45fde914..a694e1e29 100644 --- a/cstore.h +++ b/cstore.h @@ -14,13 +14,9 @@ #ifndef CSTORE_H #define CSTORE_H -#include "access/tupdesc.h" #include "fmgr.h" -#include "catalog/pg_am.h" -#include "catalog/pg_foreign_server.h" -#include "catalog/pg_foreign_table.h" #include "lib/stringinfo.h" -#include "utils/rel.h" +#include "utils/relcache.h" /* Defines for valid option names */ #define OPTION_NAME_FILENAME "filename" @@ -271,6 +267,7 @@ extern void InitializeCStoreTableFile(Oid relationId, Relation relation, CStoreOptions *cstoreOptions); extern void CreateCStoreDatabaseDirectory(Oid databaseOid); extern void RemoveCStoreDatabaseDirectory(Oid databaseOid); +extern void DeleteCStoreTableFiles(char *filename); /* Function declarations for writing to a cstore file */ extern TableWriteState * CStoreBeginWrite(const char *filename, diff --git a/cstore_compression.c b/cstore_compression.c index 3b37fd47a..a3c5f9f7d 100644 --- a/cstore_compression.c +++ b/cstore_compression.c @@ -12,7 +12,6 @@ *------------------------------------------------------------------------- */ #include "postgres.h" -#include "cstore_fdw.h" #if PG_VERSION_NUM >= 90500 #include "common/pg_lzcompress.h" @@ -20,6 +19,7 @@ #include "utils/pg_lzcompress.h" #endif +#include "cstore.h" diff --git a/cstore_fdw.c b/cstore_fdw.c index c80d53f2c..9787fd2a2 100644 --- a/cstore_fdw.c +++ b/cstore_fdw.c @@ -15,15 +15,11 @@ */ #include "postgres.h" -#include "cstore_fdw.h" -#include "cstore_version_compat.h" #include -#include -#include -#include "access/htup_details.h" + +#include "access/heapam.h" #include "access/reloptions.h" -#include "access/sysattr.h" #include "access/tuptoaster.h" #include "catalog/namespace.h" #include "catalog/pg_foreign_table.h" @@ -39,35 +35,71 @@ #include "foreign/foreign.h" #include "miscadmin.h" #include "nodes/makefuncs.h" +#if PG_VERSION_NUM < 120000 #include "optimizer/cost.h" +#endif #include "optimizer/pathnode.h" #include "optimizer/planmain.h" #include "optimizer/restrictinfo.h" #if PG_VERSION_NUM >= 120000 #include "access/heapam.h" -#include "access/tableam.h" -#include "executor/tuptable.h" #include "optimizer/optimizer.h" #else #include "optimizer/var.h" #endif #include "parser/parser.h" -#include "parser/parsetree.h" #include "parser/parse_coerce.h" #include "parser/parse_type.h" -#include "storage/fd.h" #include "tcop/utility.h" #include "utils/builtins.h" #include "utils/fmgroids.h" -#include "utils/memutils.h" #include "utils/lsyscache.h" -#include "utils/rel.h" #if PG_VERSION_NUM >= 120000 #include "utils/snapmgr.h" #else #include "utils/tqual.h" #endif +#if PG_VERSION_NUM < 120000 +#include "utils/rel.h" +#endif +#include "cstore.h" +#include "cstore_fdw.h" +#include "cstore_version_compat.h" + +/* table containing information about how to partition distributed tables */ +#define CITUS_EXTENSION_NAME "citus" +#define CITUS_PARTITION_TABLE_NAME "pg_dist_partition" + +/* human-readable names for addressing columns of the pg_dist_partition table */ +#define ATTR_NUM_PARTITION_RELATION_ID 1 +#define ATTR_NUM_PARTITION_TYPE 2 +#define ATTR_NUM_PARTITION_KEY 3 + +/* + * CStoreValidOption keeps an option name and a context. When an option is passed + * into cstore_fdw objects (server and foreign table), we compare this option's + * name and context against those of valid options. + */ +typedef struct CStoreValidOption +{ + const char *optionName; + Oid optionContextId; + +} CStoreValidOption; + +#define COMPRESSION_STRING_DELIMITED_LIST "none, pglz" + +/* Array of options that are valid for cstore_fdw */ +static const uint32 ValidOptionCount = 4; +static const CStoreValidOption ValidOptionArray[] = +{ + /* foreign table options */ + { OPTION_NAME_FILENAME, ForeignTableRelationId }, + { OPTION_NAME_COMPRESSION_TYPE, ForeignTableRelationId }, + { OPTION_NAME_STRIPE_ROW_COUNT, ForeignTableRelationId }, + { OPTION_NAME_BLOCK_ROW_COUNT, ForeignTableRelationId } +}; /* local functions forward declarations */ #if PG_VERSION_NUM >= 100000 @@ -94,7 +126,6 @@ static List * DroppedCStoreFilenameList(DropStmt *dropStatement); static List * FindCStoreTables(List *tableList); static List * OpenRelationsForTruncate(List *cstoreTableList); static void TruncateCStoreTables(List *cstoreRelationList); -static void DeleteCStoreTableFiles(char *filename); static bool CStoreTable(Oid relationId); static bool CStoreServer(ForeignServer *server); static bool DistributedTable(Oid relationId); @@ -858,41 +889,6 @@ TruncateCStoreTables(List *cstoreRelationList) } } - -/* - * DeleteCStoreTableFiles deletes the data and footer files for a cstore table - * whose data filename is given. - */ -static void -DeleteCStoreTableFiles(char *filename) -{ - int dataFileRemoved = 0; - int footerFileRemoved = 0; - - StringInfo tableFooterFilename = makeStringInfo(); - appendStringInfo(tableFooterFilename, "%s%s", filename, CSTORE_FOOTER_FILE_SUFFIX); - - /* delete the footer file */ - footerFileRemoved = unlink(tableFooterFilename->data); - if (footerFileRemoved != 0) - { - ereport(WARNING, (errcode_for_file_access(), - errmsg("could not delete file \"%s\": %m", - tableFooterFilename->data))); - } - - /* delete the data file */ - dataFileRemoved = unlink(filename); - if (dataFileRemoved != 0) - { - ereport(WARNING, (errcode_for_file_access(), - errmsg("could not delete file \"%s\": %m", - filename))); - } -} - - - /* * CStoreTable checks if the given table name belongs to a foreign columnar store * table. If it does, the function returns true. Otherwise, it returns false. diff --git a/cstore_fdw.h b/cstore_fdw.h index 7b8475497..c7b4460ed 100644 --- a/cstore_fdw.h +++ b/cstore_fdw.h @@ -14,49 +14,9 @@ #ifndef CSTORE_FDW_H #define CSTORE_FDW_H -#include "access/tupdesc.h" +#include "postgres.h" + #include "fmgr.h" -#include "catalog/pg_am.h" -#include "catalog/pg_foreign_server.h" -#include "catalog/pg_foreign_table.h" -#include "lib/stringinfo.h" -#include "utils/rel.h" - -#include "cstore.h" - -/* table containing information about how to partition distributed tables */ -#define CITUS_EXTENSION_NAME "citus" -#define CITUS_PARTITION_TABLE_NAME "pg_dist_partition" - -/* human-readable names for addressing columns of the pg_dist_partition table */ -#define ATTR_NUM_PARTITION_RELATION_ID 1 -#define ATTR_NUM_PARTITION_TYPE 2 -#define ATTR_NUM_PARTITION_KEY 3 - -/* - * CStoreValidOption keeps an option name and a context. When an option is passed - * into cstore_fdw objects (server and foreign table), we compare this option's - * name and context against those of valid options. - */ -typedef struct CStoreValidOption -{ - const char *optionName; - Oid optionContextId; - -} CStoreValidOption; - -#define COMPRESSION_STRING_DELIMITED_LIST "none, pglz" - -/* Array of options that are valid for cstore_fdw */ -static const uint32 ValidOptionCount = 4; -static const CStoreValidOption ValidOptionArray[] = -{ - /* foreign table options */ - { OPTION_NAME_FILENAME, ForeignTableRelationId }, - { OPTION_NAME_COMPRESSION_TYPE, ForeignTableRelationId }, - { OPTION_NAME_STRIPE_ROW_COUNT, ForeignTableRelationId }, - { OPTION_NAME_BLOCK_ROW_COUNT, ForeignTableRelationId } -}; void cstore_fdw_init(void); void cstore_fdw_finish(void); diff --git a/cstore_metadata_serialization.c b/cstore_metadata_serialization.c index 26402f897..67ae2ec2c 100644 --- a/cstore_metadata_serialization.c +++ b/cstore_metadata_serialization.c @@ -14,11 +14,12 @@ #include "postgres.h" -#include "cstore_fdw.h" -#include "cstore_metadata_serialization.h" -#include "cstore.pb-c.h" + #include "access/tupmacs.h" +#include "cstore.h" +#include "cstore_metadata_serialization.h" +#include "cstore.pb-c.h" /* local functions forward declarations */ static ProtobufCBinaryData DatumToProtobufBinary(Datum datum, bool typeByValue, diff --git a/cstore_metadata_serialization.h b/cstore_metadata_serialization.h index 421f8ddff..b8890a5d4 100644 --- a/cstore_metadata_serialization.h +++ b/cstore_metadata_serialization.h @@ -14,12 +14,6 @@ #ifndef CSTORE_SERIALIZATION_H #define CSTORE_SERIALIZATION_H -#include "catalog/pg_attribute.h" -#include "nodes/pg_list.h" -#include "lib/stringinfo.h" -#include "cstore_fdw.h" - - /* Function declarations for metadata serialization */ extern StringInfo SerializePostScript(uint64 tableFooterLength); extern StringInfo SerializeTableFooter(TableFooter *tableFooter); diff --git a/cstore_reader.c b/cstore_reader.c index 7e9c6bcfd..68ce5cdad 100644 --- a/cstore_reader.c +++ b/cstore_reader.c @@ -15,30 +15,26 @@ #include "postgres.h" -#include "cstore_fdw.h" -#include "cstore_metadata_serialization.h" -#include "cstore_version_compat.h" #include "access/nbtree.h" -#include "access/skey.h" +#include "catalog/pg_am.h" #include "commands/defrem.h" #include "nodes/makefuncs.h" #if PG_VERSION_NUM >= 120000 -#include "nodes/pathnodes.h" #include "nodes/nodeFuncs.h" #include "optimizer/optimizer.h" #else #include "optimizer/clauses.h" #include "optimizer/predtest.h" -#include "optimizer/var.h" #endif #include "optimizer/restrictinfo.h" -#include "port.h" #include "storage/fd.h" #include "utils/memutils.h" #include "utils/lsyscache.h" -#include "utils/rel.h" +#include "cstore.h" +#include "cstore_metadata_serialization.h" +#include "cstore_version_compat.h" /* static function declarations */ static StripeBuffers * LoadFilteredStripeBuffers(FILE *tableFile, diff --git a/cstore_version_compat.h b/cstore_version_compat.h index a7f961fcd..1b80b16c3 100644 --- a/cstore_version_compat.h +++ b/cstore_version_compat.h @@ -49,7 +49,7 @@ #define TTS_EMPTY(slot) ((slot)->tts_isempty) #define ExecForceStoreHeapTuple(tuple, slot, shouldFree) \ ExecStoreTuple(newTuple, tupleSlot, InvalidBuffer, shouldFree); -#define HeapScanDesc TableScanDesc +#define TableScanDesc HeapScanDesc #define table_beginscan heap_beginscan #define table_endscan heap_endscan diff --git a/cstore_writer.c b/cstore_writer.c index b69064215..51a01c8f3 100644 --- a/cstore_writer.c +++ b/cstore_writer.c @@ -15,25 +15,17 @@ #include "postgres.h" -#include "cstore_fdw.h" -#include "cstore_metadata_serialization.h" -#include "cstore_version_compat.h" #include + #include "access/nbtree.h" -#include "catalog/pg_collation.h" -#include "commands/defrem.h" -#if PG_VERSION_NUM >= 120000 -#include "optimizer/optimizer.h" -#else -#include "optimizer/var.h" -#endif -#include "port.h" +#include "catalog/pg_am.h" #include "storage/fd.h" #include "utils/memutils.h" -#include "utils/lsyscache.h" -#include "utils/rel.h" +#include "cstore.h" +#include "cstore_metadata_serialization.h" +#include "cstore_version_compat.h" static void CStoreWriteFooter(StringInfo footerFileName, TableFooter *tableFooter); static StripeBuffers * CreateEmptyStripeBuffers(uint32 stripeMaxRowCount, diff --git a/mod.c b/mod.c index 8cb138c62..dbc8eb923 100644 --- a/mod.c +++ b/mod.c @@ -13,6 +13,8 @@ #include "postgres.h" +#include "fmgr.h" + #include "mod.h" #include "cstore_fdw.h"