Convert task_spec to flatbuffers (#255)

* convert Ray to C++

* convert task_spec to flatbuffers

* fix

* it compiles

* latest

* tests are passing

* task2 -> task

* fix

* fix

* fix

* fix

* fix

* linting

* fix valgrind

* upgrade flatbuffers

* use debug mode for valgrind

* fix naming and comments

* downgrade flatbuffers

* fix linting

* reintroduce TaskSpec_free

* rename TaskSpec -> TaskInfo

* refactoring

* linting
This commit is contained in:
Philipp Moritz
2017-03-05 02:05:02 -08:00
committed by Robert Nishihara
parent 65a8659f3d
commit 0b8d279ef2
36 changed files with 1054 additions and 931 deletions
+2 -2
View File
@@ -17,10 +17,10 @@ typedef struct {
int available_workers;
/** The resource vector of resources generally available to this local
* scheduler. */
double static_resources[MAX_RESOURCE_INDEX];
double static_resources[ResourceIndex_MAX];
/** The resource vector of resources currently available to this local
* scheduler. */
double dynamic_resources[MAX_RESOURCE_INDEX];
double dynamic_resources[ResourceIndex_MAX];
} LocalSchedulerInfo;
/*
+18 -16
View File
@@ -358,7 +358,7 @@ Task *parse_and_construct_task_from_redis_reply(redisReply *reply) {
} else if (reply->type == REDIS_REPLY_ARRAY) {
/* Check that the reply is as expected. The 0th element is the scheduling
* state. The 1st element is the db_client_id of the associated local
* scheduler, and the 2nd element is the task_spec. */
* scheduler, and the 2nd element is the TaskSpec. */
CHECK(reply->elements == 3);
CHECK(reply->element[0]->type == REDIS_REPLY_INTEGER);
CHECK(reply->element[1]->type == REDIS_REPLY_STRING);
@@ -371,12 +371,11 @@ Task *parse_and_construct_task_from_redis_reply(redisReply *reply) {
memcpy(local_scheduler_id.id, reply->element[1]->str,
reply->element[1]->len);
/* Parse the task spec. */
task_spec *spec = (task_spec *) malloc(reply->element[2]->len);
TaskSpec *spec = (TaskSpec *) malloc(reply->element[2]->len);
memcpy(spec, reply->element[2]->str, reply->element[2]->len);
CHECK(task_spec_size(spec) == reply->element[2]->len);
task = Task_alloc(spec, state, local_scheduler_id);
task = Task_alloc(spec, reply->element[2]->len, state, local_scheduler_id);
/* Free the task spec. */
free_task_spec(spec);
TaskSpec_free(spec);
} else {
LOG_FATAL("Unexpected reply type %d", reply->type);
}
@@ -777,16 +776,16 @@ void redis_task_table_add_task(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
Task *task = (Task *) callback_data->data;
TaskID task_id = Task_task_id(task);
DBClientID local_scheduler_id = Task_local_scheduler_id(task);
DBClientID local_scheduler_id = Task_local_scheduler(task);
int state = Task_state(task);
task_spec *spec = Task_task_spec(task);
TaskSpec *spec = Task_task_spec(task);
CHECKM(task != NULL, "NULL task passed to redis_task_table_add_task.");
int status = redisAsyncCommand(
db->context, redis_task_table_add_task_callback,
(void *) callback_data->timer_id, "RAY.TASK_TABLE_ADD %b %d %b %b",
task_id.id, sizeof(task_id.id), state, local_scheduler_id.id,
sizeof(local_scheduler_id.id), spec, task_spec_size(spec));
sizeof(local_scheduler_id.id), spec, Task_task_spec_size(task));
if ((status == REDIS_ERR) || db->context->err) {
LOG_REDIS_DEBUG(db->context, "error in redis_task_table_add_task");
}
@@ -814,7 +813,7 @@ void redis_task_table_update(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
Task *task = (Task *) callback_data->data;
TaskID task_id = Task_task_id(task);
DBClientID local_scheduler_id = Task_local_scheduler_id(task);
DBClientID local_scheduler_id = Task_local_scheduler(task);
int state = Task_state(task);
CHECKM(task != NULL, "NULL task passed to redis_task_table_update.");
@@ -875,7 +874,8 @@ void parse_task_table_subscribe_callback(char *payload,
TaskID *task_id,
int *state,
DBClientID *local_scheduler_id,
task_spec **spec) {
TaskSpec **spec,
int64_t *task_spec_size) {
/* Note that the state is padded with spaces to consist of precisely two
* characters. */
int task_spec_payload_size =
@@ -902,9 +902,9 @@ void parse_task_table_subscribe_callback(char *payload,
CHECK(memcmp(space_str, &payload[offset], strlen(space_str)) == 0);
offset += strlen(space_str);
/* Read in the task spec. */
*spec = (task_spec *) malloc(task_spec_payload_size);
*spec = (TaskSpec *) malloc(task_spec_payload_size);
memcpy(*spec, &payload[offset], task_spec_payload_size);
CHECK(task_spec_size(*spec) == task_spec_payload_size);
*task_spec_size = task_spec_payload_size;
}
void redis_task_table_subscribe_callback(redisAsyncContext *c,
@@ -932,11 +932,13 @@ void redis_task_table_subscribe_callback(redisAsyncContext *c,
TaskID task_id;
int state;
DBClientID local_scheduler_id;
task_spec *spec;
TaskSpec *spec;
int64_t task_spec_size;
parse_task_table_subscribe_callback(payload->str, payload->len, &task_id,
&state, &local_scheduler_id, &spec);
Task *task = Task_alloc(spec, state, local_scheduler_id);
free(spec);
&state, &local_scheduler_id, &spec,
&task_spec_size);
Task *task = Task_alloc(spec, task_spec_size, state, local_scheduler_id);
TaskSpec_free(spec);
/* Call the subscribe callback if there is one. */
if (data->subscribe_callback != NULL) {
data->subscribe_callback(task, data->subscribe_context);