Change type naming convention. (#315)

* Rename object_id -> ObjectID.

* Rename ray_logger -> RayLogger.

* rename task_id -> TaskID, actor_id -> ActorID, function_id -> FunctionID

* Rename plasma_store_info -> PlasmaStoreInfo.

* Rename plasma_store_state -> PlasmaStoreState.

* Rename plasma_object -> PlasmaObject.

* Rename object_request -> ObjectRequests.

* Rename eviction_state -> EvictionState.

* Bug fix.

* rename db_handle -> DBHandle

* Rename local_scheduler_state -> LocalSchedulerState.

* rename db_client_id -> DBClientID

* rename task -> Task

* make redis.c C++ compatible

* Rename scheduling_algorithm_state -> SchedulingAlgorithmState.

* Rename plasma_connection -> PlasmaConnection.

* Rename client_connection -> ClientConnection.

* Fixes from rebase.

* Rename local_scheduler_client -> LocalSchedulerClient.

* Rename object_buffer -> ObjectBuffer.

* Rename client -> Client.

* Rename notification_queue -> NotificationQueue.

* Rename object_get_requests -> ObjectGetRequests.

* Rename get_request -> GetRequest.

* Rename object_info -> ObjectInfo.

* Rename scheduler_object_info -> SchedulerObjectInfo.

* Rename local_scheduler -> LocalScheduler and some fixes.

* Rename local_scheduler_info -> LocalSchedulerInfo.

* Rename global_scheduler_state -> GlobalSchedulerState.

* Rename global_scheduler_policy_state -> GlobalSchedulerPolicyState.

* Rename object_size_entry -> ObjectSizeEntry.

* Rename aux_address_entry -> AuxAddressEntry.

* Rename various ID helper methods.

* Rename Task helper methods.

* Rename db_client_cache_entry -> DBClientCacheEntry.

* Rename local_actor_info -> LocalActorInfo.

* Rename actor_info -> ActorInfo.

* Rename retry_info -> RetryInfo.

* Rename actor_notification_table_subscribe_data -> ActorNotificationTableSubscribeData.

* Rename local_scheduler_table_send_info_data -> LocalSchedulerTableSendInfoData.

* Rename table_callback_data -> TableCallbackData.

* Rename object_info_subscribe_data -> ObjectInfoSubscribeData.

* Rename local_scheduler_table_subscribe_data -> LocalSchedulerTableSubscribeData.

* Rename more redis call data structures.

* Rename photon_conn PhotonConnection.

* Rename photon_mock -> PhotonMock.

* Fix formatting errors.
This commit is contained in:
Philipp Moritz
2017-02-26 00:32:43 -08:00
committed by Robert Nishihara
parent be1618f041
commit a30eed452e
64 changed files with 2020 additions and 2115 deletions
+10 -10
View File
@@ -9,39 +9,39 @@
#include "io.h"
/* This is used to define the array of object IDs. */
const UT_icd object_id_icd = {sizeof(object_id), NULL, NULL, NULL};
const UT_icd object_id_icd = {sizeof(ObjectID), NULL, NULL, NULL};
const unique_id NIL_ID = {{255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255}};
const UniqueID NIL_ID = {{255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255}};
const unsigned char NIL_DIGEST[DIGEST_SIZE] = {0};
unique_id globally_unique_id(void) {
UniqueID globally_unique_id(void) {
/* Use /dev/urandom for "real" randomness. */
int fd;
int const flags = 0 /* for Windows compatibility */;
if ((fd = open("/dev/urandom", O_RDONLY, flags)) == -1) {
LOG_ERROR("Could not generate random number");
}
unique_id result;
UniqueID result;
CHECK(read_bytes(fd, &result.id[0], UNIQUE_ID_SIZE) >= 0);
close(fd);
return result;
}
bool object_ids_equal(object_id first_id, object_id second_id) {
bool ObjectID_equal(ObjectID first_id, ObjectID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
bool object_id_is_nil(object_id id) {
return object_ids_equal(id, NIL_OBJECT_ID);
bool ObjectID_is_nil(ObjectID id) {
return ObjectID_equal(id, NIL_OBJECT_ID);
}
bool db_client_ids_equal(db_client_id first_id, db_client_id second_id) {
bool DBClientID_equal(DBClientID first_id, DBClientID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
char *object_id_to_string(object_id obj_id, char *id_string, int id_length) {
char *ObjectID_to_string(ObjectID obj_id, char *id_string, int id_length) {
CHECK(id_length >= ID_STRING_SIZE);
static const char hex[] = "0123456789abcdef";
char *buf = id_string;
+9 -9
View File
@@ -121,18 +121,18 @@
#define IS_NIL_ID(id) UNIQUE_ID_EQ(id, NIL_ID)
typedef struct { unsigned char id[UNIQUE_ID_SIZE]; } unique_id;
typedef struct { unsigned char id[UNIQUE_ID_SIZE]; } UniqueID;
extern const UT_icd object_id_icd;
extern const unique_id NIL_ID;
extern const UniqueID NIL_ID;
/* Generate a globally unique ID. */
unique_id globally_unique_id(void);
UniqueID globally_unique_id(void);
#define NIL_OBJECT_ID NIL_ID
typedef unique_id object_id;
typedef UniqueID ObjectID;
#define ID_STRING_SIZE (2 * UNIQUE_ID_SIZE + 1)
@@ -147,7 +147,7 @@ typedef unique_id object_id;
* string.
* @param id_length The length of the id_string buffer.
*/
char *object_id_to_string(object_id obj_id, char *id_string, int id_length);
char *ObjectID_to_string(ObjectID obj_id, char *id_string, int id_length);
/**
* Compare two object IDs.
@@ -156,7 +156,7 @@ char *object_id_to_string(object_id obj_id, char *id_string, int id_length);
* @param second_id The first object ID to compare.
* @return True if the object IDs are the same and false otherwise.
*/
bool object_ids_equal(object_id first_id, object_id second_id);
bool ObjectID_equal(ObjectID first_id, ObjectID second_id);
/**
* Compare a object ID to the nil ID.
@@ -164,9 +164,9 @@ bool object_ids_equal(object_id first_id, object_id second_id);
* @param id The object ID to compare to nil.
* @return True if the object ID is equal to nil.
*/
bool object_id_is_nil(object_id id);
bool ObjectID_is_nil(ObjectID id);
typedef unique_id db_client_id;
typedef UniqueID DBClientID;
/**
* Compare two db client IDs.
@@ -175,7 +175,7 @@ typedef unique_id db_client_id;
* @param second_id The first db client ID to compare.
* @return True if the db client IDs are the same and false otherwise.
*/
bool db_client_ids_equal(db_client_id first_id, db_client_id second_id);
bool DBClientID_equal(DBClientID first_id, DBClientID second_id);
#define MAX(x, y) ((x) >= (y) ? (x) : (y))
#define MIN(x, y) ((x) <= (y) ? (x) : (y))
+2 -2
View File
@@ -37,7 +37,7 @@ int bind_inet_sock(const int port, bool shall_listen) {
close(socket_fd);
return -1;
}
int *const pon = (char const *) &on;
int *const pon = (int *const) & on;
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, pon, sizeof(on)) < 0) {
LOG_ERROR("setsockopt failed for port %d", port);
close(socket_fd);
@@ -302,7 +302,7 @@ void read_message(int fd, int64_t *type, int64_t *length, uint8_t **bytes) {
if (closed) {
goto disconnected;
}
*bytes = malloc(*length * sizeof(uint8_t));
*bytes = (uint8_t *) malloc(*length * sizeof(uint8_t));
closed = read_bytes(fd, *bytes, *length);
if (closed) {
free(*bytes);
+22 -24
View File
@@ -35,7 +35,7 @@ void init_pickle_module(void) {
/* Define the PyObjectID class. */
int PyStringToUniqueID(PyObject *object, object_id *object_id) {
int PyStringToUniqueID(PyObject *object, ObjectID *object_id) {
if (PyBytes_Check(object)) {
memcpy(&object_id->id[0], PyBytes_AsString(object), UNIQUE_ID_SIZE);
return 1;
@@ -45,7 +45,7 @@ int PyStringToUniqueID(PyObject *object, object_id *object_id) {
}
}
int PyObjectToUniqueID(PyObject *object, object_id *objectid) {
int PyObjectToUniqueID(PyObject *object, ObjectID *objectid) {
if (PyObject_IsInstance(object, (PyObject *) &PyObjectIDType)) {
*objectid = ((PyObjectID *) object)->object_id;
return 1;
@@ -61,7 +61,7 @@ static int PyObjectID_init(PyObjectID *self, PyObject *args, PyObject *kwds) {
if (!PyArg_ParseTuple(args, "s#", &data, &size)) {
return -1;
}
if (size != sizeof(object_id)) {
if (size != sizeof(ObjectID)) {
PyErr_SetString(CommonError,
"ObjectID: object id string needs to have length 20");
return -1;
@@ -71,7 +71,7 @@ static int PyObjectID_init(PyObjectID *self, PyObject *args, PyObject *kwds) {
}
/* Create a PyObjectID from C. */
PyObject *PyObjectID_make(object_id object_id) {
PyObject *PyObjectID_make(ObjectID object_id) {
PyObjectID *result = PyObject_New(PyObjectID, &PyObjectIDType);
result = (PyObjectID *) PyObject_Init((PyObject *) result, &PyObjectIDType);
result->object_id = object_id;
@@ -136,7 +136,7 @@ static PyObject *PyObjectID_id(PyObject *self) {
static PyObject *PyObjectID_hex(PyObject *self) {
PyObjectID *s = (PyObjectID *) self;
char hex_id[ID_STRING_SIZE];
object_id_to_string(s->object_id, hex_id, ID_STRING_SIZE);
ObjectID_to_string(s->object_id, hex_id, ID_STRING_SIZE);
PyObject *result = PyUnicode_FromString(hex_id);
return result;
}
@@ -157,14 +157,12 @@ static PyObject *PyObjectID_richcompare(PyObjectID *self,
result = Py_NotImplemented;
break;
case Py_EQ:
result = object_ids_equal(self->object_id, other_id->object_id)
? Py_True
: Py_False;
result = ObjectID_equal(self->object_id, other_id->object_id) ? Py_True
: Py_False;
break;
case Py_NE:
result = !object_ids_equal(self->object_id, other_id->object_id)
? Py_True
: Py_False;
result = !ObjectID_equal(self->object_id, other_id->object_id) ? Py_True
: Py_False;
break;
case Py_GT:
result = Py_NotImplemented;
@@ -190,7 +188,7 @@ static long PyObjectID_hash(PyObjectID *self) {
static PyObject *PyObjectID_repr(PyObjectID *self) {
char hex_id[ID_STRING_SIZE];
object_id_to_string(self->object_id, hex_id, ID_STRING_SIZE);
ObjectID_to_string(self->object_id, hex_id, ID_STRING_SIZE);
UT_string *repr;
utstring_new(repr);
utstring_printf(repr, "ObjectID(%s)", hex_id);
@@ -264,13 +262,13 @@ PyTypeObject PyObjectIDType = {
static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
/* ID of the driver that this task originates from. */
unique_id driver_id;
UniqueID driver_id;
/* ID of the actor this task should run on. */
unique_id actor_id = NIL_ACTOR_ID;
UniqueID actor_id = NIL_ACTOR_ID;
/* How many tasks have been launched on the actor so far? */
int actor_counter = 0;
/* ID of the function this task executes. */
function_id function_id;
FunctionID function_id;
/* Arguments of the task (can be PyObjectIDs or Python values). */
PyObject *arguments;
/* Array of pointers to string representations of pass-by-value args. */
@@ -278,7 +276,7 @@ static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
utarray_new(val_repr_ptrs, &ut_ptr_icd);
int num_returns;
/* The ID of the task that called this task. */
task_id parent_task_id;
TaskID parent_task_id;
/* The number of tasks that the parent task has called prior to this one. */
int parent_counter;
/* Resource vector of the required resources to execute this task. */
@@ -353,22 +351,22 @@ static void PyTask_dealloc(PyTask *self) {
}
static PyObject *PyTask_function_id(PyObject *self) {
function_id function_id = task_function(((PyTask *) self)->spec);
FunctionID function_id = task_function(((PyTask *) self)->spec);
return PyObjectID_make(function_id);
}
static PyObject *PyTask_actor_id(PyObject *self) {
actor_id actor_id = task_spec_actor_id(((PyTask *) self)->spec);
ActorID actor_id = task_spec_actor_id(((PyTask *) self)->spec);
return PyObjectID_make(actor_id);
}
static PyObject *PyTask_driver_id(PyObject *self) {
unique_id driver_id = task_spec_driver_id(((PyTask *) self)->spec);
UniqueID driver_id = task_spec_driver_id(((PyTask *) self)->spec);
return PyObjectID_make(driver_id);
}
static PyObject *PyTask_task_id(PyObject *self) {
task_id task_id = task_spec_id(((PyTask *) self)->spec);
TaskID task_id = task_spec_id(((PyTask *) self)->spec);
return PyObjectID_make(task_id);
}
@@ -378,7 +376,7 @@ static PyObject *PyTask_arguments(PyObject *self) {
PyObject *arg_list = PyList_New((Py_ssize_t) num_args);
for (int i = 0; i < num_args; ++i) {
if (task_arg_type(task, i) == ARG_BY_REF) {
object_id object_id = task_arg_id(task, i);
ObjectID object_id = task_arg_id(task, i);
PyList_SetItem(arg_list, i, PyObjectID_make(object_id));
} else {
CHECK(pickle_module != NULL);
@@ -410,7 +408,7 @@ static PyObject *PyTask_returns(PyObject *self) {
int64_t num_returns = task_num_returns(task);
PyObject *return_id_list = PyList_New((Py_ssize_t) num_returns);
for (int i = 0; i < num_returns; ++i) {
object_id object_id = task_return(task, i);
ObjectID object_id = task_return(task, i);
PyList_SetItem(return_id_list, i, PyObjectID_make(object_id));
}
return return_id_list;
@@ -569,11 +567,11 @@ PyObject *check_simple_value(PyObject *self, PyObject *args) {
PyObject *compute_put_id(PyObject *self, PyObject *args) {
int put_index;
task_id task_id;
TaskID task_id;
if (!PyArg_ParseTuple(args, "O&i", &PyObjectToUniqueID, &task_id,
&put_index)) {
return NULL;
}
object_id put_id = task_compute_put_id(task_id, put_index);
ObjectID put_id = task_compute_put_id(task_id, put_index);
return PyObjectID_make(put_id);
}
+4 -4
View File
@@ -13,7 +13,7 @@ extern PyObject *CommonError;
// clang-format off
typedef struct {
PyObject_HEAD
object_id object_id;
ObjectID object_id;
} PyObjectID;
typedef struct {
@@ -33,11 +33,11 @@ extern PyObject *pickle_loads;
void init_pickle_module(void);
int PyStringToUniqueID(PyObject *object, object_id *object_id);
int PyStringToUniqueID(PyObject *object, ObjectID *object_id);
int PyObjectToUniqueID(PyObject *object, object_id *objectid);
int PyObjectToUniqueID(PyObject *object, ObjectID *objectid);
PyObject *PyObjectID_make(object_id object_id);
PyObject *PyObjectID_make(ObjectID object_id);
PyObject *check_simple_value(PyObject *self, PyObject *args);
+17 -17
View File
@@ -14,7 +14,7 @@ static const char *log_levels[5] = {"DEBUG", "INFO", "WARN", "ERROR", "FATAL"};
static const char *log_fmt =
"HMSET log:%s:%s log_level %s event_type %s message %s timestamp %s";
struct ray_logger_impl {
struct RayLoggerImpl {
/* String that identifies this client type. */
const char *client_type;
/* Suppress all log messages below this level. */
@@ -26,11 +26,11 @@ struct ray_logger_impl {
void *conn;
};
ray_logger *init_ray_logger(const char *client_type,
int log_level,
int is_direct,
void *conn) {
ray_logger *logger = malloc(sizeof(ray_logger));
RayLogger *RayLogger_init(const char *client_type,
int log_level,
int is_direct,
void *conn) {
RayLogger *logger = (RayLogger *) malloc(sizeof(RayLogger));
logger->client_type = client_type;
logger->log_level = log_level;
logger->is_direct = is_direct;
@@ -38,14 +38,14 @@ ray_logger *init_ray_logger(const char *client_type,
return logger;
}
void free_ray_logger(ray_logger *logger) {
void RayLogger_free(RayLogger *logger) {
free(logger);
}
void ray_log(ray_logger *logger,
int log_level,
const char *event_type,
const char *message) {
void RayLogger_log(RayLogger *logger,
int log_level,
const char *event_type,
const char *message) {
if (log_level < logger->log_level) {
return;
}
@@ -65,7 +65,7 @@ void ray_log(ray_logger *logger,
log_levels[log_level], event_type, message,
utstring_body(timestamp));
if (logger->is_direct) {
db_handle *db = (db_handle *) logger->conn;
DBHandle *db = (DBHandle *) logger->conn;
/* Fill in the client ID and send the message to Redis. */
int status = redisAsyncCommand(
db->context, NULL, NULL, utstring_body(formatted_message),
@@ -83,11 +83,11 @@ void ray_log(ray_logger *logger,
utstring_free(timestamp);
}
void ray_log_event(db_handle *db,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length) {
void RayLogger_log_event(DBHandle *db,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length) {
int status = redisAsyncCommand(db->context, NULL, NULL, "RPUSH %b %b", key,
key_length, value, value_length);
if ((status == REDIS_ERR) || db->context->err) {
+15 -15
View File
@@ -15,28 +15,28 @@
#include "state/db.h"
typedef struct ray_logger_impl ray_logger;
typedef struct RayLoggerImpl RayLogger;
/* Initialize a Ray logger for the given client type and logging level. If the
* is_direct flag is set, the logger will treat the given connection as a
* direct connection to the log. Otherwise, it will treat it as a socket to
* another process with a connection to the log.
* NOTE: User is responsible for freeing the returned logger. */
ray_logger *init_ray_logger(const char *client_type,
int log_level,
int is_direct,
void *conn);
RayLogger *RayLogger_init(const char *client_type,
int log_level,
int is_direct,
void *conn);
/* Free the logger. This does not free the connection to the log. */
void free_ray_logger(ray_logger *logger);
void RayLogger_free(RayLogger *logger);
/* Log an event at the given log level with the given event_type.
* NOTE: message cannot contain spaces! JSON format is recommended.
* TODO: Support spaces in messages. */
void ray_log(ray_logger *logger,
int log_level,
const char *event_type,
const char *message);
void RayLogger_log(RayLogger *logger,
int log_level,
const char *event_type,
const char *message);
/**
* Log an event to the event log.
@@ -48,10 +48,10 @@ void ray_log(ray_logger *logger,
* @param value_length The length of the value.
* @return Void.
*/
void ray_log_event(db_handle *db,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length);
void RayLogger_log_event(DBHandle *db,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length);
#endif /* LOGGING_H */
+2 -2
View File
@@ -9,13 +9,13 @@
* Object information data structure.
*/
typedef struct {
object_id obj_id;
ObjectID obj_id;
int64_t data_size;
int64_t metadata_size;
int64_t create_time;
int64_t construct_duration;
unsigned char digest[DIGEST_SIZE];
bool is_deletion;
} object_info;
} ObjectInfo;
#endif
+4 -4
View File
@@ -2,12 +2,12 @@
#include "redis.h"
void actor_notification_table_subscribe(
db_handle *db_handle,
DBHandle *db_handle,
actor_notification_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry) {
actor_notification_table_subscribe_data *sub_data =
malloc(sizeof(actor_notification_table_subscribe_data));
RetryInfo *retry) {
ActorNotificationTableSubscribeData *sub_data =
malloc(sizeof(ActorNotificationTableSubscribeData));
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
+7 -7
View File
@@ -7,17 +7,17 @@
typedef struct {
/** The ID of the actor. */
actor_id actor_id;
ActorID actor_id;
/** The ID of the local scheduler that is responsible for the actor. */
db_client_id local_scheduler_id;
} actor_info;
DBClientID local_scheduler_id;
} ActorInfo;
/*
* ==== Subscribing to the actor notification table ====
*/
/* Callback for subscribing to the local scheduler table. */
typedef void (*actor_notification_table_subscribe_callback)(actor_info info,
typedef void (*actor_notification_table_subscribe_callback)(ActorInfo info,
void *user_context);
/**
@@ -32,16 +32,16 @@ typedef void (*actor_notification_table_subscribe_callback)(actor_info info,
* @return Void.
*/
void actor_notification_table_subscribe(
db_handle *db_handle,
DBHandle *db_handle,
actor_notification_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry);
RetryInfo *retry);
/* Data that is needed to register local scheduler table subscribe callbacks
* with the state database. */
typedef struct {
actor_notification_table_subscribe_callback subscribe_callback;
void *subscribe_context;
} actor_notification_table_subscribe_data;
} ActorNotificationTableSubscribeData;
#endif /* ACTOR_NOTIFICATION_TABLE_H */
+10 -10
View File
@@ -4,7 +4,7 @@
#include "common.h"
#include "event_loop.h"
typedef struct db_handle db_handle;
typedef struct DBHandle DBHandle;
/**
* Connect to the global system store.
@@ -21,12 +21,12 @@ typedef struct db_handle db_handle;
* @return This returns a handle to the database, which must be freed with
* db_disconnect after use.
*/
db_handle *db_connect(const char *db_address,
int db_port,
const char *client_type,
const char *node_ip_address,
int num_args,
const char **args);
DBHandle *db_connect(const char *db_address,
int db_port,
const char *client_type,
const char *node_ip_address,
int num_args,
const char **args);
/**
* Attach global system store connection to an event loop. Callbacks from
@@ -38,7 +38,7 @@ db_handle *db_connect(const char *db_address,
* reattached to the loop.
* @return Void.
*/
void db_attach(db_handle *db, event_loop *loop, bool reattach);
void db_attach(DBHandle *db, event_loop *loop, bool reattach);
/**
* Disconnect from the global system store.
@@ -46,7 +46,7 @@ void db_attach(db_handle *db, event_loop *loop, bool reattach);
* @param db The database connection to close and clean up.
* @return Void.
*/
void db_disconnect(db_handle *db);
void db_disconnect(DBHandle *db);
/**
* Returns the db client ID.
@@ -54,6 +54,6 @@ void db_disconnect(db_handle *db);
* @param db The handle to the database.
* @returns int The db client ID for this connection to the database.
*/
db_client_id get_db_client_id(db_handle *db);
DBClientID get_db_client_id(DBHandle *db);
#endif
+4 -4
View File
@@ -2,14 +2,14 @@
#include "redis.h"
void db_client_table_subscribe(
db_handle *db_handle,
DBHandle *db_handle,
db_client_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
db_client_table_done_callback done_callback,
void *user_context) {
db_client_table_subscribe_data *sub_data =
malloc(sizeof(db_client_table_subscribe_data));
DBClientTableSubscribeData *sub_data =
malloc(sizeof(DBClientTableSubscribeData));
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
+5 -5
View File
@@ -4,7 +4,7 @@
#include "db.h"
#include "table.h"
typedef void (*db_client_table_done_callback)(db_client_id db_client_id,
typedef void (*db_client_table_done_callback)(DBClientID db_client_id,
void *user_context);
/*
@@ -12,7 +12,7 @@ typedef void (*db_client_table_done_callback)(db_client_id db_client_id,
*/
/* Callback for subscribing to the db client table. */
typedef void (*db_client_table_subscribe_callback)(db_client_id db_client_id,
typedef void (*db_client_table_subscribe_callback)(DBClientID db_client_id,
const char *client_type,
const char *aux_address,
void *user_context);
@@ -32,10 +32,10 @@ typedef void (*db_client_table_subscribe_callback)(db_client_id db_client_id,
* @return Void.
*/
void db_client_table_subscribe(
db_handle *db_handle,
DBHandle *db_handle,
db_client_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
db_client_table_done_callback done_callback,
void *user_context);
@@ -44,6 +44,6 @@ void db_client_table_subscribe(
typedef struct {
db_client_table_subscribe_callback subscribe_callback;
void *subscribe_context;
} db_client_table_subscribe_data;
} DBClientTableSubscribeData;
#endif /* DB_CLIENT_TABLE_H */
+9 -9
View File
@@ -2,12 +2,12 @@
#include "redis.h"
void local_scheduler_table_subscribe(
db_handle *db_handle,
DBHandle *db_handle,
local_scheduler_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry) {
local_scheduler_table_subscribe_data *sub_data =
malloc(sizeof(local_scheduler_table_subscribe_data));
RetryInfo *retry) {
LocalSchedulerTableSubscribeData *sub_data =
malloc(sizeof(LocalSchedulerTableSubscribeData));
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
@@ -15,11 +15,11 @@ void local_scheduler_table_subscribe(
redis_local_scheduler_table_subscribe, NULL);
}
void local_scheduler_table_send_info(db_handle *db_handle,
local_scheduler_info *info,
retry_info *retry) {
local_scheduler_table_send_info_data *data =
malloc(sizeof(local_scheduler_table_send_info_data));
void local_scheduler_table_send_info(DBHandle *db_handle,
LocalSchedulerInfo *info,
RetryInfo *retry) {
LocalSchedulerTableSendInfoData *data =
malloc(sizeof(LocalSchedulerTableSendInfoData));
data->info = *info;
init_table_callback(db_handle, NIL_ID, __func__, data, retry, NULL,
+12 -11
View File
@@ -21,7 +21,7 @@ typedef struct {
/** The resource vector of resources currently available to this local
* scheduler. */
double dynamic_resources[MAX_RESOURCE_INDEX];
} local_scheduler_info;
} LocalSchedulerInfo;
/*
* ==== Subscribing to the local scheduler table ====
@@ -29,8 +29,8 @@ typedef struct {
/* Callback for subscribing to the local scheduler table. */
typedef void (*local_scheduler_table_subscribe_callback)(
db_client_id client_id,
local_scheduler_info info,
DBClientID client_id,
LocalSchedulerInfo info,
void *user_context);
/**
@@ -45,17 +45,17 @@ typedef void (*local_scheduler_table_subscribe_callback)(
* @return Void.
*/
void local_scheduler_table_subscribe(
db_handle *db_handle,
DBHandle *db_handle,
local_scheduler_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry);
RetryInfo *retry);
/* Data that is needed to register local scheduler table subscribe callbacks
* with the state database. */
typedef struct {
local_scheduler_table_subscribe_callback subscribe_callback;
void *subscribe_context;
} local_scheduler_table_subscribe_data;
} LocalSchedulerTableSubscribeData;
/**
* Send a heartbeat to all subscriers to the local scheduler table. This
@@ -66,14 +66,15 @@ typedef struct {
* local scheduler.
* @param retry Information about retrying the request to the database.
*/
void local_scheduler_table_send_info(db_handle *db_handle,
local_scheduler_info *info,
retry_info *retry);
void local_scheduler_table_send_info(DBHandle *db_handle,
LocalSchedulerInfo *info,
RetryInfo *retry);
/* Data that is needed to publish local scheduler heartbeats to the local
* scheduler table. */
typedef struct {
local_scheduler_info info;
} local_scheduler_table_send_info_data;
/* The information to be sent. */
LocalSchedulerInfo info;
} LocalSchedulerTableSendInfoData;
#endif /* LOCAL_SCHEDULER_TABLE_H */
+34 -36
View File
@@ -2,9 +2,9 @@
#include "redis.h"
#include "object_info.h"
void object_table_lookup(db_handle *db_handle,
object_id object_id,
retry_info *retry,
void object_table_lookup(DBHandle *db_handle,
ObjectID object_id,
RetryInfo *retry,
object_table_lookup_done_callback done_callback,
void *user_context) {
CHECK(db_handle != NULL);
@@ -12,33 +12,33 @@ void object_table_lookup(db_handle *db_handle,
done_callback, redis_object_table_lookup, user_context);
}
void object_table_add(db_handle *db_handle,
object_id object_id,
void object_table_add(DBHandle *db_handle,
ObjectID object_id,
int64_t object_size,
unsigned char digest[],
retry_info *retry,
RetryInfo *retry,
object_table_done_callback done_callback,
void *user_context) {
CHECK(db_handle != NULL);
object_table_add_data *info = malloc(sizeof(object_table_add_data));
ObjectTableAddData *info = malloc(sizeof(ObjectTableAddData));
info->object_size = object_size;
memcpy(&info->digest[0], digest, DIGEST_SIZE);
init_table_callback(db_handle, object_id, __func__, info, retry,
done_callback, redis_object_table_add, user_context);
}
void object_table_remove(db_handle *db_handle,
object_id object_id,
db_client_id *client_id,
retry_info *retry,
void object_table_remove(DBHandle *db_handle,
ObjectID object_id,
DBClientID *client_id,
RetryInfo *retry,
object_table_done_callback done_callback,
void *user_context) {
CHECK(db_handle != NULL);
/* Copy the client ID, if one was provided. */
db_client_id *client_id_copy = NULL;
DBClientID *client_id_copy = NULL;
if (client_id != NULL) {
client_id_copy = malloc(sizeof(db_client_id));
client_id_copy = malloc(sizeof(DBClientID));
*client_id_copy = *client_id;
}
init_table_callback(db_handle, object_id, __func__, client_id_copy, retry,
@@ -46,16 +46,15 @@ void object_table_remove(db_handle *db_handle,
}
void object_table_subscribe_to_notifications(
db_handle *db_handle,
DBHandle *db_handle,
bool subscribe_all,
object_table_object_available_callback object_available_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
object_table_lookup_done_callback done_callback,
void *user_context) {
CHECK(db_handle != NULL);
object_table_subscribe_data *sub_data =
malloc(sizeof(object_table_subscribe_data));
ObjectTableSubscribeData *sub_data = malloc(sizeof(ObjectTableSubscribeData));
sub_data->object_available_callback = object_available_callback;
sub_data->subscribe_context = subscribe_context;
sub_data->subscribe_all = subscribe_all;
@@ -65,30 +64,29 @@ void object_table_subscribe_to_notifications(
redis_object_table_subscribe_to_notifications, user_context);
}
void object_table_request_notifications(db_handle *db_handle,
void object_table_request_notifications(DBHandle *db_handle,
int num_object_ids,
object_id object_ids[],
retry_info *retry) {
ObjectID object_ids[],
RetryInfo *retry) {
CHECK(db_handle != NULL);
CHECK(num_object_ids > 0);
object_table_request_notifications_data *data =
malloc(sizeof(object_table_request_notifications_data) +
num_object_ids * sizeof(object_id));
ObjectTableRequestNotificationsData *data =
malloc(sizeof(ObjectTableRequestNotificationsData) +
num_object_ids * sizeof(ObjectID));
data->num_object_ids = num_object_ids;
memcpy(data->object_ids, object_ids, num_object_ids * sizeof(object_id));
memcpy(data->object_ids, object_ids, num_object_ids * sizeof(ObjectID));
init_table_callback(db_handle, NIL_OBJECT_ID, __func__, data, retry, NULL,
redis_object_table_request_notifications, NULL);
}
void object_info_subscribe(db_handle *db_handle,
void object_info_subscribe(DBHandle *db_handle,
object_info_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
object_info_done_callback done_callback,
void *user_context) {
object_info_subscribe_data *sub_data =
malloc(sizeof(object_info_subscribe_data));
ObjectInfoSubscribeData *sub_data = malloc(sizeof(ObjectInfoSubscribeData));
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
@@ -96,21 +94,21 @@ void object_info_subscribe(db_handle *db_handle,
done_callback, redis_object_info_subscribe, user_context);
}
void result_table_add(db_handle *db_handle,
object_id object_id,
task_id task_id_arg,
retry_info *retry,
void result_table_add(DBHandle *db_handle,
ObjectID object_id,
TaskID task_id_arg,
RetryInfo *retry,
result_table_done_callback done_callback,
void *user_context) {
task_id *task_id_copy = malloc(sizeof(task_id));
TaskID *task_id_copy = malloc(sizeof(TaskID));
memcpy(task_id_copy, task_id_arg.id, sizeof(*task_id_copy));
init_table_callback(db_handle, object_id, __func__, task_id_copy, retry,
done_callback, redis_result_table_add, user_context);
}
void result_table_lookup(db_handle *db_handle,
object_id object_id,
retry_info *retry,
void result_table_lookup(DBHandle *db_handle,
ObjectID object_id,
RetryInfo *retry,
result_table_lookup_callback done_callback,
void *user_context) {
init_table_callback(db_handle, object_id, __func__, NULL, retry,
+38 -38
View File
@@ -16,14 +16,14 @@
* before), then manager_count will be -1.
*/
typedef void (*object_table_lookup_done_callback)(
object_id object_id,
ObjectID object_id,
int manager_count,
OWNER const char *manager_vector[],
void *user_context);
/* Callback called when object object_id is available. */
/* Callback called when object ObjectID is available. */
typedef void (*object_table_object_available_callback)(
object_id object_id,
ObjectID object_id,
int64_t data_size,
int manager_count,
OWNER const char *manager_vector[],
@@ -39,9 +39,9 @@ typedef void (*object_table_object_available_callback)(
* @param user_context Context passed by the caller.
* @return Void.
*/
void object_table_lookup(db_handle *db_handle,
object_id object_id,
retry_info *retry,
void object_table_lookup(DBHandle *db_handle,
ObjectID object_id,
RetryInfo *retry,
object_table_lookup_done_callback done_callback,
void *user_context);
@@ -50,7 +50,7 @@ void object_table_lookup(db_handle *db_handle,
*/
/* Callback called when the object add/remove operation completes. */
typedef void (*object_table_done_callback)(object_id object_id,
typedef void (*object_table_done_callback)(ObjectID object_id,
void *user_context);
/**
@@ -65,11 +65,11 @@ typedef void (*object_table_done_callback)(object_id object_id,
* @param user_context User context to be passed in the callbacks.
* @return Void.
*/
void object_table_add(db_handle *db_handle,
object_id object_id,
void object_table_add(DBHandle *db_handle,
ObjectID object_id,
int64_t object_size,
unsigned char digest[],
retry_info *retry,
RetryInfo *retry,
object_table_done_callback done_callback,
void *user_context);
@@ -77,7 +77,7 @@ void object_table_add(db_handle *db_handle,
typedef struct {
int64_t object_size;
unsigned char digest[DIGEST_SIZE];
} object_table_add_data;
} ObjectTableAddData;
/*
* ==== Remove object call and callback ====
@@ -96,10 +96,10 @@ typedef struct {
* @param user_context User context to be passed in the callbacks.
* @return Void.
*/
void object_table_remove(db_handle *db_handle,
object_id object_id,
db_client_id *client_id,
retry_info *retry,
void object_table_remove(DBHandle *db_handle,
ObjectID object_id,
DBClientID *client_id,
RetryInfo *retry,
object_table_done_callback done_callback,
void *user_context);
@@ -125,11 +125,11 @@ void object_table_remove(db_handle *db_handle,
* @return Void.
*/
void object_table_subscribe_to_notifications(
db_handle *db_handle,
DBHandle *db_handle,
bool subscribe_all,
object_table_object_available_callback object_available_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
object_table_lookup_done_callback done_callback,
void *user_context);
@@ -144,18 +144,18 @@ void object_table_subscribe_to_notifications(
* @param retry Information about retrying the request to the database.
* @return Void.
*/
void object_table_request_notifications(db_handle *db,
void object_table_request_notifications(DBHandle *db,
int num_object_ids,
object_id object_ids[],
retry_info *retry);
ObjectID object_ids[],
RetryInfo *retry);
/** Data that is needed to run object_request_notifications requests. */
typedef struct {
/** The number of object IDs. */
int num_object_ids;
/** This field is used to store a variable number of object IDs. */
object_id object_ids[0];
} object_table_request_notifications_data;
ObjectID object_ids[0];
} ObjectTableRequestNotificationsData;
/** Data that is needed to register new object available callbacks with the
* state database. */
@@ -163,16 +163,16 @@ typedef struct {
bool subscribe_all;
object_table_object_available_callback object_available_callback;
void *subscribe_context;
} object_table_subscribe_data;
} ObjectTableSubscribeData;
/*
* ==== Object info table, contains size of the object ====
*/
typedef void (*object_info_done_callback)(object_id object_id,
typedef void (*object_info_done_callback)(ObjectID object_id,
void *user_context);
typedef void (*object_info_subscribe_callback)(object_id object_id,
typedef void (*object_info_subscribe_callback)(ObjectID object_id,
int64_t object_size,
void *user_context);
@@ -190,10 +190,10 @@ typedef void (*object_info_subscribe_callback)(object_id object_id,
* callbacks.
* @return Void.
*/
void object_info_subscribe(db_handle *db_handle,
void object_info_subscribe(DBHandle *db_handle,
object_info_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
object_info_done_callback done_callback,
void *user_context);
@@ -202,7 +202,7 @@ void object_info_subscribe(db_handle *db_handle,
typedef struct {
object_info_subscribe_callback subscribe_callback;
void *subscribe_context;
} object_info_subscribe_data;
} ObjectInfoSubscribeData;
/*
* ==== Result table ====
@@ -211,7 +211,7 @@ typedef struct {
/**
* Callback called when the add/remove operation for a result table entry
* completes. */
typedef void (*result_table_done_callback)(object_id object_id,
typedef void (*result_table_done_callback)(ObjectID object_id,
void *user_context);
/**
@@ -227,16 +227,16 @@ typedef void (*result_table_done_callback)(object_id object_id,
* @param user_context Context passed by the caller.
* @return Void.
*/
void result_table_add(db_handle *db_handle,
object_id object_id,
task_id task_id,
retry_info *retry,
void result_table_add(DBHandle *db_handle,
ObjectID object_id,
TaskID task_id,
RetryInfo *retry,
result_table_done_callback done_callback,
void *user_context);
/** Callback called when the result table lookup completes. */
typedef void (*result_table_lookup_callback)(object_id object_id,
task_id task_id,
typedef void (*result_table_lookup_callback)(ObjectID object_id,
TaskID task_id,
void *user_context);
/**
@@ -250,9 +250,9 @@ typedef void (*result_table_lookup_callback)(object_id object_id,
* @param user_context Context passed by the caller.
* @return Void.
*/
void result_table_lookup(db_handle *db_handle,
object_id object_id,
retry_info *retry,
void result_table_lookup(DBHandle *db_handle,
ObjectID object_id,
RetryInfo *retry,
result_table_lookup_callback done_callback,
void *user_context);
+195 -197
View File
@@ -54,54 +54,33 @@ extern int usleep(useconds_t usec);
* already removed, meaning that the operation was already marked as succeeded
* or failed.
*/
#define REDIS_CALLBACK_HEADER(DB, CB_DATA, REPLY) \
if ((REPLY) == NULL) { \
return; \
} \
db_handle *DB = c->data; \
table_callback_data *CB_DATA = \
outstanding_callbacks_find((int64_t) privdata); \
if (CB_DATA == NULL) { \
/* the callback data structure has been \
* already freed; just ignore this reply */ \
return; \
} \
do { \
#define REDIS_CALLBACK_HEADER(DB, CB_DATA, REPLY) \
if ((REPLY) == NULL) { \
return; \
} \
DBHandle *DB = (DBHandle *) c->data; \
TableCallbackData *CB_DATA = outstanding_callbacks_find((int64_t) privdata); \
if (CB_DATA == NULL) { \
/* the callback data structure has been \
* already freed; just ignore this reply */ \
return; \
} \
do { \
} while (0)
/**
* A data structure to track the status of a table operation attempt that spans
* multiple Redis commands. Each attempt at a table operation is associated
* with a unique redis_requests_info instance. To use this data structure, pass
* it as the `privdata` argument for the callback of each asynchronous Redis
* command.
*/
typedef struct {
/** The timer ID that uniquely identifies this table operation. All retry
* attempts of a table operation share the same timer ID. */
int64_t timer_id;
/** The index of the next command to try for this operation. This may be
* different across different attempts of the same table operation. */
int request_index;
/** Whether the current invocation of the callback was triggered by a reply
* to an asynchronous Redis command. If not, then the callback was called
* directly. */
bool is_redis_reply;
} redis_requests_info;
db_handle *db_connect(const char *db_address,
int db_port,
const char *client_type,
const char *node_ip_address,
int num_args,
const char **args) {
DBHandle *db_connect(const char *db_address,
int db_port,
const char *client_type,
const char *node_ip_address,
int num_args,
const char **args) {
/* Check that the number of args is even. These args will be passed to the
* RAY.CONNECT Redis command, which takes arguments in pairs. */
if (num_args % 2 != 0) {
LOG_FATAL("The number of extra args must be divisible by two.");
}
db_handle *db = malloc(sizeof(db_handle));
DBHandle *db = (DBHandle *) malloc(sizeof(DBHandle));
/* Sync connection for initial handshake */
redisReply *reply;
int connection_attempts = 0;
@@ -124,21 +103,22 @@ db_handle *db_connect(const char *db_address,
* should only need to be done once (by whoever started Redis), but since
* Redis may be started in multiple places (e.g., for testing or when starting
* processes by hand), it is easier to do it multiple times. */
reply = redisCommand(context, "CONFIG SET notify-keyspace-events Kl");
reply = (redisReply *) redisCommand(context,
"CONFIG SET notify-keyspace-events Kl");
CHECKM(reply != NULL, "db_connect failed on CONFIG SET");
freeReplyObject(reply);
/* Also configure Redis to not run in protected mode, so clients on other
* hosts can connect to it. */
reply = redisCommand(context, "CONFIG SET protected-mode no");
reply = (redisReply *) redisCommand(context, "CONFIG SET protected-mode no");
CHECKM(reply != NULL, "db_connect failed on CONFIG SET");
freeReplyObject(reply);
/* Create a client ID for this client. */
db_client_id client = globally_unique_id();
DBClientID client = globally_unique_id();
/* Construct the argument arrays for RAY.CONNECT. */
int argc = num_args + 4;
const char **argv = malloc(sizeof(char *) * argc);
size_t *argvlen = malloc(sizeof(size_t) * argc);
const char **argv = (const char **) malloc(sizeof(char *) * argc);
size_t *argvlen = (size_t *) malloc(sizeof(size_t) * argc);
/* Set the command name argument. */
argv[0] = "RAY.CONNECT";
argvlen[0] = strlen(argv[0]);
@@ -163,7 +143,7 @@ db_handle *db_connect(const char *db_address,
/* Register this client with Redis. RAY.CONNECT is a custom Redis command that
* we've defined. */
reply = redisCommandArgv(context, argc, argv, argvlen);
reply = (redisReply *) redisCommandArgv(context, argc, argv, argvlen);
CHECKM(reply != NULL, "db_connect failed on RAY.CONNECT");
CHECK(reply->type != REDIS_REPLY_ERROR);
CHECK(strcmp(reply->str, "OK") == 0);
@@ -194,11 +174,11 @@ db_handle *db_connect(const char *db_address,
return db;
}
void db_disconnect(db_handle *db) {
void db_disconnect(DBHandle *db) {
redisFree(db->sync_context);
redisAsyncFree(db->context);
redisAsyncFree(db->sub_context);
db_client_cache_entry *e, *tmp;
DBClientCacheEntry *e, *tmp;
HASH_ITER(hh, db->db_client_cache, e, tmp) {
free(e->addr);
HASH_DELETE(hh, db->db_client_cache, e);
@@ -208,7 +188,7 @@ void db_disconnect(db_handle *db) {
free(db);
}
void db_attach(db_handle *db, event_loop *loop, bool reattach) {
void db_attach(DBHandle *db, event_loop *loop, bool reattach) {
db->loop = loop;
int err = redisAeAttach(loop, db->context);
/* If the database is reattached in the tests, redis normally gives
@@ -232,7 +212,7 @@ void redis_object_table_add_callback(redisAsyncContext *c,
REDIS_CALLBACK_HEADER(db, callback_data, r);
/* Do some minimal checking. */
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
if (strcmp(reply->str, "hash mismatch") == 0) {
/* If our object hash doesn't match the one recorded in the table, report
* the error back to the user and exit immediately. */
@@ -245,18 +225,19 @@ void redis_object_table_add_callback(redisAsyncContext *c,
CHECK(strcmp(reply->str, "OK") == 0);
/* Call the done callback if there is one. */
if (callback_data->done_callback != NULL) {
object_table_done_callback done_callback = callback_data->done_callback;
object_table_done_callback done_callback =
(object_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
/* Clean up the timer and callback. */
destroy_timer_callback(db->loop, callback_data);
}
void redis_object_table_add(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
void redis_object_table_add(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
object_table_add_data *info = callback_data->data;
object_id obj_id = callback_data->id;
ObjectTableAddData *info = (ObjectTableAddData *) callback_data->data;
ObjectID obj_id = callback_data->id;
int64_t object_size = info->object_size;
unsigned char *digest = info->digest;
@@ -277,7 +258,7 @@ void redis_object_table_remove_callback(redisAsyncContext *c,
REDIS_CALLBACK_HEADER(db, callback_data, r);
/* Do some minimal checking. */
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
if (strcmp(reply->str, "object not found") == 0) {
/* If our object entry was not in the table, it's probably a race
* condition with an object_table_add. */
@@ -287,20 +268,21 @@ void redis_object_table_remove_callback(redisAsyncContext *c,
CHECK(strcmp(reply->str, "OK") == 0);
/* Call the done callback if there is one. */
if (callback_data->done_callback != NULL) {
object_table_done_callback done_callback = callback_data->done_callback;
object_table_done_callback done_callback =
(object_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
/* Clean up the timer and callback. */
destroy_timer_callback(db->loop, callback_data);
}
void redis_object_table_remove(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
void redis_object_table_remove(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
object_id obj_id = callback_data->id;
ObjectID obj_id = callback_data->id;
/* If the caller provided a manager ID to delete, use it. Otherwise, use our
* own client ID as the ID to delete. */
db_client_id *client_id = callback_data->data;
DBClientID *client_id = (DBClientID *) callback_data->data;
if (client_id == NULL) {
client_id = &db->client;
}
@@ -314,11 +296,11 @@ void redis_object_table_remove(table_callback_data *callback_data) {
}
}
void redis_object_table_lookup(table_callback_data *callback_data) {
void redis_object_table_lookup(TableCallbackData *callback_data) {
CHECK(callback_data);
db_handle *db = callback_data->db_handle;
DBHandle *db = callback_data->db_handle;
object_id obj_id = callback_data->id;
ObjectID obj_id = callback_data->id;
int status = redisAsyncCommand(
db->context, redis_object_table_lookup_callback,
(void *) callback_data->timer_id, "RAY.OBJECT_TABLE_LOOKUP %b", obj_id.id,
@@ -332,24 +314,25 @@ void redis_result_table_add_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
/* Check that the command succeeded. */
CHECK(reply->type != REDIS_REPLY_ERROR);
CHECKM(strncmp(reply->str, "OK", strlen("OK")) == 0, "reply->str is %s",
reply->str);
/* Call the done callback if there is one. */
if (callback_data->done_callback) {
result_table_done_callback done_callback = callback_data->done_callback;
result_table_done_callback done_callback =
(result_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
destroy_timer_callback(db->loop, callback_data);
}
void redis_result_table_add(table_callback_data *callback_data) {
void redis_result_table_add(TableCallbackData *callback_data) {
CHECK(callback_data);
db_handle *db = callback_data->db_handle;
object_id id = callback_data->id;
task_id *result_task_id = (task_id *) callback_data->data;
DBHandle *db = callback_data->db_handle;
ObjectID id = callback_data->id;
TaskID *result_task_id = (TaskID *) callback_data->data;
/* Add the result entry to the result table. */
int status = redisAsyncCommand(
db->context, redis_result_table_add_callback,
@@ -363,8 +346,8 @@ void redis_result_table_add(table_callback_data *callback_data) {
/* This allocates a task which must be freed by the caller, unless the returned
* task is NULL. This is used by both redis_result_table_lookup_callback and
* redis_task_table_get_task_callback. */
task *parse_and_construct_task_from_redis_reply(redisReply *reply) {
task *task;
Task *parse_and_construct_task_from_redis_reply(redisReply *reply) {
Task *task;
if (reply->type == REDIS_REPLY_NIL) {
/* There is no task in the reply, so return NULL. */
task = NULL;
@@ -379,15 +362,15 @@ task *parse_and_construct_task_from_redis_reply(redisReply *reply) {
/* Parse the scheduling state. */
long long state = reply->element[0]->integer;
/* Parse the local scheduler db_client_id. */
db_client_id local_scheduler_id;
DBClientID local_scheduler_id;
CHECK(sizeof(local_scheduler_id) == reply->element[1]->len);
memcpy(local_scheduler_id.id, reply->element[1]->str,
reply->element[1]->len);
/* Parse the task spec. */
task_spec *spec = malloc(reply->element[2]->len);
task_spec *spec = (task_spec *) 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 = alloc_task(spec, state, local_scheduler_id);
task = Task_alloc(spec, state, local_scheduler_id);
/* Free the task spec. */
free_task_spec(spec);
} else {
@@ -401,19 +384,20 @@ void redis_result_table_lookup_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECKM(reply->type == REDIS_REPLY_NIL || reply->type == REDIS_REPLY_STRING,
"Unexpected reply type %d in redis_result_table_lookup_callback",
reply->type);
/* Parse the task from the reply. */
task_id result_id = NIL_TASK_ID;
TaskID result_id = NIL_TASK_ID;
if (reply->type == REDIS_REPLY_STRING) {
CHECK(reply->len == sizeof(result_id));
memcpy(&result_id, reply->str, reply->len);
}
/* Call the done callback if there is one. */
result_table_lookup_callback done_callback = callback_data->done_callback;
result_table_lookup_callback done_callback =
(result_table_lookup_callback) callback_data->done_callback;
if (done_callback != NULL) {
done_callback(callback_data->id, result_id, callback_data->user_context);
}
@@ -421,10 +405,10 @@ void redis_result_table_lookup_callback(redisAsyncContext *c,
destroy_timer_callback(db->loop, callback_data);
}
void redis_result_table_lookup(table_callback_data *callback_data) {
void redis_result_table_lookup(TableCallbackData *callback_data) {
CHECK(callback_data);
db_handle *db = callback_data->db_handle;
object_id id = callback_data->id;
DBHandle *db = callback_data->db_handle;
ObjectID id = callback_data->id;
int status =
redisAsyncCommand(db->context, redis_result_table_lookup_callback,
(void *) callback_data->timer_id,
@@ -442,20 +426,20 @@ void redis_result_table_lookup(table_callback_data *callback_data) {
* @param manager The pointer where the IP address of the manager gets written.
* @return Void.
*/
void redis_get_cached_db_client(db_handle *db,
db_client_id db_client_id,
void redis_get_cached_db_client(DBHandle *db,
DBClientID db_client_id,
const char **manager) {
db_client_cache_entry *entry;
DBClientCacheEntry *entry;
HASH_FIND(hh, db->db_client_cache, &db_client_id, sizeof(db_client_id),
entry);
if (!entry) {
/* This is a very rare case. It should happen at most once per db client. */
redisReply *reply =
redisCommand(db->sync_context, "RAY.GET_CLIENT_ADDRESS %b",
(char *) db_client_id.id, sizeof(db_client_id.id));
redisReply *reply = (redisReply *) redisCommand(
db->sync_context, "RAY.GET_CLIENT_ADDRESS %b", (char *) db_client_id.id,
sizeof(db_client_id.id));
CHECKM(reply->type == REDIS_REPLY_STRING, "REDIS reply type=%d, str=%s",
reply->type, reply->str);
entry = malloc(sizeof(db_client_cache_entry));
entry = (DBClientCacheEntry *) malloc(sizeof(DBClientCacheEntry));
entry->db_client_id = db_client_id;
entry->addr = strdup(reply->str);
HASH_ADD(hh, db->db_client_cache, db_client_id, sizeof(db_client_id),
@@ -469,13 +453,13 @@ void redis_object_table_lookup_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
LOG_DEBUG("Object table lookup callback");
CHECK(reply->type == REDIS_REPLY_NIL || reply->type == REDIS_REPLY_ARRAY);
object_id obj_id = callback_data->id;
ObjectID obj_id = callback_data->id;
int64_t manager_count = 0;
db_client_id *managers = NULL;
DBClientID *managers = NULL;
const char **manager_vector = NULL;
/* Parse the Redis reply. */
@@ -485,8 +469,8 @@ void redis_object_table_lookup_callback(redisAsyncContext *c,
} else if (reply->type == REDIS_REPLY_ARRAY) {
manager_count = reply->elements;
if (manager_count > 0) {
managers = malloc(reply->elements * sizeof(db_client_id));
manager_vector = malloc(manager_count * sizeof(char *));
managers = (DBClientID *) malloc(reply->elements * sizeof(DBClientID));
manager_vector = (const char **) malloc(manager_count * sizeof(char *));
}
for (int j = 0; j < reply->elements; ++j) {
CHECK(reply->element[j]->type == REDIS_REPLY_STRING);
@@ -498,7 +482,7 @@ void redis_object_table_lookup_callback(redisAsyncContext *c,
}
object_table_lookup_done_callback done_callback =
callback_data->done_callback;
(object_table_lookup_done_callback) callback_data->done_callback;
if (done_callback) {
done_callback(obj_id, manager_count, manager_vector,
callback_data->user_context);
@@ -530,50 +514,50 @@ void redis_object_table_lookup_callback(redisAsyncContext *c,
* The caller is responsible for freeing this array.
* @return The object ID that the notification is about.
*/
object_id parse_subscribe_to_notifications_payload(
db_handle *db,
ObjectID parse_subscribe_to_notifications_payload(
DBHandle *db,
char *payload,
int length,
int64_t *data_size,
int *manager_count,
const char ***manager_vector) {
long long data_size_value = 0;
int num_managers = (length - sizeof(object_id) - 1 - sizeof(data_size_value) -
int num_managers = (length - sizeof(ObjectID) - 1 - sizeof(data_size_value) -
1 - strlen("MANAGERS")) /
(1 + sizeof(db_client_id));
(1 + sizeof(DBClientID));
int64_t rval = sizeof(object_id) + 1 + sizeof(data_size_value) + 1 +
strlen("MANAGERS") + num_managers * (1 + sizeof(db_client_id));
int64_t rval = sizeof(ObjectID) + 1 + sizeof(data_size_value) + 1 +
strlen("MANAGERS") + num_managers * (1 + sizeof(DBClientID));
CHECKM(length == rval,
"length mismatch: num_managers = %d, length = %d, rval = %" PRId64,
num_managers, length, rval);
CHECK(num_managers > 0);
object_id obj_id;
ObjectID obj_id;
/* Track our current offset in the payload. */
int offset = 0;
/* Parse the object ID. */
memcpy(&obj_id.id, &payload[offset], sizeof(obj_id.id));
offset += sizeof(obj_id.id);
/* The next part of the payload is a space. */
char *space_str = " ";
const char *space_str = " ";
CHECK(memcmp(&payload[offset], space_str, strlen(space_str)) == 0);
offset += strlen(space_str);
/* The next part of the payload is binary data_size. */
memcpy(&data_size_value, &payload[offset], sizeof(data_size_value));
offset += sizeof(data_size_value);
/* The next part of the payload is the string " MANAGERS" with leading ' '. */
char *managers_str = " MANAGERS";
const char *managers_str = " MANAGERS";
CHECK(memcmp(&payload[offset], managers_str, strlen(managers_str)) == 0);
offset += strlen(managers_str);
/* Parse the managers. */
const char **managers = malloc(num_managers * sizeof(char *));
const char **managers = (const char **) malloc(num_managers * sizeof(char *));
for (int i = 0; i < num_managers; ++i) {
/* First there is a space. */
CHECK(memcmp(&payload[offset], " ", strlen(" ")) == 0);
offset += strlen(" ");
/* Get the manager ID. */
db_client_id manager_id;
DBClientID manager_id;
memcpy(&manager_id.id, &payload[offset], sizeof(manager_id.id));
offset += sizeof(manager_id.id);
/* Write the address of the corresponding manager to the returned array. */
@@ -605,7 +589,7 @@ void object_table_redis_subscribe_to_notifications_callback(
* - reply->element[1]->str is the name of the channel
* - reply->emement[2]->str is the contents of the message.
*/
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(reply->type == REDIS_REPLY_ARRAY);
CHECK(reply->elements == 3);
redisReply *message_type = reply->element[0];
@@ -617,11 +601,12 @@ void object_table_redis_subscribe_to_notifications_callback(
int64_t data_size = 0;
int manager_count;
const char **manager_vector;
object_id obj_id = parse_subscribe_to_notifications_payload(
ObjectID obj_id = parse_subscribe_to_notifications_payload(
db, reply->element[2]->str, reply->element[2]->len, &data_size,
&manager_count, &manager_vector);
/* Call the subscribe callback. */
object_table_subscribe_data *data = callback_data->data;
ObjectTableSubscribeData *data =
(ObjectTableSubscribeData *) callback_data->data;
if (data->object_available_callback) {
data->object_available_callback(obj_id, data_size, manager_count,
manager_vector, data->subscribe_context);
@@ -633,7 +618,7 @@ void object_table_redis_subscribe_to_notifications_callback(
* used in the tests. */
if (callback_data->done_callback != NULL) {
object_table_lookup_done_callback done_callback =
callback_data->done_callback;
(object_table_lookup_done_callback) callback_data->done_callback;
done_callback(NIL_ID, 0, NULL, callback_data->user_context);
}
/* If the initial SUBSCRIBE was successful, clean up the timer, but don't
@@ -647,8 +632,8 @@ void object_table_redis_subscribe_to_notifications_callback(
}
void redis_object_table_subscribe_to_notifications(
table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
/* The object channel prefix must match the value defined in
* src/common/redismodule/ray_redis_module.c. */
const char *object_channel_prefix = "OC:";
@@ -659,7 +644,7 @@ void redis_object_table_subscribe_to_notifications(
* The channel name should probably be the client ID with some prefix. */
CHECKM(callback_data->data != NULL,
"Object table subscribe data passed as NULL.");
if (((object_table_subscribe_data *) (callback_data->data))->subscribe_all) {
if (((ObjectTableSubscribeData *) (callback_data->data))->subscribe_all) {
/* Subscribe to the object broadcast channel. */
status = redisAsyncCommand(
db->sub_context, object_table_redis_subscribe_to_notifications_callback,
@@ -684,7 +669,7 @@ void redis_object_table_request_notifications_callback(redisAsyncContext *c,
REDIS_CALLBACK_HEADER(db, callback_data, r);
/* Do some minimal checking. */
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(strcmp(reply->str, "OK") == 0);
CHECK(callback_data->done_callback == NULL);
/* Clean up the timer and callback. */
@@ -692,17 +677,18 @@ void redis_object_table_request_notifications_callback(redisAsyncContext *c,
}
void redis_object_table_request_notifications(
table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
object_table_request_notifications_data *request_data = callback_data->data;
ObjectTableRequestNotificationsData *request_data =
(ObjectTableRequestNotificationsData *) callback_data->data;
int num_object_ids = request_data->num_object_ids;
object_id *object_ids = request_data->object_ids;
ObjectID *object_ids = request_data->object_ids;
/* Create the arguments for the Redis command. */
int num_args = 1 + 1 + num_object_ids;
const char **argv = malloc(sizeof(char *) * num_args);
size_t *argvlen = malloc(sizeof(size_t) * num_args);
const char **argv = (const char **) malloc(sizeof(char *) * num_args);
size_t *argvlen = (size_t *) malloc(sizeof(size_t) * num_args);
/* Set the command name argument. */
argv[0] = "RAY.OBJECT_TABLE_REQUEST_NOTIFICATIONS";
argvlen[0] = strlen(argv[0]);
@@ -735,25 +721,26 @@ void redis_task_table_get_task_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
/* Parse the task from the reply. */
task *task = parse_and_construct_task_from_redis_reply(reply);
Task *task = parse_and_construct_task_from_redis_reply(reply);
/* Call the done callback if there is one. */
task_table_get_callback done_callback = callback_data->done_callback;
task_table_get_callback done_callback =
(task_table_get_callback) callback_data->done_callback;
if (done_callback != NULL) {
done_callback(task, callback_data->user_context);
}
/* Free the task if it is not NULL. */
free_task(task);
Task_free(task);
/* Clean up the timer and callback. */
destroy_timer_callback(db->loop, callback_data);
}
void redis_task_table_get_task(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
void redis_task_table_get_task(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
CHECK(callback_data->data == NULL);
task_id task_id = callback_data->id;
TaskID task_id = callback_data->id;
int status = redisAsyncCommand(
db->context, redis_task_table_get_task_callback,
@@ -770,24 +757,25 @@ void redis_task_table_add_task_callback(redisAsyncContext *c,
REDIS_CALLBACK_HEADER(db, callback_data, r);
/* Do some minimal checking. */
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECKM(strcmp(reply->str, "OK") == 0, "reply->str is %s", reply->str);
/* Call the done callback if there is one. */
if (callback_data->done_callback != NULL) {
task_table_done_callback done_callback = callback_data->done_callback;
task_table_done_callback done_callback =
(task_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
/* Clean up the timer and callback. */
destroy_timer_callback(db->loop, callback_data);
}
void redis_task_table_add_task(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
task *task = callback_data->data;
task_id task_id = task_task_id(task);
db_client_id local_scheduler_id = task_local_scheduler(task);
int state = task_state(task);
task_spec *spec = task_task_spec(task);
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);
int state = Task_state(task);
task_spec *spec = Task_task_spec(task);
CHECKM(task != NULL, "NULL task passed to redis_task_table_add_task.");
int status = redisAsyncCommand(
@@ -806,23 +794,24 @@ void redis_task_table_update_callback(redisAsyncContext *c,
REDIS_CALLBACK_HEADER(db, callback_data, r);
/* Do some minimal checking. */
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECKM(strcmp(reply->str, "OK") == 0, "reply->str is %s", reply->str);
/* Call the done callback if there is one. */
if (callback_data->done_callback != NULL) {
task_table_done_callback done_callback = callback_data->done_callback;
task_table_done_callback done_callback =
(task_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
/* Clean up the timer and callback. */
destroy_timer_callback(db->loop, callback_data);
}
void redis_task_table_update(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
task *task = callback_data->data;
task_id task_id = task_task_id(task);
db_client_id local_scheduler_id = task_local_scheduler(task);
int state = task_state(task);
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);
int state = Task_state(task);
CHECKM(task != NULL, "NULL task passed to redis_task_table_update.");
int status = redisAsyncCommand(
@@ -839,26 +828,28 @@ void redis_task_table_test_and_update_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
/* Parse the task from the reply. */
task *task = parse_and_construct_task_from_redis_reply(reply);
Task *task = parse_and_construct_task_from_redis_reply(reply);
/* Call the done callback if there is one. */
task_table_get_callback done_callback = callback_data->done_callback;
task_table_get_callback done_callback =
(task_table_get_callback) callback_data->done_callback;
if (done_callback != NULL) {
done_callback(task, callback_data->user_context);
}
/* Free the task if it is not NULL. */
if (task != NULL) {
free_task(task);
Task_free(task);
}
/* Clean up timer and callback. */
destroy_timer_callback(db->loop, callback_data);
}
void redis_task_table_test_and_update(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
task_id task_id = callback_data->id;
task_table_test_and_update_data *update_data = callback_data->data;
void redis_task_table_test_and_update(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
TaskID task_id = callback_data->id;
TaskTableTestAndUpdateData *update_data =
(TaskTableTestAndUpdateData *) callback_data->data;
int status = redisAsyncCommand(
db->context, redis_task_table_test_and_update_callback,
@@ -877,9 +868,9 @@ void redis_task_table_test_and_update(table_callback_data *callback_data) {
* Make this code nicer. */
void parse_task_table_subscribe_callback(char *payload,
int length,
task_id *task_id,
TaskID *task_id,
int *state,
db_client_id *local_scheduler_id,
DBClientID *local_scheduler_id,
task_spec **spec) {
/* Note that the state is padded with spaces to consist of precisely two
* characters. */
@@ -890,7 +881,7 @@ void parse_task_table_subscribe_callback(char *payload,
memcpy(task_id, &payload[offset], sizeof(*task_id));
offset += sizeof(*task_id);
/* Read in a space. */
char *space_str = " ";
const char *space_str = (const char *) " ";
CHECK(memcmp(space_str, &payload[offset], strlen(space_str)) == 0);
offset += strlen(space_str);
/* Read in the state, which is an integer left-padded with spaces to two
@@ -907,7 +898,7 @@ 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 = malloc(task_spec_payload_size);
*spec = (task_spec *) malloc(task_spec_payload_size);
memcpy(*spec, &payload[offset], task_spec_payload_size);
CHECK(task_spec_size(*spec) == task_spec_payload_size);
}
@@ -916,7 +907,7 @@ void redis_task_table_subscribe_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(reply->type == REDIS_REPLY_ARRAY);
/* The number of elements is 3 for a reply to SUBSCRIBE, and 4 for a reply to
@@ -931,27 +922,29 @@ void redis_task_table_subscribe_callback(redisAsyncContext *c,
if (strcmp(message_type->str, "message") == 0 ||
strcmp(message_type->str, "pmessage") == 0) {
/* Handle a task table event. Parse the payload and call the callback. */
task_table_subscribe_data *data = callback_data->data;
TaskTableSubscribeData *data =
(TaskTableSubscribeData *) callback_data->data;
/* Read out the information from the payload. */
task_id task_id;
TaskID task_id;
int state;
db_client_id local_scheduler_id;
DBClientID local_scheduler_id;
task_spec *spec;
parse_task_table_subscribe_callback(payload->str, payload->len, &task_id,
&state, &local_scheduler_id, &spec);
task *task = alloc_task(spec, state, local_scheduler_id);
Task *task = Task_alloc(spec, state, local_scheduler_id);
free(spec);
/* Call the subscribe callback if there is one. */
if (data->subscribe_callback != NULL) {
data->subscribe_callback(task, data->subscribe_context);
}
free_task(task);
Task_free(task);
} else if (strcmp(message_type->str, "subscribe") == 0 ||
strcmp(message_type->str, "psubscribe") == 0) {
/* If this condition is true, we got the initial message that acknowledged
* the subscription. */
if (callback_data->done_callback != NULL) {
task_table_done_callback done_callback = callback_data->done_callback;
task_table_done_callback done_callback =
(task_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
/* Note that we do not destroy the callback data yet because the
@@ -964,9 +957,9 @@ void redis_task_table_subscribe_callback(redisAsyncContext *c,
}
}
void redis_task_table_subscribe(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
task_table_subscribe_data *data = callback_data->data;
void redis_task_table_subscribe(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
TaskTableSubscribeData *data = (TaskTableSubscribeData *) callback_data->data;
/* TASK_CHANNEL_PREFIX is defined in ray_redis_module.c and must be kept in
* sync with that file. */
const char *TASK_CHANNEL_PREFIX = "TT:";
@@ -979,7 +972,7 @@ void redis_task_table_subscribe(table_callback_data *callback_data) {
(void *) callback_data->timer_id, "PSUBSCRIBE %s*:%2d",
TASK_CHANNEL_PREFIX, data->state_filter);
} else {
db_client_id local_scheduler_id = data->local_scheduler_id;
DBClientID local_scheduler_id = data->local_scheduler_id;
status = redisAsyncCommand(
db->sub_context, redis_task_table_subscribe_callback,
(void *) callback_data->timer_id, "SUBSCRIBE %s%b:%2d",
@@ -999,7 +992,7 @@ void redis_db_client_table_subscribe_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(reply->type == REDIS_REPLY_ARRAY);
CHECK(reply->elements > 2);
@@ -1011,7 +1004,7 @@ void redis_db_client_table_subscribe_callback(redisAsyncContext *c,
if (payload->str == NULL) {
if (callback_data->done_callback) {
db_client_table_done_callback done_callback =
callback_data->done_callback;
(db_client_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
/* Note that we do not destroy the callback data yet because the
@@ -1020,14 +1013,15 @@ void redis_db_client_table_subscribe_callback(redisAsyncContext *c,
return;
}
/* Otherwise, parse the payload and call the callback. */
db_client_table_subscribe_data *data = callback_data->data;
db_client_id client;
DBClientTableSubscribeData *data =
(DBClientTableSubscribeData *) callback_data->data;
DBClientID client;
memcpy(client.id, payload->str, sizeof(client.id));
/* We subtract 1 + sizeof(client.id) to compute the length of the
* client_type string, and we add 1 to null-terminate the string. */
int client_type_length = payload->len - 1 - sizeof(client.id) + 1;
char *client_type = malloc(client_type_length);
char *aux_address = malloc(client_type_length);
char *client_type = (char *) malloc(client_type_length);
char *aux_address = (char *) malloc(client_type_length);
memset(aux_address, 0, client_type_length);
/* Published message format: <client_id:client_type aux_addr> */
int rv = sscanf(&payload->str[1 + sizeof(client.id)], "%s %s", client_type,
@@ -1044,8 +1038,8 @@ void redis_db_client_table_subscribe_callback(redisAsyncContext *c,
free(aux_address);
}
void redis_db_client_table_subscribe(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
void redis_db_client_table_subscribe(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
int status = redisAsyncCommand(
db->sub_context, redis_db_client_table_subscribe_callback,
(void *) callback_data->timer_id, "SUBSCRIBE db_clients");
@@ -1060,7 +1054,7 @@ void redis_local_scheduler_table_subscribe_callback(redisAsyncContext *c,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(reply->type == REDIS_REPLY_ARRAY);
CHECK(reply->elements == 3);
redisReply *message_type = reply->element[0];
@@ -1071,9 +1065,10 @@ void redis_local_scheduler_table_subscribe_callback(redisAsyncContext *c,
/* Handle a local scheduler heartbeat. Parse the payload and call the
* subscribe callback. */
redisReply *payload = reply->element[2];
local_scheduler_table_subscribe_data *data = callback_data->data;
db_client_id client_id;
local_scheduler_info info;
LocalSchedulerTableSubscribeData *data =
(LocalSchedulerTableSubscribeData *) callback_data->data;
DBClientID client_id;
LocalSchedulerInfo info;
/* The payload should be the concatenation of these two structs. */
CHECK(sizeof(client_id) + sizeof(info) == payload->len);
memcpy(&client_id, payload->str, sizeof(client_id));
@@ -1093,8 +1088,8 @@ void redis_local_scheduler_table_subscribe_callback(redisAsyncContext *c,
}
}
void redis_local_scheduler_table_subscribe(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
void redis_local_scheduler_table_subscribe(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
int status = redisAsyncCommand(
db->sub_context, redis_local_scheduler_table_subscribe_callback,
(void *) callback_data->timer_id, "SUBSCRIBE local_schedulers");
@@ -1109,7 +1104,7 @@ void redis_local_scheduler_table_send_info_callback(redisAsyncContext *c,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(reply->type == REDIS_REPLY_INTEGER);
LOG_DEBUG("%" PRId64 " subscribers received this publish.\n", reply->integer);
@@ -1118,9 +1113,10 @@ void redis_local_scheduler_table_send_info_callback(redisAsyncContext *c,
destroy_timer_callback(db->loop, callback_data);
}
void redis_local_scheduler_table_send_info(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
local_scheduler_table_send_info_data *data = callback_data->data;
void redis_local_scheduler_table_send_info(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
LocalSchedulerTableSendInfoData *data =
(LocalSchedulerTableSendInfoData *) callback_data->data;
int status = redisAsyncCommand(
db->context, redis_local_scheduler_table_send_info_callback,
(void *) callback_data->timer_id, "PUBLISH local_schedulers %b%b",
@@ -1136,7 +1132,7 @@ void redis_actor_notification_table_subscribe_callback(redisAsyncContext *c,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(reply->type == REDIS_REPLY_ARRAY);
CHECK(reply->elements == 3);
redisReply *message_type = reply->element[0];
@@ -1147,8 +1143,9 @@ void redis_actor_notification_table_subscribe_callback(redisAsyncContext *c,
/* Handle an actor notification message. Parse the payload and call the
* subscribe callback. */
redisReply *payload = reply->element[2];
actor_notification_table_subscribe_data *data = callback_data->data;
actor_info info;
ActorNotificationTableSubscribeData *data =
(ActorNotificationTableSubscribeData *) callback_data->data;
ActorInfo info;
/* The payload should be the concatenation of these two structs. */
CHECK(sizeof(info.actor_id) + sizeof(info.local_scheduler_id) ==
payload->len);
@@ -1171,8 +1168,8 @@ void redis_actor_notification_table_subscribe_callback(redisAsyncContext *c,
}
void redis_actor_notification_table_subscribe(
table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
int status = redisAsyncCommand(
db->sub_context, redis_actor_notification_table_subscribe_callback,
(void *) callback_data->timer_id, "SUBSCRIBE actor_notifications");
@@ -1186,7 +1183,7 @@ void redis_object_info_subscribe_callback(redisAsyncContext *c,
void *r,
void *privdata) {
REDIS_CALLBACK_HEADER(db, callback_data, r);
redisReply *reply = r;
redisReply *reply = (redisReply *) r;
CHECK(reply->type == REDIS_REPLY_ARRAY);
@@ -1199,7 +1196,7 @@ void redis_object_info_subscribe_callback(redisAsyncContext *c,
if (payload->str == NULL) {
if (callback_data->done_callback) {
db_client_table_done_callback done_callback =
callback_data->done_callback;
(db_client_table_done_callback) callback_data->done_callback;
done_callback(callback_data->id, callback_data->user_context);
}
/* Note that we do not destroy the callback data yet because the
@@ -1208,10 +1205,11 @@ void redis_object_info_subscribe_callback(redisAsyncContext *c,
return;
}
/* Otherwise, parse the payload and call the callback. */
object_info_subscribe_data *data = callback_data->data;
object_id object_id;
ObjectInfoSubscribeData *data =
(ObjectInfoSubscribeData *) callback_data->data;
ObjectID object_id;
memcpy(object_id.id, payload->str, sizeof(object_id.id));
/* payload->str should have the format: "object_id:object_size_int" */
/* payload->str should have the format: "ObjectID:object_size_int" */
LOG_DEBUG("obj:info channel received message <%s>", payload->str);
if (data->subscribe_callback) {
data->subscribe_callback(
@@ -1220,8 +1218,8 @@ void redis_object_info_subscribe_callback(redisAsyncContext *c,
}
}
void redis_object_info_subscribe(table_callback_data *callback_data) {
db_handle *db = callback_data->db_handle;
void redis_object_info_subscribe(TableCallbackData *callback_data) {
DBHandle *db = callback_data->db_handle;
int status = redisAsyncCommand(
db->sub_context, redis_object_info_subscribe_callback,
(void *) callback_data->timer_id, "PSUBSCRIBE obj:info");
@@ -1230,7 +1228,7 @@ void redis_object_info_subscribe(table_callback_data *callback_data) {
}
}
db_client_id get_db_client_id(db_handle *db) {
DBClientID get_db_client_id(DBHandle *db) {
CHECK(db != NULL);
return db->client;
}
+22 -24
View File
@@ -22,18 +22,18 @@
typedef struct {
/** Unique ID for this db client. */
db_client_id db_client_id;
DBClientID db_client_id;
/** IP address and port of this db client. */
char *addr;
/** Handle for the uthash table. */
UT_hash_handle hh;
} db_client_cache_entry;
} DBClientCacheEntry;
struct db_handle {
struct DBHandle {
/** String that identifies this client type. */
char *client_type;
/** Unique ID for this client. */
db_client_id client;
DBClientID client;
/** Redis context for all non-subscribe connections. */
redisAsyncContext *context;
/** Redis context for "subscribe" communication. Yes, we need a separate one
@@ -45,7 +45,7 @@ struct db_handle {
int64_t db_index;
/** Cache for the IP addresses of db clients. This is a hash table mapping
* client IDs to addresses. */
db_client_cache_entry *db_client_cache;
DBClientCacheEntry *db_client_cache;
/** Redis context for synchronous connections. This should only be used very
* rarely, it is not asynchronous. */
redisContext *sync_context;
@@ -70,7 +70,7 @@ void object_table_lookup_callback(redisAsyncContext *c,
* information.
* @return Void.
*/
void redis_object_table_lookup(table_callback_data *callback_data);
void redis_object_table_lookup(TableCallbackData *callback_data);
/**
* Add a location entry to the object table in redis.
@@ -79,7 +79,7 @@ void redis_object_table_lookup(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_object_table_add(table_callback_data *callback_data);
void redis_object_table_add(TableCallbackData *callback_data);
/**
* Remove a location entry from the object table in redis.
@@ -88,7 +88,7 @@ void redis_object_table_add(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_object_table_remove(table_callback_data *callback_data);
void redis_object_table_remove(TableCallbackData *callback_data);
/**
* Create a client-specific channel for receiving notifications from the object
@@ -99,7 +99,7 @@ void redis_object_table_remove(table_callback_data *callback_data);
* @return Void.
*/
void redis_object_table_subscribe_to_notifications(
table_callback_data *callback_data);
TableCallbackData *callback_data);
/**
* Request notifications about when certain objects become available.
@@ -108,8 +108,7 @@ void redis_object_table_subscribe_to_notifications(
* information.
* @return Void.
*/
void redis_object_table_request_notifications(
table_callback_data *callback_data);
void redis_object_table_request_notifications(TableCallbackData *callback_data);
/**
* Add a new object to the object table in redis.
@@ -118,7 +117,7 @@ void redis_object_table_request_notifications(
* information.
* @return Void.
*/
void redis_result_table_add(table_callback_data *callback_data);
void redis_result_table_add(TableCallbackData *callback_data);
/**
* Lookup the task that created the object in redis. The result is the task ID.
@@ -127,7 +126,7 @@ void redis_result_table_add(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_result_table_lookup(table_callback_data *callback_data);
void redis_result_table_lookup(TableCallbackData *callback_data);
/**
* Callback invoked when the reply from the object table lookup command is
@@ -154,7 +153,7 @@ void redis_object_table_lookup_callback(redisAsyncContext *c,
* information.
* @return Void.
*/
void redis_task_table_get_task(table_callback_data *callback_data);
void redis_task_table_get_task(TableCallbackData *callback_data);
/**
* Add a task table entry with a new task spec and the task's scheduling
@@ -164,7 +163,7 @@ void redis_task_table_get_task(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_task_table_add_task(table_callback_data *callback_data);
void redis_task_table_add_task(TableCallbackData *callback_data);
/**
* Update a task table entry with the task's scheduling information.
@@ -173,7 +172,7 @@ void redis_task_table_add_task(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_task_table_update(table_callback_data *callback_data);
void redis_task_table_update(TableCallbackData *callback_data);
/**
* Update a task table entry with the task's scheduling information, if the
@@ -183,7 +182,7 @@ void redis_task_table_update(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_task_table_test_and_update(table_callback_data *callback_data);
void redis_task_table_test_and_update(TableCallbackData *callback_data);
/**
* Callback invoked when the reply from the task push command is received.
@@ -216,7 +215,7 @@ void redis_task_table_publish_publish_callback(redisAsyncContext *c,
* information.
* @return Void.
*/
void redis_task_table_subscribe(table_callback_data *callback_data);
void redis_task_table_subscribe(TableCallbackData *callback_data);
/**
* Subscribe to updates from the db client table.
@@ -225,7 +224,7 @@ void redis_task_table_subscribe(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_db_client_table_subscribe(table_callback_data *callback_data);
void redis_db_client_table_subscribe(TableCallbackData *callback_data);
/**
* Subscribe to updates from the local scheduler table.
@@ -234,7 +233,7 @@ void redis_db_client_table_subscribe(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_local_scheduler_table_subscribe(table_callback_data *callback_data);
void redis_local_scheduler_table_subscribe(TableCallbackData *callback_data);
/**
* Publish an update to the local scheduler table.
@@ -243,7 +242,7 @@ void redis_local_scheduler_table_subscribe(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_local_scheduler_table_send_info(table_callback_data *callback_data);
void redis_local_scheduler_table_send_info(TableCallbackData *callback_data);
/**
* Subscribe to updates about newly created actors.
@@ -252,9 +251,8 @@ void redis_local_scheduler_table_send_info(table_callback_data *callback_data);
* information.
* @return Void.
*/
void redis_actor_notification_table_subscribe(
table_callback_data *callback_data);
void redis_actor_notification_table_subscribe(TableCallbackData *callback_data);
void redis_object_info_subscribe(table_callback_data *callback_data);
void redis_object_info_subscribe(TableCallbackData *callback_data);
#endif /* REDIS_H */
+22 -22
View File
@@ -4,27 +4,27 @@
#include "redis.h"
/* The default behavior is to retry every ten seconds forever. */
static const retry_info default_retry = {.num_retries = -1,
.timeout = 10000,
.fail_callback = NULL};
static const RetryInfo default_retry = {.num_retries = -1,
.timeout = 10000,
.fail_callback = NULL};
table_callback_data *init_table_callback(db_handle *db_handle,
unique_id id,
const char *label,
OWNER void *data,
retry_info *retry,
table_done_callback done_callback,
table_retry_callback retry_callback,
void *user_context) {
TableCallbackData *init_table_callback(DBHandle *db_handle,
UniqueID id,
const char *label,
OWNER void *data,
RetryInfo *retry,
table_done_callback done_callback,
table_retry_callback retry_callback,
void *user_context) {
CHECK(db_handle);
CHECK(db_handle->loop);
/* If no retry info is provided, use the default retry info. */
if (retry == NULL) {
retry = (retry_info *) &default_retry;
retry = (RetryInfo *) &default_retry;
}
CHECK(retry);
/* Allocate and initialize callback data structure for object table */
table_callback_data *callback_data = malloc(sizeof(table_callback_data));
TableCallbackData *callback_data = malloc(sizeof(TableCallbackData));
CHECKM(callback_data != NULL, "Memory allocation error!")
callback_data->id = id;
callback_data->label = label;
@@ -49,12 +49,12 @@ table_callback_data *init_table_callback(db_handle *db_handle,
}
void destroy_timer_callback(event_loop *loop,
table_callback_data *callback_data) {
TableCallbackData *callback_data) {
event_loop_remove_timer(loop, callback_data->timer_id);
destroy_table_callback(callback_data);
}
void destroy_table_callback(table_callback_data *callback_data) {
void destroy_table_callback(TableCallbackData *callback_data) {
CHECK(callback_data != NULL);
if (callback_data->requests_info)
@@ -76,7 +76,7 @@ int64_t table_timeout_handler(event_loop *loop,
void *user_context) {
CHECK(loop != NULL);
CHECK(user_context != NULL);
table_callback_data *callback_data = (table_callback_data *) user_context;
TableCallbackData *callback_data = (TableCallbackData *) user_context;
CHECK(callback_data->retry.num_retries >= 0 ||
callback_data->retry.num_retries == -1);
@@ -133,24 +133,24 @@ int64_t table_timeout_handler(event_loop *loop,
* When the last timeout associated to the command expires we remove the entry
* associated to the callback.
*/
static table_callback_data *outstanding_callbacks = NULL;
static TableCallbackData *outstanding_callbacks = NULL;
void outstanding_callbacks_add(table_callback_data *callback_data) {
void outstanding_callbacks_add(TableCallbackData *callback_data) {
HASH_ADD_INT(outstanding_callbacks, timer_id, callback_data);
}
table_callback_data *outstanding_callbacks_find(int64_t key) {
table_callback_data *callback_data = NULL;
TableCallbackData *outstanding_callbacks_find(int64_t key) {
TableCallbackData *callback_data = NULL;
HASH_FIND_INT(outstanding_callbacks, &key, callback_data);
return callback_data;
}
void outstanding_callbacks_remove(table_callback_data *callback_data) {
void outstanding_callbacks_remove(TableCallbackData *callback_data) {
HASH_DEL(outstanding_callbacks, callback_data);
}
void destroy_outstanding_callbacks(event_loop *loop) {
table_callback_data *callback_data, *tmp;
TableCallbackData *callback_data, *tmp;
HASH_ITER(hh, outstanding_callbacks, callback_data, tmp) {
destroy_timer_callback(loop, callback_data);
}
+24 -25
View File
@@ -7,7 +7,7 @@
#include "common.h"
#include "db.h"
typedef struct table_callback_data table_callback_data;
typedef struct TableCallbackData TableCallbackData;
typedef void *table_done_callback;
@@ -17,20 +17,20 @@ typedef void *table_done_callback;
* @param id The unique ID that identifies this callback. Examples include an
* object ID or task ID.
* @param user_context The state context for the callback. This is equivalent
* to the user_context field in table_callback_data.
* to the user_context field in TableCallbackData.
* @param user_data A data argument for the callback. This is equivalent to the
* data field in table_callback_data. The user is responsible for
* data field in TableCallbackData. The user is responsible for
* freeing user_data.
*/
typedef void (*table_fail_callback)(unique_id id,
typedef void (*table_fail_callback)(UniqueID id,
void *user_context,
void *user_data);
typedef void (*table_retry_callback)(table_callback_data *callback_data);
typedef void (*table_retry_callback)(TableCallbackData *callback_data);
/**
* Data structure consolidating the retry related variables. If a NULL
* retry_info struct is used, the default behavior will be to retry infinitely
* RetryInfo struct is used, the default behavior will be to retry infinitely
* many times.
*/
typedef struct {
@@ -42,12 +42,12 @@ typedef struct {
uint64_t timeout;
/** The callback that will be called if there are no more retries left. */
table_fail_callback fail_callback;
} retry_info;
} RetryInfo;
struct table_callback_data {
struct TableCallbackData {
/** ID of the entry in the table that we are going to look up, remove or add.
*/
unique_id id;
UniqueID id;
/** A label to identify the original request for logging purposes. */
const char *label;
/** The callback that will be called when results is returned. */
@@ -57,7 +57,7 @@ struct table_callback_data {
/** Retry information containing the remaining number of retries, the timeout
* before the next retry, and a pointer to the failure callback.
*/
retry_info retry;
RetryInfo retry;
/** Pointer to the data that is entered into the table. This can be used to
* pass the result of the call to the callback. The callback takes ownership
* over this data and will free it. */
@@ -68,7 +68,7 @@ struct table_callback_data {
/** User context. */
void *user_context;
/** Handle to db. */
db_handle *db_handle;
DBHandle *db_handle;
/** Handle to timer. */
int64_t timer_id;
UT_hash_handle hh; /* makes this structure hashable */
@@ -104,14 +104,14 @@ int64_t table_timeout_handler(event_loop *loop,
* passed on to the various callbacks.
* @return New table callback data struct.
*/
table_callback_data *init_table_callback(db_handle *db_handle,
unique_id id,
const char *label,
OWNER void *data,
retry_info *retry,
table_done_callback done_callback,
table_retry_callback retry_callback,
void *user_context);
TableCallbackData *init_table_callback(DBHandle *db_handle,
UniqueID id,
const char *label,
OWNER void *data,
RetryInfo *retry,
table_done_callback done_callback,
table_retry_callback retry_callback,
void *user_context);
/**
* Destroy any state associated with the callback data. This removes all
@@ -122,7 +122,7 @@ table_callback_data *init_table_callback(db_handle *db_handle,
* want to remove.
* @return Void.
*/
void destroy_table_callback(table_callback_data *callback_data);
void destroy_table_callback(TableCallbackData *callback_data);
/**
* Destroy all state events associated with the callback data, including memory
@@ -132,8 +132,7 @@ void destroy_table_callback(table_callback_data *callback_data);
* want to remove.
* @return Void.
*/
void destroy_timer_callback(event_loop *loop,
table_callback_data *callback_data);
void destroy_timer_callback(event_loop *loop, TableCallbackData *callback_data);
/**
* Add an outstanding callback entry.
@@ -142,7 +141,7 @@ void destroy_timer_callback(event_loop *loop,
* want to insert.
* @return None.
*/
void outstanding_callbacks_add(table_callback_data *callback_data);
void outstanding_callbacks_add(TableCallbackData *callback_data);
/**
* Find an outstanding callback entry.
@@ -151,7 +150,7 @@ void outstanding_callbacks_add(table_callback_data *callback_data);
* timer ID assigned by the Redis ae event loop.
* @return Returns the callback data if found, NULL otherwise.
*/
table_callback_data *outstanding_callbacks_find(int64_t key);
TableCallbackData *outstanding_callbacks_find(int64_t key);
/**
* Remove an outstanding callback entry. This only removes the callback entry
@@ -162,7 +161,7 @@ table_callback_data *outstanding_callbacks_find(int64_t key);
* want to remove.
* @return Void.
*/
void outstanding_callbacks_remove(table_callback_data *callback_data);
void outstanding_callbacks_remove(TableCallbackData *callback_data);
/**
* Destroy all outstanding callbacks and remove their associated timer events
+20 -21
View File
@@ -3,42 +3,42 @@
#define NUM_DB_REQUESTS 2
void task_table_get_task(db_handle *db_handle,
task_id task_id,
retry_info *retry,
void task_table_get_task(DBHandle *db_handle,
TaskID task_id,
RetryInfo *retry,
task_table_get_callback done_callback,
void *user_context) {
init_table_callback(db_handle, task_id, __func__, NULL, retry, done_callback,
redis_task_table_get_task, user_context);
}
void task_table_add_task(db_handle *db_handle,
OWNER task *task,
retry_info *retry,
void task_table_add_task(DBHandle *db_handle,
OWNER Task *task,
RetryInfo *retry,
task_table_done_callback done_callback,
void *user_context) {
init_table_callback(db_handle, task_task_id(task), __func__, task, retry,
init_table_callback(db_handle, Task_task_id(task), __func__, task, retry,
done_callback, redis_task_table_add_task, user_context);
}
void task_table_update(db_handle *db_handle,
OWNER task *task,
retry_info *retry,
void task_table_update(DBHandle *db_handle,
OWNER Task *task,
RetryInfo *retry,
task_table_done_callback done_callback,
void *user_context) {
init_table_callback(db_handle, task_task_id(task), __func__, task, retry,
init_table_callback(db_handle, Task_task_id(task), __func__, task, retry,
done_callback, redis_task_table_update, user_context);
}
void task_table_test_and_update(db_handle *db_handle,
task_id task_id,
void task_table_test_and_update(DBHandle *db_handle,
TaskID task_id,
int test_state_bitmask,
int update_state,
retry_info *retry,
RetryInfo *retry,
task_table_get_callback done_callback,
void *user_context) {
task_table_test_and_update_data *update_data =
malloc(sizeof(task_table_test_and_update_data));
TaskTableTestAndUpdateData *update_data =
malloc(sizeof(TaskTableTestAndUpdateData));
update_data->test_state_bitmask = test_state_bitmask;
update_data->update_state = update_state;
/* Update the task entry's local scheduler with this client's ID. */
@@ -49,16 +49,15 @@ void task_table_test_and_update(db_handle *db_handle,
}
/* TODO(swang): A corresponding task_table_unsubscribe. */
void task_table_subscribe(db_handle *db_handle,
db_client_id local_scheduler_id,
void task_table_subscribe(DBHandle *db_handle,
DBClientID local_scheduler_id,
int state_filter,
task_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
task_table_done_callback done_callback,
void *user_context) {
task_table_subscribe_data *sub_data =
malloc(sizeof(task_table_subscribe_data));
TaskTableSubscribeData *sub_data = malloc(sizeof(TaskTableSubscribeData));
sub_data->local_scheduler_id = local_scheduler_id;
sub_data->state_filter = state_filter;
sub_data->subscribe_callback = subscribe_callback;
+22 -22
View File
@@ -22,11 +22,11 @@
*/
/* Callback called when a task table write operation completes. */
typedef void (*task_table_done_callback)(task_id task_id, void *user_context);
typedef void (*task_table_done_callback)(TaskID task_id, void *user_context);
/* Callback called when a task table read operation completes. If the task ID
* was not in the task table, then the task pointer will be NULL. */
typedef void (*task_table_get_callback)(task *task, void *user_context);
typedef void (*task_table_get_callback)(Task *task, void *user_context);
/**
* Get a task's entry from the task table.
@@ -39,9 +39,9 @@ typedef void (*task_table_get_callback)(task *task, void *user_context);
* fail_callback.
* @return Void.
*/
void task_table_get_task(db_handle *db,
task_id task_id,
retry_info *retry,
void task_table_get_task(DBHandle *db,
TaskID task_id,
RetryInfo *retry,
task_table_get_callback done_callback,
void *user_context);
@@ -58,9 +58,9 @@ void task_table_get_task(db_handle *db,
* fail_callback.
* @return Void.
*/
void task_table_add_task(db_handle *db_handle,
OWNER task *task,
retry_info *retry,
void task_table_add_task(DBHandle *db_handle,
OWNER Task *task,
RetryInfo *retry,
task_table_done_callback done_callback,
void *user_context);
@@ -81,9 +81,9 @@ void task_table_add_task(db_handle *db_handle,
* fail_callback.
* @return Void.
*/
void task_table_update(db_handle *db_handle,
OWNER task *task,
retry_info *retry,
void task_table_update(DBHandle *db_handle,
OWNER Task *task,
RetryInfo *retry,
task_table_done_callback done_callback,
void *user_context);
@@ -107,11 +107,11 @@ void task_table_update(db_handle *db_handle,
* fail_callback.
* @return Void.
*/
void task_table_test_and_update(db_handle *db_handle,
task_id task_id,
void task_table_test_and_update(DBHandle *db_handle,
TaskID task_id,
int test_state_bitmask,
int update_state,
retry_info *retry,
RetryInfo *retry,
task_table_get_callback done_callback,
void *user_context);
@@ -119,15 +119,15 @@ void task_table_test_and_update(db_handle *db_handle,
typedef struct {
int test_state_bitmask;
int update_state;
db_client_id local_scheduler_id;
} task_table_test_and_update_data;
DBClientID local_scheduler_id;
} TaskTableTestAndUpdateData;
/*
* ==== Subscribing to the task table ====
*/
/* Callback for subscribing to the task table. */
typedef void (*task_table_subscribe_callback)(task *task, void *user_context);
typedef void (*task_table_subscribe_callback)(Task *task, void *user_context);
/**
* Register a callback for a task event. An event is any update of a task in
@@ -152,22 +152,22 @@ typedef void (*task_table_subscribe_callback)(task *task, void *user_context);
* fail_callback.
* @return Void.
*/
void task_table_subscribe(db_handle *db_handle,
db_client_id local_scheduler_id,
void task_table_subscribe(DBHandle *db_handle,
DBClientID local_scheduler_id,
int state_filter,
task_table_subscribe_callback subscribe_callback,
void *subscribe_context,
retry_info *retry,
RetryInfo *retry,
task_table_done_callback done_callback,
void *user_context);
/* Data that is needed to register task table subscribe callbacks with the state
* database. */
typedef struct {
db_client_id local_scheduler_id;
DBClientID local_scheduler_id;
int state_filter;
task_table_subscribe_callback subscribe_callback;
void *subscribe_context;
} task_table_subscribe_data;
} TaskTableSubscribeData;
#endif /* task_table_H */
+67 -67
View File
@@ -24,7 +24,7 @@ typedef struct {
/* Either ARG_BY_REF or ARG_BY_VAL. */
int8_t type;
union {
object_id obj_id;
ObjectID obj_id;
struct {
/* Offset where the data associated to this arg is located relative
* to &task_spec.args_and_returns[0]. */
@@ -36,21 +36,21 @@ typedef struct {
struct task_spec_impl {
/** ID of the driver that created this task. */
unique_id driver_id;
UniqueID driver_id;
/** Task ID of the task. */
task_id task_id;
TaskID task_id;
/** Task ID of the parent task. */
task_id parent_task_id;
TaskID parent_task_id;
/** A count of the number of tasks submitted by the parent task before this
* one. */
int64_t parent_counter;
/** Actor ID of the task. This is the actor that this task is executed on
* or NIL_ACTOR_ID if the task is just a normal task. */
actor_id actor_id;
ActorID actor_id;
/** Number of tasks that have been submitted to this actor so far. */
int64_t actor_counter;
/** Function ID of the task. */
function_id function_id;
FunctionID function_id;
/** Total number of arguments. */
int64_t num_args;
/** Index of the last argument that has been constructed. */
@@ -78,27 +78,27 @@ struct task_spec_impl {
(sizeof(task_spec) + ((NUM_ARGS) + (NUM_RETURNS)) * sizeof(task_arg) + \
(ARGS_VALUE_SIZE))
bool task_ids_equal(task_id first_id, task_id second_id) {
bool TaskID_equal(TaskID first_id, TaskID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
bool task_id_is_nil(task_id id) {
return task_ids_equal(id, NIL_TASK_ID);
bool TaskID_is_nil(TaskID id) {
return TaskID_equal(id, NIL_TASK_ID);
}
bool actor_ids_equal(actor_id first_id, actor_id second_id) {
bool ActorID_equal(ActorID first_id, ActorID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
bool function_ids_equal(function_id first_id, function_id second_id) {
bool FunctionID_equal(FunctionID first_id, FunctionID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
bool function_id_is_nil(function_id id) {
return function_ids_equal(id, NIL_FUNCTION_ID);
bool FunctionID_is_nil(FunctionID id) {
return FunctionID_equal(id, NIL_FUNCTION_ID);
}
task_id *task_return_ptr(task_spec *spec, int64_t return_index) {
TaskID *task_return_ptr(task_spec *spec, int64_t return_index) {
DCHECK(0 <= return_index && return_index < spec->num_returns);
task_arg *ret = &spec->args_and_returns[spec->num_args + return_index];
DCHECK(ret->type == ARG_BY_REF);
@@ -109,12 +109,12 @@ task_id *task_return_ptr(task_spec *spec, int64_t return_index) {
* and that the return IDs have not been set. It assumes the task_spec was
* zero-initialized so that uninitialized fields will not make the task ID
* nondeterministic. */
task_id compute_task_id(task_spec *spec) {
TaskID compute_task_id(task_spec *spec) {
/* Check that the task ID and return ID fields of the task_spec are
* uninitialized. */
DCHECK(task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(TaskID_equal(spec->task_id, NIL_TASK_ID));
for (int i = 0; i < spec->num_returns; ++i) {
DCHECK(object_ids_equal(*task_return_ptr(spec, i), NIL_ID));
DCHECK(ObjectID_equal(*task_return_ptr(spec, i), NIL_ID));
}
/* Compute a SHA256 hash of the task_spec. */
SHA256_CTX ctx;
@@ -123,18 +123,18 @@ task_id compute_task_id(task_spec *spec) {
sha256_update(&ctx, (BYTE *) spec, task_spec_size(spec));
sha256_final(&ctx, buff);
/* Create a task ID out of the hash. This will truncate the hash. */
task_id task_id;
TaskID task_id;
CHECK(sizeof(task_id) <= DIGEST_SIZE);
memcpy(&task_id.id, buff, sizeof(task_id.id));
return task_id;
}
object_id task_compute_return_id(task_id task_id, int64_t return_index) {
ObjectID task_compute_return_id(TaskID task_id, int64_t return_index) {
/* Here, return_indices need to be >= 0, so we can use negative
* indices for put. */
DCHECK(return_index >= 0);
/* TODO(rkn): This line requires object and task IDs to be the same size. */
object_id return_id = task_id;
ObjectID return_id = task_id;
int64_t *first_bytes = (int64_t *) &return_id;
/* XOR the first bytes of the object ID with the return index. We add one so
* the first return ID is not the same as the task ID. */
@@ -142,10 +142,10 @@ object_id task_compute_return_id(task_id task_id, int64_t return_index) {
return return_id;
}
object_id task_compute_put_id(task_id task_id, int64_t put_index) {
ObjectID task_compute_put_id(TaskID task_id, int64_t put_index) {
DCHECK(put_index >= 0);
/* TODO(pcm): This line requires object and task IDs to be the same size. */
object_id put_id = task_id;
ObjectID put_id = task_id;
int64_t *first_bytes = (int64_t *) &put_id;
/* XOR the first bytes of the object ID with the return index. We add one so
* the first return ID is not the same as the task ID. */
@@ -153,17 +153,17 @@ object_id task_compute_put_id(task_id task_id, int64_t put_index) {
return put_id;
}
task_spec *start_construct_task_spec(unique_id driver_id,
task_id parent_task_id,
task_spec *start_construct_task_spec(UniqueID driver_id,
TaskID parent_task_id,
int64_t parent_counter,
actor_id actor_id,
ActorID actor_id,
int64_t actor_counter,
function_id function_id,
FunctionID function_id,
int64_t num_args,
int64_t num_returns,
int64_t args_value_size) {
int64_t size = TASK_SPEC_SIZE(num_args, num_returns, args_value_size);
task_spec *task = malloc(size);
task_spec *task = (task_spec *) malloc(size);
memset(task, 0, size);
task->driver_id = driver_id;
task->task_id = NIL_TASK_ID;
@@ -197,33 +197,33 @@ int64_t task_spec_size(task_spec *spec) {
spec->args_value_size);
}
function_id task_function(task_spec *spec) {
FunctionID task_function(task_spec *spec) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
return spec->function_id;
}
actor_id task_spec_actor_id(task_spec *spec) {
ActorID task_spec_actor_id(task_spec *spec) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
return spec->actor_id;
}
int64_t task_spec_actor_counter(task_spec *spec) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
return spec->actor_counter;
}
unique_id task_spec_driver_id(task_spec *spec) {
UniqueID task_spec_driver_id(task_spec *spec) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
return spec->driver_id;
}
task_id task_spec_id(task_spec *spec) {
TaskID task_spec_id(task_spec *spec) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
return spec->task_id;
}
@@ -240,9 +240,9 @@ int8_t task_arg_type(task_spec *spec, int64_t arg_index) {
return spec->args_and_returns[arg_index].type;
}
object_id task_arg_id(task_spec *spec, int64_t arg_index) {
ObjectID task_arg_id(task_spec *spec, int64_t arg_index) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
DCHECK(0 <= arg_index && arg_index < spec->num_args);
task_arg *arg = &spec->args_and_returns[arg_index];
DCHECK(arg->type == ARG_BY_REF)
@@ -265,9 +265,9 @@ int64_t task_arg_length(task_spec *spec, int64_t arg_index) {
return arg->value.length;
}
int64_t task_args_add_ref(task_spec *spec, object_id obj_id) {
int64_t task_args_add_ref(task_spec *spec, ObjectID obj_id) {
/* Check that the task is still under construction. */
DCHECK(task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(TaskID_equal(spec->task_id, NIL_TASK_ID));
task_arg *arg = &spec->args_and_returns[spec->arg_index];
arg->type = ARG_BY_REF;
arg->obj_id = obj_id;
@@ -276,7 +276,7 @@ int64_t task_args_add_ref(task_spec *spec, object_id obj_id) {
int64_t task_args_add_val(task_spec *spec, uint8_t *data, int64_t length) {
/* Check that the task is still under construction. */
DCHECK(task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(TaskID_equal(spec->task_id, NIL_TASK_ID));
task_arg *arg = &spec->args_and_returns[spec->arg_index];
arg->type = ARG_BY_VAL;
arg->value.offset = spec->args_value_offset;
@@ -296,9 +296,9 @@ void task_spec_set_required_resource(task_spec *spec,
spec->required_resources[resource_index] = value;
}
object_id task_return(task_spec *spec, int64_t return_index) {
ObjectID task_return(task_spec *spec, int64_t return_index) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
DCHECK(0 <= return_index && return_index < spec->num_returns);
task_arg *ret = &spec->args_and_returns[spec->num_args + return_index];
DCHECK(ret->type == ARG_BY_REF);
@@ -312,7 +312,7 @@ double task_spec_get_required_resource(const task_spec *spec,
void free_task_spec(task_spec *spec) {
/* Check that the task has been constructed. */
DCHECK(!task_ids_equal(spec->task_id, NIL_TASK_ID));
DCHECK(!TaskID_equal(spec->task_id, NIL_TASK_ID));
DCHECK(spec->arg_index == spec->num_args);
free(spec);
}
@@ -322,36 +322,36 @@ void print_task(task_spec *spec, UT_string *output) {
* of bytes compared to the id (+ 1 byte for '\0'). */
static char hex[ID_STRING_SIZE];
/* Print function id. */
object_id_to_string((object_id) task_function(spec), &hex[0], ID_STRING_SIZE);
ObjectID_to_string((ObjectID) task_function(spec), &hex[0], ID_STRING_SIZE);
utstring_printf(output, "fun %s ", &hex[0]);
/* Print arguments. */
for (int i = 0; i < task_num_args(spec); ++i) {
object_id_to_string((object_id) task_arg_id(spec, i), &hex[0],
ID_STRING_SIZE);
ObjectID_to_string((ObjectID) task_arg_id(spec, i), &hex[0],
ID_STRING_SIZE);
utstring_printf(output, " id:%d %s", i, &hex[0]);
}
/* Print return ids. */
for (int i = 0; i < task_num_returns(spec); ++i) {
object_id obj_id = task_return(spec, i);
object_id_to_string(obj_id, &hex[0], ID_STRING_SIZE);
ObjectID obj_id = task_return(spec, i);
ObjectID_to_string(obj_id, &hex[0], ID_STRING_SIZE);
utstring_printf(output, " ret:%d %s", i, &hex[0]);
}
}
/* TASK INSTANCES */
struct task_impl {
struct TaskImpl {
/** The scheduling state of the task. */
int state;
/** The ID of the local scheduler involved. */
db_client_id local_scheduler_id;
DBClientID local_scheduler_id;
/** The task specification for this task. */
task_spec spec;
};
task *alloc_task(task_spec *spec, int state, db_client_id local_scheduler_id) {
int64_t size = sizeof(task) - sizeof(task_spec) + task_spec_size(spec);
task *result = malloc(size);
Task *Task_alloc(task_spec *spec, int state, DBClientID local_scheduler_id) {
int64_t size = sizeof(Task) - sizeof(task_spec) + task_spec_size(spec);
Task *result = (Task *) malloc(size);
memset(result, 0, size);
result->state = state;
result->local_scheduler_id = local_scheduler_id;
@@ -359,43 +359,43 @@ task *alloc_task(task_spec *spec, int state, db_client_id local_scheduler_id) {
return result;
}
task *copy_task(task *other) {
int64_t size = task_size(other);
task *copy = malloc(size);
Task *Task_copy(Task *other) {
int64_t size = Task_size(other);
Task *copy = (Task *) malloc(size);
CHECK(copy != NULL);
memcpy(copy, other, size);
return copy;
}
int64_t task_size(task *task_arg) {
return sizeof(task) - sizeof(task_spec) + task_spec_size(&task_arg->spec);
int64_t Task_size(Task *task_arg) {
return sizeof(Task) - sizeof(task_spec) + task_spec_size(&task_arg->spec);
}
int task_state(task *task) {
int Task_state(Task *task) {
return task->state;
}
void task_set_state(task *task, int state) {
void Task_set_state(Task *task, int state) {
task->state = state;
}
db_client_id task_local_scheduler(task *task) {
DBClientID Task_local_scheduler_id(Task *task) {
return task->local_scheduler_id;
}
void task_set_local_scheduler(task *task, db_client_id local_scheduler_id) {
void Task_set_local_scheduler_id(Task *task, DBClientID local_scheduler_id) {
task->local_scheduler_id = local_scheduler_id;
}
task_spec *task_task_spec(task *task) {
task_spec *Task_task_spec(Task *task) {
return &task->spec;
}
task_id task_task_id(task *task) {
task_spec *spec = task_task_spec(task);
TaskID Task_task_id(Task *task) {
task_spec *spec = Task_task_spec(task);
return task_spec_id(spec);
}
void free_task(task *task) {
void Task_free(Task *task) {
free(task);
}
+31 -35
View File
@@ -18,19 +18,15 @@
#define NIL_ACTOR_ID NIL_ID
#define NIL_FUNCTION_ID NIL_ID
typedef unique_id function_id;
typedef UniqueID FunctionID;
/** The task ID is a deterministic hash of the function ID that the task
* executes and the argument IDs or argument values. */
typedef unique_id task_id;
typedef UniqueID TaskID;
/** The actor ID is the ID of the actor that a task must run on. If the task is
* not run on an actor, then NIL_ACTOR_ID should be used. */
typedef unique_id actor_id;
/** The task instance ID is a globally unique ID generated which identifies this
* particular execution of the task. */
typedef unique_id task_iid;
typedef UniqueID ActorID;
/**
* ==== Task specifications ====
@@ -50,7 +46,7 @@ enum arg_type { ARG_BY_REF, ARG_BY_VAL };
* @param second_id The first task ID to compare.
* @return True if the task IDs are the same and false otherwise.
*/
bool task_ids_equal(task_id first_id, task_id second_id);
bool TaskID_equal(TaskID first_id, TaskID second_id);
/**
* Compare a task ID to the nil ID.
@@ -58,7 +54,7 @@ bool task_ids_equal(task_id first_id, task_id second_id);
* @param id The task ID to compare to nil.
* @return True if the task ID is equal to nil.
*/
bool task_id_is_nil(task_id id);
bool TaskID_is_nil(TaskID id);
/**
* Compare two actor IDs.
@@ -67,7 +63,7 @@ bool task_id_is_nil(task_id id);
* @param second_id The first actor ID to compare.
* @return True if the actor IDs are the same and false otherwise.
*/
bool actor_ids_equal(actor_id first_id, actor_id second_id);
bool ActorID_equal(ActorID first_id, ActorID second_id);
/**
* Compare two function IDs.
@@ -76,7 +72,7 @@ bool actor_ids_equal(actor_id first_id, actor_id second_id);
* @param second_id The first function ID to compare.
* @return True if the function IDs are the same and false otherwise.
*/
bool function_ids_equal(function_id first_id, function_id second_id);
bool FunctionID_equal(FunctionID first_id, FunctionID second_id);
/**
* Compare a function ID to the nil ID.
@@ -84,7 +80,7 @@ bool function_ids_equal(function_id first_id, function_id second_id);
* @param id The function ID to compare to nil.
* @return True if the function ID is equal to nil.
*/
bool function_id_is_nil(function_id id);
bool FunctionID_is_nil(FunctionID id);
/* Construct and modify task specifications. */
@@ -106,12 +102,12 @@ bool function_id_is_nil(function_id id);
ignoring object ID arguments.
* @return The partially constructed task_spec.
*/
task_spec *start_construct_task_spec(unique_id driver_id,
task_id parent_task_id,
task_spec *start_construct_task_spec(UniqueID driver_id,
TaskID parent_task_id,
int64_t parent_counter,
unique_id actor_id,
UniqueID actor_id,
int64_t actor_counter,
function_id function_id,
FunctionID function_id,
int64_t num_args,
int64_t num_returns,
int64_t args_value_size);
@@ -140,7 +136,7 @@ int64_t task_spec_size(task_spec *spec);
* @param spec The task_spec in question.
* @return The function ID of the function to execute in this task.
*/
function_id task_function(task_spec *spec);
FunctionID task_function(task_spec *spec);
/**
* Return the actor ID of the task.
@@ -148,7 +144,7 @@ function_id task_function(task_spec *spec);
* @param spec The task_spec in question.
* @return The actor ID of the actor the task is part of.
*/
unique_id task_spec_actor_id(task_spec *spec);
UniqueID task_spec_actor_id(task_spec *spec);
/**
* Return the actor counter of the task. This starts at 0 and increments by 1
@@ -165,7 +161,7 @@ int64_t task_spec_actor_counter(task_spec *spec);
* @param spec The task_spec in question.
* @return The driver ID of the task.
*/
unique_id task_spec_driver_id(task_spec *spec);
UniqueID task_spec_driver_id(task_spec *spec);
/**
* Return the task ID of the task.
@@ -173,7 +169,7 @@ unique_id task_spec_driver_id(task_spec *spec);
* @param spec The task_spec in question.
* @return The task ID of the task.
*/
task_id task_spec_id(task_spec *spec);
TaskID task_spec_id(task_spec *spec);
/**
* Get the number of arguments to this task.
@@ -209,7 +205,7 @@ int8_t task_arg_type(task_spec *spec, int64_t arg_index);
* @param arg_index The index of the argument in question.
* @return The argument at that index.
*/
object_id task_arg_id(task_spec *spec, int64_t arg_index);
ObjectID task_arg_id(task_spec *spec, int64_t arg_index);
/**
* Get a particular argument to this task. This assumes the argument is a value.
@@ -239,7 +235,7 @@ int64_t task_arg_length(task_spec *spec, int64_t arg_index);
* @return The number of task arguments that have been set before this one. This
* is only used for testing.
*/
int64_t task_args_add_ref(task_spec *spec, object_id obj_id);
int64_t task_args_add_ref(task_spec *spec, ObjectID obj_id);
/**
* Set the next task argument. Note that this API only allows you to set the
@@ -260,7 +256,7 @@ int64_t task_args_add_val(task_spec *spec, uint8_t *data, int64_t length);
* @param return_index The index of the return object ID in question.
* @return The relevant return object ID.
*/
object_id task_return(task_spec *spec, int64_t return_index);
ObjectID task_return(task_spec *spec, int64_t return_index);
/**
* Indices into resource vectors.
@@ -308,7 +304,7 @@ double task_spec_get_required_resource(const task_spec *spec,
* @param put_index The number of put calls in this task so far.
* @return The object ID for the object that was put.
*/
object_id task_compute_put_id(task_id task_id, int64_t put_index);
ObjectID task_compute_put_id(TaskID task_id, int64_t put_index);
/**
* Free a task_spec.
@@ -357,7 +353,7 @@ typedef enum {
/** 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
* or running on. */
typedef struct task_impl task;
typedef struct TaskImpl Task;
/**
* Allocate a new task. Must be freed with free_task after use.
@@ -367,7 +363,7 @@ typedef struct task_impl task;
* @param local_scheduler_id The ID of the local scheduler that the task is
* scheduled on, if any.
*/
task *alloc_task(task_spec *spec, int state, db_client_id local_scheduler_id);
Task *Task_alloc(task_spec *spec, int state, DBClientID local_scheduler_id);
/**
* Create a copy of the task. Must be freed with free_task after use.
@@ -375,30 +371,30 @@ task *alloc_task(task_spec *spec, int state, db_client_id local_scheduler_id);
* @param other The task that will be copied.
* @returns Pointer to the copy of the task.
*/
task *copy_task(task *other);
Task *Task_copy(Task *other);
/** Size of task structure in bytes. */
int64_t task_size(task *task);
int64_t Task_size(Task *task);
/** The scheduling state of the task. */
int task_state(task *task);
int 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, int state);
/** Local scheduler this task has been assigned to or is running on. */
db_client_id task_local_scheduler(task *task);
DBClientID Task_local_scheduler_id(Task *task);
/** Set the local scheduler ID for this task. */
void task_set_local_scheduler(task *task, db_client_id local_scheduler_id);
void Task_set_local_scheduler_id(Task *task, DBClientID local_scheduler_id);
/** Task specification of this task. */
task_spec *task_task_spec(task *task);
task_spec *Task_task_spec(Task *task);
/** Task ID of this task. */
task_id task_task_id(task *task);
TaskID Task_task_id(Task *task);
/** Free this task datastructure. */
void free_task(task *task);
void Task_free(Task *task);
#endif
+2 -2
View File
@@ -6,8 +6,8 @@ SUITE(common_tests);
TEST sha1_test(void) {
static char hex[ID_STRING_SIZE];
unique_id uid = globally_unique_id();
object_id_to_string((object_id) uid, &hex[0], ID_STRING_SIZE);
UniqueID uid = globally_unique_id();
ObjectID_to_string((ObjectID) uid, &hex[0], ID_STRING_SIZE);
PASS();
}
+31 -31
View File
@@ -34,7 +34,7 @@ const int TEST_NUMBER = 10;
/* Test if entries have been written to the database. */
void lookup_done_callback(object_id object_id,
void lookup_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *user_context) {
@@ -52,10 +52,10 @@ void lookup_done_callback(object_id object_id,
}
/* Entry added to database successfully. */
void add_done_callback(object_id object_id, void *user_context) {}
void add_done_callback(ObjectID object_id, void *user_context) {}
/* Test if we got a timeout callback if we couldn't connect database. */
void timeout_callback(object_id object_id, void *context, void *user_data) {
void timeout_callback(ObjectID object_id, void *context, void *user_data) {
user_context *uc = (user_context *) context;
CHECK(uc->test_number == TEST_NUMBER)
}
@@ -69,16 +69,16 @@ TEST object_table_lookup_test(void) {
event_loop *loop = event_loop_create();
/* This uses manager_port1. */
const char *db_connect_args1[] = {"address", "127.0.0.1:12345"};
db_handle *db1 = db_connect("127.0.0.1", 6379, "plasma_manager", manager_addr,
2, db_connect_args1);
DBHandle *db1 = db_connect("127.0.0.1", 6379, "plasma_manager", manager_addr,
2, db_connect_args1);
/* This uses manager_port2. */
const char *db_connect_args2[] = {"address", "127.0.0.1:12346"};
db_handle *db2 = db_connect("127.0.0.1", 6379, "plasma_manager", manager_addr,
2, db_connect_args2);
DBHandle *db2 = db_connect("127.0.0.1", 6379, "plasma_manager", manager_addr,
2, db_connect_args2);
db_attach(db1, loop, false);
db_attach(db2, loop, false);
unique_id id = globally_unique_id();
retry_info retry = {
UniqueID id = globally_unique_id();
RetryInfo retry = {
.num_retries = NUM_RETRIES,
.timeout = TIMEOUT,
.fail_callback = timeout_callback,
@@ -109,9 +109,9 @@ TEST object_table_lookup_test(void) {
}
int task_table_test_callback_called = 0;
task *task_table_test_task;
Task *task_table_test_task;
void task_table_test_fail_callback(unique_id id,
void task_table_test_fail_callback(UniqueID id,
void *context,
void *user_data) {
event_loop *loop = user_data;
@@ -121,22 +121,22 @@ void task_table_test_fail_callback(unique_id id,
int64_t task_table_delayed_add_task(event_loop *loop,
int64_t id,
void *context) {
db_handle *db = context;
retry_info retry = {
DBHandle *db = context;
RetryInfo retry = {
.num_retries = NUM_RETRIES,
.timeout = TIMEOUT,
.fail_callback = task_table_test_fail_callback,
};
task_table_add_task(db, copy_task(task_table_test_task), &retry, NULL,
task_table_add_task(db, Task_copy(task_table_test_task), &retry, NULL,
(void *) loop);
return EVENT_LOOP_TIMER_DONE;
}
void task_table_test_callback(task *callback_task, void *user_data) {
void task_table_test_callback(Task *callback_task, void *user_data) {
task_table_test_callback_called = 1;
CHECK(task_state(callback_task) == TASK_STATUS_SCHEDULED);
CHECK(task_size(callback_task) == task_size(task_table_test_task));
CHECK(memcmp(callback_task, task_table_test_task, task_size(callback_task)) ==
CHECK(Task_state(callback_task) == TASK_STATUS_SCHEDULED);
CHECK(Task_size(callback_task) == Task_size(task_table_test_task));
CHECK(memcmp(callback_task, task_table_test_task, Task_size(callback_task)) ==
0);
event_loop *loop = user_data;
event_loop_stop(loop);
@@ -145,15 +145,15 @@ void task_table_test_callback(task *callback_task, void *user_data) {
TEST task_table_test(void) {
task_table_test_callback_called = 0;
event_loop *loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "local_scheduler", "127.0.0.1", 0, NULL);
db_attach(db, loop, false);
db_client_id local_scheduler_id = globally_unique_id();
DBClientID local_scheduler_id = globally_unique_id();
task_spec *spec = example_task_spec(1, 1);
task_table_test_task =
alloc_task(spec, TASK_STATUS_SCHEDULED, local_scheduler_id);
Task_alloc(spec, TASK_STATUS_SCHEDULED, local_scheduler_id);
free_task_spec(spec);
retry_info retry = {
RetryInfo retry = {
.num_retries = NUM_RETRIES,
.timeout = TIMEOUT,
.fail_callback = task_table_test_fail_callback,
@@ -164,7 +164,7 @@ TEST task_table_test(void) {
event_loop_add_timer(
loop, 200, (event_loop_timer_handler) task_table_delayed_add_task, db);
event_loop_run(loop);
free_task(task_table_test_task);
Task_free(task_table_test_task);
db_disconnect(db);
destroy_outstanding_callbacks(loop);
event_loop_destroy(loop);
@@ -174,20 +174,20 @@ TEST task_table_test(void) {
int num_test_callback_called = 0;
void task_table_all_test_callback(task *task, void *user_data) {
void task_table_all_test_callback(Task *task, void *user_data) {
num_test_callback_called += 1;
}
TEST task_table_all_test(void) {
event_loop *loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "local_scheduler", "127.0.0.1", 0, NULL);
db_attach(db, loop, false);
task_spec *spec = example_task_spec(1, 1);
/* Schedule two tasks on different local local schedulers. */
task *task1 = alloc_task(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
task *task2 = alloc_task(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
retry_info retry = {
Task *task1 = Task_alloc(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
Task *task2 = Task_alloc(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
RetryInfo retry = {
.num_retries = NUM_RETRIES, .timeout = TIMEOUT, .fail_callback = NULL,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_SCHEDULED,
@@ -212,8 +212,8 @@ TEST task_table_all_test(void) {
TEST unique_client_id_test(void) {
enum { num_conns = 100 };
db_client_id ids[num_conns];
db_handle *db;
DBClientID ids[num_conns];
DBHandle *db;
for (int i = 0; i < num_conns; ++i) {
db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
ids[i] = get_db_client_id(db);
@@ -221,7 +221,7 @@ TEST unique_client_id_test(void) {
}
for (int i = 0; i < num_conns; ++i) {
for (int j = 0; j < i; ++j) {
ASSERT(!db_client_ids_equal(ids[i], ids[j]));
ASSERT(!DBClientID_equal(ids[i], ids[j]));
}
}
PASS();
+100 -102
View File
@@ -16,12 +16,12 @@ static event_loop *g_loop;
int new_object_failed = 0;
int new_object_succeeded = 0;
object_id new_object_id;
task *new_object_task;
ObjectID new_object_id;
Task *new_object_task;
task_spec *new_object_task_spec;
task_id new_object_task_id;
TaskID new_object_task_id;
void new_object_fail_callback(unique_id id,
void new_object_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
new_object_failed = 1;
@@ -30,34 +30,34 @@ void new_object_fail_callback(unique_id id,
/* === Test adding an object with an associated task === */
void new_object_done_callback(object_id object_id,
task_id task_id,
void new_object_done_callback(ObjectID object_id,
TaskID task_id,
void *user_context) {
new_object_succeeded = 1;
CHECK(object_ids_equal(object_id, new_object_id));
CHECK(task_ids_equal(task_id, new_object_task_id));
CHECK(ObjectID_equal(object_id, new_object_id));
CHECK(TaskID_equal(task_id, new_object_task_id));
event_loop_stop(g_loop);
}
void new_object_lookup_callback(object_id object_id, void *user_context) {
CHECK(object_ids_equal(object_id, new_object_id));
retry_info retry = {
void new_object_lookup_callback(ObjectID object_id, void *user_context) {
CHECK(ObjectID_equal(object_id, new_object_id));
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = new_object_fail_callback,
};
db_handle *db = user_context;
DBHandle *db = user_context;
result_table_lookup(db, new_object_id, &retry, new_object_done_callback,
NULL);
}
void new_object_task_callback(task_id task_id, void *user_context) {
retry_info retry = {
void new_object_task_callback(TaskID task_id, void *user_context) {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = new_object_fail_callback,
};
db_handle *db = user_context;
DBHandle *db = user_context;
result_table_add(db, new_object_id, new_object_task_id, &retry,
new_object_lookup_callback, (void *) db);
}
@@ -67,18 +67,18 @@ TEST new_object_test(void) {
new_object_succeeded = 0;
new_object_id = globally_unique_id();
new_object_task = example_task(1, 1, TASK_STATUS_WAITING);
new_object_task_spec = task_task_spec(new_object_task);
new_object_task_spec = Task_task_spec(new_object_task);
new_object_task_id = task_spec_id(new_object_task_spec);
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = new_object_fail_callback,
};
task_table_add_task(db, copy_task(new_object_task), &retry,
task_table_add_task(db, Task_copy(new_object_task), &retry,
new_object_task_callback, db);
event_loop_run(g_loop);
db_disconnect(db);
@@ -91,8 +91,8 @@ TEST new_object_test(void) {
/* === Test adding an object without an associated task === */
void new_object_no_task_callback(object_id object_id,
task_id task_id,
void new_object_no_task_callback(ObjectID object_id,
TaskID task_id,
void *user_context) {
new_object_succeeded = 1;
CHECK(IS_NIL_ID(task_id));
@@ -105,10 +105,10 @@ TEST new_object_no_task_test(void) {
new_object_id = globally_unique_id();
new_object_task_id = globally_unique_id();
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = new_object_fail_callback,
@@ -131,7 +131,7 @@ TEST new_object_no_task_test(void) {
const char *lookup_timeout_context = "lookup_timeout";
int lookup_failed = 0;
void lookup_done_callback(object_id object_id,
void lookup_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *context) {
@@ -139,7 +139,7 @@ void lookup_done_callback(object_id object_id,
CHECK(0);
}
void lookup_fail_callback(unique_id id, void *user_context, void *user_data) {
void lookup_fail_callback(UniqueID id, void *user_context, void *user_data) {
lookup_failed = 1;
CHECK(user_context == (void *) lookup_timeout_context);
event_loop_stop(g_loop);
@@ -147,10 +147,10 @@ void lookup_fail_callback(unique_id id, void *user_context, void *user_data) {
TEST lookup_timeout_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = lookup_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, lookup_done_callback,
@@ -170,12 +170,12 @@ TEST lookup_timeout_test(void) {
const char *add_timeout_context = "add_timeout";
int add_failed = 0;
void add_done_callback(object_id object_id, void *user_context) {
void add_done_callback(ObjectID object_id, void *user_context) {
/* The done callback should not be called. */
CHECK(0);
}
void add_fail_callback(unique_id id, void *user_context, void *user_data) {
void add_fail_callback(UniqueID id, void *user_context, void *user_data) {
add_failed = 1;
CHECK(user_context == (void *) add_timeout_context);
event_loop_stop(g_loop);
@@ -183,10 +183,10 @@ void add_fail_callback(unique_id id, void *user_context, void *user_data) {
TEST add_timeout_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = add_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
@@ -205,7 +205,7 @@ TEST add_timeout_test(void) {
int subscribe_failed = 0;
void subscribe_done_callback(object_id object_id,
void subscribe_done_callback(ObjectID object_id,
int64_t data_size,
int manager_count,
const char *manager_vector[],
@@ -214,19 +214,17 @@ void subscribe_done_callback(object_id object_id,
CHECK(0);
}
void subscribe_fail_callback(unique_id id,
void *user_context,
void *user_data) {
void subscribe_fail_callback(UniqueID id, void *user_context, void *user_data) {
subscribe_failed = 1;
event_loop_stop(g_loop);
}
TEST subscribe_timeout_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = subscribe_fail_callback,
@@ -248,7 +246,7 @@ TEST subscribe_timeout_test(void) {
int64_t reconnect_context_callback(event_loop *loop,
int64_t timer_id,
void *context) {
db_handle *db = context;
DBHandle *db = context;
/* Reconnect to redis. This is not reconnecting the pub/sub channel. */
redisAsyncFree(db->context);
redisFree(db->sync_context);
@@ -273,7 +271,7 @@ int64_t terminate_event_loop_callback(event_loop *loop,
const char *lookup_retry_context = "lookup_retry";
int lookup_retry_succeeded = 0;
void lookup_retry_done_callback(object_id object_id,
void lookup_retry_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *context) {
@@ -281,7 +279,7 @@ void lookup_retry_done_callback(object_id object_id,
lookup_retry_succeeded = 1;
}
void lookup_retry_fail_callback(unique_id id,
void lookup_retry_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
/* The fail callback should not be called. */
@@ -295,7 +293,7 @@ int add_retry_succeeded = 0;
/* === Test add then lookup retry === */
void add_lookup_done_callback(object_id object_id,
void add_lookup_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *context) {
@@ -305,9 +303,9 @@ void add_lookup_done_callback(object_id object_id,
lookup_retry_succeeded = 1;
}
void add_lookup_callback(object_id object_id, void *user_context) {
db_handle *db = user_context;
retry_info retry = {
void add_lookup_callback(ObjectID object_id, void *user_context) {
DBHandle *db = user_context;
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
@@ -321,10 +319,10 @@ TEST add_lookup_test(void) {
lookup_retry_succeeded = 0;
/* Construct the arguments to db_connect. */
const char *db_connect_args[] = {"address", "127.0.0.1:11235"};
db_handle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1",
2, db_connect_args);
DBHandle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 2,
db_connect_args);
db_attach(db, g_loop, true);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
@@ -344,7 +342,7 @@ TEST add_lookup_test(void) {
}
/* === Test add, remove, then lookup === */
void add_remove_lookup_done_callback(object_id object_id,
void add_remove_lookup_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *context) {
@@ -353,9 +351,9 @@ void add_remove_lookup_done_callback(object_id object_id,
lookup_retry_succeeded = 1;
}
void add_remove_lookup_callback(object_id object_id, void *user_context) {
db_handle *db = user_context;
retry_info retry = {
void add_remove_lookup_callback(ObjectID object_id, void *user_context) {
DBHandle *db = user_context;
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
@@ -364,9 +362,9 @@ void add_remove_lookup_callback(object_id object_id, void *user_context) {
(void *) lookup_retry_context);
}
void add_remove_callback(object_id object_id, void *user_context) {
db_handle *db = user_context;
retry_info retry = {
void add_remove_callback(ObjectID object_id, void *user_context) {
DBHandle *db = user_context;
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
@@ -378,10 +376,10 @@ void add_remove_callback(object_id object_id, void *user_context) {
TEST add_remove_lookup_test(void) {
g_loop = event_loop_create();
lookup_retry_succeeded = 0;
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, true);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
@@ -408,7 +406,7 @@ int subscribe_retry_succeeded = 0;
int64_t reconnect_sub_context_callback(event_loop *loop,
int64_t timer_id,
void *context) {
db_handle *db = context;
DBHandle *db = context;
/* Reconnect to redis. This is not reconnecting the pub/sub channel. */
redisAsyncFree(db->sub_context);
redisAsyncFree(db->context);
@@ -430,14 +428,14 @@ int64_t reconnect_sub_context_callback(event_loop *loop,
const char *lookup_late_context = "lookup_late";
int lookup_late_failed = 0;
void lookup_late_fail_callback(unique_id id,
void lookup_late_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
CHECK(user_context == (void *) lookup_late_context);
lookup_late_failed = 1;
}
void lookup_late_done_callback(object_id object_id,
void lookup_late_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *context) {
@@ -447,10 +445,10 @@ void lookup_late_done_callback(object_id object_id,
TEST lookup_late_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 0,
.timeout = 0,
.fail_callback = lookup_late_fail_callback,
@@ -477,22 +475,22 @@ TEST lookup_late_test(void) {
const char *add_late_context = "add_late";
int add_late_failed = 0;
void add_late_fail_callback(unique_id id, void *user_context, void *user_data) {
void add_late_fail_callback(UniqueID id, void *user_context, void *user_data) {
CHECK(user_context == (void *) add_late_context);
add_late_failed = 1;
}
void add_late_done_callback(object_id object_id, void *user_context) {
void add_late_done_callback(ObjectID object_id, void *user_context) {
/* This function should never be called. */
CHECK(0);
}
TEST add_late_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 0, .timeout = 0, .fail_callback = add_late_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
@@ -517,14 +515,14 @@ TEST add_late_test(void) {
const char *subscribe_late_context = "subscribe_late";
int subscribe_late_failed = 0;
void subscribe_late_fail_callback(unique_id id,
void subscribe_late_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
CHECK(user_context == (void *) subscribe_late_context);
subscribe_late_failed = 1;
}
void subscribe_late_done_callback(object_id object_id,
void subscribe_late_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *user_context) {
@@ -534,10 +532,10 @@ void subscribe_late_done_callback(object_id object_id,
TEST subscribe_late_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 0,
.timeout = 0,
.fail_callback = subscribe_late_fail_callback,
@@ -565,34 +563,34 @@ TEST subscribe_late_test(void) {
const char *subscribe_success_context = "subscribe_success";
int subscribe_success_done = 0;
int subscribe_success_succeeded = 0;
object_id subscribe_id;
ObjectID subscribe_id;
void subscribe_success_fail_callback(unique_id id,
void subscribe_success_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
/* This function should never be called. */
CHECK(0);
}
void subscribe_success_done_callback(object_id object_id,
void subscribe_success_done_callback(ObjectID object_id,
int manager_count,
const char *manager_vector[],
void *user_context) {
retry_info retry = {
RetryInfo retry = {
.num_retries = 0, .timeout = 750, .fail_callback = NULL,
};
object_table_add((db_handle *) user_context, subscribe_id, 0,
object_table_add((DBHandle *) user_context, subscribe_id, 0,
(unsigned char *) NIL_DIGEST, &retry, NULL, NULL);
subscribe_success_done = 1;
}
void subscribe_success_object_available_callback(object_id object_id,
void subscribe_success_object_available_callback(ObjectID object_id,
int64_t data_size,
int manager_count,
const char *manager_vector[],
void *user_context) {
CHECK(user_context == (void *) subscribe_success_context);
CHECK(object_ids_equal(object_id, subscribe_id));
CHECK(ObjectID_equal(object_id, subscribe_id));
CHECK(manager_count == 1);
subscribe_success_succeeded = 1;
}
@@ -602,12 +600,12 @@ TEST subscribe_success_test(void) {
/* Construct the arguments to db_connect. */
const char *db_connect_args[] = {"address", "127.0.0.1:11236"};
db_handle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1",
2, db_connect_args);
DBHandle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 2,
db_connect_args);
db_attach(db, g_loop, false);
subscribe_id = globally_unique_id();
retry_info retry = {
RetryInfo retry = {
.num_retries = 0,
.timeout = 100,
.fail_callback = subscribe_success_fail_callback,
@@ -617,7 +615,7 @@ TEST subscribe_success_test(void) {
(void *) subscribe_success_context, &retry,
subscribe_success_done_callback, (void *) db);
object_id object_ids[1] = {subscribe_id};
ObjectID object_ids[1] = {subscribe_id};
object_table_request_notifications(db, 1, object_ids, &retry);
/* Install handler for terminating the event loop. */
@@ -645,7 +643,7 @@ const char *subscribe_object_present_str = "subscribe_object_present";
int subscribe_object_present_succeeded = 0;
void subscribe_object_present_object_available_callback(
object_id object_id,
ObjectID object_id,
int64_t data_size,
int manager_count,
const char *manager_vector[],
@@ -658,7 +656,7 @@ void subscribe_object_present_object_available_callback(
CHECK(manager_count == 1);
}
void fatal_fail_callback(unique_id id, void *user_context, void *user_data) {
void fatal_fail_callback(UniqueID id, void *user_context, void *user_data) {
/* This function should never be called. */
CHECK(0);
}
@@ -671,11 +669,11 @@ TEST subscribe_object_present_test(void) {
g_loop = event_loop_create();
/* Construct the arguments to db_connect. */
const char *db_connect_args[] = {"address", "127.0.0.1:11236"};
db_handle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1",
2, db_connect_args);
DBHandle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 2,
db_connect_args);
db_attach(db, g_loop, false);
unique_id id = globally_unique_id();
retry_info retry = {
UniqueID id = globally_unique_id();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = fatal_fail_callback,
};
object_table_add(db, id, data_size, (unsigned char *) NIL_DIGEST, &retry,
@@ -690,7 +688,7 @@ TEST subscribe_object_present_test(void) {
/* Run the event loop to create do the add and subscribe. */
event_loop_run(g_loop);
object_id object_ids[1] = {id};
ObjectID object_ids[1] = {id};
object_table_request_notifications(db, 1, object_ids, &retry);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -712,7 +710,7 @@ const char *subscribe_object_not_present_context =
"subscribe_object_not_present";
void subscribe_object_not_present_object_available_callback(
object_id object_id,
ObjectID object_id,
int64_t data_size,
int manager_count,
const char *manager_vector[],
@@ -723,11 +721,11 @@ void subscribe_object_not_present_object_available_callback(
TEST subscribe_object_not_present_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
unique_id id = globally_unique_id();
retry_info retry = {
UniqueID id = globally_unique_id();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
object_table_subscribe_to_notifications(
@@ -740,7 +738,7 @@ TEST subscribe_object_not_present_test(void) {
/* Run the event loop to do the subscribe. */
event_loop_run(g_loop);
object_id object_ids[1] = {id};
ObjectID object_ids[1] = {id};
object_table_request_notifications(db, 1, object_ids, &retry);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -762,7 +760,7 @@ const char *subscribe_object_available_later_context =
int subscribe_object_available_later_succeeded = 0;
void subscribe_object_available_later_object_available_callback(
object_id object_id,
ObjectID object_id,
int64_t data_size,
int manager_count,
const char *manager_vector[],
@@ -786,11 +784,11 @@ TEST subscribe_object_available_later_test(void) {
g_loop = event_loop_create();
/* Construct the arguments to db_connect. */
const char *db_connect_args[] = {"address", "127.0.0.1:11236"};
db_handle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1",
2, db_connect_args);
DBHandle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 2,
db_connect_args);
db_attach(db, g_loop, false);
unique_id id = globally_unique_id();
retry_info retry = {
UniqueID id = globally_unique_id();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
object_table_subscribe_to_notifications(
@@ -803,7 +801,7 @@ TEST subscribe_object_available_later_test(void) {
/* Run the event loop to do the subscribe. */
event_loop_run(g_loop);
object_id object_ids[1] = {id};
ObjectID object_ids[1] = {id};
object_table_request_notifications(db, 1, object_ids, &retry);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -839,11 +837,11 @@ TEST subscribe_object_available_subscribe_all(void) {
g_loop = event_loop_create();
/* Construct the arguments to db_connect. */
const char *db_connect_args[] = {"address", "127.0.0.1:11236"};
db_handle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1",
2, db_connect_args);
DBHandle *db = db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 2,
db_connect_args);
db_attach(db, g_loop, false);
unique_id id = globally_unique_id();
retry_info retry = {
UniqueID id = globally_unique_id();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
object_table_subscribe_to_notifications(
+7 -7
View File
@@ -69,7 +69,7 @@ TEST redis_socket_test(void) {
}
void redis_read_callback(event_loop *loop, int fd, void *context, int events) {
db_handle *db = context;
DBHandle *db = context;
char *cmd = read_log_message(fd);
redisAsyncCommand(db->context, async_redis_socket_test_callback, NULL, cmd);
free(cmd);
@@ -102,7 +102,7 @@ TEST async_redis_socket_test(void) {
utarray_push_back(connections, &socket_fd);
/* Start connection to Redis. */
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "test_process", "127.0.0.1", 0, NULL);
db_attach(db, loop, false);
@@ -148,7 +148,7 @@ void logging_read_callback(event_loop *loop,
int fd,
void *context,
int events) {
db_handle *conn = context;
DBHandle *conn = context;
char *cmd = read_log_message(fd);
redisAsyncCommand(conn->context, logging_test_callback, NULL, cmd,
(char *) conn->client.id, sizeof(conn->client.id));
@@ -177,7 +177,7 @@ TEST logging_test(void) {
utarray_push_back(connections, &socket_fd);
/* Start connection to Redis. */
db_handle *conn =
DBHandle *conn =
db_connect("127.0.0.1", 6379, "test_process", "127.0.0.1", 0, NULL);
db_attach(conn, loop, false);
@@ -185,8 +185,8 @@ TEST logging_test(void) {
int client_fd = connect_ipc_sock(socket_pathname);
ASSERT(client_fd >= 0);
utarray_push_back(connections, &client_fd);
ray_logger *logger = init_ray_logger("worker", RAY_INFO, 0, &client_fd);
ray_log(logger, RAY_INFO, "TEST", "Message");
RayLogger *logger = RayLogger_init("worker", RAY_INFO, 0, &client_fd);
RayLogger_log(logger, RAY_INFO, "TEST", "Message");
event_loop_add_file(loop, socket_fd, EVENT_LOOP_READ, logging_accept_callback,
conn);
@@ -197,7 +197,7 @@ TEST logging_test(void) {
ASSERT(logging_test_callback_called);
free_ray_logger(logger);
RayLogger_free(logger);
db_disconnect(conn);
event_loop_destroy(loop);
for (int *p = (int *) utarray_front(connections); p != NULL;
+44 -46
View File
@@ -17,18 +17,18 @@ event_loop *g_loop;
/* === A lookup of a task not in the table === */
task_id lookup_nil_id;
TaskID lookup_nil_id;
int lookup_nil_success = 0;
const char *lookup_nil_context = "lookup_nil";
void lookup_nil_fail_callback(unique_id id,
void lookup_nil_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
/* The fail callback should not be called. */
CHECK(0);
}
void lookup_nil_success_callback(task *task, void *context) {
void lookup_nil_success_callback(Task *task, void *context) {
lookup_nil_success = 1;
CHECK(task == NULL);
CHECK(context == (void *) lookup_nil_context);
@@ -38,10 +38,10 @@ void lookup_nil_success_callback(task *task, void *context) {
TEST lookup_nil_test(void) {
lookup_nil_id = globally_unique_id();
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 1000,
.fail_callback = lookup_nil_fail_callback,
@@ -61,28 +61,28 @@ TEST lookup_nil_test(void) {
int add_success = 0;
int lookup_success = 0;
task *add_lookup_task;
Task *add_lookup_task;
const char *add_lookup_context = "add_lookup";
void add_lookup_fail_callback(unique_id id,
void add_lookup_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
/* The fail callback should not be called. */
CHECK(0);
}
void lookup_success_callback(task *task, void *context) {
void lookup_success_callback(Task *task, void *context) {
lookup_success = 1;
CHECK(memcmp(task, add_lookup_task, task_size(task)) == 0);
CHECK(memcmp(task, add_lookup_task, Task_size(task)) == 0);
event_loop_stop(g_loop);
}
void add_success_callback(task_id task_id, void *context) {
void add_success_callback(TaskID task_id, void *context) {
add_success = 1;
CHECK(task_ids_equal(task_id, task_task_id(add_lookup_task)));
CHECK(TaskID_equal(task_id, Task_task_id(add_lookup_task)));
db_handle *db = context;
retry_info retry = {
DBHandle *db = context;
RetryInfo retry = {
.num_retries = 5,
.timeout = 1000,
.fail_callback = add_lookup_fail_callback,
@@ -94,15 +94,15 @@ void add_success_callback(task_id task_id, void *context) {
TEST add_lookup_test(void) {
add_lookup_task = example_task(1, 1, TASK_STATUS_WAITING);
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 1000,
.fail_callback = add_lookup_fail_callback,
};
task_table_add_task(db, copy_task(add_lookup_task), &retry,
task_table_add_task(db, Task_copy(add_lookup_task), &retry,
add_success_callback, (void *) db);
/* Disconnect the database to see if the lookup times out. */
event_loop_run(g_loop);
@@ -121,14 +121,12 @@ TEST add_lookup_test(void) {
const char *subscribe_timeout_context = "subscribe_timeout";
int subscribe_failed = 0;
void subscribe_done_callback(task_id task_id, void *user_context) {
void subscribe_done_callback(TaskID task_id, void *user_context) {
/* The done callback should not be called. */
CHECK(0);
}
void subscribe_fail_callback(unique_id id,
void *user_context,
void *user_data) {
void subscribe_fail_callback(UniqueID id, void *user_context, void *user_data) {
subscribe_failed = 1;
CHECK(user_context == (void *) subscribe_timeout_context);
event_loop_stop(g_loop);
@@ -136,10 +134,10 @@ void subscribe_fail_callback(unique_id id,
TEST subscribe_timeout_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = subscribe_fail_callback,
@@ -164,12 +162,12 @@ const char *publish_timeout_context = "publish_timeout";
const int publish_test_number = 272;
int publish_failed = 0;
void publish_done_callback(task_id task_id, void *user_context) {
void publish_done_callback(TaskID task_id, void *user_context) {
/* The done callback should not be called. */
CHECK(0);
}
void publish_fail_callback(unique_id id, void *user_context, void *user_data) {
void publish_fail_callback(UniqueID id, void *user_context, void *user_data) {
publish_failed = 1;
CHECK(user_context == (void *) publish_timeout_context);
event_loop_stop(g_loop);
@@ -177,11 +175,11 @@ void publish_fail_callback(unique_id id, void *user_context, void *user_data) {
TEST publish_timeout_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
task *task = example_task(1, 1, TASK_STATUS_WAITING);
retry_info retry = {
Task *task = example_task(1, 1, TASK_STATUS_WAITING);
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = publish_fail_callback,
};
task_table_add_task(db, task, &retry, publish_done_callback,
@@ -202,7 +200,7 @@ TEST publish_timeout_test(void) {
int64_t reconnect_db_callback(event_loop *loop,
int64_t timer_id,
void *context) {
db_handle *db = context;
DBHandle *db = context;
/* Reconnect to redis. */
redisAsyncFree(db->sub_context);
db->sub_context = redisAsyncConnect("127.0.0.1", 6379);
@@ -225,12 +223,12 @@ const char *subscribe_retry_context = "subscribe_retry";
const int subscribe_retry_test_number = 273;
int subscribe_retry_succeeded = 0;
void subscribe_retry_done_callback(object_id object_id, void *user_context) {
void subscribe_retry_done_callback(ObjectID object_id, void *user_context) {
CHECK(user_context == (void *) subscribe_retry_context);
subscribe_retry_succeeded = 1;
}
void subscribe_retry_fail_callback(unique_id id,
void subscribe_retry_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
/* The fail callback should not be called. */
@@ -239,10 +237,10 @@ void subscribe_retry_fail_callback(unique_id id,
TEST subscribe_retry_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = subscribe_retry_fail_callback,
@@ -272,12 +270,12 @@ TEST subscribe_retry_test(void) {
const char *publish_retry_context = "publish_retry";
int publish_retry_succeeded = 0;
void publish_retry_done_callback(object_id object_id, void *user_context) {
void publish_retry_done_callback(ObjectID object_id, void *user_context) {
CHECK(user_context == (void *) publish_retry_context);
publish_retry_succeeded = 1;
}
void publish_retry_fail_callback(unique_id id,
void publish_retry_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
/* The fail callback should not be called. */
@@ -286,11 +284,11 @@ void publish_retry_fail_callback(unique_id id,
TEST publish_retry_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
task *task = example_task(1, 1, TASK_STATUS_WAITING);
retry_info retry = {
Task *task = example_task(1, 1, TASK_STATUS_WAITING);
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
.fail_callback = publish_retry_fail_callback,
@@ -321,24 +319,24 @@ TEST publish_retry_test(void) {
const char *subscribe_late_context = "subscribe_late";
int subscribe_late_failed = 0;
void subscribe_late_fail_callback(unique_id id,
void subscribe_late_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
CHECK(user_context == (void *) subscribe_late_context);
subscribe_late_failed = 1;
}
void subscribe_late_done_callback(task_id task_id, void *user_context) {
void subscribe_late_done_callback(TaskID task_id, void *user_context) {
/* This function should never be called. */
CHECK(0);
}
TEST subscribe_late_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
retry_info retry = {
RetryInfo retry = {
.num_retries = 0,
.timeout = 0,
.fail_callback = subscribe_late_fail_callback,
@@ -366,25 +364,25 @@ TEST subscribe_late_test(void) {
const char *publish_late_context = "publish_late";
int publish_late_failed = 0;
void publish_late_fail_callback(unique_id id,
void publish_late_fail_callback(UniqueID id,
void *user_context,
void *user_data) {
CHECK(user_context == (void *) publish_late_context);
publish_late_failed = 1;
}
void publish_late_done_callback(task_id task_id, void *user_context) {
void publish_late_done_callback(TaskID task_id, void *user_context) {
/* This function should never be called. */
CHECK(0);
}
TEST publish_late_test(void) {
g_loop = event_loop_create();
db_handle *db =
DBHandle *db =
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 0, NULL);
db_attach(db, g_loop, false);
task *task = example_task(1, 1, TASK_STATUS_WAITING);
retry_info retry = {
Task *task = example_task(1, 1, TASK_STATUS_WAITING);
RetryInfo retry = {
.num_retries = 0,
.timeout = 0,
.fail_callback = publish_late_fail_callback,
+25 -25
View File
@@ -12,17 +12,17 @@
SUITE(task_tests);
TEST task_test(void) {
task_id parent_task_id = globally_unique_id();
function_id func_id = globally_unique_id();
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
task_spec *spec = start_construct_task_spec(
NIL_ID, parent_task_id, 0, NIL_ACTOR_ID, 0, func_id, 4, 2, 10);
ASSERT(task_num_args(spec) == 4);
ASSERT(task_num_returns(spec) == 2);
unique_id arg1 = globally_unique_id();
UniqueID arg1 = globally_unique_id();
ASSERT(task_args_add_ref(spec, arg1) == 0);
ASSERT(task_args_add_val(spec, (uint8_t *) "hello", 5) == 1);
unique_id arg2 = globally_unique_id();
UniqueID arg2 = globally_unique_id();
ASSERT(task_args_add_ref(spec, arg2) == 2);
ASSERT(task_args_add_val(spec, (uint8_t *) "world", 5) == 3);
/* Finish constructing the spec. This constructs the task ID and the
@@ -32,11 +32,11 @@ TEST task_test(void) {
/* Check that the spec was constructed as expected. */
ASSERT(task_num_args(spec) == 4);
ASSERT(task_num_returns(spec) == 2);
ASSERT(function_ids_equal(task_function(spec), func_id));
ASSERT(object_ids_equal(task_arg_id(spec, 0), arg1));
ASSERT(FunctionID_equal(task_function(spec), func_id));
ASSERT(ObjectID_equal(task_arg_id(spec, 0), arg1));
ASSERT(memcmp(task_arg_val(spec, 1), (uint8_t *) "hello",
task_arg_length(spec, 1)) == 0);
ASSERT(object_ids_equal(task_arg_id(spec, 2), arg2));
ASSERT(ObjectID_equal(task_arg_id(spec, 2), arg2));
ASSERT(memcmp(task_arg_val(spec, 3), (uint8_t *) "world",
task_arg_length(spec, 3)) == 0);
@@ -46,9 +46,9 @@ TEST task_test(void) {
TEST deterministic_ids_test(void) {
/* Define the inputs to the task construction. */
task_id parent_task_id = globally_unique_id();
function_id func_id = globally_unique_id();
unique_id arg1 = globally_unique_id();
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
UniqueID arg1 = globally_unique_id();
uint8_t *arg2 = (uint8_t *) "hello world";
/* Construct a first task. */
@@ -66,14 +66,14 @@ TEST deterministic_ids_test(void) {
finish_construct_task_spec(spec2);
/* Check that these tasks have the same task IDs and the same return IDs.*/
ASSERT(task_ids_equal(task_spec_id(spec1), task_spec_id(spec2)));
ASSERT(object_ids_equal(task_return(spec1, 0), task_return(spec2, 0)));
ASSERT(object_ids_equal(task_return(spec1, 1), task_return(spec2, 1)));
ASSERT(object_ids_equal(task_return(spec1, 2), task_return(spec2, 2)));
ASSERT(TaskID_equal(task_spec_id(spec1), task_spec_id(spec2)));
ASSERT(ObjectID_equal(task_return(spec1, 0), task_return(spec2, 0)));
ASSERT(ObjectID_equal(task_return(spec1, 1), task_return(spec2, 1)));
ASSERT(ObjectID_equal(task_return(spec1, 2), task_return(spec2, 2)));
/* Check that the return IDs are all distinct. */
ASSERT(!object_ids_equal(task_return(spec1, 0), task_return(spec2, 1)));
ASSERT(!object_ids_equal(task_return(spec1, 0), task_return(spec2, 2)));
ASSERT(!object_ids_equal(task_return(spec1, 1), task_return(spec2, 2)));
ASSERT(!ObjectID_equal(task_return(spec1, 0), task_return(spec2, 1)));
ASSERT(!ObjectID_equal(task_return(spec1, 0), task_return(spec2, 2)));
ASSERT(!ObjectID_equal(task_return(spec1, 1), task_return(spec2, 2)));
/* Create more tasks that are only mildly different. */
@@ -114,11 +114,11 @@ TEST deterministic_ids_test(void) {
finish_construct_task_spec(spec7);
/* Check that the task IDs are all distinct from the original. */
ASSERT(!task_ids_equal(task_spec_id(spec1), task_spec_id(spec3)));
ASSERT(!task_ids_equal(task_spec_id(spec1), task_spec_id(spec4)));
ASSERT(!task_ids_equal(task_spec_id(spec1), task_spec_id(spec5)));
ASSERT(!task_ids_equal(task_spec_id(spec1), task_spec_id(spec6)));
ASSERT(!task_ids_equal(task_spec_id(spec1), task_spec_id(spec7)));
ASSERT(!TaskID_equal(task_spec_id(spec1), task_spec_id(spec3)));
ASSERT(!TaskID_equal(task_spec_id(spec1), task_spec_id(spec4)));
ASSERT(!TaskID_equal(task_spec_id(spec1), task_spec_id(spec5)));
ASSERT(!TaskID_equal(task_spec_id(spec1), task_spec_id(spec6)));
ASSERT(!TaskID_equal(task_spec_id(spec1), task_spec_id(spec7)));
/* Check that the return object IDs are distinct from the originals. */
task_spec *specs[6] = {spec1, spec3, spec4, spec5, spec6, spec7};
@@ -127,7 +127,7 @@ TEST deterministic_ids_test(void) {
for (int task_index2 = 0; task_index2 < 6; ++task_index2) {
for (int return_index2 = 0; return_index2 < 3; ++return_index2) {
if (task_index1 != task_index2 && return_index1 != return_index2) {
ASSERT(!object_ids_equal(
ASSERT(!ObjectID_equal(
task_return(specs[task_index1], return_index1),
task_return(specs[task_index2], return_index2)));
}
@@ -147,8 +147,8 @@ TEST deterministic_ids_test(void) {
}
TEST send_task(void) {
task_id parent_task_id = globally_unique_id();
function_id func_id = globally_unique_id();
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
task_spec *spec = start_construct_task_spec(
NIL_ID, parent_task_id, 0, NIL_ACTOR_ID, 0, func_id, 4, 2, 10);
task_args_add_ref(spec, globally_unique_id());
+11 -11
View File
@@ -18,14 +18,14 @@ const int64_t arg_value_size = 1000;
static inline task_spec *example_task_spec_with_args(int64_t num_args,
int64_t num_returns,
object_id arg_ids[]) {
task_id parent_task_id = globally_unique_id();
function_id func_id = globally_unique_id();
ObjectID arg_ids[]) {
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
task_spec *task =
start_construct_task_spec(NIL_ID, parent_task_id, 0, NIL_ACTOR_ID, 0,
func_id, num_args, num_returns, arg_value_size);
for (int64_t i = 0; i < num_args; ++i) {
object_id arg_id;
ObjectID arg_id;
if (arg_ids == NULL) {
arg_id = globally_unique_id();
} else {
@@ -42,21 +42,21 @@ static inline task_spec *example_task_spec(int64_t num_args,
return example_task_spec_with_args(num_args, num_returns, NULL);
}
static inline task *example_task_with_args(int64_t num_args,
static inline Task *example_task_with_args(int64_t num_args,
int64_t num_returns,
int task_state,
object_id arg_ids[]) {
int Task_state,
ObjectID arg_ids[]) {
task_spec *spec = example_task_spec_with_args(num_args, num_returns, arg_ids);
task *instance = alloc_task(spec, task_state, NIL_ID);
Task *instance = Task_alloc(spec, Task_state, NIL_ID);
free_task_spec(spec);
return instance;
}
static inline task *example_task(int64_t num_args,
static inline Task *example_task(int64_t num_args,
int64_t num_returns,
int task_state) {
int Task_state) {
task_spec *spec = example_task_spec(num_args, num_returns);
task *instance = alloc_task(spec, task_state, NIL_ID);
Task *instance = Task_alloc(spec, Task_state, NIL_ID);
free_task_spec(spec);
return instance;
}