Robust Distributed System Nucleus (rDSN)  ver 1.0.0
app_model.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  * application model in rDSN
30  *
31  * Revision history:
32  * Mar., 2015, @imzhenyu (Zhenyu Guo), first version
33  * xxxx-xx-xx, author, fix bug about xxx
34  */
35 
36 # pragma once
37 
38 # include <dsn/c/api_common.h>
39 
40 # ifdef __cplusplus
41 namespace dsn { class service_app; }
42 extern "C" {
43 # endif
44 
45 
99 typedef void* (*dsn_app_create)(
100  const char* app_name,
101  dsn_gpid id
102  );
103 
113 typedef dsn_error_t(*dsn_app_start)(
114  void* app,
115  int argc,
116  char** argv
117  );
118 
127 typedef dsn_error_t(*dsn_app_destroy)(
128  void* app,
129  bool cleanup
130  );
131 
141  void* app,
142  dsn_gpid gpid,
143  bool is_write_operation,
144  dsn_message_t request
145  );
146 
149 {
156  const char** files;
157 };
158 
159 
162 {
165 };
166 
176  void* app,
177  int64_t decree,
178  dsn_message_t* requests,
179  int request_count
180  );
181 
189  void* app
190  );
191 
200 typedef dsn_error_t(*dsn_app_sync_checkpoint)(
201  void* app,
202  int64_t last_decree
203  );
204 
213 typedef dsn_error_t(*dsn_app_async_checkpoint)(
214  void* app,
215  int64_t last_decree
216  );
217 
226  void* app
227  );
228 
241 typedef dsn_error_t(*dsn_app_prepare_get_checkpoint)(
242  void* app,
243  void* request_buffer,
244  int capacity,
245  /*out*/ int* used_size
246  );
247 
263 typedef dsn_error_t(*dsn_app_get_checkpoint)(
264  void* app,
265  int64_t learn_start_decree,
266  int64_t local_last_decree,
267  void* learn_request,
268  int learn_request_size,
269  dsn_app_learn_state* learn_state_buffer,
270  int capacity
271  );
272 
283 typedef dsn_error_t(*dsn_app_apply_checkpoint)(
284  void* app,
286  int64_t local_last_decree,
287  const dsn_app_learn_state* learn_state
288  );
289 
290 # define DSN_APP_MASK_APP 0x01
291 # define DSN_APP_MASK_FRAMEWORK 0x02
292 
293 
300 typedef dsn_error_t(*dsn_app_bridge_t)(int, const char**);
301 
302 # pragma pack(push, 4)
303 
309 typedef union dsn_app_callbacks
310 {
311  dsn_app_create placeholder[DSN_MAX_CALLBAC_COUNT];
313  {
314  dsn_app_on_batched_write_requests on_batched_write_requests;
315  dsn_app_get_physical_error get_physical_error;
316  dsn_app_sync_checkpoint sync_checkpoint;
317  dsn_app_async_checkpoint async_checkpoint;
318  dsn_app_get_last_checkpoint_decree get_last_checkpoint_decree;
319  dsn_app_prepare_get_checkpoint prepare_get_checkpoint;
320  dsn_app_get_checkpoint get_checkpoint;
321  dsn_app_apply_checkpoint apply_checkpoint;
322  } calls;
324 
325 
333 typedef struct dsn_app
334 {
335  uint64_t mask;
336  char type_name[DSN_MAX_APP_TYPE_NAME_LENGTH];
337 
340  {
344  } layer1;
345 
346  struct
347  {
349  struct layer2_framework_callbacks
350  {
351  dsn_framework_rpc_request_handler on_rpc_request;
352  } frameworks;
353 
356  } layer2;
357 } dsn_app;
358 # pragma pack(pop)
359 
360 # pragma pack(push, 4)
361 
362 typedef struct dsn_app_info
363 {
364  //
365  // app information
366  //
367  union {
369 # ifdef __cplusplus
370  ::dsn::service_app *app_ptr_cpp;
371 # endif
372  } app;
373 
374  int app_id;
375  int index;
376  char role[DSN_MAX_APP_TYPE_NAME_LENGTH];
377  char type[DSN_MAX_APP_TYPE_NAME_LENGTH];
378  char name[DSN_MAX_APP_TYPE_NAME_LENGTH];
379  char data_dir[DSN_MAX_PATH];
381 } dsn_app_info;
382 # pragma pack(pop)
383 
404 extern DSN_API bool dsn_register_app(dsn_app* app_type);
405 
415 extern DSN_API bool dsn_get_app_callbacks(const char* name, /* out */ dsn_app_callbacks* callbacks);
416 
435 extern DSN_API bool dsn_mimic_app(
436  const char* app_name,
437  int index
438  );
439 
448 extern DSN_API bool dsn_run_config(
449  const char* config,
450  bool sleep_after_init DEFAULT(false)
451  );
452 
475 extern DSN_API void dsn_run(int argc, char** argv, bool sleep_after_init DEFAULT(false));
476 
485 NORETURN extern DSN_API void dsn_exit(int code);
486 
498 extern DSN_API int dsn_get_all_apps(/*out*/ dsn_app_info* info_buffer, int count);
499 
507 extern DSN_API bool dsn_get_current_app_info(/*out*/ dsn_app_info* app_info);
508 
509 extern DSN_API dsn_app_info* dsn_get_app_info_ptr(dsn_gpid gpid DEFAULT(dsn_gpid{ 0 }));
510 
516 extern DSN_API const char* dsn_get_app_data_dir(dsn_gpid gpid DEFAULT(dsn_gpid{ 0 }));
517 
539 extern DSN_API void dsn_app_loader_signal();
540 
542 extern DSN_API void dsn_app_loader_wait();
543 
547 # ifdef __cplusplus
548 }
549 # endif
basic structure for state (e.g., full/delta checkpoint) transfer across nodes for an app...
Definition: app_model.h:148
dsn_error_t(* dsn_app_start)(void *app, int argc, char **argv)
callback to run the app with the app context, similar to main(argc, argv)
Definition: app_model.h:113
developers define the following dsn_app data structure, and passes it to rDSN through dsn_register_ap...
Definition: app_model.h:333
simply a checkpoint from remote machine is given, do not change the local state
Definition: app_model.h:163
struct dsn_app dsn_app
developers define the following dsn_app data structure, and passes it to rDSN through dsn_register_ap...
int64_t(* dsn_app_get_last_checkpoint_decree)(void *app)
get the decree of last done checkpoint, used by frameworks, implemented by apps
Definition: app_model.h:225
rpc address, which is always encoded into a 64-bit integer
Definition: api_layer1.h:471
int app_id
app id, see service_app_spec for more details.
Definition: app_model.h:374
dsn_address_t primary_address
primary address
Definition: app_model.h:380
DSN_API void dsn_app_loader_signal()
signal the application loader that application types are registered.
DSN_API void dsn_run(int argc, char **argv, bool sleep_after_init DEFAULT(false))
start the system with given arguments
int file_state_count
on-disk file count to be transferred
Definition: app_model.h:154
dsn_error_t(* dsn_app_destroy)(void *app, bool cleanup)
callback to stop and destroy the app
Definition: app_model.h:127
application information retrived at runtime
Definition: app_model.h:362
given a checkpoint from remote machine, prepare to change the local state
Definition: app_model.h:164
DSN_API const char * dsn_get_app_data_dir(dsn_gpid gpid DEFAULT(dsn_gpid{0}))
get current application data dir.
dsn_app_callbacks apps
app model (for integration with frameworks)
Definition: app_model.h:355
int64_t to_decree_included
the end decree of the state
Definition: app_model.h:152
struct dsn_app_info dsn_app_info
application information retrived at runtime
callbacks needed by the frameworks, application developers need to implement some of them so that cer...
Definition: app_model.h:309
int(* dsn_app_get_physical_error)(void *app)
get physical error (e.g., disk failure) from the app, used by frameworks, implemented by apps ...
Definition: app_model.h:188
dsn_app_start start
callback to start the app, similar to main
Definition: app_model.h:342
void * app_context_ptr
returned by dsn_app_create
Definition: app_model.h:368
dsn_app_destroy destroy
callback to stop and destroy the app
Definition: app_model.h:343
const char ** files
on-disk file path array, end with nullptr
Definition: app_model.h:156
Definition: api_layer1.h:683
NORETURN DSN_API void dsn_exit(int code)
exit the process with the given exit code
void *(* dsn_app_create)(const char *app_name, dsn_gpid id)
callback to create the app context
Definition: app_model.h:99
DSN_API bool dsn_mimic_app(const char *app_name, int index)
mimic an app as if the following execution in the current thread are executed in the target app&#39;s thr...
dsn_app_create create
callback to create the context for the app
Definition: app_model.h:341
int total_learn_state_size
memory used in the given buffer by this learn-state
Definition: app_model.h:150
app definition, mask = DSN_APP_MASK_APP
Definition: app_model.h:339
DSN_API int dsn_get_all_apps(dsn_app_info *info_buffer, int count)
get rDSN application (instance)s information in the current process
dsn_error_t(* dsn_app_apply_checkpoint)(void *app, dsn_chkpt_apply_mode mode, int64_t local_last_decree, const dsn_app_learn_state *learn_state)
apply checkpoint from remote nodes, used by frameworks, implemented by apps
Definition: app_model.h:283
DSN_API bool dsn_register_app(dsn_app *app_type)
register application/framework into rDSN runtime
dsn_error_t(* dsn_app_async_checkpoint)(void *app, int64_t last_decree)
checkpoint the application asynchronously, used by frameworks, implemented by apps ...
Definition: app_model.h:213
Definition: app_model.h:312
Definition: service_app.h:51
int meta_state_size
in-memory state size as stored in meta_state_ptr below
Definition: app_model.h:153
DSN_API bool dsn_get_app_callbacks(const char *name, dsn_app_callbacks *callbacks)
get application callbacks registered into rDSN runtime
Definition: address.h:52
dsn_error_t(* dsn_app_sync_checkpoint)(void *app, int64_t last_decree)
checkpoint the application synchronously, used by frameworks, implemented by apps ...
Definition: app_model.h:200
void(* dsn_framework_rpc_request_handler)(void *app, dsn_gpid gpid, bool is_write_operation, dsn_message_t request)
callback for framework to handle incoming rpc request, implemented by frameworks
Definition: app_model.h:140
void(* dsn_app_on_batched_write_requests)(void *app, int64_t decree, dsn_message_t *requests, int request_count)
batched rpc request from frameworks, used by frameworks, implemented by apps
Definition: app_model.h:175
DSN_API bool dsn_run_config(const char *config, bool sleep_after_init DEFAULT(false))
start the system with given configuration
int index
app role index
Definition: app_model.h:375
union dsn_app_callbacks dsn_app_callbacks
callbacks needed by the frameworks, application developers need to implement some of them so that cer...
dsn_error_t(* dsn_app_prepare_get_checkpoint)(void *app, void *request_buffer, int capacity, int *used_size)
learner prepares a get checkpoint request for better fitting the local state (e.g., for delta learning), the request will be used by dsn_app_get_checkpoint below, used by frameworks, implemented by apps
Definition: app_model.h:241
dsn_error_t(* dsn_app_bridge_t)(int, const char **)
when the service cannot automatically register its app types into rdsn through dmoudule&#39;s dllmain or ...
Definition: app_model.h:300
DSN_API bool dsn_get_current_app_info(dsn_app_info *app_info)
get current rDSN application information.
int64_t from_decree_excluded
the start decree(sequence number, version) of the state
Definition: app_model.h:151
uint64_t mask
application capability mask
Definition: app_model.h:335
void * meta_state_ptr
in-memory state
Definition: app_model.h:155
dsn_chkpt_apply_mode
checkpoint apply mode, see dsn_app_apply_checkpoint, used by frameworks
Definition: app_model.h:161
DSN_API void dsn_app_loader_wait()
wait signal from dsn_app_loader_signal.
dsn_error_t(* dsn_app_get_checkpoint)(void *app, int64_t learn_start_decree, int64_t local_last_decree, void *learn_request, int learn_request_size, dsn_app_learn_state *learn_state_buffer, int capacity)
get checkpoint information from learnee, used by frameworks, implemented by apps
Definition: app_model.h:263