Schooner memslap changes
[m6w6/libmemcached] / clients / ms_task.h
1 /*
2 * File: ms_task.h
3 * Author: Mingqiang Zhuang
4 *
5 * Created on February 10, 2009
6 *
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
9 *
10 */
11 #ifndef MS_TASK_H
12 #define MS_TASK_H
13
14 #include <sys/types.h>
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include <time.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #define UNIT_ITEMS_COUNT 1024 /* each window unit has 1024 items */
24 #define KEY_PREFIX_SIZE (sizeof(uint64_t)) /* key prefix length: 8 bytes */
25 #define INVALID_OFFSET (-1) /* invalid offset in the character table */
26 #define FIXED_EXPIRE_TIME 60 /* default expire time is 60s */
27 #define EXPIRE_TIME_ERROR 5 /* default expire time error is 5s */
28
29 /* information of a task item(object) */
30 typedef struct task_item {
31 uint64_t key_prefix; /* prefix of the key, 8 bytes, binary */
32 int key_size; /* key size */
33 int key_suffix_offset; /* suffix offset in the global character table */
34
35 int value_size; /* data size */
36 int value_offset; /* data offset in the global character table */
37
38 time_t client_time; /* the current client time */
39 int exp_time; /* expire time */
40 } ms_task_item_t;
41
42 /* task item for multi-get */
43 typedef struct mlget_task_item {
44 ms_task_item_t *item; /* task item */
45 bool verify; /* whether verify data or not */
46 bool finish_verify; /* whether finish data verify or not */
47 bool get_miss; /* whether get miss or not */
48 } ms_mlget_task_item_t;
49
50 /* information of multi-get task */
51 typedef struct mlget_task {
52 ms_mlget_task_item_t *mlget_item; /* multi-get task array */
53 int mlget_num; /* how many tasks in mlget_task array */
54 int value_index; /* the nth value received by the connect, for multi-get */
55 } ms_mlget_task_t;
56
57 /* structure used to store the state of the running task */
58 typedef struct task {
59 int cmd; /* command name */
60 bool verify; /* whether verify data or not */
61 bool finish_verify; /* whether finish data verify or not */
62 bool get_miss; /* whether get miss or not */
63 ms_task_item_t *item; /* task item */
64
65 /* counter for command distribution adjustment */
66 uint64_t get_opt; /* number of total get operations */
67 uint64_t set_opt; /* number of total set operations, no including warmup set count */
68 int cycle_undo_get; /* number of undo get in an adjustment cycle */
69 int cycle_undo_set; /* number of undo set in an adjustment cycle */
70 uint64_t verified_get; /* number of total verified get operations */
71 uint64_t overwrite_set; /* number of total overwrite set operations */
72 } ms_task_t;
73
74 struct conn;
75
76 /* the state machine call the function to execute task.*/
77 int ms_exec_task(struct conn *c);
78
79 /* calculate the difference value of two time points */
80 int64_t ms_time_diff(struct timeval *start_time, struct timeval *end_time);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif /* end of MS_TASK_H */