memaslap: mv src/bin/contrib => contrib/bin
[m6w6/libmemcached] / contrib / bin / memaslap / ms_task.h
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #ifndef MS_TASK_H
17 #define MS_TASK_H
18
19 #include <sys/types.h>
20 #include <stdint.h>
21 #if !defined(__cplusplus)
22 # include <stdbool.h>
23 #endif
24 #include <time.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define UNIT_ITEMS_COUNT 1024 /* each window unit has 1024 items */
31 #define KEY_PREFIX_SIZE (sizeof(uint64_t)) /* key prefix length: 8 bytes */
32 #define INVALID_OFFSET (-1) /* invalid offset in the character table */
33 #define FIXED_EXPIRE_TIME 60 /* default expire time is 60s */
34 #define EXPIRE_TIME_ERROR 5 /* default expire time error is 5s */
35
36 /* information of a task item(object) */
37 typedef struct task_item {
38 uint64_t key_prefix; /* prefix of the key, 8 bytes, binary */
39 int key_size; /* key size */
40 int key_suffix_offset; /* suffix offset in the global character table */
41
42 int value_size; /* data size */
43 int value_offset; /* data offset in the global character table */
44
45 time_t client_time; /* the current client time */
46 int exp_time; /* expire time */
47 } ms_task_item_t;
48
49 /* task item for multi-get */
50 typedef struct mlget_task_item {
51 ms_task_item_t *item; /* task item */
52 bool verify; /* whether verify data or not */
53 bool finish_verify; /* whether finish data verify or not */
54 bool get_miss; /* whether get miss or not */
55 } ms_mlget_task_item_t;
56
57 /* information of multi-get task */
58 typedef struct mlget_task {
59 ms_mlget_task_item_t *mlget_item; /* multi-get task array */
60 int mlget_num; /* how many tasks in mlget_task array */
61 int value_index; /* the nth value received by the connect, for multi-get */
62 } ms_mlget_task_t;
63
64 /* structure used to store the state of the running task */
65 typedef struct task {
66 int cmd; /* command name */
67 bool verify; /* whether verify data or not */
68 bool finish_verify; /* whether finish data verify or not */
69 bool get_miss; /* whether get miss or not */
70 ms_task_item_t *item; /* task item */
71
72 /* counter for command distribution adjustment */
73 uint64_t get_opt; /* number of total get operations */
74 uint64_t set_opt; /* number of total set operations, no including warmup set count */
75 int cycle_undo_get; /* number of undo get in an adjustment cycle */
76 int cycle_undo_set; /* number of undo set in an adjustment cycle */
77 uint64_t verified_get; /* number of total verified get operations */
78 uint64_t overwrite_set; /* number of total overwrite set operations */
79 } ms_task_t;
80
81 struct conn;
82
83 /* the state machine call the function to execute task.*/
84 int ms_exec_task(struct conn *c);
85
86 /* calculate the difference value of two time points */
87 int64_t ms_time_diff(struct timeval *start_time, struct timeval *end_time);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* end of MS_TASK_H */