39 # include <dsn/c/api_common.h> 40 # include <dsn/c/api_task.h> 230 extern DSN_API
bool dsn_task_cancel(dsn_task_t task,
bool wait_until_finished);
253 bool wait_until_finished,
279 int timeout_milliseconds
365 dsn_task_code_t code,
369 dsn_task_tracker_t tracker DEFAULT(
nullptr)
393 dsn_task_code_t code,
397 int interval_milliseconds,
398 dsn_task_tracker_t tracker DEFAULT(
nullptr)
407 dsn_task_code_t code,
412 dsn_task_tracker_t tracker DEFAULT(
nullptr)
421 dsn_task_code_t code,
426 int interval_milliseconds,
427 dsn_task_tracker_t tracker DEFAULT(
nullptr)
438 int delay_milliseconds DEFAULT(0)
464 HOST_TYPE_INVALID = 0,
475 unsigned long long type : 2;
476 unsigned long long padding : 14;
477 unsigned long long port : 16;
478 unsigned long long ip : 32;
481 unsigned long long type : 2;
482 unsigned long long uri : 62;
485 unsigned long long type : 2;
496 extern DSN_API uint32_t
dsn_ipv4_local(
const char* network_interface);
624 dsn_task_code_t rpc_code,
625 int timeout_milliseconds DEFAULT(0),
626 uint64_t hash DEFAULT(0)
633 extern DSN_API dsn_message_t
dsn_msg_copy(dsn_message_t msg,
bool clone_content,
bool copy_for_receive);
645 DSF_THRIFT_BINARY = 1,
646 DSF_THRIFT_COMPACT = 2,
648 DSF_PROTOC_BINARY = 4,
655 dsn_task_code_t rpc_code,
659 uint64_t hash DEFAULT(0)
672 uint64_t is_request : 1;
673 uint64_t is_forwarded : 1;
675 uint64_t serialize_format : 4;
676 uint64_t is_forward_supported : 1;
677 uint64_t parameter_type : 3;
678 uint64_t parameter : 50;
692 inline uint64_t dsn_gpid_to_hash(
dsn_gpid gpid)
697 # define DSN_MSGM_TIMEOUT (0x1 << 0) 698 # define DSN_MSGM_HASH (0x1 << 1) 699 # define DSN_MSGM_VNID (0x1 << 2) 700 # define DSN_MSGM_CONTEXT (0x1 << 3) 715 "sizeof(dsn_address_t) must equal to sizeof(uint64_t)");
718 "sizeof(dsn_msg_context_t) must equal to sizeof(uint64_t)");
720 static_assert (
sizeof(
dsn_gpid) ==
sizeof(uint64_t),
721 "sizeof(dsn_gpid) must equal to sizeof(uint64_t)");
756 extern DSN_API
void*
dsn_msg_rw_ptr(dsn_message_t msg,
size_t offset_begin);
819 dsn_task_code_t code,
828 dsn_task_code_t code,
833 extern DSN_API
void dsn_rpc_reply(dsn_message_t response, dsn_error_t err DEFAULT(0));
862 dsn_message_t request,
865 int reply_thread_hash DEFAULT(0),
866 dsn_task_tracker_t tracker DEFAULT(
nullptr)
884 dsn_message_t request,
888 int reply_thread_hash DEFAULT(0),
889 dsn_task_tracker_t tracker DEFAULT(
nullptr)
904 dsn_message_t request
910 dsn_message_t request
923 dsn_message_t response
948 CTL_BATCH_INVALID = 0,
964 const char* file_name,
994 dsn_task_code_t code,
998 dsn_task_tracker_t tracker DEFAULT(
nullptr)
1014 dsn_task_code_t code,
1018 int hash DEFAULT(0),
1019 dsn_task_tracker_t tracker DEFAULT(
nullptr)
1084 const char* source_dir,
1085 const char* dest_dir,
1103 const char* source_dir,
1104 const char** source_files,
1105 const char* dest_dir,
1132 extern DSN_API uint64_t dsn_now_ns();
1135 extern DSN_API uint64_t
dsn_random64(uint64_t min, uint64_t max);
1137 __inline uint64_t dsn_now_us() {
return dsn_now_ns() / 1000; }
1138 __inline uint64_t dsn_now_ms() {
return dsn_now_ns() / 1000000; }
1146 __inline
double dsn_probability()
1148 return (
double)(
dsn_random64(0, 1000000000)) / 1000000000.0;
1171 extern DSN_API
void dsn_exlock_destroy(dsn_handle_t l);
1172 extern DSN_API
void dsn_exlock_lock(dsn_handle_t l);
1173 extern DSN_API
bool dsn_exlock_try_lock(dsn_handle_t l);
1174 extern DSN_API
void dsn_exlock_unlock(dsn_handle_t l);
1182 extern DSN_API dsn_handle_t dsn_rwlock_nr_create();
1183 extern DSN_API
void dsn_rwlock_nr_destroy(dsn_handle_t l);
1184 extern DSN_API
void dsn_rwlock_nr_lock_read(dsn_handle_t l);
1185 extern DSN_API
void dsn_rwlock_nr_unlock_read(dsn_handle_t l);
1186 extern DSN_API
bool dsn_rwlock_nr_try_lock_read(dsn_handle_t l);
1187 extern DSN_API
void dsn_rwlock_nr_lock_write(dsn_handle_t l);
1188 extern DSN_API
void dsn_rwlock_nr_unlock_write(dsn_handle_t l);
1189 extern DSN_API
bool dsn_rwlock_nr_try_lock_write(dsn_handle_t l);
1199 extern DSN_API
void dsn_semaphore_destroy(dsn_handle_t s);
1200 extern DSN_API
void dsn_semaphore_signal(dsn_handle_t s,
int count);
1201 extern DSN_API
void dsn_semaphore_wait(dsn_handle_t s);
1202 extern DSN_API
bool dsn_semaphore_wait_timeout(
1204 int timeout_milliseconds
DSN_API bool dsn_group_is_update_leader_automatically(dsn_group_t g)
whether auto-update of the leader in rDSN runtime is allowed, default is true
DSN_API dsn_error_t dsn_file_flush(dsn_handle_t file)
flush the buffer of the given file
void(* dsn_task_cancelled_handler_t)(void *)
callback prototype for task cancellation (called on task-being-cancelled)
Definition: api_task.h:111
DSN_API void * dsn_msg_rw_ptr(dsn_message_t msg, size_t offset_begin)
get read/write pointer with the given offset
DSN_API void dsn_uri_destroy(dsn_uri_t uri)
destroy a URI address
DSN_API bool dsn_task_cancel2(dsn_task_t task, bool wait_until_finished, bool *finished)
cancel a task
DSN_API void dsn_task_cancel_current_timer()
cancel the later execution of the timer task inside the timer
DSN_API bool dsn_msg_read_next(dsn_message_t msg, void **ptr, size_t *size)
get message read buffer
rpc address, which is always encoded into a 64-bit integer
Definition: api_layer1.h:471
DSN_API dsn_message_t dsn_msg_create_response(dsn_message_t request)
create a RPC response message correspondent to the given request message
dsn_msg_parameter_type_t
type of the parameter in dsn_msg_context_t
Definition: api_layer1.h:663
DSN_API void dsn_file_task_enqueue(dsn_task_t cb_task, dsn_error_t err, size_t size)
mimic io completion when no io operation is really issued
DSN_API dsn_address_t dsn_group_get_leader(dsn_group_t g)
get leader from the group address
int32_t app_id
1-based app id (0 for invalid)
Definition: api_layer1.h:686
DSN_API dsn_task_t dsn_file_create_aio_task_ex(dsn_task_code_t code, dsn_aio_handler_t cb, dsn_task_cancelled_handler_t on_cancel, void *context, int hash DEFAULT(0), dsn_task_tracker_t tracker DEFAULT(nullptr))
create aio task which is executed on completion of the file operations
4 bytes for IPv4
Definition: api_layer1.h:465
DSN_API dsn_address_t dsn_primary_address()
get the primary address of the rpc engine attached to the current thread
DSN_API void dsn_rpc_call(dsn_address_t server, dsn_task_t rpc_call)
client invokes the RPC call
DSN_API void dsn_task_add_ref(dsn_task_t task)
Add reference count for a task created from dsn_task_create etc.
DSN_API void dsn_msg_add_ref(dsn_message_t msg)
add reference to the message, paired with /ref dsn_msg_release_ref
union dsn_msg_context_t dsn_msg_context_t
RPC message context.
DSN_API dsn_message_t dsn_rpc_call_wait(dsn_address_t server, dsn_message_t request)
client invokes the RPC call and waits for its response, note returned msg must be explicitly released...
void(* dsn_task_handler_t)(void *)
callback prototype for TASK_TYPE_COMPUTE
Definition: api_task.h:64
(throttling) maximum concurrent write ops
Definition: api_layer1.h:951
Definition: api_layer1.h:473
DSN_API dsn_group_t dsn_group_build(const char *name)
build a group address with a name, must be destroyed later using dsn_group_destroy ...
DSN_API uint32_t dsn_ipv4_local(const char *network_interface)
get local ipv4 according to the given network interface name
DSN_API void dsn_file_write_vector(dsn_handle_t file, const dsn_file_buffer_t *buffers, int buffer_count, uint64_t offset, dsn_task_t cb)
write file asynchronously with vector buffers
uint64_t context
msg_context is of sizeof(uint64_t)
Definition: api_layer1.h:680
DSN_API size_t dsn_msg_body_size(dsn_message_t msg)
get message body size
DSN_API dsn_task_t dsn_file_create_aio_task(dsn_task_code_t code, dsn_aio_handler_t cb, void *context, int hash DEFAULT(0), dsn_task_tracker_t tracker DEFAULT(nullptr))
create aio task which is executed on completion of the file operations
DSN_API dsn_task_t dsn_rpc_create_response_task(dsn_message_t request, dsn_rpc_response_handler_t cb, void *context, int reply_thread_hash DEFAULT(0), dsn_task_tracker_t tracker DEFAULT(nullptr))
create a callback task to handle the response message from RPC server, or timeout.
struct dsn_address_t::u_t::@2 v4
HOST_TYPE_IPV4
Definition: api_layer1.h:939
DSN_API void dsn_task_tracker_cancel_all(dsn_task_tracker_t tracker)
cancels all pending tasks bound to this tracker
DSN_API dsn_address_t dsn_group_forward_leader(dsn_group_t g)
set the next address after (circularly) the current leader as the group leader
DSN_API int dsn_group_count(dsn_group_t g)
get the RPC address count contained in the group address
unsigned long long group
dsn_group_t
Definition: api_layer1.h:486
DSN_API uint64_t dsn_random64(uint64_t min, uint64_t max)
return [min, max]
DSN_API void dsn_group_destroy(dsn_group_t g)
destroy the group address object
DSN_API void dsn_file_write(dsn_handle_t file, const char *buffer, int count, uint64_t offset, dsn_task_t cb)
write file asynchronously
DSN_API const char * dsn_address_to_string(dsn_address_t addr)
dump a RPC address to a meaningful string for logging purpose
DSN_API dsn_message_t dsn_msg_create_received_request(dsn_task_code_t rpc_code, dsn_msg_serialize_format serialization_type, void *buffer, int size, uint64_t hash DEFAULT(0))
explicitly create a received RPC request, MUST released mannually later using dsn_msg_release_ref ...
DSN_API dsn_task_t dsn_task_create(dsn_task_code_t code, dsn_task_handler_t cb, void *context, int hash DEFAULT(0), dsn_task_tracker_t tracker DEFAULT(nullptr))
create an asynchronous task.
DSN_API dsn_address_t dsn_address_build_ipv4(uint32_t ipv4, uint16_t port)
build a RPC address from a given ipv4 in host machine order and port
DSN_API bool dsn_group_add(dsn_group_t g, dsn_address_t ep)
add an RPC address into the group address
DSN_API void dsn_rpc_reply(dsn_message_t response, dsn_error_t err DEFAULT(0))
reply with a response which is created using dsn_msg_create_response
reference to an address group object
Definition: api_layer1.h:466
void(* dsn_rpc_request_handler_t)(dsn_message_t, void *)
callback prototype for TASK_TYPE_RPC_REQUEST
Definition: api_task.h:69
DSN_API bool dsn_task_cancel(dsn_task_t task, bool wait_until_finished)
cancel a task
Definition: api_layer1.h:683
DSN_API void dsn_rpc_enqueue_response(dsn_task_t rpc_call, dsn_error_t err, dsn_message_t response)
this is to mimic a response is received when no real rpc is called
DSN_API void dsn_task_tracker_destroy(dsn_task_tracker_t tracker)
destroy a task tracker, which cancels all pending tasks as well
DSN_API dsn_task_t dsn_task_create_ex(dsn_task_code_t code, dsn_task_handler_t cb, dsn_task_cancelled_handler_t on_cancel, void *context, int hash DEFAULT(0), dsn_task_tracker_t tracker DEFAULT(nullptr))
similar to dsn_task_create, except an on_cancel callback is provided to be executed when the task is ...
DSN_API void * dsn_rpc_unregiser_handler(dsn_task_code_t code, dsn_gpid gpid DEFAULT(dsn_gpid{0}))
unregister callback to handle RPC request, and returns void* context upon dsn_rpc_register_handler ...
DSN_API void dsn_task_set_delay(dsn_task_t task, int delay_ms)
set delay for a task
DSN_API dsn_address_t dsn_group_next(dsn_group_t g, dsn_address_t ep)
get the next address in the group right after (circularly) given ep, if ep is invalid, a random member is returned
dsn_msg_context_t context
see dsn_msg_context_t
Definition: api_layer1.h:708
DSN_API dsn_message_t dsn_msg_copy(dsn_message_t msg, bool clone_content, bool copy_for_receive)
make a copy of the given message
DSN_API void dsn_file_copy_remote_files(dsn_address_t remote, const char *source_dir, const char **source_files, const char *dest_dir, bool overwrite, dsn_task_t cb)
copy remote files to the local machine
DSN_API dsn_task_t dsn_task_create_timer_ex(dsn_task_code_t code, dsn_task_handler_t cb, dsn_task_cancelled_handler_t on_cancel, void *context, int hash, int interval_milliseconds, dsn_task_tracker_t tracker DEFAULT(nullptr))
similar to dsn_task_create_timer, except an on_cancel callback is provided to be executed when the ta...
void(* dsn_rpc_response_handler_t)(dsn_error_t, dsn_message_t, dsn_message_t, void *)
callback prototype for TASK_TYPE_RPC_RESPONSE
Definition: api_task.h:75
DSN_API void * dsn_file_native_handle(dsn_handle_t file)
get native handle: HANDLE for windows, int for non-windows
int timeout_ms
RPC timeout in milliseconds.
Definition: api_layer1.h:705
DSN_API void dsn_msg_release_ref(dsn_message_t msg)
release reference to the message, paired with /ref dsn_msg_add_ref
DSN_API void dsn_msg_get_options(dsn_message_t msg, dsn_msg_options_t *opts)
get options for the given message
DSN_API uint64_t dsn_msg_trace_id(dsn_message_t msg)
get trace id of the message
void dsn_address_size_checker()
make sure type sizes match as we simply use uint64_t across language boundaries
Definition: api_layer1.h:712
DSN_API dsn_uri_t dsn_uri_build(const char *url)
build URI address from a string URL, must be destroyed later using dsn_uri_destroy ...
RPC message context.
Definition: api_layer1.h:669
DSN_API dsn_handle_t dsn_exlock_create(bool recursive)
create a recursive? or not exlusive lock
DSN_API dsn_address_t dsn_msg_from_address(dsn_message_t msg)
get from-address where the message is sent
DSN_API void dsn_rpc_call_one_way(dsn_address_t server, dsn_message_t request)
one-way RPC from client, no rpc response is expected
DSN_API void dsn_msg_write_commit(dsn_message_t msg, size_t size)
commit the write buffer after the message content is written with the real written size ...
void(* dsn_aio_handler_t)(dsn_error_t, size_t, void *)
callback prototype for TASK_TYPE_AIO
Definition: api_task.h:83
DSN_API void dsn_task_call(dsn_task_t task, int delay_milliseconds DEFAULT(0))
start the task
DSN_API bool dsn_rpc_register_handler(dsn_task_code_t code, const char *name, dsn_rpc_request_handler_t cb, void *context, dsn_gpid gpid DEFAULT(dsn_gpid{0}))
register callback to handle RPC request
dsn_gpid gpid
virtual node id, 0 for none
Definition: api_layer1.h:707
options for RPC messages, used by dsn_msg_set_options and dsn_msg_get_options
Definition: api_layer1.h:703
DSN_API dsn_error_t dsn_task_error(dsn_task_t task)
get result error code of a task
DSN_API void dsn_file_copy_remote_directory(dsn_address_t remote, const char *source_dir, const char *dest_dir, bool overwrite, dsn_task_t cb)
copy remote directory to the local machine
DSN_API int dsn_task_get_ref(dsn_task_t task)
get reference for a given task handle
DSN_API void dsn_task_wait(dsn_task_t task)
wait until a task is completed
__inline uint32_t dsn_random32(uint32_t min, uint32_t max)
return [min, max]
Definition: api_layer1.h:1141
DSN_API void dsn_group_set_update_leader_automatically(dsn_group_t g, bool v)
set auto-update mode of the leader in rDSN runtime for this group address, true for yes ...
DSN_API bool dsn_task_is_running_inside(dsn_task_t t)
check whether the task is currently running inside the given task
DSN_API dsn_task_t dsn_task_create_timer(dsn_task_code_t code, dsn_task_handler_t cb, void *context, int hash, int interval_milliseconds, dsn_task_tracker_t tracker DEFAULT(nullptr))
create a timer task
DSN_API void dsn_msg_read_commit(dsn_message_t msg, size_t size)
commit the read buffer after the message content is read with the real read size, it is possible to u...
DSN_API dsn_message_t dsn_msg_create_request(dsn_task_code_t rpc_code, int timeout_milliseconds DEFAULT(0), uint64_t hash DEFAULT(0))
create a rpc request message
(batch) set write batch size
Definition: api_layer1.h:949
DSN_API dsn_address_t dsn_address_build_uri(dsn_uri_t uri)
build a RPC address from a URI address (created using dsn_uri_build)
DSN_API void dsn_task_tracker_wait_all(dsn_task_tracker_t tracker)
wait all pending tasks to be completed bound to this tracker
DSN_API dsn_task_t dsn_rpc_create_response_task_ex(dsn_message_t request, dsn_rpc_response_handler_t cb, dsn_task_cancelled_handler_t on_cancel, void *context, int reply_thread_hash DEFAULT(0), dsn_task_tracker_t tracker DEFAULT(nullptr))
create a callback task to handle the response message from RPC server, or timeout.
DSN_API bool dsn_task_wait_timeout(dsn_task_t task, int timeout_milliseconds)
wait until a task is completed
DSN_API dsn_error_t dsn_file_close(dsn_handle_t file)
close the file handle
DSN_API dsn_handle_t dsn_semaphore_create(int initial_count)
create a semaphore with initial count equals to inital_count
DSN_API dsn_address_t dsn_msg_to_address(dsn_message_t msg)
get to-address where the message is sent to
dsn_ctrl_code_t
the following ctrl code are used by dsn_file_ctrl.
Definition: api_layer1.h:946
DSN_API dsn_message_t dsn_rpc_get_response(dsn_task_t rpc_call)
get response message from the response task, note returned msg must be explicitly released using dsn_...
DSN_API dsn_task_code_t dsn_msg_task_code(dsn_message_t msg)
get task code of the message
nothing
Definition: api_layer1.h:665
DSN_API uint32_t dsn_ipv4_from_host(const char *name)
translate from hostname to ipv4 in host machine order
DSN_API dsn_handle_t dsn_file_open(const char *file_name, int flag, int pmode)
open file
universal resource identifier as a string
Definition: api_layer1.h:467
dsn_host_type_t
rpc address host type
Definition: api_layer1.h:462
DSN_API void dsn_msg_set_options(dsn_message_t msg, dsn_msg_options_t *opts, uint32_t mask)
set options for the given message
struct dsn_msg_options_t dsn_msg_options_t
options for RPC messages, used by dsn_msg_set_options and dsn_msg_get_options
DSN_API void dsn_group_set_leader(dsn_group_t g, dsn_address_t ep)
set an RPC address as the leader in the group address
DSN_API void dsn_msg_write_next(dsn_message_t msg, void **ptr, size_t *size, size_t min_size)
get message write buffer
DSN_API size_t dsn_file_get_io_size(dsn_task_t cb_task)
get read/written io size for the given aio task
DSN_API bool dsn_group_remove(dsn_group_t g, dsn_address_t ep)
remove an RPC address into the group address
struct dsn_address_t dsn_address_t
rpc address, which is always encoded into a 64-bit integer
DSN_API void dsn_rpc_forward(dsn_message_t request, dsn_address_t addr)
forward the request to another server instead
uint64_t hash
partition and thread hash
Definition: api_layer1.h:706
DSN_API dsn_address_t dsn_address_build(const char *host, uint16_t port)
build a RPC address from given host name or IPV4 string, and port
DSN_API dsn_task_tracker_t dsn_task_tracker_create(int task_bucket_count)
task trackers are used to track task context
DSN_API dsn_address_t dsn_address_build_group(dsn_group_t g)
build a RPC address from a group address (created using dsn_group_build)
DSN_API void dsn_task_release_ref(dsn_task_t task)
release reference for a given task handle
int32_t partition_index
zero-based partition index
Definition: api_layer1.h:687
dsn_msg_serialize_format
define various serialization format supported by rDSN, note any changes here must also be reflected i...
Definition: api_layer1.h:642
DSN_API bool dsn_group_is_leader(dsn_group_t g, dsn_address_t ep)
check whether the given endpoint is the leader in the group
(throttling) maximum concurrent read ops
Definition: api_layer1.h:950
DSN_API void dsn_file_read(dsn_handle_t file, char *buffer, int count, uint64_t offset, dsn_task_t cb)
read file asynchronously