mirror of
https://github.com/wassname/ray.git
synced 2026-09-09 11:32:43 +08:00
Use scoped enums in C++ and flatbuffers. (#2194)
* Enable --scoped-enums in flatbuffer compiler. * Change enum to c++11 style (enum class). * Resolve conflicts. * Solve building failure when RAY_USE_NEW_GCS=on and remove ERROR_INDEX suffix. * Merge with master and fix CI failure.
This commit is contained in:
committed by
Philipp Moritz
parent
f0907a6ee9
commit
0a34bea0b0
@@ -24,7 +24,7 @@ add_custom_command(
|
||||
# flatbuffers message Message, which can be used to store deserialized
|
||||
# messages in data structures. This is currently used for ObjectInfo for
|
||||
# example.
|
||||
COMMAND ${FLATBUFFERS_COMPILER} -c -o ${OUTPUT_DIR} ${COMMON_FBS_SRC} --gen-object-api
|
||||
COMMAND ${FLATBUFFERS_COMPILER} -c -o ${OUTPUT_DIR} ${COMMON_FBS_SRC} --gen-object-api --scoped-enums
|
||||
DEPENDS ${FBS_DEPENDS}
|
||||
COMMENT "Running flatc compiler on ${COMMON_FBS_SRC}"
|
||||
VERBATIM)
|
||||
|
||||
+6
-4
@@ -322,7 +322,7 @@ void read_message(int fd, int64_t *type, int64_t *length, uint8_t **bytes) {
|
||||
|
||||
disconnected:
|
||||
/* Handle the case in which the socket is closed. */
|
||||
*type = DISCONNECT_CLIENT;
|
||||
*type = static_cast<int64_t>(CommonMessageType::DISCONNECT_CLIENT);
|
||||
*length = 0;
|
||||
*bytes = NULL;
|
||||
return;
|
||||
@@ -382,13 +382,14 @@ int64_t read_vector(int fd, int64_t *type, std::vector<uint8_t> &buffer) {
|
||||
return length;
|
||||
disconnected:
|
||||
/* Handle the case in which the socket is closed. */
|
||||
*type = DISCONNECT_CLIENT;
|
||||
*type = static_cast<int64_t>(CommonMessageType::DISCONNECT_CLIENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void write_log_message(int fd, const char *message) {
|
||||
/* Account for the \0 at the end of the string. */
|
||||
write_message(fd, LOG_MESSAGE, strlen(message) + 1, (uint8_t *) message);
|
||||
write_message(fd, static_cast<int64_t>(CommonMessageType::LOG_MESSAGE),
|
||||
strlen(message) + 1, (uint8_t *) message);
|
||||
}
|
||||
|
||||
char *read_log_message(int fd) {
|
||||
@@ -396,6 +397,7 @@ char *read_log_message(int fd) {
|
||||
int64_t type;
|
||||
int64_t length;
|
||||
read_message(fd, &type, &length, &bytes);
|
||||
RAY_CHECK(type == LOG_MESSAGE);
|
||||
RAY_CHECK(static_cast<CommonMessageType>(type) ==
|
||||
CommonMessageType::LOG_MESSAGE);
|
||||
return (char *) bytes;
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
struct aeEventLoop;
|
||||
typedef aeEventLoop event_loop;
|
||||
|
||||
enum common_message_type {
|
||||
enum class CommonMessageType : int32_t {
|
||||
/** Disconnect a client. */
|
||||
DISCONNECT_CLIENT,
|
||||
/** Log a message from a client. */
|
||||
|
||||
@@ -76,8 +76,8 @@ TablePubsub ParseTablePubsub(const RedisModuleString *pubsub_channel_str) {
|
||||
pubsub_channel_str, &pubsub_channel_long) == REDISMODULE_OK)
|
||||
<< "Pubsub channel must be a valid TablePubsub";
|
||||
auto pubsub_channel = static_cast<TablePubsub>(pubsub_channel_long);
|
||||
RAY_CHECK(pubsub_channel >= TablePubsub_MIN &&
|
||||
pubsub_channel <= TablePubsub_MAX)
|
||||
RAY_CHECK(pubsub_channel >= TablePubsub::MIN &&
|
||||
pubsub_channel <= TablePubsub::MAX)
|
||||
<< "Pubsub channel must be a valid TablePubsub";
|
||||
return pubsub_channel;
|
||||
}
|
||||
@@ -90,8 +90,9 @@ RedisModuleString *FormatPubsubChannel(
|
||||
const RedisModuleString *id) {
|
||||
// Format the pubsub channel enum to a string. TablePubsub_MAX should be more
|
||||
// than enough digits, but add 1 just in case for the null terminator.
|
||||
char pubsub_channel[TablePubsub_MAX + 1];
|
||||
sprintf(pubsub_channel, "%d", ParseTablePubsub(pubsub_channel_str));
|
||||
char pubsub_channel[static_cast<int>(TablePubsub::MAX) + 1];
|
||||
sprintf(pubsub_channel, "%d",
|
||||
static_cast<int>(ParseTablePubsub(pubsub_channel_str)));
|
||||
return RedisString_Format(ctx, "%s:%S", pubsub_channel, id);
|
||||
}
|
||||
|
||||
@@ -123,12 +124,12 @@ RedisModuleKey *OpenPrefixedKey(RedisModuleCtx *ctx,
|
||||
REDISMODULE_OK)
|
||||
<< "Prefix must be a valid TablePrefix";
|
||||
auto prefix = static_cast<TablePrefix>(prefix_long);
|
||||
RAY_CHECK(prefix != TablePrefix_UNUSED)
|
||||
RAY_CHECK(prefix != TablePrefix::UNUSED)
|
||||
<< "This table has no prefix registered";
|
||||
RAY_CHECK(prefix >= TablePrefix_MIN && prefix <= TablePrefix_MAX)
|
||||
RAY_CHECK(prefix >= TablePrefix::MIN && prefix <= TablePrefix::MAX)
|
||||
<< "Prefix must be a valid TablePrefix";
|
||||
return OpenPrefixedKey(ctx, table_prefixes[prefix], keyname, mode,
|
||||
mutated_key_str);
|
||||
return OpenPrefixedKey(ctx, table_prefixes[static_cast<long long>(prefix)],
|
||||
keyname, mode, mutated_key_str);
|
||||
}
|
||||
|
||||
RedisModuleKey *OpenPrefixedKey(RedisModuleCtx *ctx,
|
||||
@@ -486,14 +487,15 @@ int PublishTaskTableAdd(RedisModuleCtx *ctx,
|
||||
auto message = flatbuffers::GetRoot<TaskTableData>(buf);
|
||||
RAY_CHECK(message != nullptr);
|
||||
|
||||
if (message->scheduling_state() == SchedulingState_WAITING ||
|
||||
message->scheduling_state() == SchedulingState_SCHEDULED) {
|
||||
if (message->scheduling_state() == SchedulingState::WAITING ||
|
||||
message->scheduling_state() == SchedulingState::SCHEDULED) {
|
||||
/* Build the PUBLISH topic and message for task table subscribers. The
|
||||
* topic
|
||||
* is a string in the format "TASK_PREFIX:<local scheduler ID>:<state>".
|
||||
* The
|
||||
* message is a serialized SubscribeToTasksReply flatbuffer object. */
|
||||
std::string state = std::to_string(message->scheduling_state());
|
||||
std::string state =
|
||||
std::to_string(static_cast<int>(message->scheduling_state()));
|
||||
RedisModuleString *publish_topic = RedisString_Format(
|
||||
ctx, "%s%b:%s", TASK_PREFIX, message->scheduler_id()->str().data(),
|
||||
sizeof(DBClientID), state.c_str());
|
||||
@@ -501,12 +503,13 @@ int PublishTaskTableAdd(RedisModuleCtx *ctx,
|
||||
/* Construct the flatbuffers object for the payload. */
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
/* Create the flatbuffers message. */
|
||||
auto msg = CreateTaskReply(
|
||||
fbb, RedisStringToFlatbuf(fbb, id), message->scheduling_state(),
|
||||
fbb.CreateString(message->scheduler_id()),
|
||||
fbb.CreateString(message->execution_dependencies()),
|
||||
fbb.CreateString(message->task_info()), message->spillback_count(),
|
||||
true /* not used */);
|
||||
auto msg =
|
||||
CreateTaskReply(fbb, RedisStringToFlatbuf(fbb, id),
|
||||
static_cast<long long>(message->scheduling_state()),
|
||||
fbb.CreateString(message->scheduler_id()),
|
||||
fbb.CreateString(message->execution_dependencies()),
|
||||
fbb.CreateString(message->task_info()),
|
||||
message->spillback_count(), true /* not used */);
|
||||
fbb.Finish(msg);
|
||||
|
||||
RedisModuleString *publish_message = RedisModule_CreateString(
|
||||
@@ -613,12 +616,12 @@ int TableAdd_DoPublish(RedisModuleCtx *ctx,
|
||||
|
||||
TablePubsub pubsub_channel = ParseTablePubsub(pubsub_channel_str);
|
||||
|
||||
if (pubsub_channel == TablePubsub_TASK) {
|
||||
if (pubsub_channel == TablePubsub::TASK) {
|
||||
// Publish the task to its subscribers.
|
||||
// TODO(swang): This is only necessary for legacy Ray and should be removed
|
||||
// once we switch to using the new GCS API for the task table.
|
||||
return PublishTaskTableAdd(ctx, id, data);
|
||||
} else if (pubsub_channel != TablePubsub_NO_PUBLISH) {
|
||||
} else if (pubsub_channel != TablePubsub::NO_PUBLISH) {
|
||||
// All other pubsub channels write the data back directly onto the channel.
|
||||
return PublishTableAdd(ctx, pubsub_channel_str, id, data);
|
||||
} else {
|
||||
@@ -723,7 +726,7 @@ int TableAppend_RedisCommand(RedisModuleCtx *ctx,
|
||||
RAY_CHECK(flags == REDISMODULE_ZADD_ADDED) << "Appended a duplicate entry";
|
||||
// Publish a message on the requested pubsub channel if necessary.
|
||||
TablePubsub pubsub_channel = ParseTablePubsub(pubsub_channel_str);
|
||||
if (pubsub_channel != TablePubsub_NO_PUBLISH) {
|
||||
if (pubsub_channel != TablePubsub::NO_PUBLISH) {
|
||||
// All other pubsub channels write the data back directly onto the
|
||||
// channel.
|
||||
return PublishTableAdd(ctx, pubsub_channel_str, id, data);
|
||||
@@ -956,7 +959,8 @@ int TableTestAndUpdate_RedisCommand(RedisModuleCtx *ctx,
|
||||
|
||||
auto update = flatbuffers::GetRoot<TaskTableTestAndUpdate>(update_buf);
|
||||
|
||||
bool do_update = data->scheduling_state() & update->test_state_bitmask();
|
||||
bool do_update = static_cast<int>(data->scheduling_state()) &
|
||||
static_cast<int>(update->test_state_bitmask());
|
||||
|
||||
if (!is_nil(update->test_scheduler_id()->str())) {
|
||||
do_update =
|
||||
@@ -1460,8 +1464,8 @@ int TaskTableWrite(RedisModuleCtx *ctx,
|
||||
"TaskSpec", task_spec, "spillback_count", spillback_count, NULL);
|
||||
}
|
||||
|
||||
if (state_value == TASK_STATUS_WAITING ||
|
||||
state_value == TASK_STATUS_SCHEDULED) {
|
||||
if (static_cast<TaskStatus>(state_value) == TaskStatus::WAITING ||
|
||||
static_cast<TaskStatus>(state_value) == TaskStatus::SCHEDULED) {
|
||||
/* Build the PUBLISH topic and message for task table subscribers. The
|
||||
* topic is a string in the format
|
||||
* "TASK_PREFIX:<local scheduler ID>:<state>". The message is a serialized
|
||||
|
||||
@@ -6,7 +6,7 @@ const char *error_types[] = {"object_hash_mismatch", "put_reconstruction",
|
||||
|
||||
void push_error(DBHandle *db_handle,
|
||||
DBClientID driver_id,
|
||||
int error_type,
|
||||
ErrorIndex error_type,
|
||||
const std::string &error_message) {
|
||||
int64_t message_size = error_message.size();
|
||||
|
||||
|
||||
@@ -4,12 +4,26 @@
|
||||
#include "db.h"
|
||||
#include "table.h"
|
||||
|
||||
/// An ErrorIndex may be used as an index into error_types.
|
||||
enum class ErrorIndex : int32_t {
|
||||
/// An object was added with a different hash from the existing one.
|
||||
OBJECT_HASH_MISMATCH = 0,
|
||||
/// An object that was created through a ray.put is lost.
|
||||
PUT_RECONSTRUCTION,
|
||||
/// A worker died or was killed while executing a task.
|
||||
WORKER_DIED,
|
||||
/// An actor hasn't been created for a while.
|
||||
ACTOR_NOT_CREATED,
|
||||
/// The total number of error types.
|
||||
MAX
|
||||
};
|
||||
|
||||
/// Data that is needed to push an error.
|
||||
typedef struct {
|
||||
/// The ID of the driver to push the error to.
|
||||
DBClientID driver_id;
|
||||
/// An index into the error_types array indicating the type of the error.
|
||||
int error_type;
|
||||
ErrorIndex error_type;
|
||||
/// The key to use for the error message in Redis.
|
||||
UniqueID error_key;
|
||||
/// The length of the error message.
|
||||
@@ -18,20 +32,6 @@ typedef struct {
|
||||
uint8_t error_message[0];
|
||||
} ErrorInfo;
|
||||
|
||||
/// An error_index may be used as an index into error_types.
|
||||
typedef enum {
|
||||
/// An object was added with a different hash from the existing one.
|
||||
OBJECT_HASH_MISMATCH_ERROR_INDEX = 0,
|
||||
/// An object that was created through a ray.put is lost.
|
||||
PUT_RECONSTRUCTION_ERROR_INDEX,
|
||||
/// A worker died or was killed while executing a task.
|
||||
WORKER_DIED_ERROR_INDEX,
|
||||
/// An actor hasn't been created for a while.
|
||||
ACTOR_NOT_CREATED_ERROR_INDEX,
|
||||
/// The total number of error types.
|
||||
MAX_ERROR_INDEX
|
||||
} error_index;
|
||||
|
||||
extern const char *error_types[];
|
||||
|
||||
/// Push an error to the given Python driver.
|
||||
@@ -39,12 +39,12 @@ extern const char *error_types[];
|
||||
/// \param db_handle Database handle.
|
||||
/// \param driver_id The ID of the Python driver to push the error to.
|
||||
/// \param error_type An index specifying the type of the error. This should
|
||||
/// be a value from the error_index enum.
|
||||
/// be a value from the ErrorIndex enum.
|
||||
/// \param error_message The error message to print.
|
||||
/// \return Void.
|
||||
void push_error(DBHandle *db_handle,
|
||||
DBClientID driver_id,
|
||||
int error_type,
|
||||
ErrorIndex error_type,
|
||||
const std::string &error_message);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -536,7 +536,7 @@ Task *parse_and_construct_task_from_redis_reply(redisReply *reply) {
|
||||
flatbuffers::GetRoot<TaskExecutionDependencies>(
|
||||
message->execution_dependencies()->data());
|
||||
task = Task_alloc(
|
||||
spec, task_spec_size, message->state(),
|
||||
spec, task_spec_size, static_cast<TaskStatus>(message->state()),
|
||||
from_flatbuf(*message->local_scheduler_id()),
|
||||
from_flatbuf(*execution_dependencies->execution_dependencies()));
|
||||
} else {
|
||||
@@ -932,7 +932,7 @@ void redis_task_table_add_task(TableCallbackData *callback_data) {
|
||||
TaskID task_id = Task_task_id(task);
|
||||
DBClientID local_scheduler_id = Task_local_scheduler(task);
|
||||
redisAsyncContext *context = get_redis_context(db, task_id);
|
||||
int state = Task_state(task);
|
||||
int state = static_cast<int>(Task_state(task));
|
||||
|
||||
TaskExecutionSpec *execution_spec = Task_task_execution_spec(task);
|
||||
TaskSpec *spec = execution_spec->Spec();
|
||||
@@ -998,7 +998,7 @@ void redis_task_table_update(TableCallbackData *callback_data) {
|
||||
TaskID task_id = Task_task_id(task);
|
||||
redisAsyncContext *context = get_redis_context(db, task_id);
|
||||
DBClientID local_scheduler_id = Task_local_scheduler(task);
|
||||
int state = Task_state(task);
|
||||
int state = static_cast<int>(Task_state(task));
|
||||
|
||||
TaskExecutionSpec *execution_spec = Task_task_execution_spec(task);
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
@@ -1108,7 +1108,7 @@ void redis_task_table_subscribe_callback(redisAsyncContext *c,
|
||||
/* Handle a task table event. Parse the payload and call the callback. */
|
||||
auto message = flatbuffers::GetRoot<TaskReply>(payload->str);
|
||||
/* Extract the scheduling state. */
|
||||
int64_t state = message->state();
|
||||
TaskStatus state = static_cast<TaskStatus>(message->state());
|
||||
/* Extract the local scheduler ID. */
|
||||
DBClientID local_scheduler_id =
|
||||
from_flatbuf(*message->local_scheduler_id());
|
||||
@@ -1673,9 +1673,10 @@ void redis_push_error_hmset_callback(redisAsyncContext *c,
|
||||
void redis_push_error(TableCallbackData *callback_data) {
|
||||
DBHandle *db = callback_data->db_handle;
|
||||
ErrorInfo *info = (ErrorInfo *) callback_data->data->Get();
|
||||
RAY_CHECK(info->error_type < MAX_ERROR_INDEX && info->error_type >= 0);
|
||||
RAY_CHECK(info->error_type < ErrorIndex::MAX &&
|
||||
info->error_type >= ErrorIndex::OBJECT_HASH_MISMATCH);
|
||||
/// Look up the error type.
|
||||
const char *error_type = error_types[info->error_type];
|
||||
const char *error_type = error_types[static_cast<int>(info->error_type)];
|
||||
|
||||
/* Set the error information. */
|
||||
int status = redisAsyncCommand(
|
||||
|
||||
@@ -39,8 +39,8 @@ void task_table_test_and_update(
|
||||
DBHandle *db_handle,
|
||||
TaskID task_id,
|
||||
DBClientID test_local_scheduler_id,
|
||||
int test_state_bitmask,
|
||||
int update_state,
|
||||
TaskStatus test_state_bitmask,
|
||||
TaskStatus update_state,
|
||||
RetryInfo *retry,
|
||||
task_table_test_and_update_callback done_callback,
|
||||
void *user_context) {
|
||||
@@ -60,7 +60,7 @@ void task_table_test_and_update(
|
||||
/* TODO(swang): A corresponding task_table_unsubscribe. */
|
||||
void task_table_subscribe(DBHandle *db_handle,
|
||||
DBClientID local_scheduler_id,
|
||||
int state_filter,
|
||||
TaskStatus state_filter,
|
||||
task_table_subscribe_callback subscribe_callback,
|
||||
void *subscribe_context,
|
||||
RetryInfo *retry,
|
||||
|
||||
@@ -122,8 +122,8 @@ void task_table_test_and_update(
|
||||
DBHandle *db_handle,
|
||||
TaskID task_id,
|
||||
DBClientID test_local_scheduler_id,
|
||||
int test_state_bitmask,
|
||||
int update_state,
|
||||
TaskStatus test_state_bitmask,
|
||||
TaskStatus update_state,
|
||||
RetryInfo *retry,
|
||||
task_table_test_and_update_callback done_callback,
|
||||
void *user_context);
|
||||
@@ -133,8 +133,8 @@ typedef struct {
|
||||
/** The value to test the current local scheduler ID against. This field is
|
||||
* ignored if equal to NIL_ID. */
|
||||
DBClientID test_local_scheduler_id;
|
||||
int test_state_bitmask;
|
||||
int update_state;
|
||||
TaskStatus test_state_bitmask;
|
||||
TaskStatus update_state;
|
||||
DBClientID local_scheduler_id;
|
||||
} TaskTableTestAndUpdateData;
|
||||
|
||||
@@ -171,7 +171,7 @@ typedef void (*task_table_subscribe_callback)(Task *task, void *user_context);
|
||||
*/
|
||||
void task_table_subscribe(DBHandle *db_handle,
|
||||
DBClientID local_scheduler_id,
|
||||
int state_filter,
|
||||
TaskStatus state_filter,
|
||||
task_table_subscribe_callback subscribe_callback,
|
||||
void *subscribe_context,
|
||||
RetryInfo *retry,
|
||||
@@ -182,7 +182,7 @@ void task_table_subscribe(DBHandle *db_handle,
|
||||
* database. */
|
||||
typedef struct {
|
||||
DBClientID local_scheduler_id;
|
||||
int state_filter;
|
||||
TaskStatus state_filter;
|
||||
task_table_subscribe_callback subscribe_callback;
|
||||
void *subscribe_context;
|
||||
} TaskTableSubscribeData;
|
||||
|
||||
+4
-4
@@ -543,7 +543,7 @@ bool TaskExecutionSpec::IsStaticDependency(int64_t dependency_index) const {
|
||||
|
||||
Task *Task_alloc(const TaskSpec *spec,
|
||||
int64_t task_spec_size,
|
||||
int state,
|
||||
TaskStatus state,
|
||||
DBClientID local_scheduler_id,
|
||||
const std::vector<ObjectID> &execution_dependencies) {
|
||||
Task *result = new Task();
|
||||
@@ -556,7 +556,7 @@ Task *Task_alloc(const TaskSpec *spec,
|
||||
}
|
||||
|
||||
Task *Task_alloc(TaskExecutionSpec &execution_spec,
|
||||
int state,
|
||||
TaskStatus state,
|
||||
DBClientID local_scheduler_id) {
|
||||
Task *result = new Task();
|
||||
result->execution_spec = std::unique_ptr<TaskExecutionSpec>(
|
||||
@@ -575,11 +575,11 @@ int64_t Task_size(Task *task_arg) {
|
||||
return sizeof(Task) - sizeof(TaskSpec) + task_arg->execution_spec->SpecSize();
|
||||
}
|
||||
|
||||
int Task_state(Task *task) {
|
||||
TaskStatus Task_state(Task *task) {
|
||||
return task->state;
|
||||
}
|
||||
|
||||
void Task_set_state(Task *task, int state) {
|
||||
void Task_set_state(Task *task, TaskStatus state) {
|
||||
task->state = state;
|
||||
}
|
||||
|
||||
|
||||
+20
-15
@@ -518,26 +518,31 @@ void TaskSpec_free(TaskSpec *spec);
|
||||
|
||||
/** The scheduling_state can be used as a flag when we are listening
|
||||
* for an event, for example TASK_WAITING | TASK_SCHEDULED. */
|
||||
typedef enum {
|
||||
enum class TaskStatus : uint {
|
||||
/** The task is waiting to be scheduled. */
|
||||
TASK_STATUS_WAITING = 1,
|
||||
WAITING = 1,
|
||||
/** The task has been scheduled to a node, but has not been queued yet. */
|
||||
TASK_STATUS_SCHEDULED = 2,
|
||||
SCHEDULED = 2,
|
||||
/** The task has been queued on a node, where it will wait for its
|
||||
* dependencies to become ready and a worker to become available. */
|
||||
TASK_STATUS_QUEUED = 4,
|
||||
QUEUED = 4,
|
||||
/** The task is running on a worker. */
|
||||
TASK_STATUS_RUNNING = 8,
|
||||
RUNNING = 8,
|
||||
/** The task is done executing. */
|
||||
TASK_STATUS_DONE = 16,
|
||||
DONE = 16,
|
||||
/** The task was not able to finish. */
|
||||
TASK_STATUS_LOST = 32,
|
||||
LOST = 32,
|
||||
/** The task will be submitted for reexecution. */
|
||||
TASK_STATUS_RECONSTRUCTING = 64,
|
||||
RECONSTRUCTING = 64,
|
||||
/** An actor task is cached at a local scheduler and is waiting for the
|
||||
* corresponding actor to be created. */
|
||||
TASK_STATUS_ACTOR_CACHED = 128
|
||||
} scheduling_state;
|
||||
ACTOR_CACHED = 128
|
||||
};
|
||||
|
||||
inline TaskStatus operator|(const TaskStatus &a, const TaskStatus &b) {
|
||||
uint c = static_cast<uint>(a) | static_cast<uint>(b);
|
||||
return static_cast<TaskStatus>(c);
|
||||
}
|
||||
|
||||
/** A task is an execution of a task specification. It has a state of execution
|
||||
* (see scheduling_state) and the ID of the local scheduler it is scheduled on
|
||||
@@ -545,7 +550,7 @@ typedef enum {
|
||||
|
||||
struct Task {
|
||||
/** The scheduling state of the task. */
|
||||
int state;
|
||||
TaskStatus state;
|
||||
/** The ID of the local scheduler involved. */
|
||||
DBClientID local_scheduler_id;
|
||||
/** The execution specification for this task. */
|
||||
@@ -562,12 +567,12 @@ struct Task {
|
||||
*/
|
||||
Task *Task_alloc(const TaskSpec *spec,
|
||||
int64_t task_spec_size,
|
||||
int state,
|
||||
TaskStatus state,
|
||||
DBClientID local_scheduler_id,
|
||||
const std::vector<ObjectID> &execution_dependencies);
|
||||
|
||||
Task *Task_alloc(TaskExecutionSpec &execution_spec,
|
||||
int state,
|
||||
TaskStatus state,
|
||||
DBClientID local_scheduler_id);
|
||||
|
||||
/**
|
||||
@@ -582,10 +587,10 @@ Task *Task_copy(Task *other);
|
||||
int64_t Task_size(Task *task);
|
||||
|
||||
/** The scheduling state of the task. */
|
||||
int Task_state(Task *task);
|
||||
TaskStatus Task_state(Task *task);
|
||||
|
||||
/** Update the schedule state of the task. */
|
||||
void Task_set_state(Task *task, int state);
|
||||
void Task_set_state(Task *task, TaskStatus state);
|
||||
|
||||
/** Local scheduler this task has been assigned to or is running on. */
|
||||
DBClientID Task_local_scheduler(Task *task);
|
||||
|
||||
@@ -136,7 +136,7 @@ int64_t task_table_delayed_add_task(event_loop *loop,
|
||||
|
||||
void task_table_test_callback(Task *callback_task, void *user_data) {
|
||||
task_table_test_callback_called = 1;
|
||||
RAY_CHECK(Task_state(callback_task) == TASK_STATUS_SCHEDULED);
|
||||
RAY_CHECK(Task_state(callback_task) == TaskStatus::SCHEDULED);
|
||||
RAY_CHECK(Task_size(callback_task) == Task_size(task_table_test_task));
|
||||
RAY_CHECK(Task_equals(callback_task, task_table_test_task));
|
||||
event_loop *loop = (event_loop *) user_data;
|
||||
@@ -152,13 +152,13 @@ TEST task_table_test(void) {
|
||||
DBClientID local_scheduler_id = DBClientID::from_random();
|
||||
TaskExecutionSpec spec = example_task_execution_spec(1, 1);
|
||||
task_table_test_task =
|
||||
Task_alloc(spec, TASK_STATUS_SCHEDULED, local_scheduler_id);
|
||||
Task_alloc(spec, TaskStatus::SCHEDULED, local_scheduler_id);
|
||||
RetryInfo retry = {
|
||||
.num_retries = NUM_RETRIES,
|
||||
.timeout = TIMEOUT,
|
||||
.fail_callback = task_table_test_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, local_scheduler_id, TASK_STATUS_SCHEDULED,
|
||||
task_table_subscribe(db, local_scheduler_id, TaskStatus::SCHEDULED,
|
||||
task_table_test_callback, (void *) loop, &retry, NULL,
|
||||
(void *) loop);
|
||||
event_loop_add_timer(
|
||||
@@ -186,13 +186,13 @@ TEST task_table_all_test(void) {
|
||||
TaskExecutionSpec spec = example_task_execution_spec(1, 1);
|
||||
/* Schedule two tasks on different local local schedulers. */
|
||||
Task *task1 =
|
||||
Task_alloc(spec, TASK_STATUS_SCHEDULED, DBClientID::from_random());
|
||||
Task_alloc(spec, TaskStatus::SCHEDULED, DBClientID::from_random());
|
||||
Task *task2 =
|
||||
Task_alloc(spec, TASK_STATUS_SCHEDULED, DBClientID::from_random());
|
||||
Task_alloc(spec, TaskStatus::SCHEDULED, DBClientID::from_random());
|
||||
RetryInfo retry = {
|
||||
.num_retries = NUM_RETRIES, .timeout = TIMEOUT, .fail_callback = NULL,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_SCHEDULED,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::SCHEDULED,
|
||||
task_table_all_test_callback, NULL, &retry, NULL, NULL);
|
||||
event_loop_add_timer(loop, 50, (event_loop_timer_handler) timeout_handler,
|
||||
NULL);
|
||||
@@ -211,7 +211,7 @@ TEST task_table_all_test(void) {
|
||||
}
|
||||
|
||||
TEST unique_client_id_test(void) {
|
||||
enum { num_conns = 100 };
|
||||
const int num_conns = 100;
|
||||
|
||||
DBClientID ids[num_conns];
|
||||
DBHandle *db;
|
||||
|
||||
@@ -42,7 +42,7 @@ static inline TaskExecutionSpec example_task_execution_spec(
|
||||
|
||||
static inline Task *example_task_with_args(int64_t num_args,
|
||||
int64_t num_returns,
|
||||
int task_state,
|
||||
TaskStatus task_state,
|
||||
ObjectID arg_ids[]) {
|
||||
TaskExecutionSpec spec =
|
||||
example_task_execution_spec_with_args(num_args, num_returns, arg_ids);
|
||||
@@ -52,7 +52,7 @@ static inline Task *example_task_with_args(int64_t num_args,
|
||||
|
||||
static inline Task *example_task(int64_t num_args,
|
||||
int64_t num_returns,
|
||||
int task_state) {
|
||||
TaskStatus task_state) {
|
||||
TaskExecutionSpec spec = example_task_execution_spec(num_args, num_returns);
|
||||
Task *instance = Task_alloc(spec, task_state, UniqueID::nil());
|
||||
return instance;
|
||||
|
||||
@@ -25,8 +25,9 @@ TEST ipc_socket_test(void) {
|
||||
socket_fd = connect_ipc_sock(socket_pathname);
|
||||
ASSERT(socket_fd >= 0);
|
||||
write_log_message(socket_fd, test_string);
|
||||
write_message(socket_fd, LOG_MESSAGE, strlen(test_bytes),
|
||||
(uint8_t *) test_bytes);
|
||||
write_message(socket_fd,
|
||||
static_cast<int64_t>(CommonMessageType::LOG_MESSAGE),
|
||||
strlen(test_bytes), (uint8_t *) test_bytes);
|
||||
close(socket_fd);
|
||||
exit(0);
|
||||
} else {
|
||||
@@ -40,7 +41,8 @@ TEST ipc_socket_test(void) {
|
||||
int64_t len;
|
||||
uint8_t *bytes;
|
||||
read_message(client_fd, &type, &len, &bytes);
|
||||
ASSERT(type == LOG_MESSAGE);
|
||||
ASSERT(static_cast<CommonMessageType>(type) ==
|
||||
CommonMessageType::LOG_MESSAGE);
|
||||
ASSERT(memcmp(test_bytes, bytes, len) == 0);
|
||||
free(bytes);
|
||||
close(client_fd);
|
||||
@@ -69,8 +71,9 @@ TEST long_ipc_socket_test(void) {
|
||||
socket_fd = connect_ipc_sock(socket_pathname);
|
||||
ASSERT(socket_fd >= 0);
|
||||
write_log_message(socket_fd, test_string.c_str());
|
||||
write_message(socket_fd, LOG_MESSAGE, strlen(test_bytes),
|
||||
(uint8_t *) test_bytes);
|
||||
write_message(socket_fd,
|
||||
static_cast<int64_t>(CommonMessageType::LOG_MESSAGE),
|
||||
strlen(test_bytes), (uint8_t *) test_bytes);
|
||||
close(socket_fd);
|
||||
exit(0);
|
||||
} else {
|
||||
@@ -84,7 +87,8 @@ TEST long_ipc_socket_test(void) {
|
||||
int64_t len;
|
||||
uint8_t *bytes;
|
||||
read_message(client_fd, &type, &len, &bytes);
|
||||
ASSERT(type == LOG_MESSAGE);
|
||||
ASSERT(static_cast<CommonMessageType>(type) ==
|
||||
CommonMessageType::LOG_MESSAGE);
|
||||
ASSERT(memcmp(test_bytes, bytes, len) == 0);
|
||||
free(bytes);
|
||||
close(client_fd);
|
||||
|
||||
@@ -79,7 +79,7 @@ TEST new_object_test(void) {
|
||||
new_object_failed = 0;
|
||||
new_object_succeeded = 0;
|
||||
new_object_id = ObjectID::from_random();
|
||||
new_object_task = example_task(1, 1, TASK_STATUS_WAITING);
|
||||
new_object_task = example_task(1, 1, TaskStatus::WAITING);
|
||||
new_object_task_spec = Task_task_execution_spec(new_object_task)->Spec();
|
||||
new_object_task_id = TaskSpec_task_id(new_object_task_spec);
|
||||
g_loop = event_loop_create();
|
||||
@@ -91,7 +91,7 @@ TEST new_object_test(void) {
|
||||
.timeout = 100,
|
||||
.fail_callback = new_object_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
&retry, task_table_subscribe_done, db);
|
||||
event_loop_run(g_loop);
|
||||
db_disconnect(db);
|
||||
|
||||
@@ -105,7 +105,7 @@ void subscribe_success_callback(TaskID task_id, void *context) {
|
||||
}
|
||||
|
||||
TEST add_lookup_test(void) {
|
||||
add_lookup_task = example_task(1, 1, TASK_STATUS_WAITING);
|
||||
add_lookup_task = example_task(1, 1, TaskStatus::WAITING);
|
||||
g_loop = event_loop_create();
|
||||
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
|
||||
"127.0.0.1", std::vector<std::string>());
|
||||
@@ -116,7 +116,7 @@ TEST add_lookup_test(void) {
|
||||
.fail_callback = add_lookup_fail_callback,
|
||||
};
|
||||
/* Wait for subscription to succeed before adding the task. */
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
&retry, subscribe_success_callback, (void *) db);
|
||||
/* Disconnect the database to see if the lookup times out. */
|
||||
event_loop_run(g_loop);
|
||||
@@ -156,7 +156,7 @@ TEST subscribe_timeout_test(void) {
|
||||
.timeout = 100,
|
||||
.fail_callback = subscribe_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
&retry, subscribe_done_callback,
|
||||
(void *) subscribe_timeout_context);
|
||||
/* Disconnect the database to see if the subscribe times out. */
|
||||
@@ -194,11 +194,11 @@ TEST publish_timeout_test(void) {
|
||||
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
|
||||
"127.0.0.1", std::vector<std::string>());
|
||||
db_attach(db, g_loop, false);
|
||||
Task *task = example_task(1, 1, TASK_STATUS_WAITING);
|
||||
Task *task = example_task(1, 1, TaskStatus::WAITING);
|
||||
RetryInfo retry = {
|
||||
.num_retries = 5, .timeout = 100, .fail_callback = publish_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
&retry, NULL, NULL);
|
||||
task_table_add_task(db, task, &retry, publish_done_callback,
|
||||
(void *) publish_timeout_context);
|
||||
@@ -270,7 +270,7 @@ TEST subscribe_retry_test(void) {
|
||||
.timeout = 100,
|
||||
.fail_callback = subscribe_retry_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
&retry, subscribe_retry_done_callback,
|
||||
(void *) subscribe_retry_context);
|
||||
/* Disconnect the database to see if the subscribe times out. */
|
||||
@@ -315,13 +315,13 @@ TEST publish_retry_test(void) {
|
||||
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
|
||||
"127.0.0.1", std::vector<std::string>());
|
||||
db_attach(db, g_loop, false);
|
||||
Task *task = example_task(1, 1, TASK_STATUS_WAITING);
|
||||
Task *task = example_task(1, 1, TaskStatus::WAITING);
|
||||
RetryInfo retry = {
|
||||
.num_retries = 5,
|
||||
.timeout = 100,
|
||||
.fail_callback = publish_retry_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
&retry, NULL, NULL);
|
||||
task_table_add_task(db, task, &retry, publish_retry_done_callback,
|
||||
(void *) publish_retry_context);
|
||||
@@ -374,7 +374,7 @@ TEST subscribe_late_test(void) {
|
||||
.timeout = 0,
|
||||
.fail_callback = subscribe_late_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
&retry, subscribe_late_done_callback,
|
||||
(void *) subscribe_late_context);
|
||||
/* Install handler for terminating the event loop. */
|
||||
@@ -414,13 +414,13 @@ TEST publish_late_test(void) {
|
||||
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
|
||||
"127.0.0.1", std::vector<std::string>());
|
||||
db_attach(db, g_loop, false);
|
||||
Task *task = example_task(1, 1, TASK_STATUS_WAITING);
|
||||
Task *task = example_task(1, 1, TaskStatus::WAITING);
|
||||
RetryInfo retry = {
|
||||
.num_retries = 0,
|
||||
.timeout = 0,
|
||||
.fail_callback = publish_late_fail_callback,
|
||||
};
|
||||
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
|
||||
task_table_subscribe(db, UniqueID::nil(), TaskStatus::WAITING, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
task_table_add_task(db, task, &retry, publish_late_done_callback,
|
||||
(void *) publish_late_context);
|
||||
|
||||
@@ -181,13 +181,15 @@ TEST send_task(void) {
|
||||
TaskSpec *spec = TaskSpec_finish_construct(builder, &size);
|
||||
int fd[2];
|
||||
socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
|
||||
write_message(fd[0], SUBMIT_TASK, size, (uint8_t *) spec);
|
||||
write_message(fd[0], static_cast<int64_t>(CommonMessageType::SUBMIT_TASK),
|
||||
size, (uint8_t *) spec);
|
||||
int64_t type;
|
||||
int64_t length;
|
||||
uint8_t *message;
|
||||
read_message(fd[1], &type, &length, &message);
|
||||
TaskSpec *result = (TaskSpec *) message;
|
||||
ASSERT(type == SUBMIT_TASK);
|
||||
ASSERT(static_cast<CommonMessageType>(type) ==
|
||||
CommonMessageType::SUBMIT_TASK);
|
||||
ASSERT(memcmp(spec, result, size) == 0);
|
||||
TaskSpec_free(spec);
|
||||
free(result);
|
||||
|
||||
Reference in New Issue
Block a user