Skip to content

Commit

Permalink
Move enterprise features to community
Browse files Browse the repository at this point in the history
This patch removes enterprise license support and moves
move_chunk() function under community license (TSL).

Licensing validation code been reworked and simplified.
Previously used timescaledb.license_key guc been renamed to
timescaledb.license.
  • Loading branch information
pmwkaa committed Sep 24, 2020
1 parent eb30e54 commit 31fd1c3
Show file tree
Hide file tree
Showing 49 changed files with 375 additions and 1,413 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ test_script:
# Normally we use different config files for apache and enterprise tests, but Windows was having problems with that
# Thus, just append the license key to the regular config file instead
Add-Content "C:\Program Files\postgresql\12\data\postgresql.conf" "timescaledb.license_key = 'E1eyJlbmRfdGltZSI6IjIwMTgtMTAtMDEgKzAwMDAiLCAic3RhcnRfdGltZSI6IjIwMTgtMDktMDEgKzAwMDAiLCAiaWQiOiI0OTBGQjI2MC1BMjkyLTRBRDktOUFBMi0wMzYwODM1NzkxQjgiLCAia2luZCI6InRyaWFsIn0K'"
Add-Content "C:\Program Files\postgresql\12\data\postgresql.conf" "timescaledb.license = 'tsl'"
Restart-Service postgresql-x64-12
Expand Down
1 change: 0 additions & 1 deletion sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ set(SOURCE_FILES
hypertable.sql
chunk.sql
ddl_internal.sql
edition.sql
util_time.sql
util_internal_table_ddl.sql
chunk_constraint.sql
Expand Down
37 changes: 0 additions & 37 deletions sql/edition.sql

This file was deleted.

27 changes: 2 additions & 25 deletions sql/notice.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@

DO language plpgsql $$
DECLARE
end_time TIMESTAMPTZ;
expiration_time_string TEXT;
telemetry_string TEXT;
BEGIN
end_time := _timescaledb_internal.license_expiration_time();

IF end_time IS NOT NULL AND isfinite(end_time)
THEN
expiration_time_string = format(E'\nYour license expires on %s\n', end_time);
ELSE
expiration_time_string = '';
END IF;

IF current_setting('timescaledb.telemetry_level') = 'off'
THEN
telemetry_string = E'Note: Please enable telemetry to help us improve our product by running: ALTER DATABASE "' || current_database() || E'" SET timescaledb.telemetry_level = ''basic'';';
ELSE
telemetry_string = E'Note: TimescaleDB collects anonymous reports to better understand and assist our users.\nFor more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.';
END IF;

RAISE WARNING E'%\n%\n%',
RAISE WARNING E'%\n%\n',
E'\nWELCOME TO\n' ||
E' _____ _ _ ____________ \n' ||
E'|_ _(_) | | | _ \\ ___ \\ \n' ||
Expand All @@ -39,18 +28,6 @@ BEGIN
E' 1. Getting started: https://docs.timescale.com/getting-started\n' ||
E' 2. API reference documentation: https://docs.timescale.com/api\n' ||
E' 3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture\n',
telemetry_string,
expiration_time_string;

IF now() > end_time
THEN
RAISE WARNING E'%\n', format('Your license expired on %s', end_time);
ELSIF now() + INTERVAL '1 week' >= end_time
THEN
RAISE WARNING E'%\n', format('Your license will expire on %s', end_time);
END IF;

telemetry_string;
END;
$$;

select _timescaledb_internal.print_license_expiration_info();
7 changes: 7 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ DROP FUNCTION IF EXISTS _timescaledb_internal.range_value_to_pretty;
DROP FUNCTION IF EXISTS hypertable_approximate_row_count;
DROP VIEW IF EXISTS timescaledb_information.compressed_chunk_stats;
DROP VIEW IF EXISTS timescaledb_information.compressed_hypertable_stats;
DROP VIEW IF EXISTS timescaledb_information.license;

-- Add new function definitions, columns and tables for distributed hypertables
DROP FUNCTION IF EXISTS create_hypertable(regclass,name,name,integer,name,name,anyelement,boolean,boolean,regproc,boolean,text,regproc,regproc);
Expand All @@ -23,6 +24,12 @@ DROP FUNCTION IF EXISTS show_chunks;
DROP FUNCTION IF EXISTS add_compress_chunks_policy;
DROP FUNCTION IF EXISTS remove_compress_chunks_policy;
DROP FUNCTION IF EXISTS alter_job_schedule;
DROP FUNCTION IF EXISTS _timescaledb_internal.enterprise_enabled;
DROP FUNCTION IF EXISTS _timescaledb_internal.current_license_key;
DROP FUNCTION IF EXISTS _timescaledb_internal.license_expiration_time;
DROP FUNCTION IF EXISTS _timescaledb_internal.print_license_expiration_info;
DROP FUNCTION IF EXISTS _timescaledb_internal.license_edition;
DROP FUNCTION IF EXISTS _timescaledb_internal.current_db_set_license_key;

DROP VIEW IF EXISTS timescaledb_information.policy_stats;
DROP VIEW IF EXISTS timescaledb_information.drop_chunks_policies;
Expand Down
3 changes: 3 additions & 0 deletions sql/version.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ CREATE OR REPLACE FUNCTION _timescaledb_internal.get_os_info()

CREATE OR REPLACE FUNCTION get_telemetry_report(always_display_report boolean DEFAULT false) RETURNS TEXT
AS '@MODULE_PATHNAME@', 'ts_get_telemetry_report' LANGUAGE C STABLE PARALLEL SAFE;

CREATE OR REPLACE FUNCTION _timescaledb_internal.tsl_loaded() RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_tsl_loaded' LANGUAGE C;
5 changes: 0 additions & 5 deletions sql/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ CREATE OR REPLACE VIEW timescaledb_information.hypertables AS
WHERE ht.compressed is false --> no internal compression tables
AND ca.mat_hypertable_id IS NULL;

CREATE OR REPLACE VIEW timescaledb_information.license AS
SELECT _timescaledb_internal.license_edition() as edition,
_timescaledb_internal.license_expiration_time() <= now() AS expired,
_timescaledb_internal.license_expiration_time() AS expiration_time;

CREATE OR REPLACE VIEW timescaledb_information.policy_stats as
SELECT format('%1$I.%2$I', ht.schema_name, ht.table_name)::regclass as hypertable, j.id AS job_id,
js.last_start as last_run_started_at,
Expand Down
76 changes: 20 additions & 56 deletions src/cross_module_fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,8 @@ error_no_default_fn_community(void)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("functionality not supported under the current license \"%s\", license",
ts_guc_license_key),
errhint(
"Upgrade to a Timescale-licensed binary to access this free community feature")));
}

