1 /*
2  Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation.  The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License, version 2.0, for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23  */
24 #ifndef NDBMEMCACHE_KEYPREFIX_H
25 #define NDBMEMCACHE_KEYPREFIX_H
26 
27 #include <stdio.h>
28 
29 /***** This section defines data structures available to C. ***/
30 /* The prefix_info_t is the compacted form of the parts of the
31    KeyPrefix that must be available to C code.
32 */
33 
34 /* The value of 13 imposes a limit of 8,192 prefixes */
35 #define KEY_PREFIX_BITS 13
36 #define MAX_KEY_PREFIXES ( 1 << KEY_PREFIX_BITS )
37 
38 /* The value of 4 imposes a limit of 16 clusters */
39 #define CLUSTER_ID_BITS 4
40 #define MAX_CLUSTERS ( 1 << CLUSTER_ID_BITS )
41 
42 typedef struct ndb_prefix_bitfield {
43   unsigned usable         : 1;
44   unsigned use_ndb        : 1;
45   unsigned _unused1       : 1;
46   unsigned prefix_id      : KEY_PREFIX_BITS;
47 
48   unsigned do_mc_read     : 1;
49   unsigned do_db_read     : 1;
50   unsigned do_mc_write    : 1;
51   unsigned do_db_write    : 1;
52   unsigned do_mc_delete   : 1;
53   unsigned do_db_delete   : 1;
54   unsigned do_db_flush    : 1;
55   unsigned has_cas_col    : 1;
56 
57   unsigned has_flags_col  : 1;
58   unsigned has_expire_col : 1;
59   unsigned has_math_col   : 1;
60   unsigned cluster_id     : CLUSTER_ID_BITS;
61 } prefix_info_t;
62 
63 
64 /***** This section is available to C++ only. ***/
65 #ifdef __cplusplus
66 
67 #include <sys/types.h>
68 #include <string.h>
69 #include <stdlib.h>
70 
71 #include "TableSpec.h"
72 
73 class KeyPrefix {
74 public:
75   /* public methods */
76   KeyPrefix(const char *name);
77   KeyPrefix(const KeyPrefix &);
78   ~KeyPrefix();
79   int cmp(const char *key, int nkey);
80   void dump(FILE *) const;
81 
82   /* public instance variables */
83   TableSpec *table;
84   prefix_info_t info;
85   const char *prefix;
86   const size_t prefix_len;
87 };
88 
89 
90 /**** Inline methods for KeyPrefix ****/
cmp(const char * key,int nkey)91 inline int KeyPrefix::cmp(const char *key, int nkey) {
92   return strncmp(prefix, key, prefix_len);
93 }
94 
95 #endif
96 
97 #endif
98 
99