-
Notifications
You must be signed in to change notification settings - Fork 388
[Store] Add Pure C Interface of Client #866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JINGE-ui
wants to merge
1
commit into
kvcache-ai:main
Choose a base branch
from
JINGE-ui:add-client-c-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright 2024 KVCache.AI | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef MOONCAKE_CLIENT_C | ||
#define MOONCAKE_CLIENT_C | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
// types.h 中的 ErrorCode Code | ||
typedef int32_t ErrorCode_t; | ||
|
||
#define MOONCAKE_ERROR_OK ((ErrorCode_t)0) | ||
#define MOONCAKE_ERROR_INTERNAL_ERROR ((ErrorCode_t) - 1) | ||
#define MOONCAKE_ERROR_BUFFER_OVERFLOW ((ErrorCode_t) - 10) | ||
#define MOONCAKE_ERROR_SHARD_INDEX_OUT_OF_RANGE ((ErrorCode_t) - 100) | ||
#define MOONCAKE_ERROR_SEGMENT_NOT_FOUND ((ErrorCode_t) - 101) | ||
#define MOONCAKE_ERROR_SEGMENT_ALREADY_EXISTS ((ErrorCode_t) - 102) | ||
#define MOONCAKE_ERROR_NO_AVAILABLE_HANDLE ((ErrorCode_t) - 200) | ||
#define MOONCAKE_ERROR_INVALID_VERSION ((ErrorCode_t) - 300) | ||
#define MOONCAKE_ERROR_INVALID_KEY ((ErrorCode_t) - 400) | ||
#define MOONCAKE_ERROR_WRITE_FAIL ((ErrorCode_t) - 500) | ||
#define MOONCAKE_ERROR_INVALID_PARAMS ((ErrorCode_t) - 600) | ||
#define MOONCAKE_ERROR_INVALID_WRITE ((ErrorCode_t) - 700) | ||
#define MOONCAKE_ERROR_INVALID_READ ((ErrorCode_t) - 701) | ||
#define MOONCAKE_ERROR_INVALID_REPLICA ((ErrorCode_t) - 702) | ||
#define MOONCAKE_ERROR_REPLICA_IS_NOT_READY ((ErrorCode_t) - 703) | ||
#define MOONCAKE_ERROR_OBJECT_NOT_FOUND ((ErrorCode_t) - 704) | ||
#define MOONCAKE_ERROR_OBJECT_ALREADY_EXISTS ((ErrorCode_t) - 705) | ||
#define MOONCAKE_ERROR_OBJECT_HAS_LEASE ((ErrorCode_t) - 706) | ||
#define MOONCAKE_ERROR_TRANSFER_FAIL ((ErrorCode_t) - 800) | ||
#define MOONCAKE_ERROR_RPC_FAIL ((ErrorCode_t) - 900) | ||
#define MOONCAKE_ERROR_ETCD_OPERATION_ERROR ((ErrorCode_t) - 1000) | ||
#define MOONCAKE_ERROR_ETCD_KEY_NOT_EXIST ((ErrorCode_t) - 1001) | ||
#define MOONCAKE_ERROR_ETCD_TRANSACTION_FAIL ((ErrorCode_t) - 1002) | ||
#define MOONCAKE_ERROR_ETCD_CTX_CANCELLED ((ErrorCode_t) - 1003) | ||
#define MOONCAKE_ERROR_UNAVAILABLE_IN_CURRENT_STATUS ((ErrorCode_t) - 1010) | ||
#define MOONCAKE_ERROR_UNAVAILABLE_IN_CURRENT_MODE ((ErrorCode_t) - 1011) | ||
#define MOONCAKE_ERROR_FILE_NOT_FOUND ((ErrorCode_t) - 1100) | ||
#define MOONCAKE_ERROR_FILE_OPEN_FAIL ((ErrorCode_t) - 1101) | ||
#define MOONCAKE_ERROR_FILE_READ_FAIL ((ErrorCode_t) - 1102) | ||
#define MOONCAKE_ERROR_FILE_WRITE_FAIL ((ErrorCode_t) - 1103) | ||
#define MOONCAKE_ERROR_FILE_INVALID_BUFFER ((ErrorCode_t) - 1104) | ||
#define MOONCAKE_ERROR_FILE_LOCK_FAIL ((ErrorCode_t) - 1105) | ||
#define MOONCAKE_ERROR_FILE_INVALID_HANDLE ((ErrorCode_t) - 1106) | ||
|
||
typedef struct { | ||
void* ptr = NULL; | ||
size_t size = 0; | ||
} Slice_t; | ||
|
||
typedef struct { | ||
Slice_t* slices; | ||
size_t slices_count; | ||
} Slice_span_t; | ||
|
||
typedef struct { | ||
size_t replica_num; | ||
const char* preferred_segment; | ||
} ReplicateConfig_t; | ||
|
||
typedef struct { | ||
const char* key; | ||
Slice_span_t* slices_span; | ||
} BatchItem_t; | ||
|
||
typedef struct { | ||
ErrorCode_t* results; | ||
size_t results_count; | ||
} ErrorCode_span_t; | ||
|
||
typedef void* client_t; | ||
|
||
client_t mooncake_client_create(const char* local_hostname, | ||
const char* metadata_connstring, | ||
const char* protocol, const char* rdma_devices, | ||
const char* master_server_entry); | ||
|
||
ErrorCode_t mooncake_client_register_local_memory(client_t client, void* addr, | ||
size_t length, | ||
const char* location, | ||
bool remote_accessible, | ||
bool update_metadata); | ||
|
||
ErrorCode_t mooncake_client_unregister_local_memory(client_t client, void* addr, | ||
bool update_metadata); | ||
|
||
ErrorCode_t mooncake_client_mount_segment(client_t client, void* segment_ptr, | ||
size_t size); | ||
|
||
ErrorCode_t mooncake_client_unmount_segment(client_t client, void* segment_ptr, | ||
size_t size); | ||
|
||
ErrorCode_t mooncake_client_get(client_t client, const char* key, | ||
Slice_t* slices, size_t slices_count); | ||
|
||
ErrorCode_t mooncake_client_put(client_t client, const char* key, | ||
Slice_t* slices, size_t slices_count, | ||
const ReplicateConfig_t config); | ||
|
||
ErrorCode_t mooncake_client_isexist(client_t client, const char* key); | ||
|
||
ErrorCode_t mooncake_client_remove(client_t client, const char* key); | ||
|
||
long mooncake_client_remove_byregex(client_t client, const char* regex); | ||
|
||
long mooncake_client_remove_all(client_t client); | ||
|
||
ErrorCode_span_t mooncake_client_batch_get(client_t client, BatchItem_t* items, | ||
size_t items_count); | ||
|
||
ErrorCode_span_t mooncake_client_batch_put(client_t client, BatchItem_t* items, | ||
size_t items_count, | ||
const ReplicateConfig_t config); | ||
|
||
void mooncake_client_destroy(client_t client); | ||
|
||
uint64_t mooncake_max_slice_size(); | ||
|
||
void* mooncake_allocate_segment_memory(size_t size); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // __cplusplus | ||
|
||
#endif // MOONCAKE_CLIENT_C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.