static void
error_no_default_fn_enterprise(void)
{
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("functionality not supported under the current license \"%s\", license",
ts_guc_license_key),
errhint("Request a trial license to try this feature for free or contact us for more "
"information at https://www.timescale.com/pricing")));
ts_guc_license),
errhint("Upgrade your license to TSL to use this free community feature.")));
}

static bool
Expand All @@ -151,26 +139,6 @@ error_no_default_fn_bool_void_community(void)
pg_unreachable();
}

static bool
error_no_default_fn_bool_void_enterprise(void)
{
error_no_default_fn_enterprise();
pg_unreachable();
}

static void
tsl_license_on_assign_default_fn(const char *newval, const void *license)
{
error_no_default_fn_community();
}

static TimestampTz
license_end_time_default_fn(void)
{
error_no_default_fn_community();
pg_unreachable();
}

static void
add_tsl_telemetry_info_default(JsonbParseState **parse_state)
{
Expand Down Expand Up @@ -199,9 +167,8 @@ error_no_default_fn_pg_community(PG_FUNCTION_ARGS)
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function \"%s\" is not supported under the current license \"%s\"",
get_func_name(fcinfo->flinfo->fn_oid),
ts_guc_license_key),
errhint(
"Upgrade to a Timescale-licensed binary to access this free community feature")));
ts_guc_license),
errhint("Upgrade your license to TSL to use this free community feature.")));
pg_unreachable();
}

Expand All @@ -226,19 +193,6 @@ cache_syscache_invalidate_default(Datum arg, int cacheid, uint32 hashvalue)
/* The default is a no-op */
}

static Datum
error_no_default_fn_pg_enterprise(PG_FUNCTION_ARGS)
{
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function \"%s\" is not supported under the current license \"%s\"",
get_func_name(fcinfo->flinfo->fn_oid),
ts_guc_license_key),
errhint("Request a trial license to try this feature for free or contact us for more "
"information at https://www.timescale.com/pricing")));
pg_unreachable();
}

static DDLResult
process_cagg_viewstmt_default(Node *stmt, const char *query_string, void *pstmt,
WithClauseResult *with_clause_options)
Expand Down Expand Up @@ -308,17 +262,27 @@ func_call_on_data_nodes_default(FunctionCallInfo finfo, List *data_node_oids)
pg_unreachable();
}

TS_FUNCTION_INFO_V1(ts_tsl_loaded);

PGDLLEXPORT Datum
ts_tsl_loaded(PG_FUNCTION_ARGS)
{
return ts_cm_functions->check_tsl_loaded();
}

