1
+ // Copyright 2024 KVCache.AI
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef MOONCAKE_CLIENT_C
16
+ #define MOONCAKE_CLIENT_C
17
+
18
+ #include <stddef.h>
19
+ #include <stdint.h>
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif // __cplusplus
24
+
25
+ // types.h 中的 ErrorCode Code
26
+ typedef int32_t ErrorCode_t ;
27
+
28
+ #define MOONCAKE_ERROR_OK ((ErrorCode_t)0)
29
+ #define MOONCAKE_ERROR_INTERNAL_ERROR ((ErrorCode_t) - 1)
30
+ #define MOONCAKE_ERROR_BUFFER_OVERFLOW ((ErrorCode_t) - 10)
31
+ #define MOONCAKE_ERROR_SHARD_INDEX_OUT_OF_RANGE ((ErrorCode_t) - 100)
32
+ #define MOONCAKE_ERROR_SEGMENT_NOT_FOUND ((ErrorCode_t) - 101)
33
+ #define MOONCAKE_ERROR_SEGMENT_ALREADY_EXISTS ((ErrorCode_t) - 102)
34
+ #define MOONCAKE_ERROR_NO_AVAILABLE_HANDLE ((ErrorCode_t) - 200)
35
+ #define MOONCAKE_ERROR_INVALID_VERSION ((ErrorCode_t) - 300)
36
+ #define MOONCAKE_ERROR_INVALID_KEY ((ErrorCode_t) - 400)
37
+ #define MOONCAKE_ERROR_WRITE_FAIL ((ErrorCode_t) - 500)
38
+ #define MOONCAKE_ERROR_INVALID_PARAMS ((ErrorCode_t) - 600)
39
+ #define MOONCAKE_ERROR_INVALID_WRITE ((ErrorCode_t) - 700)
40
+ #define MOONCAKE_ERROR_INVALID_READ ((ErrorCode_t) - 701)
41
+ #define MOONCAKE_ERROR_INVALID_REPLICA ((ErrorCode_t) - 702)
42
+ #define MOONCAKE_ERROR_REPLICA_IS_NOT_READY ((ErrorCode_t) - 703)
43
+ #define MOONCAKE_ERROR_OBJECT_NOT_FOUND ((ErrorCode_t) - 704)
44
+ #define MOONCAKE_ERROR_OBJECT_ALREADY_EXISTS ((ErrorCode_t) - 705)
45
+ #define MOONCAKE_ERROR_OBJECT_HAS_LEASE ((ErrorCode_t) - 706)
46
+ #define MOONCAKE_ERROR_TRANSFER_FAIL ((ErrorCode_t) - 800)
47
+ #define MOONCAKE_ERROR_RPC_FAIL ((ErrorCode_t) - 900)
48
+ #define MOONCAKE_ERROR_ETCD_OPERATION_ERROR ((ErrorCode_t) - 1000)
49
+ #define MOONCAKE_ERROR_ETCD_KEY_NOT_EXIST ((ErrorCode_t) - 1001)
50
+ #define MOONCAKE_ERROR_ETCD_TRANSACTION_FAIL ((ErrorCode_t) - 1002)
51
+ #define MOONCAKE_ERROR_ETCD_CTX_CANCELLED ((ErrorCode_t) - 1003)
52
+ #define MOONCAKE_ERROR_UNAVAILABLE_IN_CURRENT_STATUS ((ErrorCode_t) - 1010)
53
+ #define MOONCAKE_ERROR_UNAVAILABLE_IN_CURRENT_MODE ((ErrorCode_t) - 1011)
54
+ #define MOONCAKE_ERROR_FILE_NOT_FOUND ((ErrorCode_t) - 1100)
55
+ #define MOONCAKE_ERROR_FILE_OPEN_FAIL ((ErrorCode_t) - 1101)
56
+ #define MOONCAKE_ERROR_FILE_READ_FAIL ((ErrorCode_t) - 1102)
57
+ #define MOONCAKE_ERROR_FILE_WRITE_FAIL ((ErrorCode_t) - 1103)
58
+ #define MOONCAKE_ERROR_FILE_INVALID_BUFFER ((ErrorCode_t) - 1104)
59
+ #define MOONCAKE_ERROR_FILE_LOCK_FAIL ((ErrorCode_t) - 1105)
60
+ #define MOONCAKE_ERROR_FILE_INVALID_HANDLE ((ErrorCode_t) - 1106)
61
+
62
+ typedef struct {
63
+ void * ptr = NULL;
64
+ size_t size = 0 ;
65
+ } Slice_t ;
66
+
67
+ typedef struct {
68
+ Slice_t * slices ;
69
+ size_t slices_count ;
70
+ } Slice_span_t ;
71
+
72
+ typedef struct {
73
+ size_t replica_num ;
74
+ const char * preferred_segment ;
75
+ } ReplicateConfig_t ;
76
+
77
+ typedef struct {
78
+ const char * key ;
79
+ Slice_span_t * slices_span ;
80
+ } BatchItem_t ;
81
+
82
+ typedef struct {
83
+ ErrorCode_t * results ;
84
+ size_t results_count ;
85
+ } ErrorCode_span_t ;
86
+
87
+ typedef void * client_t ;
88
+
89
+ client_t mooncake_client_create (const char * local_hostname ,
90
+ const char * metadata_connstring ,
91
+ const char * protocol , const char * rdma_devices ,
92
+ const char * master_server_entry );
93
+
94
+ ErrorCode_t mooncake_client_register_local_memory (client_t client , void * addr ,
95
+ size_t length ,
96
+ const char * location ,
97
+ bool remote_accessible ,
98
+ bool update_metadata );
99
+
100
+ ErrorCode_t mooncake_client_unregister_local_memory (client_t client , void * addr ,
101
+ bool update_metadata );
102
+
103
+ ErrorCode_t mooncake_client_mount_segment (client_t client , void * segment_ptr ,
104
+ size_t size );
105
+
106
+ ErrorCode_t mooncake_client_unmount_segment (client_t client , void * segment_ptr ,
107
+ size_t size );
108
+
109
+ ErrorCode_t mooncake_client_get (client_t client , const char * key ,
110
+ Slice_t * slices , size_t slices_count );
111
+
112
+ ErrorCode_t mooncake_client_put (client_t client , const char * key ,
113
+ Slice_t * slices , size_t slices_count ,
114
+ const ReplicateConfig_t config );
115
+
116
+ ErrorCode_t mooncake_client_isexist (client_t client , const char * key );
117
+
118
+ ErrorCode_t mooncake_client_remove (client_t client , const char * key );
119
+
120
+ long mooncake_client_remove_byregex (client_t client , const char * regex );
121
+
122
+ long mooncake_client_remove_all (client_t client );
123
+
124
+ ErrorCode_span_t mooncake_client_batch_get (client_t client , BatchItem_t * items ,
125
+ size_t items_count );
126
+
127
+ ErrorCode_span_t mooncake_client_batch_put (client_t client , BatchItem_t * items ,
128
+ size_t items_count ,
129
+ const ReplicateConfig_t config );
130
+
131
+ void mooncake_client_destroy (client_t client );
132
+
133
+ uint64_t mooncake_max_slice_size ();
134
+
135
+ void * mooncake_allocate_segment_memory (size_t size );
136
+
137
+ #ifdef __cplusplus
138
+ }
139
+ #endif // __cplusplus
140
+
141
+ #endif // MOONCAKE_CLIENT_C
0 commit comments