forked from vmware/splinterdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_data_config.c
100 lines (81 loc) · 2.59 KB
/
default_data_config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2018-2021 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
// A default data_config suitable for simple key/value applications
// using a lexicographical sort-order (memcmp)
//
// This data_config does not support blind mutation operations
#include "platform.h"
#include "splinterdb/default_data_config.h"
#include "splinterdb/splinterdb.h"
#include "util.h"
#include "poison.h"
typedef struct ONDISK {
uint8 type;
uint8 value[0];
} message_encoding;
static int
key_compare(const data_config *cfg, slice key1, slice key2)
{
platform_assert(slice_data(key1) != NULL);
platform_assert(slice_data(key2) != NULL);
return slice_lex_cmp(key1, key2);
}
static int
merge_tuples(const data_config *cfg,
slice key,
message old_raw_message,
merge_accumulator *new_data)
{
// we don't implement UPDATEs, so this is a no-op:
// new is always left intact
return 0;
}
static int
merge_tuples_final(const data_config *cfg,
slice key,
merge_accumulator *oldest_data // IN/OUT
)
{
// we don't implement UPDATEs, so this is a no-op:
// new is always left intact
return 0;
}
static void
key_to_string(const data_config *cfg, slice key, char *str, size_t max_len)
{
debug_hex_encode(str, max_len, slice_data(key), slice_length(key));
}
static void
message_to_string(const data_config *cfg,
message msg,
char *str,
size_t max_len)
{
debug_hex_encode(str, max_len, message_data(msg), message_length(msg));
}
void
default_data_config_init(const size_t max_key_size, // IN
data_config *out_cfg // OUT
)
{
platform_assert(max_key_size <= SPLINTERDB_MAX_KEY_SIZE && max_key_size > 0,
"default_data_config_init: must have 0 < max_key_size (%lu) "
"<= SPLINTERDB_MAX_KEY_SIZE (%d)",
max_key_size,
SPLINTERDB_MAX_KEY_SIZE);
data_config cfg = {
.key_size = max_key_size,
.min_key = {0},
.min_key_length = 0,
.max_key = {0}, // see memset below
.max_key_length = max_key_size,
.key_compare = key_compare,
.key_hash = platform_hash32,
.merge_tuples = merge_tuples,
.merge_tuples_final = merge_tuples_final,
.key_to_string = key_to_string,
.message_to_string = message_to_string,
};
memset(cfg.max_key, 0xFF, sizeof(cfg.max_key));
*out_cfg = cfg;
}