38 # include <dsn/service_api_c.h> 39 # include <dsn/utility/ports.h> 40 # include <dsn/utility/autoref_ptr.h> 44 #ifdef DSN_USE_THRIFT_SERIALIZATION 45 # include <thrift/protocol/TProtocol.h> 48 # define TRACK_ERROR_CODE 1 52 typedef void(*safe_handle_release)(
void*);
54 template<safe_handle_release releaser>
70 void assign(
void* handle,
bool is_owner)
78 void set_owner(
bool owner =
true)
88 void* native_handle()
const {
return _handle; }
93 if (_is_owner &&
nullptr != _handle)
111 gpid(
int app_id,
int pidx)
124 _value.value = gd._value.value;
132 uint64_t value()
const 142 bool operator < (
const gpid & r)
const 148 bool operator == (
const gpid & r)
const 150 return value() == r.value();
153 bool operator != (
const gpid & r)
const 155 return value() != r.value();
158 int32_t get_app_id()
const {
return _value.u.
app_id; }
159 int32_t get_partition_index()
const {
return _value.u.
partition_index; }
160 void set_app_id(int32_t v) { _value.u.
app_id = v; }
164 #ifdef DSN_USE_THRIFT_SERIALIZATION 165 uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
166 uint32_t write(::apache::thrift::protocol::TProtocol* oprot)
const;
189 _internal_code = code;
194 _internal_code = r._internal_code;
197 const char* to_string()
const 199 return dsn_task_code_to_string(_internal_code);
204 _internal_code = source._internal_code;
210 return _internal_code == r._internal_code;
215 return !(*
this == r);
218 operator dsn_task_code_t()
const 220 return _internal_code;
223 #ifdef DSN_USE_THRIFT_SERIALIZATION 224 uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
225 uint32_t write(::apache::thrift::protocol::TProtocol* oprot)
const;
228 dsn_task_code_t _internal_code;
231 #define DEFINE_NAMED_TASK_CODE(x, name, pri, pool) __selectany const ::dsn::task_code x(#name, TASK_TYPE_COMPUTE, pri, pool); 232 #define DEFINE_NAMED_TASK_CODE_AIO(x, name, pri, pool) __selectany const ::dsn::task_code x(#name, TASK_TYPE_AIO, pri, pool); 233 #define DEFINE_NAMED_TASK_CODE_RPC(x, name, pri, pool) \ 234 __selectany const ::dsn::task_code x(#name, TASK_TYPE_RPC_REQUEST, pri, pool); \ 235 __selectany const ::dsn::task_code x##_ACK(#name"_ACK", TASK_TYPE_RPC_RESPONSE, pri, pool); 238 #define DEFINE_TASK_CODE(x, pri, pool) DEFINE_NAMED_TASK_CODE(x, x, pri, pool) 239 #define DEFINE_TASK_CODE_AIO(x, pri, pool) DEFINE_NAMED_TASK_CODE_AIO(x, x, pri, pool) 240 #define DEFINE_TASK_CODE_RPC(x, pri, pool) DEFINE_NAMED_TASK_CODE_RPC(x, x, pri, pool) 257 _internal_code = r._internal_code;
260 const char* to_string()
const 262 return dsn_task_code_to_string(_internal_code);
267 _internal_code = source._internal_code;
273 return _internal_code == r._internal_code;
278 return !(*
this == r);
281 operator dsn_threadpool_code_t()
const 283 return _internal_code;
287 dsn_threadpool_code_t _internal_code;
291 #define DEFINE_THREAD_POOL_CODE(x) __selectany const ::dsn::threadpool_code x(#x); 296 DEFINE_TASK_CODE(TASK_CODE_INVALID, TASK_PRIORITY_COMMON, THREAD_POOL_DEFAULT)
306 error_code(
const char* name)
310 dassert (name,
"name for an error code cannot be empty");
311 # ifdef TRACK_ERROR_CODE 320 # ifdef TRACK_ERROR_CODE 325 error_code(dsn_error_t err)
327 _internal_code = err;
329 # ifdef TRACK_ERROR_CODE 334 error_code(
const error_code& err)
336 _internal_code = err._internal_code;
337 # ifdef TRACK_ERROR_CODE 343 const char* to_string()
const 345 # ifdef TRACK_ERROR_CODE 351 error_code& operator=(
const error_code& source)
353 _internal_code = source._internal_code;
354 # ifdef TRACK_ERROR_CODE 361 bool operator == (
const error_code& r)
363 # ifdef TRACK_ERROR_CODE 367 return _internal_code == r._internal_code;
370 bool operator != (
const error_code& r)
372 return !(*
this == r);
375 # ifdef TRACK_ERROR_CODE 383 if (_internal_code != 0)
385 dlog(LOG_LEVEL_ERROR,
"error-code",
386 "error code is not handled, err = %s", to_string());
392 dsn_error_t
get()
const 394 # ifdef TRACK_ERROR_CODE 397 return _internal_code;
400 operator dsn_error_t()
const 402 # ifdef TRACK_ERROR_CODE 405 return _internal_code;
408 void end_tracking()
const 410 # ifdef TRACK_ERROR_CODE 415 #ifdef DSN_USE_THRIFT_SERIALIZATION 416 uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
417 uint32_t write(::apache::thrift::protocol::TProtocol* oprot)
const;
420 # ifdef TRACK_ERROR_CODE 423 dsn_error_t _internal_code;
426 #define DEFINE_ERR_CODE(x) __selectany const dsn::error_code x(#x); 428 DEFINE_ERR_CODE(ERR_OK)
430 DEFINE_ERR_CODE(ERR_UNKNOWN)
431 DEFINE_ERR_CODE(ERR_SERVICE_NOT_FOUND)
432 DEFINE_ERR_CODE(ERR_SERVICE_ALREADY_RUNNING)
433 DEFINE_ERR_CODE(ERR_IO_PENDING)
434 DEFINE_ERR_CODE(ERR_TIMEOUT)
435 DEFINE_ERR_CODE(ERR_SERVICE_NOT_ACTIVE)
436 DEFINE_ERR_CODE(ERR_BUSY)
437 DEFINE_ERR_CODE(ERR_NETWORK_INIT_FAILED)
438 DEFINE_ERR_CODE(ERR_FORWARD_TO_OTHERS)
439 DEFINE_ERR_CODE(ERR_OBJECT_NOT_FOUND)
441 DEFINE_ERR_CODE(ERR_HANDLER_NOT_FOUND)
442 DEFINE_ERR_CODE(ERR_LEARN_FILE_FAILED)
443 DEFINE_ERR_CODE(ERR_GET_LEARN_STATE_FAILED)
444 DEFINE_ERR_CODE(ERR_INVALID_VERSION)
445 DEFINE_ERR_CODE(ERR_INVALID_PARAMETERS)
446 DEFINE_ERR_CODE(ERR_CAPACITY_EXCEEDED)
447 DEFINE_ERR_CODE(ERR_INVALID_STATE)
448 DEFINE_ERR_CODE(ERR_INACTIVE_STATE)
449 DEFINE_ERR_CODE(ERR_NOT_ENOUGH_MEMBER)
450 DEFINE_ERR_CODE(ERR_FILE_OPERATION_FAILED)
452 DEFINE_ERR_CODE(ERR_HANDLE_EOF)
453 DEFINE_ERR_CODE(ERR_WRONG_CHECKSUM)
454 DEFINE_ERR_CODE(ERR_INVALID_DATA)
455 DEFINE_ERR_CODE(ERR_INVALID_HANDLE)
456 DEFINE_ERR_CODE(ERR_INCOMPLETE_DATA)
457 DEFINE_ERR_CODE(ERR_VERSION_OUTDATED)
458 DEFINE_ERR_CODE(ERR_PATH_NOT_FOUND)
459 DEFINE_ERR_CODE(ERR_PATH_ALREADY_EXIST)
460 DEFINE_ERR_CODE(ERR_ADDRESS_ALREADY_USED)
461 DEFINE_ERR_CODE(ERR_STATE_FREEZED)
463 DEFINE_ERR_CODE(ERR_LOCAL_APP_FAILURE)
464 DEFINE_ERR_CODE(ERR_BIND_IOCP_FAILED)
465 DEFINE_ERR_CODE(ERR_NETWORK_START_FAILED)
466 DEFINE_ERR_CODE(ERR_NOT_IMPLEMENTED)
467 DEFINE_ERR_CODE(ERR_CHECKPOINT_FAILED)
468 DEFINE_ERR_CODE(ERR_WRONG_TIMING)
469 DEFINE_ERR_CODE(ERR_NO_NEED_OPERATE)
470 DEFINE_ERR_CODE(ERR_CORRUPTION)
471 DEFINE_ERR_CODE(ERR_TRY_AGAIN)
472 DEFINE_ERR_CODE(ERR_CLUSTER_NOT_FOUND)
474 DEFINE_ERR_CODE(ERR_CLUSTER_ALREADY_EXIST)
475 DEFINE_ERR_CODE(ERR_SERVICE_ALREADY_EXIST)
476 DEFINE_ERR_CODE(ERR_INJECTED)
477 DEFINE_ERR_CODE(ERR_REPLICATION_FAILURE)
478 DEFINE_ERR_CODE(ERR_APP_EXIST)
479 DEFINE_ERR_CODE(ERR_APP_NOT_EXIST)
480 DEFINE_ERR_CODE(ERR_BUSY_CREATING)
481 DEFINE_ERR_CODE(ERR_BUSY_DROPPING)
482 DEFINE_ERR_CODE(ERR_NETWORK_FAILURE)
#define DEFINE_TASK_CODE(x, pri, pool)
define a new task code with TASK_TYPE_COMPUTATION
Definition: auto_codes.h:238
Definition: auto_codes.h:242
dsn_task_priority_t
task priority
Definition: api_task.h:90
int32_t app_id
1-based app id (0 for invalid)
Definition: api_layer1.h:686
DSN_API dsn_error_t dsn_error_register(const char *name)
register error code
Definition: auto_codes.h:55
DSN_API dsn_threadpool_code_t dsn_threadpool_code_register(const char *name)
define a new thread pool with a given name
Definition: auto_codes.h:174
Definition: auto_codes.h:303
Definition: auto_codes.h:105
Definition: api_layer1.h:683
#define DEFINE_THREAD_POOL_CODE(x)
define a new thread pool named x
Definition: auto_codes.h:291
DSN_API dsn_task_code_t dsn_task_code_register(const char *name, dsn_task_type_t type, dsn_task_priority_t, dsn_threadpool_code_t pool)
register a new task code
dsn_task_type_t
task/event type definition
Definition: api_task.h:50
DSN_API const char * dsn_error_to_string(dsn_error_t err)
translate interger error code to a string
int32_t partition_index
zero-based partition index
Definition: api_layer1.h:687