Robust Distributed System Nucleus (rDSN)  ver 1.0.0
api_layer1.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2015 Microsoft Corporation
5  *
6  * -=- Robust Distributed System Nucleus (rDSN) -=-
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 /*
28  * Description:
29  * Service API in rDSN
30  *
31  * Revision history:
32  * Mar., 2015, @imzhenyu (Zhenyu Guo), first version
33  * Feb., 2016, @imzhenyu (Zhenyu Guo), add comments for V1 release
34  * xxxx-xx-xx, author, fix bug about xxx
35  */
36 
37 # pragma once
38 
39 # include <dsn/c/api_common.h>
40 # include <dsn/c/api_task.h>
41 
42 # ifdef __cplusplus
43 extern "C" {
44 # endif
45 
201 extern DSN_API void dsn_task_add_ref(dsn_task_t task);
202 
210 extern DSN_API void dsn_task_release_ref(dsn_task_t task);
211 
219 extern DSN_API int dsn_task_get_ref(dsn_task_t task);
220 
230 extern DSN_API bool dsn_task_cancel(dsn_task_t task, bool wait_until_finished);
231 
238 extern DSN_API void dsn_task_set_delay(dsn_task_t task, int delay_ms);
239 
251 extern DSN_API bool dsn_task_cancel2(
252  dsn_task_t task,
253  bool wait_until_finished,
254  /*out*/ bool* finished
255  );
256 
258 extern DSN_API void dsn_task_cancel_current_timer();
259 
267 extern DSN_API void dsn_task_wait(dsn_task_t task);
268 
277 extern DSN_API bool dsn_task_wait_timeout(
278  dsn_task_t task,
279  int timeout_milliseconds
280  );
281 
289 extern DSN_API dsn_error_t dsn_task_error(dsn_task_t task);
290 
298 extern DSN_API bool dsn_task_is_running_inside(dsn_task_t t);
299 
312 extern DSN_API dsn_task_tracker_t dsn_task_tracker_create(int task_bucket_count);
313 
319 extern DSN_API void dsn_task_tracker_destroy(dsn_task_tracker_t tracker);
320 
326 extern DSN_API void dsn_task_tracker_cancel_all(dsn_task_tracker_t tracker);
327 
333 extern DSN_API void dsn_task_tracker_wait_all(dsn_task_tracker_t tracker);
334 
364 extern DSN_API dsn_task_t dsn_task_create(
365  dsn_task_code_t code,
367  void* context,
368  int hash DEFAULT(0),
369  dsn_task_tracker_t tracker DEFAULT(nullptr)
370  );
371 
392 extern DSN_API dsn_task_t dsn_task_create_timer(
393  dsn_task_code_t code,
394  dsn_task_handler_t cb,
395  void* context,
396  int hash,
397  int interval_milliseconds,
398  dsn_task_tracker_t tracker DEFAULT(nullptr)
399  );
400 
406 extern DSN_API dsn_task_t dsn_task_create_ex(
407  dsn_task_code_t code, // task label
408  dsn_task_handler_t cb, // callback function
409  dsn_task_cancelled_handler_t on_cancel,
410  void* context, // context to the two callbacks above
411  int hash DEFAULT(0), // hash to callback
412  dsn_task_tracker_t tracker DEFAULT(nullptr)
413  );
414 
420 extern DSN_API dsn_task_t dsn_task_create_timer_ex(
421  dsn_task_code_t code,
424  void* context,
425  int hash,
426  int interval_milliseconds, // timer period
427  dsn_task_tracker_t tracker DEFAULT(nullptr)
428  );
429 
436 extern DSN_API void dsn_task_call(
437  dsn_task_t task,
438  int delay_milliseconds DEFAULT(0)
439  );
462 typedef enum dsn_host_type_t
463 {
464  HOST_TYPE_INVALID = 0,
469 
471 typedef struct dsn_address_t
472 {
473  union u_t {
474  struct {
475  unsigned long long type : 2;
476  unsigned long long padding : 14;
477  unsigned long long port : 16;
478  unsigned long long ip : 32;
479  } v4;
480  struct {
481  unsigned long long type : 2;
482  unsigned long long uri : 62;
483  } uri;
484  struct {
485  unsigned long long type : 2;
486  unsigned long long group : 62;
487  } group;
488  uint64_t value;
489  } u;
490 } dsn_address_t;
491 
493 extern DSN_API uint32_t dsn_ipv4_from_host(const char* name);
494 
496 extern DSN_API uint32_t dsn_ipv4_local(const char* network_interface);
497 
499 extern DSN_API dsn_address_t dsn_address_build(
500  const char* host,
501  uint16_t port
502  );
503 
506  uint32_t ipv4,
507  uint16_t port
508  );
509 
512  dsn_group_t g
513  );
514 
516 extern DSN_API dsn_address_t dsn_address_build_uri(
517  dsn_uri_t uri
518  );
519 
521 extern DSN_API const char* dsn_address_to_string(dsn_address_t addr);
522 
524 extern DSN_API dsn_uri_t dsn_uri_build(const char* url);
525 
527 extern DSN_API void dsn_uri_destroy(dsn_uri_t uri);
528 
530 extern DSN_API dsn_group_t dsn_group_build(const char* name);
531 
533 extern DSN_API int dsn_group_count(dsn_group_t g);
534 
536 extern DSN_API bool dsn_group_add(dsn_group_t g, dsn_address_t ep);
537 
539 extern DSN_API bool dsn_group_remove(dsn_group_t g, dsn_address_t ep);
540 
542 extern DSN_API void dsn_group_set_leader(dsn_group_t g, dsn_address_t ep);
543 
545 extern DSN_API dsn_address_t dsn_group_get_leader(dsn_group_t g);
546 
548 extern DSN_API bool dsn_group_is_leader(dsn_group_t g, dsn_address_t ep);
549 
551 extern DSN_API bool dsn_group_is_update_leader_automatically(dsn_group_t g);
552 
554 extern DSN_API void dsn_group_set_update_leader_automatically(dsn_group_t g, bool v);
555 
557 extern DSN_API dsn_address_t dsn_group_next(dsn_group_t g, dsn_address_t ep);
558 
560 extern DSN_API dsn_address_t dsn_group_forward_leader(dsn_group_t g);
561 
563 extern DSN_API void dsn_group_destroy(dsn_group_t g);
564 
566 extern DSN_API dsn_address_t dsn_primary_address();
567 
623 extern DSN_API dsn_message_t dsn_msg_create_request(
624  dsn_task_code_t rpc_code,
625  int timeout_milliseconds DEFAULT(0),
626  uint64_t hash DEFAULT(0)
627  );
628 
630 extern DSN_API dsn_message_t dsn_msg_create_response(dsn_message_t request);
631 
633 extern DSN_API dsn_message_t dsn_msg_copy(dsn_message_t msg, bool clone_content, bool copy_for_receive);
634 
636 extern DSN_API void dsn_msg_add_ref(dsn_message_t msg);
637 
639 extern DSN_API void dsn_msg_release_ref(dsn_message_t msg);
640 
643 {
644  DSF_INVALID = 0,
645  DSF_THRIFT_BINARY = 1,
646  DSF_THRIFT_COMPACT = 2,
647  DSF_THRIFT_JSON = 3,
648  DSF_PROTOC_BINARY = 4,
649  DSF_PROTOC_JSON = 5,
650  DSF_JSON = 6
652 
654 extern DSN_API dsn_message_t dsn_msg_create_received_request(
655  dsn_task_code_t rpc_code,
656  dsn_msg_serialize_format serialization_type,
657  void* buffer,
658  int size,
659  uint64_t hash DEFAULT(0)
660  );
661 
664 {
667 
669 typedef union dsn_msg_context_t
670 {
671  struct {
672  uint64_t is_request : 1;
673  uint64_t is_forwarded : 1;
674  uint64_t unused : 4;
675  uint64_t serialize_format : 4;
676  uint64_t is_forward_supported : 1;
677  uint64_t parameter_type : 3;
678  uint64_t parameter : 50;
679  } u;
680  uint64_t context;
682 
684 {
685  struct {
686  int32_t app_id;
687  int32_t partition_index;
688  } u;
689  uint64_t value;
690 } dsn_gpid;
691 
692 inline uint64_t dsn_gpid_to_hash(dsn_gpid gpid)
693 {
694  return (((uint64_t)gpid.u.app_id) << 32) + gpid.u.partition_index;
695 }
696 
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)
701 
702 
703 typedef struct dsn_msg_options_t
704 {
706  uint64_t hash;
710 
713 {
714  static_assert (sizeof(dsn_address_t) == sizeof(uint64_t),
715  "sizeof(dsn_address_t) must equal to sizeof(uint64_t)");
716 
717  static_assert (sizeof(dsn_msg_context_t) == sizeof(uint64_t),
718  "sizeof(dsn_msg_context_t) must equal to sizeof(uint64_t)");
719 
720  static_assert (sizeof(dsn_gpid) == sizeof(uint64_t),
721  "sizeof(dsn_gpid) must equal to sizeof(uint64_t)");
722 }
723 
731 extern DSN_API void dsn_msg_set_options(
732  dsn_message_t msg,
733  dsn_msg_options_t *opts,
734  uint32_t mask
735  );
736 
743 extern DSN_API void dsn_msg_get_options(
744  dsn_message_t msg,
745  /*out*/ dsn_msg_options_t* opts
746  );
747 
748 DSN_API void dsn_msg_set_serailize_format(dsn_message_t msg, dsn_msg_serialize_format fmt);
749 
750 DSN_API dsn_msg_serialize_format dsn_msg_get_serialize_format(dsn_message_t msg);
751 
753 extern DSN_API size_t dsn_msg_body_size(dsn_message_t msg);
754 
756 extern DSN_API void* dsn_msg_rw_ptr(dsn_message_t msg, size_t offset_begin);
757 
759 extern DSN_API dsn_address_t dsn_msg_from_address(dsn_message_t msg);
760 
762 extern DSN_API dsn_address_t dsn_msg_to_address(dsn_message_t msg);
763 
765 extern DSN_API uint64_t dsn_msg_trace_id(dsn_message_t msg);
766 
768 extern DSN_API dsn_task_code_t dsn_msg_task_code(dsn_message_t msg);
769 
778 extern DSN_API void dsn_msg_write_next(
779  dsn_message_t msg,
780  /*out*/ void** ptr,
781  /*out*/ size_t* size,
782  size_t min_size
783  );
784 
786 extern DSN_API void dsn_msg_write_commit(dsn_message_t msg, size_t size);
787 
797 extern DSN_API bool dsn_msg_read_next(
798  dsn_message_t msg,
799  /*out*/ void** ptr,
800  /*out*/ size_t* size
801  );
802 
806 extern DSN_API void dsn_msg_read_commit(dsn_message_t msg, size_t size);
807 
818 extern DSN_API bool dsn_rpc_register_handler(
819  dsn_task_code_t code,
820  const char* name,
822  void* context,
823  dsn_gpid gpid DEFAULT(dsn_gpid{ 0 })
824  );
825 
827 extern DSN_API void* dsn_rpc_unregiser_handler(
828  dsn_task_code_t code,
829  dsn_gpid gpid DEFAULT(dsn_gpid{ 0 })
830  );
831 
833 extern DSN_API void dsn_rpc_reply(dsn_message_t response, dsn_error_t err DEFAULT(0));
834 
836 extern DSN_API void dsn_rpc_forward(dsn_message_t request, dsn_address_t addr);
837 
838 
861 extern DSN_API dsn_task_t dsn_rpc_create_response_task(
862  dsn_message_t request,
864  void* context,
865  int reply_thread_hash DEFAULT(0),
866  dsn_task_tracker_t tracker DEFAULT(nullptr)
867  );
868 
883 extern DSN_API dsn_task_t dsn_rpc_create_response_task_ex(
884  dsn_message_t request,
887  void* context,
888  int reply_thread_hash DEFAULT(0),
889  dsn_task_tracker_t tracker DEFAULT(nullptr)
890  );
891 
893 extern DSN_API void dsn_rpc_call(
894  dsn_address_t server,
895  dsn_task_t rpc_call
896  );
897 
902 extern DSN_API dsn_message_t dsn_rpc_call_wait(
903  dsn_address_t server,
904  dsn_message_t request
905  );
906 
908 extern DSN_API void dsn_rpc_call_one_way(
909  dsn_address_t server,
910  dsn_message_t request
911  );
912 
917 extern DSN_API dsn_message_t dsn_rpc_get_response(dsn_task_t rpc_call);
918 
920 extern DSN_API void dsn_rpc_enqueue_response(
921  dsn_task_t rpc_call,
922  dsn_error_t err,
923  dsn_message_t response
924  );
925 
929 
939 typedef struct
940 {
941  void* buffer;
942  int size;
944 
946 typedef enum dsn_ctrl_code_t
947 {
948  CTL_BATCH_INVALID = 0,
953 
963 extern DSN_API dsn_handle_t dsn_file_open(
964  const char* file_name,
965  int flag,
966  int pmode
967  );
968 
970 extern DSN_API dsn_error_t dsn_file_close(
971  dsn_handle_t file
972  );
973 
975 extern DSN_API dsn_error_t dsn_file_flush(
976  dsn_handle_t file
977  );
978 
980 extern DSN_API void* dsn_file_native_handle(dsn_handle_t file);
981 
993 extern DSN_API dsn_task_t dsn_file_create_aio_task(
994  dsn_task_code_t code,
995  dsn_aio_handler_t cb,
996  void* context,
997  int hash DEFAULT(0),
998  dsn_task_tracker_t tracker DEFAULT(nullptr)
999  );
1000 
1013 extern DSN_API dsn_task_t dsn_file_create_aio_task_ex(
1014  dsn_task_code_t code,
1015  dsn_aio_handler_t cb,
1016  dsn_task_cancelled_handler_t on_cancel,
1017  void* context,
1018  int hash DEFAULT(0),
1019  dsn_task_tracker_t tracker DEFAULT(nullptr)
1020  );
1021 
1031 extern DSN_API void dsn_file_read(
1032  dsn_handle_t file,
1033  char* buffer,
1034  int count,
1035  uint64_t offset,
1036  dsn_task_t cb
1037  );
1038 
1048 extern DSN_API void dsn_file_write(
1049  dsn_handle_t file,
1050  const char* buffer,
1051  int count,
1052  uint64_t offset,
1053  dsn_task_t cb
1054  );
1055 
1065 extern DSN_API void dsn_file_write_vector(
1066  dsn_handle_t file,
1067  const dsn_file_buffer_t* buffers,
1068  int buffer_count,
1069  uint64_t offset,
1070  dsn_task_t cb
1071  );
1072 
1082 extern DSN_API void dsn_file_copy_remote_directory(
1083  dsn_address_t remote,
1084  const char* source_dir,
1085  const char* dest_dir,
1086  bool overwrite,
1087  dsn_task_t cb
1088  );
1089 
1101 extern DSN_API void dsn_file_copy_remote_files(
1102  dsn_address_t remote,
1103  const char* source_dir,
1104  const char** source_files,
1105  const char* dest_dir,
1106  bool overwrite,
1107  dsn_task_t cb
1108  );
1109 
1111 extern DSN_API size_t dsn_file_get_io_size(dsn_task_t cb_task);
1112 
1114 extern DSN_API void dsn_file_task_enqueue(
1115  dsn_task_t cb_task,
1116  dsn_error_t err,
1117  size_t size
1118  );
1119 
1120 
1132 extern DSN_API uint64_t dsn_now_ns();
1133 
1135 extern DSN_API uint64_t dsn_random64(uint64_t min, uint64_t max);
1136 
1137 __inline uint64_t dsn_now_us() { return dsn_now_ns() / 1000; }
1138 __inline uint64_t dsn_now_ms() { return dsn_now_ns() / 1000000; }
1139 
1141 __inline uint32_t dsn_random32(uint32_t min, uint32_t max)
1142 {
1143  return (uint32_t)(dsn_random64(min, max));
1144 }
1145 
1146 __inline double dsn_probability()
1147 {
1148  return (double)(dsn_random64(0, 1000000000)) / 1000000000.0;
1149 }
1150 
1170 extern DSN_API dsn_handle_t dsn_exlock_create(bool recursive);
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);
1198 extern DSN_API dsn_handle_t dsn_semaphore_create(int initial_count);
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(
1203  dsn_handle_t s,
1204  int timeout_milliseconds
1205  );
1209 
1212 # ifdef __cplusplus
1213 }
1214 # endif
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