Implement pro badge and trial timeout

Former-commit-id: 9d6a284eb45c8a137c7f59645294b4fa4be389e5
This commit is contained in:
John Sully 2019-12-17 20:32:53 -05:00
parent a0d8d52ef3
commit d50da19fb4
4 changed files with 36 additions and 1 deletions

View File

@ -30,7 +30,7 @@
const char *ascii_logo =
" \n"
" \n"
" KeyDB %s (%s/%d) %s bit\n"
" KeyDB Pro %s (%s/%d) %s bit \n"
" \n"
" Running in %s mode\n"
" Port: %d\n"

View File

@ -840,6 +840,8 @@ void loadServerConfigFromString(char *config) {
} else if (!strcasecmp(argv[0],"storage-provider") && argc >= 2) {
if (!initializeStorageProvider(argv+1, argc-1, &err))
goto loaderr;
} else if (!strcasecmp(argv[0],"enable-pro") && argc == 2) {
cserver.license_key = zstrdup(argv[1]);
} else {
err = "Bad directive or wrong number of arguments"; goto loaderr;
}
@ -2258,6 +2260,7 @@ int rewriteConfig(char *path) {
rewriteConfigEnumOption(state,"supervised",cserver.supervised_mode,supervised_mode_enum,SUPERVISED_NONE);
rewriteConfigYesNoOption(state,"active-replica",g_pserver->fActiveReplica,CONFIG_DEFAULT_ACTIVE_REPLICA);
rewriteConfigStringOption(state, "version-override",KEYDB_SET_VERSION,KEYDB_REAL_VERSION);
rewriteConfigStringOption(state, "enable-pro", cserver.license_key, CONFIG_DEFAULT_LICENSE_KEY);
/* Rewrite Sentinel config if in Sentinel mode. */
if (g_pserver->sentinel_mode) rewriteConfigSentinelOption(state);

View File

@ -1093,6 +1093,23 @@ void serverLog(int level, const char *fmt, ...) {
serverLogRaw(level,msg);
}
static void checkTrialTimeout()
{
time_t curtime = time(NULL);
int64_t elapsed = (int64_t)curtime - (int64_t)cserver.stat_starttime;
int64_t remaining = (cserver.trial_timeout * 60L) - elapsed;
if (remaining <= 0)
{
serverLog(LL_WARNING, "Trial timeout exceeded. KeyDB will now exit.");
prepareForShutdown(SHUTDOWN_SAVE);
exit(0);
}
else
{
serverLog(LL_WARNING, "Trial timeout in %ld:%02ld minutes", remaining/60, remaining % 60);
}
}
/* Log a fixed message without printf-alike capabilities, in a way that is
* safe to call from a signal handler.
*
@ -2071,6 +2088,10 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
migrateCloseTimedoutSockets();
}
run_with_period(15000) {
checkTrialTimeout();
}
/* Start a scheduled BGSAVE if the corresponding flag is set. This is
* useful when we are forced to postpone a BGSAVE because an AOF
* rewrite is in progress.
@ -4833,6 +4854,12 @@ void redisAsciiArt(void) {
);
serverLogRaw(LL_NOTICE|LL_RAW,buf);
}
if (cserver.license_key == nullptr)
{
serverLog(LL_WARNING, "!!!! KeyDB Pro is being run in trial mode !!!!");
serverLog(LL_WARNING, "!!!! Execution will terminate in %d minutes !!!!", cserver.trial_timeout);
}
zfree(buf);
}

View File

@ -388,6 +388,8 @@ public:
#define CONFIG_DEFAULT_ACTIVE_REPLICA 0
#define CONFIG_DEFAULT_ENABLE_MULTIMASTER 0
#define CONFIG_DEFAULT_LICENSE_KEY ""
#define ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP 64 /* Loopkups per loop. */
#define ACTIVE_EXPIRE_CYCLE_FAST_DURATION 1000 /* Microseconds */
#define ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC 25 /* CPU max % for keys collection */
@ -1958,6 +1960,9 @@ struct redisServerConst {
size_t system_memory_size; /* Total memory in system as reported by OS */
unsigned char uuid[UUID_BINARY_LEN]; /* This server's UUID - populated on boot */
sds license_key = nullptr;
int trial_timeout = 20;
};
struct redisServer {