static bool
check_tsl_loaded(void)
{
return false;
}

/*
* Define cross-module functions' default values:
* If the submodule isn't activated, using one of the cm functions will throw an
* exception.
*/
TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
.tsl_license_on_assign = tsl_license_on_assign_default_fn,
.enterprise_enabled_internal = error_no_default_fn_bool_void_enterprise,
.check_tsl_loaded = error_no_default_fn_bool_void_community,
.license_end_time = license_end_time_default_fn,
.print_tsl_license_expiration_info_hook = NULL,
.check_tsl_loaded = check_tsl_loaded,
.module_shutdown_hook = NULL,
.add_tsl_telemetry_info = add_tsl_telemetry_info_default,
.create_upper_paths_hook = NULL,
Expand Down Expand Up @@ -358,7 +322,7 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
.job_run = error_no_default_fn_pg_community,
.job_execute = job_execute_default_fn,

.move_chunk = error_no_default_fn_pg_enterprise,
.move_chunk = error_no_default_fn_pg_community,
.reorder_chunk = error_no_default_fn_pg_community,

.partialize_agg = error_no_default_fn_pg_community,
Expand Down
4 changes: 0 additions & 4 deletions src/cross_module_fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ typedef struct CopyChunkState CopyChunkState;

typedef struct CrossModuleFunctions
{
void (*tsl_license_on_assign)(const char *newval, const void *license);
bool (*enterprise_enabled_internal)(void);
bool (*check_tsl_loaded)(void);
TimestampTz (*license_end_time)(void);
void (*print_tsl_license_expiration_info_hook)(void);
void (*module_shutdown_hook)(void);
void (*add_tsl_telemetry_info)(JsonbParseState **parse_state);

Expand Down
2 changes: 2 additions & 0 deletions src/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define TSL_LIBRARY_NAME "timescaledb-tsl"
#define TS_LIBDIR "$libdir/"
#define EXTENSION_SO TS_LIBDIR "" EXTENSION_NAME
#define EXTENSION_TSL_SO TS_LIBDIR TSL_LIBRARY_NAME "-" TIMESCALEDB_VERSION_MOD

#define MAX_VERSION_LEN (NAMEDATALEN + 1)
#define MAX_SO_NAME_LEN \
(8 + NAMEDATALEN + 1 + MAX_VERSION_LEN) /* "$libdir/"+extname+"-"+version \
Expand Down
16 changes: 8 additions & 8 deletions src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int ts_guc_max_open_chunks_per_insert = 10;
int ts_guc_max_cached_chunks_per_hypertable = 10;
int ts_guc_telemetry_level = TELEMETRY_DEFAULT;

TSDLLEXPORT char *ts_guc_license_key = TS_DEFAULT_LICENSE;
TSDLLEXPORT char *ts_guc_license = TS_LICENSE_DEFAULT;
char *ts_last_tune_time = NULL;
char *ts_last_tune_version = NULL;
char *ts_telemetry_cloud = NULL;
Expand Down Expand Up @@ -360,15 +360,15 @@ _guc_init(void)
NULL,
NULL);

DefineCustomStringVariable(/* name= */ "timescaledb.license_key",
/* short_dec= */ "TimescaleDB license key",
DefineCustomStringVariable(/* name= */ "timescaledb.license",
/* short_dec= */ "TimescaleDB license type",
/* long_dec= */ "Determines which features are enabled",
/* valueAddr= */ &ts_guc_license_key,
/* bootValue= */ TS_DEFAULT_LICENSE,
/* valueAddr= */ &ts_guc_license,
/* bootValue= */ TS_LICENSE_DEFAULT,
/* context= */ PGC_SUSET,
/* flags= */ GUC_SUPERUSER_ONLY,
/* check_hook= */ ts_license_update_check,
/* assign_hook= */ ts_license_on_assign,
/* flags= */ 0,
/* check_hook= */ ts_license_guc_check_hook,
/* assign_hook= */ ts_license_guc_assign_hook,
/* show_hook= */ NULL);

DefineCustomStringVariable(/* name= */ "timescaledb.last_tuned",
Expand Down
2 changes: 1 addition & 1 deletion src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern bool ts_guc_restoring;
extern int ts_guc_max_open_chunks_per_insert;
extern int ts_guc_max_cached_chunks_per_hypertable;
extern int ts_guc_telemetry_level;
extern TSDLLEXPORT char *ts_guc_license_key;
extern TSDLLEXPORT char *ts_guc_license;
extern char *ts_last_tune_time;
extern char *ts_last_tune_version;
extern char *ts_telemetry_cloud;
Expand Down

0 comments on commit 31fd1c3

Please sign in to comment.