Skip to content

Commit

Permalink
Rename engine to scriptingEngine
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Dias <ricardo.dias@percona.com>
  • Loading branch information
rjd15372 committed Dec 24, 2024
1 parent 12caad7 commit bc5760b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 55 deletions.
2 changes: 1 addition & 1 deletion cmake/Modules/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ set(VALKEY_SERVER_SRCS
${CMAKE_SOURCE_DIR}/src/unix.c
${CMAKE_SOURCE_DIR}/src/server.c
${CMAKE_SOURCE_DIR}/src/logreqres.c
${CMAKE_SOURCE_DIR}/src/engine.c)
${CMAKE_SOURCE_DIR}/src/scripting_engine.c)

# valkey-cli
set(VALKEY_CLI_SRCS
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ endif
ENGINE_NAME=valkey
SERVER_NAME=$(ENGINE_NAME)-server$(PROG_SUFFIX)
ENGINE_SENTINEL_NAME=$(ENGINE_NAME)-sentinel$(PROG_SUFFIX)
ENGINE_SERVER_OBJ=threads_mngr.o adlist.o quicklist.o ae.o anet.o dict.o hashtable.o kvstore.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o memory_prefetch.o io_threads.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o cluster_legacy.o cluster_slot_stats.o crc16.o endianconv.o slowlog.o eval.o bio.o rio.o rand.o memtest.o syscheck.o crcspeed.o crccombine.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o valkey-check-rdb.o valkey-check-aof.o geo.o lazyfree.o module.o evict.o expire.o geohash.o geohash_helper.o childinfo.o allocator_defrag.o defrag.o siphash.o rax.o t_stream.o listpack.o localtime.o lolwut.o lolwut5.o lolwut6.o acl.o tracking.o socket.o tls.o sha256.o timeout.o setcpuaffinity.o monotonic.o mt19937-64.o resp_parser.o call_reply.o script_lua.o script.o functions.o function_lua.o commands.o strl.o connection.o unix.o logreqres.o rdma.o engine.o
ENGINE_SERVER_OBJ=threads_mngr.o adlist.o quicklist.o ae.o anet.o dict.o hashtable.o kvstore.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o memory_prefetch.o io_threads.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o cluster_legacy.o cluster_slot_stats.o crc16.o endianconv.o slowlog.o eval.o bio.o rio.o rand.o memtest.o syscheck.o crcspeed.o crccombine.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o valkey-check-rdb.o valkey-check-aof.o geo.o lazyfree.o module.o evict.o expire.o geohash.o geohash_helper.o childinfo.o allocator_defrag.o defrag.o siphash.o rax.o t_stream.o listpack.o localtime.o lolwut.o lolwut5.o lolwut6.o acl.o tracking.o socket.o tls.o sha256.o timeout.o setcpuaffinity.o monotonic.o mt19937-64.o resp_parser.o call_reply.o script_lua.o script.o functions.o function_lua.o commands.o strl.o connection.o unix.o logreqres.o rdma.o scripting_engine.o
ENGINE_CLI_NAME=$(ENGINE_NAME)-cli$(PROG_SUFFIX)
ENGINE_CLI_OBJ=anet.o adlist.o dict.o valkey-cli.o zmalloc.o release.o ae.o serverassert.o crcspeed.o crccombine.o crc64.o siphash.o crc16.o monotonic.o cli_common.o mt19937-64.o strl.o cli_commands.o
ENGINE_BENCHMARK_NAME=$(ENGINE_NAME)-benchmark$(PROG_SUFFIX)
Expand Down
2 changes: 1 addition & 1 deletion src/function_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* Uses script_lua.c to run the Lua code.
*/

#include "engine.h"
#include "scripting_engine.h"
#include "functions.h"
#include "script_lua.h"
#include <lua.h>
Expand Down
16 changes: 8 additions & 8 deletions src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ functionsLibCtx *functionsLibCtxGetCurrent(void) {
return curr_functions_lib_ctx;
}

static int initializeFunctionsLibEngineStats(engine *engine, void *context) {
static int initializeFunctionsLibEngineStats(scriptingEngine *engine, void *context) {
functionsLibCtx *lib_ctx = (functionsLibCtx *)context;
functionsLibEngineStats *stats = zcalloc(sizeof(*stats));
dictAdd(lib_ctx->engines_stats, engineGetName(engine), stats);
Expand Down Expand Up @@ -276,7 +276,7 @@ static int functionLibCreateFunction(robj *name,
return C_OK;
}

static functionLibInfo *engineLibraryCreate(sds name, engine *e, sds code) {
static functionLibInfo *engineLibraryCreate(sds name, scriptingEngine *e, sds code) {
functionLibInfo *li = zmalloc(sizeof(*li));
*li = (functionLibInfo){
.name = sdsdup(name),
Expand Down Expand Up @@ -410,7 +410,7 @@ libraryJoin(functionsLibCtx *functions_lib_ctx_dst, functionsLibCtx *functions_l
return ret;
}

static int replyEngineStats(engine *engine, void *context) {
static int replyEngineStats(scriptingEngine *engine, void *context) {
client *c = (client *)context;
addReplyBulkCString(c, engineGetName(engine));
addReplyMapLen(c, 2);
Expand All @@ -423,7 +423,7 @@ static int replyEngineStats(engine *engine, void *context) {
return 1;
}

void functionsRemoveLibFromEngine(engine *engine) {
void functionsRemoveLibFromEngine(scriptingEngine *engine) {
dictIterator *iter = dictGetSafeIterator(curr_functions_lib_ctx->libraries);
dictEntry *entry = NULL;
while ((entry = dictNext(iter))) {
Expand Down Expand Up @@ -623,7 +623,7 @@ static void fcallCommandGeneric(client *c, int ro) {
return;
}
functionInfo *fi = dictGetVal(de);
engine *engine = fi->li->engine;
scriptingEngine *engine = fi->li->engine;

long long numkeys;
/* Get the number of arguments that are keys */
Expand Down Expand Up @@ -949,7 +949,7 @@ void functionFreeLibMetaData(functionsLibMetaData *md) {
if (md->engine) sdsfree(md->engine);
}

static void freeCompiledFunctions(engine *engine,
static void freeCompiledFunctions(scriptingEngine *engine,
compiledFunction **compiled_functions,
size_t num_compiled_functions,
size_t free_function_from_idx) {
Expand Down Expand Up @@ -987,7 +987,7 @@ sds functionsCreateWithLibraryCtx(sds code, int replace, sds *err, functionsLibC
goto error;
}

engine *engine = engineManagerFind(md.engine);
scriptingEngine *engine = engineManagerFind(md.engine);
if (!engine) {
*err = sdscatfmt(sdsempty(), "Engine '%S' not found", md.engine);
goto error;
Expand Down Expand Up @@ -1124,7 +1124,7 @@ void functionLoadCommand(client *c) {
addReplyBulkSds(c, library_name);
}

static int getEngineUsedMemory(engine *engine, void *context) {
static int getEngineUsedMemory(scriptingEngine *engine, void *context) {
size_t *engines_memory = (size_t *)context;
engineMemoryInfo mem_info = engineCallGetMemoryInfo(engine);
*engines_memory += mem_info.used_memory;
Expand Down
14 changes: 7 additions & 7 deletions src/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/

#include "server.h"
#include "engine.h"
#include "scripting_engine.h"
#include "script.h"
#include "valkeymodule.h"

Expand All @@ -61,7 +61,7 @@ typedef struct engineInfo {
sds name; /* Name of the engine */
ValkeyModule *engineModule; /* the module that implements the scripting engine */
ValkeyModuleCtx *module_ctx; /* Scripting engine module context */
engine *engine; /* engine callbacks that allows to interact with the engine */
scriptingEngine *engine; /* engine callbacks that allows to interact with the engine */
client *c; /* Client that is used to run commands */
} engineInfo;

Expand All @@ -79,10 +79,10 @@ typedef struct functionInfo {
/* Hold information about the specific library.
* Used on rdb.c so it must be declared here. */
struct functionLibInfo {
sds name; /* Library name */
dict *functions; /* Functions dictionary */
engine *engine; /* Pointer to the scripting engine */
sds code; /* Library code */
sds name; /* Library name */
dict *functions; /* Functions dictionary */
scriptingEngine *engine; /* Pointer to the scripting engine */
sds code; /* Library code */
};

sds functionsCreateWithLibraryCtx(sds code, int replace, sds *err, functionsLibCtx *lib_ctx, size_t timeout);
Expand All @@ -99,7 +99,7 @@ void functionsLibCtxFree(functionsLibCtx *functions_lib_ctx);
void functionsLibCtxClear(functionsLibCtx *lib_ctx, void(callback)(dict *));
void functionsLibCtxSwapWithCurrent(functionsLibCtx *new_lib_ctx, int async);

void functionsRemoveLibFromEngine(engine *engine);
void functionsRemoveLibFromEngine(scriptingEngine *engine);

int luaEngineInitEngine(void);
int functionsInit(void);
Expand Down
2 changes: 1 addition & 1 deletion src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include "crc16_slottable.h"
#include "valkeymodule.h"
#include "io_threads.h"
#include "engine.h"
#include "scripting_engine.h"
#include <dlfcn.h>
#include <sys/stat.h>
#include <sys/wait.h>
Expand Down
46 changes: 23 additions & 23 deletions src/engine.c → src/scripting_engine.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include "engine.h"
#include "scripting_engine.h"
#include "dict.h"
#include "functions.h"
#include "module.h"

typedef struct engineImpl {
typedef struct scriptingEngineImpl {
/* Engine specific context */
engineCtx *ctx;

/* Callback functions implemented by the scripting engine module */
engineMethods methods;
} engineImpl;
} scriptingEngineImpl;

typedef struct engine {
typedef struct scriptingEngine {
sds name; /* Name of the engine */
ValkeyModule *module; /* the module that implements the scripting engine */
engineImpl *impl; /* engine callbacks that allows to interact with the engine */
scriptingEngineImpl *impl; /* engine callbacks that allows to interact with the engine */
client *c; /* Client that is used to run commands */
ValkeyModuleCtx *module_ctx; /* Cache of the module context object */
} engine;
} scriptingEngine;


typedef struct engineManger {
Expand Down Expand Up @@ -91,8 +91,8 @@ int engineManagerRegisterEngine(const char *engine_name,
return C_ERR;
}

engineImpl *ei = zmalloc(sizeof(engineImpl));
*ei = (engineImpl){
scriptingEngineImpl *ei = zmalloc(sizeof(scriptingEngineImpl));
*ei = (scriptingEngineImpl){
.ctx = engine_ctx,
.methods = {
.create_functions_library = engine_methods->create_functions_library,
Expand All @@ -108,8 +108,8 @@ int engineManagerRegisterEngine(const char *engine_name,
c->flag.script = 1;
c->flag.fake = 1;

engine *e = zmalloc(sizeof(*ei));
*e = (engine){
scriptingEngine *e = zmalloc(sizeof(*ei));
*e = (scriptingEngine){
.name = engine_name_sds,
.module = engine_module,
.impl = ei,
Expand Down Expand Up @@ -139,7 +139,7 @@ int engineManagerUnregisterEngine(const char *engine_name) {
return C_ERR;
}

engine *e = dictGetVal(entry);
scriptingEngine *e = dictGetVal(entry);

functionsRemoveLibFromEngine(e);

Expand All @@ -161,23 +161,23 @@ int engineManagerUnregisterEngine(const char *engine_name) {
* Lookups the engine with `engine_name` in the engine manager and returns it if
* it exists. Otherwise returns `NULL`.
*/
engine *engineManagerFind(sds engine_name) {
scriptingEngine *engineManagerFind(sds engine_name) {
dictEntry *entry = dictFind(engineMgr.engines, engine_name);
if (entry) {
return dictGetVal(entry);
}
return NULL;
}

sds engineGetName(engine *engine) {
sds engineGetName(scriptingEngine *engine) {
return engine->name;
}

client *engineGetClient(engine *engine) {
client *engineGetClient(scriptingEngine *engine) {
return engine->c;
}

ValkeyModule *engineGetModule(engine *engine) {
ValkeyModule *engineGetModule(scriptingEngine *engine) {
return engine->module;
}

Expand All @@ -191,29 +191,29 @@ void engineManagerForEachEngine(engineIterCallback callback, void *context) {
dictIterator *iter = dictGetIterator(engineMgr.engines);
dictEntry *entry = NULL;
while ((entry = dictNext(iter))) {
engine *e = dictGetVal(entry);
scriptingEngine *e = dictGetVal(entry);
if (!callback(e, context)) {
break;
}
}
dictReleaseIterator(iter);
}

static void engineSetupModuleCtx(engine *e, client *c) {
static void engineSetupModuleCtx(scriptingEngine *e, client *c) {
if (e->module != NULL) {
serverAssert(e->module_ctx != NULL);
moduleScriptingEngineInitContext(e->module_ctx, e->module, c);
}
}

static void engineTeardownModuleCtx(engine *e) {
static void engineTeardownModuleCtx(scriptingEngine *e) {
if (e->module != NULL) {
serverAssert(e->module_ctx != NULL);
moduleFreeContext(e->module_ctx);
}
}

compiledFunction **engineCallCreateFunctionsLibrary(engine *engine,
compiledFunction **engineCallCreateFunctionsLibrary(scriptingEngine *engine,
const char *code,
size_t timeout,
size_t *out_num_compiled_functions,
Expand All @@ -233,7 +233,7 @@ compiledFunction **engineCallCreateFunctionsLibrary(engine *engine,
return functions;
}

void engineCallFunction(engine *engine,
void engineCallFunction(scriptingEngine *engine,
functionCtx *func_ctx,
client *caller,
void *compiled_function,
Expand All @@ -256,7 +256,7 @@ void engineCallFunction(engine *engine,
engineTeardownModuleCtx(engine);
}

void engineCallFreeFunction(engine *engine,
void engineCallFreeFunction(scriptingEngine *engine,
void *compiled_func) {
engineSetupModuleCtx(engine, NULL);
engine->impl->methods.free_function(engine->module_ctx,
Expand All @@ -265,7 +265,7 @@ void engineCallFreeFunction(engine *engine,
engineTeardownModuleCtx(engine);
}

size_t engineCallGetFunctionMemoryOverhead(engine *engine,
size_t engineCallGetFunctionMemoryOverhead(scriptingEngine *engine,
void *compiled_function) {
engineSetupModuleCtx(engine, NULL);
size_t mem = engine->impl->methods.get_function_memory_overhead(
Expand All @@ -274,7 +274,7 @@ size_t engineCallGetFunctionMemoryOverhead(engine *engine,
return mem;
}

engineMemoryInfo engineCallGetMemoryInfo(engine *engine) {
engineMemoryInfo engineCallGetMemoryInfo(scriptingEngine *engine) {
engineSetupModuleCtx(engine, NULL);
engineMemoryInfo mem_info = engine->impl->methods.get_memory_info(
engine->module_ctx, engine->impl->ctx);
Expand Down
25 changes: 13 additions & 12 deletions src/engine.h → src/scripting_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "server.h"

// Forward declaration of the engine structure.
typedef struct engine engine;
typedef struct scriptingEngine scriptingEngine;

/* ValkeyModule type aliases for scripting engine structs and types. */
typedef ValkeyModuleScriptingEngineCtx engineCtx;
Expand All @@ -17,14 +17,14 @@ typedef ValkeyModuleScriptingEngineMethods engineMethods;
* Callback function used to iterate the list of engines registered in the
* engine manager.
*
* - `engine`: the engine in the current iteration.
* - `engine`: the scripting engine in the current iteration.
*
* - `context`: a generic pointer to a context object.
*
* If the callback function returns 0, then the iteration is stopped
* immediately.
*/
typedef int (*engineIterCallback)(engine *engine, void *context);
typedef int (*engineIterCallback)(scriptingEngine *engine, void *context);

/*
* Engine manager API functions.
Expand All @@ -38,34 +38,35 @@ int engineManagerRegisterEngine(const char *engine_name,
engineCtx *engine_ctx,
engineMethods *engine_methods);
int engineManagerUnregisterEngine(const char *engine_name);
engine *engineManagerFind(sds engine_name);
scriptingEngine *engineManagerFind(sds engine_name);
void engineManagerForEachEngine(engineIterCallback callback, void *context);

/*
* Engine API functions.
*/
sds engineGetName(engine *engine);
client *engineGetClient(engine *engine);
ValkeyModule *engineGetModule(engine *engine);
sds engineGetName(scriptingEngine *engine);
client *engineGetClient(scriptingEngine *engine);
ValkeyModule *engineGetModule(scriptingEngine *engine);

/*
* API to call engine callback functions.
*/
compiledFunction **engineCallCreateFunctionsLibrary(engine *engine,
compiledFunction **engineCallCreateFunctionsLibrary(scriptingEngine *engine,
const char *code,
size_t timeout,
size_t *out_num_compiled_functions,
robj **err);
void engineCallFunction(engine *engine,
void engineCallFunction(scriptingEngine *engine,
functionCtx *func_ctx,
client *caller,
void *compiled_function,
robj **keys,
size_t nkeys,
robj **args,
size_t nargs);
void engineCallFreeFunction(engine *engine, void *compiled_func);
size_t engineCallGetFunctionMemoryOverhead(engine *engine, void *compiled_function);
engineMemoryInfo engineCallGetMemoryInfo(engine *engine);
void engineCallFreeFunction(scriptingEngine *engine, void *compiled_func);
size_t engineCallGetFunctionMemoryOverhead(scriptingEngine *engine,
void *compiled_function);
engineMemoryInfo engineCallGetMemoryInfo(scriptingEngine *engine);

#endif /* _ENGINE_H_ */
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "fmtargs.h"
#include "io_threads.h"
#include "sds.h"
#include "engine.h"
#include "scripting_engine.h"

#include <time.h>
#include <signal.h>
Expand Down

0 comments on commit bc5760b

Please sign in to comment.