From cc341cd6631e36425ffbfa1156278db1d49df40c Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Mon, 6 Jan 2025 13:59:19 -0800 Subject: [PATCH] declare init api --- examples/routing-plugin-c/plugin.c | 2 ++ pgdog-plugin/include/plugin.h | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/examples/routing-plugin-c/plugin.c b/examples/routing-plugin-c/plugin.c index f9c37e1..ad5bc7f 100644 --- a/examples/routing-plugin-c/plugin.c +++ b/examples/routing-plugin-c/plugin.c @@ -11,6 +11,8 @@ void pgdog_init() { Route pgdog_route_query(Query query) { Route route; + route.shard = ANY; /* No sharding */ + char *lowercase = strdup(query.query); for (int i = 0; i < strlen(lowercase); i++) { diff --git a/pgdog-plugin/include/plugin.h b/pgdog-plugin/include/plugin.h index 7acbd20..3bf3421 100644 --- a/pgdog-plugin/include/plugin.h +++ b/pgdog-plugin/include/plugin.h @@ -7,9 +7,29 @@ * implements it, the query router will use its decision * to route the query. * + * ## Thread safety + * + * This function is not synchronized and can be called + * for multiple queries at a time. If accessing global state, + * make sure to protect access with a mutex. + * + * ## Performance + * + * This function is called for every transaction. It's a hot path, + * so make sure to optimize for performance in the implementation. + * */ Route pgdog_route_query(Query query); +/* + * Perform initialization at plugin loading time. + * + * Executed only once and execution is synchronized, + * so it's safe to initialize sychroniziation primitives + * like mutexes in this method. + */ +void pgdog_init(); + /* Create new row. * * Implemented by pgdog_plugin library.