Skip to content

Commit

Permalink
CLEANUP: Refactor includes
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesecrust committed Oct 22, 2024
1 parent 477fd2c commit b79063f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions lqdetect.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "lqdetect.h"

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <pthread.h>
#include <sys/time.h>
#include <assert.h>
#include <memcached/util.h>

#include "lqdetect.h"
#include "memcached/util.h"
#include "memcached/extension_loggers.h"

#define LQ_THRESHOLD_DEFAULT 4000
#define LQ_QUERY_SIZE (64*2+64) /* bop get (longest query) : "<longest bkey>..<longest bkey> efilter <offset> <count> delete" */
Expand Down Expand Up @@ -221,9 +221,9 @@ static int do_make_bkeystring(char *buffer, const bkey_range *bkrange, const efl
}

/* external functions */
int lqdetect_init(EXTENSION_LOGGER_DESCRIPTOR *logger)
int lqdetect_init(void *logger)
{
mc_logger = logger;
mc_logger = (EXTENSION_LOGGER_DESCRIPTOR*)logger;
pthread_mutex_init(&lqdetect.lock, NULL);
lqdetect_in_use = false;

Expand Down Expand Up @@ -430,24 +430,24 @@ void lqdetect_mop_delete(char *client_ip, char *key, uint32_t del_count,
}

void lqdetect_bop_gbp(char *client_ip, char *key, uint32_t elem_count,
uint32_t from_posi, uint32_t to_posi, ENGINE_BTREE_ORDER order)
uint32_t from_posi, uint32_t to_posi, void *order)
{
if (elem_count >= lqdetect.stats.threshold) {
struct lq_detect_argument argument;
snprintf(argument.query, LQ_QUERY_SIZE, "%u..%u %s", from_posi, to_posi,
order == BTREE_ORDER_ASC ? "asc" : "desc");
*(ENGINE_BTREE_ORDER*)order == BTREE_ORDER_ASC ? "asc" : "desc");
argument.overhead = elem_count;
do_lqdetect_save_cmd(client_ip, key, LQCMD_BOP_GBP, &argument);
}
}

void lqdetect_bop_get(char *client_ip, char *key, uint32_t access_count,
const bkey_range *bkrange, const eflag_filter *efilter,
const void *bkrange, const void *efilter,
uint32_t offset, uint32_t count, const bool delete, const bool drop_if_empty)
{
if (access_count >= lqdetect.stats.threshold) {
struct lq_detect_argument argument;
int nwrite = do_make_bkeystring(argument.query, bkrange, efilter);
int nwrite = do_make_bkeystring(argument.query, (bkey_range*)bkrange, (eflag_filter*)efilter);
snprintf(argument.query + nwrite, LQ_QUERY_SIZE - nwrite, " %u %u%s",
offset, count, drop_if_empty ? " drop" : (delete ? " delete" : ""));
argument.overhead = access_count;
Expand All @@ -456,23 +456,23 @@ void lqdetect_bop_get(char *client_ip, char *key, uint32_t access_count,
}

void lqdetect_bop_count(char *client_ip, char *key, uint32_t access_count,
const bkey_range *bkrange, const eflag_filter *efilter)
const void *bkrange, const void *efilter)
{
if (access_count >= lqdetect.stats.threshold) {
struct lq_detect_argument argument;
do_make_bkeystring(argument.query, bkrange, efilter);
do_make_bkeystring(argument.query, (bkey_range*)bkrange, (eflag_filter*)efilter);
argument.overhead = access_count;
do_lqdetect_save_cmd(client_ip, key, LQCMD_BOP_COUNT, &argument);
}
}

void lqdetect_bop_delete(char *client_ip, char *key, uint32_t access_count,
const bkey_range *bkrange, const eflag_filter *efilter,
const void *bkrange, const void *efilter,
uint32_t count, const bool drop_if_empty)
{
if (access_count >= lqdetect.stats.threshold) {
struct lq_detect_argument argument;
int nwrite = do_make_bkeystring(argument.query, bkrange, efilter);
int nwrite = do_make_bkeystring(argument.query, (bkey_range*)bkrange, (eflag_filter*)efilter);
snprintf(argument.query + nwrite, LQ_QUERY_SIZE - nwrite, " %u%s",
count, drop_if_empty ? " drop" : "");
argument.count = count;
Expand Down
14 changes: 7 additions & 7 deletions lqdetect.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef LQDETECT_H
#define LQDETECT_H

#include "memcached/extension_loggers.h"
#include "memcached/util.h"
#include <stdbool.h>
#include <stdint.h>

#define DETECT_LONG_QUERY

extern bool lqdetect_in_use;

int lqdetect_init(EXTENSION_LOGGER_DESCRIPTOR *logger);
int lqdetect_init(void *logger);
void lqdetect_final(void);
char *lqdetect_result_get(int *size);
int lqdetect_start(uint32_t threshold, bool *already_started);
Expand All @@ -27,13 +27,13 @@ void lqdetect_mop_get(char *client_ip, char *key, uint32_t elem_count,
void lqdetect_mop_delete(char *client_ip, char *key, uint32_t del_count,
uint32_t coll_numkeys, const bool drop_if_empty);
void lqdetect_bop_gbp(char *client_ip, char *key, uint32_t elem_count,
uint32_t from_posi, uint32_t to_posi, ENGINE_BTREE_ORDER order);
uint32_t from_posi, uint32_t to_posi, void *order);
void lqdetect_bop_get(char *client_ip, char *key, uint32_t access_count,
const bkey_range *bkrange, const eflag_filter *efilter,
const void *bkrange, const void *efilter,
uint32_t offset, uint32_t count, const bool delete, const bool drop_if_empty);
void lqdetect_bop_count(char *client_ip, char *key, uint32_t access_count,
const bkey_range *bkrange, const eflag_filter *efilter);
const void *bkrange, const void *efilter);
void lqdetect_bop_delete(char *client_ip, char *key, uint32_t access_count,
const bkey_range *bkrange, const eflag_filter *efilter,
const void *bkrange, const void *efilter,
uint32_t count, const bool drop_if_empty);
#endif
3 changes: 2 additions & 1 deletion memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include <stdarg.h>
#include <stddef.h>

#include "lqdetect.h"

/* Lock for global stats */
static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
Expand Down Expand Up @@ -11283,7 +11284,7 @@ static void process_bop_gbp(conn *c, char *key, size_t nkey,
#ifdef DETECT_LONG_QUERY
if (lqdetect_in_use && ret == ENGINE_SUCCESS) {
lqdetect_bop_gbp(c->client_ip, key, eresult.elem_count,
from_posi, to_posi, order);
from_posi, to_posi, &order);
}
#endif

Expand Down
1 change: 0 additions & 1 deletion memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "topkeys.h"
#include "mc_util.h"
#include "cmdlog.h"
#include "lqdetect.h"
#include "engine_loader.h"
#include "sasl_defs.h"

Expand Down

0 comments on commit b79063f

Please sign in to comment.