Second Part of Internal API Refactor (#1326)

This commit is contained in:
Philipp Moritz
2017-12-26 16:22:04 -08:00
committed by Robert Nishihara
parent 4bb5b6bd5b
commit 3d224c4edf
58 changed files with 537 additions and 677 deletions
+1 -2
View File
@@ -78,11 +78,10 @@ target_link_libraries(common "${CMAKE_CURRENT_LIST_DIR}/thirdparty/hiredis/libhi
function(define_test test_name library)
add_executable(${test_name} test/${test_name}.cc ${ARGN})
add_dependencies(${test_name} hiredis flatbuffers_ep)
target_link_libraries(${test_name} common ${FLATBUFFERS_STATIC_LIB} ${ARROW_DIR}/cpp/build/release/libarrow.a ${library} -lpthread)
target_link_libraries(${test_name} common ${FLATBUFFERS_STATIC_LIB} ray_static ${PLASMA_STATIC_LIB} ${ARROW_STATIC_LIB} ${library} -lpthread)
target_compile_options(${test_name} PUBLIC "-DPLASMA_TEST -DLOCAL_SCHEDULER_TEST -DCOMMON_TEST -DRAY_COMMON_LOG_LEVEL=4")
endfunction()
define_test(common_tests "")
define_test(db_tests "")
define_test(io_tests "")
define_test(task_tests "")
-55
View File
@@ -10,63 +10,8 @@
#include "io.h"
#include <functional>
const UniqueID NIL_ID = UniqueID::nil();
const unsigned char NIL_DIGEST[DIGEST_SIZE] = {0};
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");
}
UniqueID result;
CHECK(read_bytes(fd, &result.id[0], UNIQUE_ID_SIZE) >= 0);
close(fd);
return result;
}
/* ObjectID equality function. */
bool operator==(const ObjectID &x, const ObjectID &y) {
return UNIQUE_ID_EQ(x, y);
}
bool ObjectID_equal(ObjectID first_id, ObjectID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
bool ObjectID_is_nil(ObjectID id) {
return ObjectID_equal(id, NIL_OBJECT_ID);
}
bool DBClientID_equal(DBClientID first_id, DBClientID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
bool DBClientID_is_nil(DBClientID id) {
return IS_NIL_ID(id);
}
bool WorkerID_equal(WorkerID first_id, WorkerID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
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;
for (int i = 0; i < UNIQUE_ID_SIZE; i++) {
unsigned int val = obj_id.id[i];
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];
}
*buf = '\0';
return id_string;
}
int64_t current_time_ms() {
std::chrono::milliseconds ms_since_epoch =
std::chrono::duration_cast<std::chrono::milliseconds>(
+4 -111
View File
@@ -22,8 +22,9 @@ extern "C" {
}
#endif
#include "plasma/common.h"
#include "arrow/util/macros.h"
#include "plasma/common.h"
#include "ray/id.h"
#include "state/ray_config.h"
@@ -113,118 +114,10 @@ extern "C" {
* and is responsible for freeing it. */
#define OWNER
/** Definitions for unique ID types. */
#define UNIQUE_ID_SIZE 20
#define UNIQUE_ID_EQ(id1, id2) (memcmp((id1).id, (id2).id, UNIQUE_ID_SIZE) == 0)
#define IS_NIL_ID(id) UNIQUE_ID_EQ(id, NIL_ID)
struct UniqueID {
unsigned char id[UNIQUE_ID_SIZE];
UniqueID(const plasma::UniqueID &from) {
memcpy(&id[0], from.data(), UNIQUE_ID_SIZE);
}
UniqueID() {}
static const UniqueID nil() {
UniqueID result;
std::fill_n(result.id, UNIQUE_ID_SIZE, 255);
return result;
}
plasma::UniqueID to_plasma_id() {
plasma::UniqueID result;
memcpy(result.mutable_data(), &id[0], UNIQUE_ID_SIZE);
return result;
}
};
extern const UniqueID NIL_ID;
/* Generate a globally unique ID. */
UniqueID globally_unique_id(void);
#define NIL_OBJECT_ID NIL_ID
#define NIL_WORKER_ID NIL_ID
/** The object ID is the type used to identify objects. */
typedef UniqueID ObjectID;
#ifdef __cplusplus
struct UniqueIDHasher {
/* ObjectID hashing function. */
size_t operator()(const UniqueID &id) const {
size_t result;
memcpy(&result, id.id, sizeof(size_t));
return result;
}
};
bool operator==(const ObjectID &x, const ObjectID &y);
#endif
#define ID_STRING_SIZE (2 * UNIQUE_ID_SIZE + 1)
/**
* Convert an object ID to a hexdecimal string. This function assumes that
* buffer points to an already allocated char array of size ID_STRING_SIZE. And
* it writes a null-terminated hex-formatted string to id_string.
*
* @param obj_id The object ID to convert to a string.
* @param id_string A buffer to write the string to. It is assumed that this is
* managed by the caller and is sufficiently long to store the object ID
* string.
* @param id_length The length of the id_string buffer.
*/
char *ObjectID_to_string(ObjectID obj_id, char *id_string, int id_length);
/**
* Compare two object IDs.
*
* @param first_id The first object ID to compare.
* @param second_id The first object ID to compare.
* @return True if the object IDs are the same and false otherwise.
*/
bool ObjectID_equal(ObjectID first_id, ObjectID second_id);
/**
* Compare a object ID to the nil ID.
*
* @param id The object ID to compare to nil.
* @return True if the object ID is equal to nil.
*/
bool ObjectID_is_nil(ObjectID id);
/** The worker ID is the ID of a worker or driver. */
typedef UniqueID WorkerID;
typedef ray::UniqueID WorkerID;
/**
* Compare two worker IDs.
*
* @param first_id The first worker ID to compare.
* @param second_id The first worker ID to compare.
* @return True if the worker IDs are the same and false otherwise.
*/
bool WorkerID_equal(WorkerID first_id, WorkerID second_id);
typedef UniqueID DBClientID;
/**
* Compare two db client IDs.
*
* @param first_id The first db client ID to compare.
* @param second_id The first db client ID to compare.
* @return True if the db client IDs are the same and false otherwise.
*/
bool DBClientID_equal(DBClientID first_id, DBClientID second_id);
/**
* Compare a db client ID to the nil ID.
*
* @param id The db client ID to compare to nil.
* @return True if the db client ID is equal to nil.
*/
bool DBClientID_is_nil(ObjectID id);
typedef ray::UniqueID DBClientID;
#define MAX(x, y) ((x) >= (y) ? (x) : (y))
#define MIN(x, y) ((x) <= (y) ? (x) : (y))
+11 -10
View File
@@ -2,21 +2,22 @@
flatbuffers::Offset<flatbuffers::String> to_flatbuf(
flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_id) {
return fbb.CreateString((char *) &object_id.id[0], sizeof(object_id.id));
ray::ObjectID object_id) {
return fbb.CreateString(reinterpret_cast<const char *>(object_id.data()),
sizeof(ray::ObjectID));
}
ObjectID from_flatbuf(const flatbuffers::String &string) {
ObjectID object_id;
CHECK(string.size() == sizeof(object_id.id));
memcpy(&object_id.id[0], string.data(), sizeof(object_id.id));
ray::ObjectID from_flatbuf(const flatbuffers::String &string) {
ray::ObjectID object_id;
CHECK(string.size() == sizeof(ray::ObjectID));
memcpy(object_id.mutable_data(), string.data(), sizeof(ray::ObjectID));
return object_id;
}
const std::vector<ObjectID> from_flatbuf(
const std::vector<ray::ObjectID> from_flatbuf(
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>
&vector) {
std::vector<ObjectID> object_ids;
std::vector<ray::ObjectID> object_ids;
for (int64_t i = 0; i < vector.Length(); i++) {
object_ids.push_back(from_flatbuf(*vector.Get(i)));
}
@@ -26,7 +27,7 @@ const std::vector<ObjectID> from_flatbuf(
flatbuffers::Offset<
flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>>
to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_ids[],
ray::ObjectID object_ids[],
int64_t num_objects) {
std::vector<flatbuffers::Offset<flatbuffers::String>> results;
for (int64_t i = 0; i < num_objects; i++) {
@@ -38,7 +39,7 @@ to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<
flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>>
to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
const std::vector<ObjectID> &object_ids) {
const std::vector<ray::ObjectID> &object_ids) {
std::vector<flatbuffers::Offset<flatbuffers::String>> results;
for (auto object_id : object_ids) {
results.push_back(to_flatbuf(fbb, object_id));
+5 -5
View File
@@ -16,19 +16,19 @@
/// @return The flatbuffer string contining the object ID.
flatbuffers::Offset<flatbuffers::String> to_flatbuf(
flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_id);
ray::ObjectID object_id);
/// Convert a flatbuffer string to an object ID.
///
/// @param string The flatbuffer string.
/// @return The object ID.
ObjectID from_flatbuf(const flatbuffers::String &string);
ray::ObjectID from_flatbuf(const flatbuffers::String &string);
/// Convert a flatbuffer vector of strings to a vector of object IDs.
///
/// @param vector The flatbuffer vector.
/// @return The vector of object IDs.
const std::vector<ObjectID> from_flatbuf(
const std::vector<ray::ObjectID> from_flatbuf(
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>
&vector);
@@ -41,7 +41,7 @@ const std::vector<ObjectID> from_flatbuf(
flatbuffers::Offset<
flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>>
to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
ObjectID object_ids[],
ray::ObjectID object_ids[],
int64_t num_objects);
/// Convert a vector of object IDs to a flatbuffer vector of strings.
@@ -52,7 +52,7 @@ to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<
flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>>
to_flatbuf(flatbuffers::FlatBufferBuilder &fbb,
const std::vector<ObjectID> &object_ids);
const std::vector<ray::ObjectID> &object_ids);
/// Convert a flatbuffer string to a std::string.
///
+17 -19
View File
@@ -44,7 +44,8 @@ TaskBuilder *g_task_builder = NULL;
int PyStringToUniqueID(PyObject *object, ObjectID *object_id) {
if (PyBytes_Check(object)) {
memcpy(&object_id->id[0], PyBytes_AsString(object), UNIQUE_ID_SIZE);
std::memcpy(object_id->mutable_data(), PyBytes_AsString(object),
sizeof(*object_id));
return 1;
} else {
PyErr_SetString(PyExc_TypeError, "must be a 20 character string");
@@ -73,7 +74,7 @@ static int PyObjectID_init(PyObjectID *self, PyObject *args, PyObject *kwds) {
"ObjectID: object id string needs to have length 20");
return -1;
}
memcpy(&self->object_id.id[0], data, sizeof(self->object_id.id));
std::memcpy(self->object_id.mutable_data(), data, sizeof(self->object_id));
return 0;
}
@@ -132,15 +133,14 @@ PyObject *PyTask_to_string(PyObject *self, PyObject *args) {
static PyObject *PyObjectID_id(PyObject *self) {
PyObjectID *s = (PyObjectID *) self;
return PyBytes_FromStringAndSize((char *) &s->object_id.id[0],
sizeof(s->object_id.id));
return PyBytes_FromStringAndSize((const char *) s->object_id.data(),
sizeof(s->object_id));
}
static PyObject *PyObjectID_hex(PyObject *self) {
PyObjectID *s = (PyObjectID *) self;
char hex_id[ID_STRING_SIZE];
ObjectID_to_string(s->object_id, hex_id, ID_STRING_SIZE);
PyObject *result = PyUnicode_FromString(hex_id);
std::string hex_id = s->object_id.hex();
PyObject *result = PyUnicode_FromString(hex_id.c_str());
return result;
}
@@ -160,12 +160,10 @@ static PyObject *PyObjectID_richcompare(PyObjectID *self,
result = Py_NotImplemented;
break;
case Py_EQ:
result = ObjectID_equal(self->object_id, other_id->object_id) ? Py_True
: Py_False;
result = self->object_id == other_id->object_id ? Py_True : Py_False;
break;
case Py_NE:
result = !ObjectID_equal(self->object_id, other_id->object_id) ? Py_True
: Py_False;
result = !(self->object_id == other_id->object_id) ? Py_True : Py_False;
break;
case Py_GT:
result = Py_NotImplemented;
@@ -188,9 +186,11 @@ static PyObject *PyObjectID_redis_shard_hash(PyObjectID *self) {
}
static long PyObjectID_hash(PyObjectID *self) {
PyObject *tuple = PyTuple_New(UNIQUE_ID_SIZE);
for (int i = 0; i < UNIQUE_ID_SIZE; ++i) {
PyTuple_SetItem(tuple, i, PyLong_FromLong(self->object_id.id[i]));
// TODO(pcm): Replace this with a faster hash function. This currently
// creates a tuple of length 20 and hashes it, which is slow
PyObject *tuple = PyTuple_New(kUniqueIDSize);
for (int i = 0; i < kUniqueIDSize; ++i) {
PyTuple_SetItem(tuple, i, PyLong_FromLong(self->object_id.data()[i]));
}
long hash = PyObject_Hash(tuple);
Py_XDECREF(tuple);
@@ -198,9 +198,7 @@ static long PyObjectID_hash(PyObjectID *self) {
}
static PyObject *PyObjectID_repr(PyObjectID *self) {
char hex_id[ID_STRING_SIZE];
ObjectID_to_string(self->object_id, hex_id, ID_STRING_SIZE);
std::string repr = "ObjectID(" + std::string(hex_id) + ")";
std::string repr = "ObjectID(" + self->object_id.hex() + ")";
PyObject *result = PyUnicode_FromString(repr.c_str());
return result;
}
@@ -274,9 +272,9 @@ static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
/* ID of the driver that this task originates from. */
UniqueID driver_id;
/* ID of the actor this task should run on. */
UniqueID actor_id = NIL_ACTOR_ID;
UniqueID actor_id = UniqueID::nil();
/* ID of the actor handle used to submit this task. */
UniqueID actor_handle_id = NIL_ACTOR_ID;
UniqueID actor_handle_id = UniqueID::nil();
/* How many tasks have been launched on the actor so far? */
int actor_counter = 0;
/* True if this is an actor checkpoint task and false otherwise. */
+6 -6
View File
@@ -9,7 +9,7 @@
#include "common.h"
typedef uint8_t TaskSpec;
typedef char TaskSpec;
class TaskBuilder;
extern PyObject *CommonError;
@@ -17,14 +17,14 @@ extern PyObject *CommonError;
// clang-format off
typedef struct {
PyObject_HEAD
ObjectID object_id;
ray::ObjectID object_id;
} PyObjectID;
typedef struct {
PyObject_HEAD
int64_t size;
TaskSpec *spec;
std::vector<ObjectID> *execution_dependencies;
std::vector<ray::ObjectID> *execution_dependencies;
} PyTask;
// clang-format on
@@ -41,11 +41,11 @@ void init_pickle_module(void);
extern TaskBuilder *g_task_builder;
int PyStringToUniqueID(PyObject *object, ObjectID *object_id);
int PyStringToUniqueID(PyObject *object, ray::ObjectID *object_id);
int PyObjectToUniqueID(PyObject *object, ObjectID *object_id);
int PyObjectToUniqueID(PyObject *object, ray::ObjectID *object_id);
PyObject *PyObjectID_make(ObjectID object_id);
PyObject *PyObjectID_make(ray::ObjectID object_id);
PyObject *check_simple_value(PyObject *self, PyObject *args);
+2 -2
View File
@@ -50,7 +50,7 @@ void RayLogger_log(RayLogger *logger,
if (log_level < logger->log_level) {
return;
}
if (log_level < RAY_DEBUG || log_level > RAY_FATAL) {
if (log_level < RAY_LOG_DEBUG || log_level > RAY_LOG_FATAL) {
return;
}
struct timeval tv;
@@ -79,7 +79,7 @@ void RayLogger_log(RayLogger *logger,
int status =
redisAsyncCommand(context, NULL, NULL, formatted_message,
(char *) db->client.id, sizeof(db->client.id));
(char *) db->client.data(), sizeof(db->client));
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "error while logging message to log table");
}
+6 -6
View File
@@ -1,12 +1,12 @@
#ifndef LOGGING_H
#define LOGGING_H
#define RAY_VERBOSE -1
#define RAY_DEBUG 0
#define RAY_INFO 1
#define RAY_WARNING 2
#define RAY_ERROR 3
#define RAY_FATAL 4
#define RAY_LOG_VERBOSE -1
#define RAY_LOG_DEBUG 0
#define RAY_LOG_INFO 1
#define RAY_LOG_WARNING 2
#define RAY_LOG_ERROR 3
#define RAY_LOG_FATAL 4
/* Entity types. */
#define RAY_FUNCTION "FUNCTION"
+1 -1
View File
@@ -12,7 +12,7 @@ void actor_notification_table_subscribe(
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
init_table_callback(db_handle, NIL_ID, __func__,
init_table_callback(db_handle, UniqueID::nil(), __func__,
new CommonCallbackData(sub_data), retry, NULL,
redis_actor_notification_table_subscribe, NULL);
}
+4 -3
View File
@@ -24,7 +24,7 @@ void db_client_table_subscribe(
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
init_table_callback(db_handle, NIL_ID, __func__,
init_table_callback(db_handle, UniqueID::nil(), __func__,
new CommonCallbackData(sub_data), retry,
(table_done_callback) done_callback,
redis_db_client_table_subscribe, user_context);
@@ -71,7 +71,7 @@ void db_client_table_cache_init(DBHandle *db_handle) {
}
DBClient db_client_table_cache_get(DBHandle *db_handle, DBClientID client_id) {
CHECK(!DBClientID_is_nil(client_id));
CHECK(!client_id.is_nil());
return redis_cache_get_db_client(db_handle, client_id);
}
@@ -82,7 +82,8 @@ void plasma_manager_send_heartbeat(DBHandle *db_handle) {
RayConfig::instance().heartbeat_timeout_milliseconds();
heartbeat_retry.fail_callback = NULL;
init_table_callback(db_handle, NIL_ID, __func__, new CommonCallbackData(NULL),
init_table_callback(db_handle, UniqueID::nil(), __func__,
new CommonCallbackData(NULL),
(RetryInfo *) &heartbeat_retry, NULL,
redis_plasma_manager_send_heartbeat, NULL);
}
+1 -1
View File
@@ -9,7 +9,7 @@ void driver_table_subscribe(DBHandle *db_handle,
(DriverTableSubscribeData *) malloc(sizeof(DriverTableSubscribeData));
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
init_table_callback(db_handle, NIL_ID, __func__,
init_table_callback(db_handle, UniqueID::nil(), __func__,
new CommonCallbackData(sub_data), retry, NULL,
redis_driver_table_subscribe, NULL);
}
+7 -6
View File
@@ -13,7 +13,7 @@ void push_error(DBHandle *db_handle,
DBClientID driver_id,
int error_index,
size_t data_length,
unsigned char *data) {
const unsigned char *data) {
CHECK(error_index >= 0 && error_index < MAX_ERROR_INDEX);
/* Allocate a struct to hold the error information. */
ErrorInfo *info = (ErrorInfo *) malloc(sizeof(ErrorInfo) + data_length);
@@ -22,10 +22,11 @@ void push_error(DBHandle *db_handle,
info->data_length = data_length;
memcpy(info->data, data, data_length);
/* Generate a random key to identify this error message. */
CHECK(sizeof(info->error_key) >= UNIQUE_ID_SIZE);
UniqueID error_key = globally_unique_id();
memcpy(info->error_key, error_key.id, sizeof(info->error_key));
CHECK(sizeof(info->error_key) >= sizeof(UniqueID));
UniqueID error_key = UniqueID::from_random();
memcpy(info->error_key, error_key.data(), sizeof(info->error_key));
init_table_callback(db_handle, NIL_ID, __func__, new CommonCallbackData(info),
NULL, NULL, redis_push_error, NULL);
init_table_callback(db_handle, UniqueID::nil(), __func__,
new CommonCallbackData(info), NULL, NULL,
redis_push_error, NULL);
}
+1 -1
View File
@@ -48,6 +48,6 @@ void push_error(DBHandle *db_handle,
DBClientID driver_id,
int error_index,
size_t data_length,
unsigned char *data);
const unsigned char *data);
#endif
+4 -3
View File
@@ -13,7 +13,7 @@ void local_scheduler_table_subscribe(
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
init_table_callback(db_handle, NIL_ID, __func__,
init_table_callback(db_handle, UniqueID::nil(), __func__,
new CommonCallbackData(sub_data), retry, NULL,
redis_local_scheduler_table_subscribe, NULL);
}
@@ -37,8 +37,9 @@ void local_scheduler_table_send_info(DBHandle *db_handle,
data->size = fbb.GetSize();
memcpy(&data->flatbuffer_data[0], fbb.GetBufferPointer(), fbb.GetSize());
init_table_callback(db_handle, NIL_ID, __func__, new CommonCallbackData(data),
retry, NULL, redis_local_scheduler_table_send_info, NULL);
init_table_callback(db_handle, UniqueID::nil(), __func__,
new CommonCallbackData(data), retry, NULL,
redis_local_scheduler_table_send_info, NULL);
}
void local_scheduler_table_disconnect(DBHandle *db_handle) {
+3 -3
View File
@@ -67,7 +67,7 @@ void object_table_subscribe_to_notifications(
sub_data->subscribe_all = subscribe_all;
init_table_callback(
db_handle, NIL_OBJECT_ID, __func__, new CommonCallbackData(sub_data),
db_handle, ObjectID::nil(), __func__, new CommonCallbackData(sub_data),
retry, (table_done_callback) done_callback,
redis_object_table_subscribe_to_notifications, user_context);
}
@@ -85,7 +85,7 @@ void object_table_request_notifications(DBHandle *db_handle,
data->num_object_ids = num_object_ids;
memcpy(data->object_ids, object_ids, num_object_ids * sizeof(ObjectID));
init_table_callback(db_handle, NIL_OBJECT_ID, __func__,
init_table_callback(db_handle, ObjectID::nil(), __func__,
new CommonCallbackData(data), retry, NULL,
redis_object_table_request_notifications, NULL);
}
@@ -101,7 +101,7 @@ void object_info_subscribe(DBHandle *db_handle,
sub_data->subscribe_callback = subscribe_callback;
sub_data->subscribe_context = subscribe_context;
init_table_callback(db_handle, NIL_OBJECT_ID, __func__,
init_table_callback(db_handle, ObjectID::nil(), __func__,
new CommonCallbackData(sub_data), retry,
(table_done_callback) done_callback,
redis_object_info_subscribe, user_context);
+59 -57
View File
@@ -207,8 +207,8 @@ void db_connect_shard(const std::string &db_address,
argv[0] = "RAY.CONNECT";
argvlen[0] = strlen(argv[0]);
/* Set the client ID argument. */
argv[1] = (char *) client.id;
argvlen[1] = sizeof(client.id);
argv[1] = (char *) client.data();
argvlen[1] = sizeof(client);
/* Set the node IP address argument. */
argv[2] = node_ip_address;
argvlen[2] = strlen(node_ip_address);
@@ -265,7 +265,7 @@ DBHandle *db_connect(const std::string &db_primary_address,
}
/* Create a client ID for this client. */
DBClientID client = globally_unique_id();
DBClientID client = DBClientID::from_random();
DBHandle *db = new DBHandle();
@@ -325,7 +325,7 @@ void db_disconnect(DBHandle *db) {
* reconnect and get assigned a different client ID. */
redisReply *reply =
(redisReply *) redisCommand(db->sync_context, "RAY.DISCONNECT %b",
db->client.id, sizeof(db->client.id));
db->client.data(), sizeof(db->client));
CHECK(reply->type != REDIS_REPLY_ERROR);
CHECKM(strcmp(reply->str, "OK") == 0, "reply->str is %s", reply->str);
freeReplyObject(reply);
@@ -408,8 +408,8 @@ void redis_object_table_add(TableCallbackData *callback_data) {
int status = redisAsyncCommand(
context, redis_object_table_add_callback,
(void *) callback_data->timer_id, "RAY.OBJECT_TABLE_ADD %b %lld %b %b",
obj_id.id, sizeof(obj_id.id), (long long) object_size, digest,
(size_t) DIGEST_SIZE, db->client.id, sizeof(db->client.id));
obj_id.data(), sizeof(obj_id), (long long) object_size, digest,
(size_t) DIGEST_SIZE, db->client.data(), sizeof(db->client));
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "error in redis_object_table_add");
@@ -456,7 +456,7 @@ void redis_object_table_remove(TableCallbackData *callback_data) {
int status = redisAsyncCommand(
context, redis_object_table_remove_callback,
(void *) callback_data->timer_id, "RAY.OBJECT_TABLE_REMOVE %b %b",
obj_id.id, sizeof(obj_id.id), client_id->id, sizeof(client_id->id));
obj_id.data(), sizeof(obj_id), client_id->data(), sizeof(*client_id));
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "error in redis_object_table_remove");
@@ -473,8 +473,8 @@ void redis_object_table_lookup(TableCallbackData *callback_data) {
int status = redisAsyncCommand(context, redis_object_table_lookup_callback,
(void *) callback_data->timer_id,
"RAY.OBJECT_TABLE_LOOKUP %b", obj_id.id,
sizeof(obj_id.id));
"RAY.OBJECT_TABLE_LOOKUP %b", obj_id.data(),
sizeof(obj_id));
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "error in object_table lookup");
}
@@ -508,10 +508,11 @@ void redis_result_table_add(TableCallbackData *callback_data) {
redisAsyncContext *context = get_redis_context(db, id);
/* Add the result entry to the result table. */
int status = redisAsyncCommand(
context, redis_result_table_add_callback,
(void *) callback_data->timer_id, "RAY.RESULT_TABLE_ADD %b %b %d", id.id,
sizeof(id.id), info->task_id.id, sizeof(info->task_id.id), is_put);
int status =
redisAsyncCommand(context, redis_result_table_add_callback,
(void *) callback_data->timer_id,
"RAY.RESULT_TABLE_ADD %b %b %d", id.data(), sizeof(id),
info->task_id.data(), sizeof(info->task_id), is_put);
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "Error in result table add");
}
@@ -554,7 +555,7 @@ void redis_result_table_lookup_callback(redisAsyncContext *c,
"Unexpected reply type %d in redis_result_table_lookup_callback",
reply->type);
/* Parse the task from the reply. */
TaskID result_id = NIL_TASK_ID;
TaskID result_id = TaskID::nil();
bool is_put = false;
if (reply->type == REDIS_REPLY_STRING) {
auto message = flatbuffers::GetRoot<ResultTableReply>(reply->str);
@@ -581,14 +582,14 @@ void redis_result_table_lookup(TableCallbackData *callback_data) {
int status =
redisAsyncCommand(context, redis_result_table_lookup_callback,
(void *) callback_data->timer_id,
"RAY.RESULT_TABLE_LOOKUP %b", id.id, sizeof(id.id));
"RAY.RESULT_TABLE_LOOKUP %b", id.data(), sizeof(id));
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "Error in result table lookup");
}
}
DBClient redis_db_client_table_get(DBHandle *db,
unsigned char *client_id,
const unsigned char *client_id,
size_t client_id_len) {
redisReply *reply =
(redisReply *) redisCommand(db->sync_context, "HGETALL %s%b",
@@ -602,7 +603,7 @@ DBClient redis_db_client_table_get(DBHandle *db,
const char *key = reply->element[j]->str;
const char *value = reply->element[j + 1]->str;
if (strcmp(key, "ray_client_id") == 0) {
memcpy(db_client.id.id, value, sizeof(db_client.id));
memcpy(db_client.id.mutable_data(), value, sizeof(db_client.id));
num_fields++;
} else if (strcmp(key, "client_type") == 0) {
db_client.client_type = std::string(value);
@@ -637,8 +638,8 @@ void redis_cache_set_db_client(DBHandle *db, DBClient client) {
DBClient redis_cache_get_db_client(DBHandle *db, DBClientID db_client_id) {
auto it = db->db_client_cache.find(db_client_id);
if (it == db->db_client_cache.end()) {
DBClient db_client =
redis_db_client_table_get(db, db_client_id.id, sizeof(db_client_id.id));
DBClient db_client = redis_db_client_table_get(db, db_client_id.data(),
sizeof(db_client_id));
db->db_client_cache[db_client_id] = db_client;
it = db->db_client_cache.find(db_client_id);
}
@@ -672,7 +673,8 @@ void redis_object_table_lookup_callback(redisAsyncContext *c,
for (size_t j = 0; j < reply->elements; ++j) {
CHECK(reply->element[j]->type == REDIS_REPLY_STRING);
DBClientID manager_id;
memcpy(manager_id.id, reply->element[j]->str, sizeof(manager_id.id));
memcpy(manager_id.mutable_data(), reply->element[j]->str,
sizeof(manager_id));
manager_ids.push_back(manager_id);
}
@@ -743,7 +745,7 @@ void object_table_redis_subscribe_to_notifications_callback(
if (callback_data->done_callback != NULL) {
object_table_lookup_done_callback done_callback =
(object_table_lookup_done_callback) callback_data->done_callback;
done_callback(NIL_ID, false, std::vector<DBClientID>(),
done_callback(ray::UniqueID::nil(), false, std::vector<DBClientID>(),
callback_data->user_context);
}
/* If the initial SUBSCRIBE was successful, clean up the timer, but don't
@@ -783,7 +785,7 @@ void redis_object_table_subscribe_to_notifications(
db->subscribe_contexts[i],
object_table_redis_subscribe_to_notifications_callback,
(void *) callback_data->timer_id, "SUBSCRIBE %s%b",
object_channel_prefix, db->client.id, sizeof(db->client.id));
object_channel_prefix, db->client.data(), sizeof(db->client));
}
if ((status == REDIS_ERR) || db->subscribe_contexts[i]->err) {
@@ -827,11 +829,11 @@ void redis_object_table_request_notifications(
argv[0] = "RAY.OBJECT_TABLE_REQUEST_NOTIFICATIONS";
argvlen[0] = strlen(argv[0]);
/* Set the client ID argument. */
argv[1] = (char *) db->client.id;
argvlen[1] = sizeof(db->client.id);
argv[1] = (char *) db->client.data();
argvlen[1] = sizeof(db->client);
/* Set the object ID arguments. */
argv[2] = (char *) object_ids[i].id;
argvlen[2] = sizeof(object_ids[i].id);
argv[2] = (char *) object_ids[i].data();
argvlen[2] = sizeof(object_ids[i]);
int status = redisAsyncCommandArgv(
context, redis_object_table_request_notifications_callback,
@@ -881,8 +883,8 @@ void redis_task_table_get_task(TableCallbackData *callback_data) {
int status = redisAsyncCommand(context, redis_task_table_get_task_callback,
(void *) callback_data->timer_id,
"RAY.TASK_TABLE_GET %b", task_id.id,
sizeof(task_id.id));
"RAY.TASK_TABLE_GET %b", task_id.data(),
sizeof(task_id));
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "error in redis_task_table_get_task");
}
@@ -942,8 +944,8 @@ void redis_task_table_add_task(TableCallbackData *callback_data) {
int status = redisAsyncCommand(
context, redis_task_table_add_task_callback,
(void *) callback_data->timer_id, "RAY.TASK_TABLE_ADD %b %d %b %b %b",
task_id.id, sizeof(task_id.id), state, local_scheduler_id.id,
sizeof(local_scheduler_id.id), fbb.GetBufferPointer(),
task_id.data(), sizeof(task_id), state, local_scheduler_id.data(),
sizeof(local_scheduler_id), fbb.GetBufferPointer(),
(size_t) fbb.GetSize(), spec, execution_spec->SpecSize());
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "error in redis_task_table_add_task");
@@ -1004,8 +1006,8 @@ void redis_task_table_update(TableCallbackData *callback_data) {
int status = redisAsyncCommand(
context, redis_task_table_update_callback,
(void *) callback_data->timer_id, "RAY.TASK_TABLE_UPDATE %b %d %b %b",
task_id.id, sizeof(task_id.id), state, local_scheduler_id.id,
sizeof(local_scheduler_id.id), fbb.GetBufferPointer(),
task_id.data(), sizeof(task_id), state, local_scheduler_id.data(),
sizeof(local_scheduler_id), fbb.GetBufferPointer(),
(size_t) fbb.GetSize());
if ((status == REDIS_ERR) || context->err) {
LOG_REDIS_DEBUG(context, "error in redis_task_table_update");
@@ -1055,24 +1057,24 @@ void redis_task_table_test_and_update(TableCallbackData *callback_data) {
int status;
/* If the test local scheduler ID is NIL, then ignore it. */
if (IS_NIL_ID(update_data->test_local_scheduler_id)) {
if (update_data->test_local_scheduler_id.is_nil()) {
status = redisAsyncCommand(
context, redis_task_table_test_and_update_callback,
(void *) callback_data->timer_id,
"RAY.TASK_TABLE_TEST_AND_UPDATE %b %d %d %b", task_id.id,
sizeof(task_id.id), update_data->test_state_bitmask,
update_data->update_state, update_data->local_scheduler_id.id,
sizeof(update_data->local_scheduler_id.id));
"RAY.TASK_TABLE_TEST_AND_UPDATE %b %d %d %b", task_id.data(),
sizeof(task_id), update_data->test_state_bitmask,
update_data->update_state, update_data->local_scheduler_id.data(),
sizeof(update_data->local_scheduler_id));
} else {
status = redisAsyncCommand(
context, redis_task_table_test_and_update_callback,
(void *) callback_data->timer_id,
"RAY.TASK_TABLE_TEST_AND_UPDATE %b %d %d %b %b", task_id.id,
sizeof(task_id.id), update_data->test_state_bitmask,
update_data->update_state, update_data->local_scheduler_id.id,
sizeof(update_data->local_scheduler_id.id),
update_data->test_local_scheduler_id.id,
sizeof(update_data->test_local_scheduler_id.id));
"RAY.TASK_TABLE_TEST_AND_UPDATE %b %d %d %b %b", task_id.data(),
sizeof(task_id), update_data->test_state_bitmask,
update_data->update_state, update_data->local_scheduler_id.data(),
sizeof(update_data->local_scheduler_id),
update_data->test_local_scheduler_id.data(),
sizeof(update_data->test_local_scheduler_id));
}
if ((status == REDIS_ERR) || context->err) {
@@ -1152,7 +1154,7 @@ void redis_task_table_subscribe(TableCallbackData *callback_data) {
const char *TASK_CHANNEL_PREFIX = "TT:";
for (auto subscribe_context : db->subscribe_contexts) {
int status;
if (IS_NIL_ID(data->local_scheduler_id)) {
if (data->local_scheduler_id.is_nil()) {
/* TODO(swang): Implement the state_filter by translating the bitmask into
* a Redis key-matching pattern. */
status = redisAsyncCommand(
@@ -1164,8 +1166,8 @@ void redis_task_table_subscribe(TableCallbackData *callback_data) {
status = redisAsyncCommand(
subscribe_context, redis_task_table_subscribe_callback,
(void *) callback_data->timer_id, "SUBSCRIBE %s%b:%d",
TASK_CHANNEL_PREFIX, (char *) local_scheduler_id.id,
sizeof(local_scheduler_id.id), data->state_filter);
TASK_CHANNEL_PREFIX, (char *) local_scheduler_id.data(),
sizeof(local_scheduler_id), data->state_filter);
}
if ((status == REDIS_ERR) || subscribe_context->err) {
LOG_REDIS_DEBUG(subscribe_context, "error in redis_task_table_subscribe");
@@ -1201,7 +1203,7 @@ void redis_db_client_table_remove(TableCallbackData *callback_data) {
int status =
redisAsyncCommand(db->context, redis_db_client_table_remove_callback,
(void *) callback_data->timer_id, "RAY.DISCONNECT %b",
callback_data->id.id, sizeof(callback_data->id.id));
callback_data->id.data(), sizeof(callback_data->id));
if ((status == REDIS_ERR) || db->context->err) {
LOG_REDIS_DEBUG(db->context, "error in db_client_table_remove");
}
@@ -1512,7 +1514,7 @@ void redis_plasma_manager_send_heartbeat(TableCallbackData *callback_data) {
* memory for callback data each time. */
int status = redisAsyncCommand(
db->context, NULL, (void *) callback_data->timer_id,
"PUBLISH plasma_managers %b", db->client.id, sizeof(db->client.id));
"PUBLISH plasma_managers %b", db->client.data(), sizeof(db->client));
if ((status == REDIS_ERR) || db->context->err) {
LOG_REDIS_DEBUG(db->context,
"error in redis_plasma_manager_send_heartbeat");
@@ -1598,7 +1600,7 @@ void redis_actor_notification_table_subscribe(
void redis_actor_table_mark_removed(DBHandle *db, ActorID actor_id) {
int status =
redisAsyncCommand(db->context, NULL, NULL, "HSET Actor:%b removed \"1\"",
actor_id.id, sizeof(actor_id.id));
actor_id.data(), sizeof(actor_id));
if ((status == REDIS_ERR) || db->subscribe_context->err) {
LOG_REDIS_DEBUG(db->context, "error in redis_actor_table_mark_removed");
}
@@ -1633,7 +1635,7 @@ void redis_object_info_subscribe_callback(redisAsyncContext *c,
ObjectInfoSubscribeData *data =
(ObjectInfoSubscribeData *) callback_data->data->Get();
ObjectID object_id;
memcpy(object_id.id, payload->str, sizeof(object_id.id));
memcpy(object_id.mutable_data(), payload->str, sizeof(object_id));
/* payload->str should have the format: "ObjectID:object_size_int" */
LOG_DEBUG("obj:info channel received message <%s>", payload->str);
if (data->subscribe_callback) {
@@ -1676,11 +1678,11 @@ void redis_push_error_hmset_callback(redisAsyncContext *c,
/* Add the error to this driver's list of errors. */
ErrorInfo *info = (ErrorInfo *) callback_data->data->Get();
int status = redisAsyncCommand(db->context, redis_push_error_rpush_callback,
(void *) callback_data->timer_id,
"RPUSH ErrorKeys Error:%b:%b",
info->driver_id.id, sizeof(info->driver_id.id),
info->error_key, sizeof(info->error_key));
int status = redisAsyncCommand(
db->context, redis_push_error_rpush_callback,
(void *) callback_data->timer_id, "RPUSH ErrorKeys Error:%b:%b",
info->driver_id.data(), sizeof(info->driver_id), info->error_key,
sizeof(info->error_key));
if ((status == REDIS_ERR) || db->subscribe_context->err) {
LOG_REDIS_DEBUG(db->subscribe_context, "error in redis_push_error rpush");
}
@@ -1698,8 +1700,8 @@ void redis_push_error(TableCallbackData *callback_data) {
int status = redisAsyncCommand(
db->context, redis_push_error_hmset_callback,
(void *) callback_data->timer_id,
"HMSET Error:%b:%b type %s message %s data %b", info->driver_id.id,
sizeof(info->driver_id.id), info->error_key, sizeof(info->error_key),
"HMSET Error:%b:%b type %s message %s data %b", info->driver_id.data(),
sizeof(info->driver_id), info->error_key, sizeof(info->error_key),
error_type, error_message, info->data, info->data_length);
if ((status == REDIS_ERR) || db->subscribe_context->err) {
LOG_REDIS_DEBUG(db->subscribe_context, "error in redis_push_error hmset");
+13 -13
View File
@@ -145,23 +145,23 @@ void free_task_builder(TaskBuilder *builder) {
}
bool TaskID_equal(TaskID first_id, TaskID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
return first_id == second_id;
}
bool TaskID_is_nil(TaskID id) {
return TaskID_equal(id, NIL_TASK_ID);
return id.is_nil();
}
bool ActorID_equal(ActorID first_id, ActorID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
return first_id == second_id;
}
bool FunctionID_equal(FunctionID first_id, FunctionID second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
return first_id == second_id;
}
bool FunctionID_is_nil(FunctionID id) {
return FunctionID_equal(id, NIL_FUNCTION_ID);
return id.is_nil();
}
/* Functions for building tasks. */
@@ -181,8 +181,8 @@ void TaskSpec_start_construct(TaskBuilder *builder,
function_id, num_returns);
}
uint8_t *TaskSpec_finish_construct(TaskBuilder *builder, int64_t *size) {
return builder->Finish(size);
TaskSpec *TaskSpec_finish_construct(TaskBuilder *builder, int64_t *size) {
return reinterpret_cast<TaskSpec *>(builder->Finish(size));
}
void TaskSpec_args_add_ref(TaskBuilder *builder,
@@ -205,7 +205,7 @@ void TaskSpec_set_required_resource(TaskBuilder *builder,
/* Functions for reading tasks. */
TaskID TaskSpec_task_id(TaskSpec *spec) {
TaskID TaskSpec_task_id(const TaskSpec *spec) {
CHECK(spec);
auto message = flatbuffers::GetRoot<TaskInfo>(spec);
return from_flatbuf(*message->task_id());
@@ -230,7 +230,7 @@ ActorID TaskSpec_actor_handle_id(TaskSpec *spec) {
}
bool TaskSpec_is_actor_task(TaskSpec *spec) {
return !ActorID_equal(TaskSpec_actor_id(spec), NIL_ACTOR_ID);
return !TaskSpec_actor_id(spec).is_nil();
}
int64_t TaskSpec_actor_counter(TaskSpec *spec) {
@@ -258,13 +258,13 @@ bool TaskSpec_arg_is_actor_dummy_object(TaskSpec *spec, int64_t arg_index) {
}
}
UniqueID TaskSpec_driver_id(TaskSpec *spec) {
UniqueID TaskSpec_driver_id(const TaskSpec *spec) {
CHECK(spec);
auto message = flatbuffers::GetRoot<TaskInfo>(spec);
return from_flatbuf(*message->driver_id());
}
TaskID TaskSpec_parent_task_id(TaskSpec *spec) {
TaskID TaskSpec_parent_task_id(const TaskSpec *spec) {
CHECK(spec);
auto message = flatbuffers::GetRoot<TaskInfo>(spec);
return from_flatbuf(*message->parent_task_id());
@@ -451,14 +451,14 @@ bool TaskExecutionSpec::DependsOn(ObjectID object_id) {
int count = TaskSpec_arg_id_count(spec, i);
for (int j = 0; j < count; j++) {
ObjectID arg_id = TaskSpec_arg_id(spec, i, j);
if (ObjectID_equal(arg_id, object_id)) {
if (arg_id == object_id) {
return true;
}
}
}
// Iterate through the execution dependencies to see if it contains object_id.
for (auto dependency_id : execution_dependencies_) {
if (ObjectID_equal(dependency_id, object_id)) {
if (dependency_id == object_id) {
return true;
}
}
+7 -9
View File
@@ -11,7 +11,9 @@
#include "format/common_generated.h"
typedef uint8_t TaskSpec;
using namespace ray;
typedef char TaskSpec;
class TaskExecutionSpec {
public:
@@ -82,10 +84,6 @@ class TaskExecutionSpec {
class TaskBuilder;
#define NIL_TASK_ID NIL_ID
#define NIL_ACTOR_ID NIL_ID
#define NIL_FUNCTION_ID NIL_ID
typedef UniqueID FunctionID;
/** The task ID is a deterministic hash of the function ID that the task
@@ -189,7 +187,7 @@ void TaskSpec_start_construct(TaskBuilder *B,
* @param spec The task spec whose ID and return object IDs should be computed.
* @return Void.
*/
uint8_t *TaskSpec_finish_construct(TaskBuilder *builder, int64_t *size);
TaskSpec *TaskSpec_finish_construct(TaskBuilder *builder, int64_t *size);
/**
* Return the function ID of the task.
@@ -256,7 +254,7 @@ bool TaskSpec_arg_is_actor_dummy_object(TaskSpec *spec, int64_t arg_index);
* @param spec The task_spec in question.
* @return The driver ID of the task.
*/
UniqueID TaskSpec_driver_id(TaskSpec *spec);
UniqueID TaskSpec_driver_id(const TaskSpec *spec);
/**
* Return the task ID of the parent task.
@@ -264,7 +262,7 @@ UniqueID TaskSpec_driver_id(TaskSpec *spec);
* @param spec The task_spec in question.
* @return The task ID of the parent task.
*/
TaskID TaskSpec_parent_task_id(TaskSpec *spec);
TaskID TaskSpec_parent_task_id(const TaskSpec *spec);
/**
* Return the task counter of the parent task. For example, this equals 5 if
@@ -281,7 +279,7 @@ int64_t TaskSpec_parent_counter(TaskSpec *spec);
* @param spec The task_spec in question.
* @return The task ID of the task.
*/
TaskID TaskSpec_task_id(TaskSpec *spec);
TaskID TaskSpec_task_id(const TaskSpec *spec);
/**
* Get the number of arguments to this task.
-24
View File
@@ -1,24 +0,0 @@
#include "greatest.h"
#include "common.h"
SUITE(common_tests);
TEST sha1_test(void) {
static char hex[ID_STRING_SIZE];
UniqueID uid = globally_unique_id();
ObjectID_to_string((ObjectID) uid, &hex[0], ID_STRING_SIZE);
PASS();
}
SUITE(common_tests) {
RUN_TEST(sha1_test);
}
GREATEST_MAIN_DEFS();
int main(int argc, char **argv) {
GREATEST_MAIN_BEGIN();
RUN_SUITE(common_tests);
GREATEST_MAIN_END();
}
+8 -6
View File
@@ -81,7 +81,7 @@ TEST object_table_lookup_test(void) {
manager_addr, db_connect_args2);
db_attach(db1, loop, false);
db_attach(db2, loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = NUM_RETRIES,
.timeout = TIMEOUT,
@@ -149,7 +149,7 @@ TEST task_table_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "local_scheduler",
"127.0.0.1", std::vector<std::string>());
db_attach(db, loop, false);
DBClientID local_scheduler_id = globally_unique_id();
DBClientID local_scheduler_id = DBClientID::from_random();
TaskExecutionSpec spec = example_task_execution_spec(1, 1);
task_table_test_task =
Task_alloc(spec, TASK_STATUS_SCHEDULED, local_scheduler_id);
@@ -185,12 +185,14 @@ TEST task_table_all_test(void) {
db_attach(db, loop, false);
TaskExecutionSpec spec = example_task_execution_spec(1, 1);
/* Schedule two tasks on different local local schedulers. */
Task *task1 = Task_alloc(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
Task *task2 = Task_alloc(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
Task *task1 =
Task_alloc(spec, TASK_STATUS_SCHEDULED, DBClientID::from_random());
Task *task2 =
Task_alloc(spec, TASK_STATUS_SCHEDULED, DBClientID::from_random());
RetryInfo retry = {
.num_retries = NUM_RETRIES, .timeout = TIMEOUT, .fail_callback = NULL,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_SCHEDULED,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_SCHEDULED,
task_table_all_test_callback, NULL, &retry, NULL, NULL);
event_loop_add_timer(loop, 50, (event_loop_timer_handler) timeout_handler,
NULL);
@@ -221,7 +223,7 @@ TEST unique_client_id_test(void) {
}
for (int i = 0; i < num_conns; ++i) {
for (int j = 0; j < i; ++j) {
ASSERT(!DBClientID_equal(ids[i], ids[j]));
ASSERT(!(ids[i] == ids[j]));
}
}
PASS();
+8 -8
View File
@@ -11,15 +11,15 @@ static inline TaskExecutionSpec example_task_execution_spec_with_args(
int64_t num_args,
int64_t num_returns,
ObjectID arg_ids[]) {
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
TaskSpec_start_construct(g_task_builder, NIL_ID, parent_task_id, 0,
NIL_ACTOR_ID, NIL_ACTOR_ID, 0, false, func_id,
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
TaskSpec_start_construct(g_task_builder, UniqueID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
num_returns);
for (int64_t i = 0; i < num_args; ++i) {
ObjectID arg_id;
if (arg_ids == NULL) {
arg_id = globally_unique_id();
arg_id = ObjectID::from_random();
} else {
arg_id = arg_ids[i];
}
@@ -46,7 +46,7 @@ static inline Task *example_task_with_args(int64_t num_args,
ObjectID arg_ids[]) {
TaskExecutionSpec spec =
example_task_execution_spec_with_args(num_args, num_returns, arg_ids);
Task *instance = Task_alloc(spec, task_state, NIL_ID);
Task *instance = Task_alloc(spec, task_state, UniqueID::nil());
return instance;
}
@@ -54,7 +54,7 @@ static inline Task *example_task(int64_t num_args,
int64_t num_returns,
int task_state) {
TaskExecutionSpec spec = example_task_execution_spec(num_args, num_returns);
Task *instance = Task_alloc(spec, task_state, NIL_ID);
Task *instance = Task_alloc(spec, task_state, UniqueID::nil());
return instance;
}
@@ -62,7 +62,7 @@ static inline bool Task_equals(Task *task1, Task *task2) {
if (task1->state != task2->state) {
return false;
}
if (!DBClientID_equal(task1->local_scheduler_id, task2->local_scheduler_id)) {
if (!(task1->local_scheduler_id == task2->local_scheduler_id)) {
return false;
}
auto execution_spec1 = Task_task_execution_spec(task1);
+26 -25
View File
@@ -38,13 +38,13 @@ void new_object_done_callback(ObjectID object_id,
bool is_put,
void *user_context) {
new_object_succeeded = 1;
CHECK(ObjectID_equal(object_id, new_object_id));
CHECK(TaskID_equal(task_id, new_object_task_id));
CHECK(object_id == new_object_id);
CHECK(task_id == new_object_task_id);
event_loop_stop(g_loop);
}
void new_object_lookup_callback(ObjectID object_id, void *user_context) {
CHECK(ObjectID_equal(object_id, new_object_id));
CHECK(object_id == new_object_id);
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
@@ -78,7 +78,7 @@ void task_table_subscribe_done(TaskID task_id, void *user_context) {
TEST new_object_test(void) {
new_object_failed = 0;
new_object_succeeded = 0;
new_object_id = globally_unique_id();
new_object_id = ObjectID::from_random();
new_object_task = example_task(1, 1, TASK_STATUS_WAITING);
new_object_task_spec = Task_task_execution_spec(new_object_task)->Spec();
new_object_task_id = TaskSpec_task_id(new_object_task_spec);
@@ -91,8 +91,8 @@ TEST new_object_test(void) {
.timeout = 100,
.fail_callback = new_object_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
task_table_subscribe_done, db);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, task_table_subscribe_done, db);
event_loop_run(g_loop);
db_disconnect(db);
destroy_outstanding_callbacks(g_loop);
@@ -109,15 +109,15 @@ void new_object_no_task_callback(ObjectID object_id,
bool is_put,
void *user_context) {
new_object_succeeded = 1;
CHECK(IS_NIL_ID(task_id));
CHECK(task_id.is_nil());
event_loop_stop(g_loop);
}
TEST new_object_no_task_test(void) {
new_object_failed = 0;
new_object_succeeded = 0;
new_object_id = globally_unique_id();
new_object_task_id = globally_unique_id();
new_object_id = ObjectID::from_random();
new_object_task_id = TaskID::from_random();
g_loop = event_loop_create();
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", std::vector<std::string>());
@@ -167,7 +167,7 @@ TEST lookup_timeout_test(void) {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = lookup_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, lookup_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry, lookup_done_callback,
(void *) lookup_timeout_context);
/* Disconnect the database to see if the lookup times out. */
close(db->context->c.fd);
@@ -206,7 +206,7 @@ TEST add_timeout_test(void) {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = add_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_done_callback, (void *) add_timeout_context);
/* Disconnect the database to see if the lookup times out. */
close(db->context->c.fd);
@@ -327,7 +327,7 @@ void add_lookup_callback(ObjectID object_id, bool success, void *user_context) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, add_lookup_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry, add_lookup_done_callback,
(void *) db);
}
@@ -346,7 +346,7 @@ TEST add_lookup_test(void) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_lookup_callback, (void *) db);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -381,7 +381,8 @@ void add_remove_lookup_callback(ObjectID object_id,
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, add_remove_lookup_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry,
add_remove_lookup_done_callback,
(void *) lookup_retry_context);
}
@@ -393,8 +394,8 @@ void add_remove_callback(ObjectID object_id, bool success, void *user_context) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_remove(db, NIL_ID, NULL, &retry, add_remove_lookup_callback,
(void *) db);
object_table_remove(db, UniqueID::nil(), NULL, &retry,
add_remove_lookup_callback, (void *) db);
}
TEST add_remove_lookup_test(void) {
@@ -408,7 +409,7 @@ TEST add_remove_lookup_test(void) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_remove_callback, (void *) db);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -454,7 +455,7 @@ TEST lookup_late_test(void) {
.timeout = 0,
.fail_callback = lookup_late_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, lookup_late_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry, lookup_late_done_callback,
(void *) lookup_late_context);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -496,7 +497,7 @@ TEST add_late_test(void) {
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,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_late_done_callback, (void *) add_late_context);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -594,7 +595,7 @@ void subscribe_success_object_available_callback(
const std::vector<DBClientID> &manager_vector,
void *user_context) {
CHECK(user_context == (void *) subscribe_success_context);
CHECK(ObjectID_equal(object_id, subscribe_id));
CHECK(object_id == subscribe_id);
CHECK(manager_vector.size() == 1);
subscribe_success_succeeded = 1;
}
@@ -609,7 +610,7 @@ TEST subscribe_success_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
subscribe_id = globally_unique_id();
subscribe_id = ObjectID::from_random();
RetryInfo retry = {
.num_retries = 0,
@@ -679,7 +680,7 @@ TEST subscribe_object_present_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = fatal_fail_callback,
};
@@ -730,7 +731,7 @@ TEST subscribe_object_not_present_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", std::vector<std::string>());
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
@@ -795,7 +796,7 @@ TEST subscribe_object_available_later_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
@@ -850,7 +851,7 @@ TEST subscribe_object_available_subscribe_all(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
+3 -3
View File
@@ -167,7 +167,7 @@ void logging_read_callback(event_loop *loop,
DBHandle *conn = (DBHandle *) context;
char *cmd = read_log_message(fd);
redisAsyncCommand(conn->context, logging_test_callback, NULL, cmd,
(char *) conn->client.id, sizeof(conn->client.id));
(char *) conn->client.data(), sizeof(conn->client));
free(cmd);
}
@@ -200,8 +200,8 @@ TEST logging_test(void) {
int client_fd = connect_ipc_sock(socket_pathname);
ASSERT(client_fd >= 0);
connections.push_back(client_fd);
RayLogger *logger = RayLogger_init("worker", RAY_INFO, 0, &client_fd);
RayLogger_log(logger, RAY_INFO, "TEST", "Message");
RayLogger *logger = RayLogger_init("worker", RAY_LOG_INFO, 0, &client_fd);
RayLogger_log(logger, RAY_LOG_INFO, "TEST", "Message");
event_loop_add_file(loop, socket_fd, EVENT_LOOP_READ, logging_accept_callback,
conn);
-1
View File
@@ -13,7 +13,6 @@ sleep 1s
./src/common/thirdparty/redis/src/redis-cli set NumRedisShards 1
./src/common/thirdparty/redis/src/redis-cli rpush RedisShards 127.0.0.1:6380
./src/common/common_tests
./src/common/db_tests
./src/common/io_tests
./src/common/task_tests
+6 -7
View File
@@ -15,13 +15,12 @@ sleep 1s
./src/common/thirdparty/redis/src/redis-cli set NumRedisShards 1
./src/common/thirdparty/redis/src/redis-cli rpush RedisShards 127.0.0.1:6380
valgrind --leak-check=full --error-exitcode=1 ./src/common/common_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/db_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/io_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/task_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/redis_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/task_table_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/object_table_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/db_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/io_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/task_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/redis_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/task_table_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/object_table_tests
./src/common/thirdparty/redis/src/redis-cli shutdown
./src/common/thirdparty/redis/src/redis-cli -p 6380 shutdown
+15 -15
View File
@@ -38,7 +38,7 @@ void lookup_nil_success_callback(Task *task, void *context) {
}
TEST lookup_nil_test(void) {
lookup_nil_id = globally_unique_id();
lookup_nil_id = TaskID::from_random();
g_loop = event_loop_create();
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", std::vector<std::string>());
@@ -116,8 +116,8 @@ TEST add_lookup_test(void) {
.fail_callback = add_lookup_fail_callback,
};
/* Wait for subscription to succeed before adding the task. */
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_success_callback, (void *) db);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_success_callback, (void *) db);
/* Disconnect the database to see if the lookup times out. */
event_loop_run(g_loop);
db_disconnect(db);
@@ -156,8 +156,8 @@ TEST subscribe_timeout_test(void) {
.timeout = 100,
.fail_callback = subscribe_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_done_callback,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_done_callback,
(void *) subscribe_timeout_context);
/* Disconnect the database to see if the subscribe times out. */
close(db->subscribe_context->c.fd);
@@ -198,8 +198,8 @@ TEST publish_timeout_test(void) {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = publish_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
NULL, NULL);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, NULL, NULL);
task_table_add_task(db, task, &retry, publish_done_callback,
(void *) publish_timeout_context);
/* Disconnect the database to see if the publish times out. */
@@ -270,8 +270,8 @@ TEST subscribe_retry_test(void) {
.timeout = 100,
.fail_callback = subscribe_retry_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_retry_done_callback,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_retry_done_callback,
(void *) subscribe_retry_context);
/* Disconnect the database to see if the subscribe times out. */
close(db->subscribe_context->c.fd);
@@ -321,8 +321,8 @@ TEST publish_retry_test(void) {
.timeout = 100,
.fail_callback = publish_retry_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
NULL, NULL);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, NULL, NULL);
task_table_add_task(db, task, &retry, publish_retry_done_callback,
(void *) publish_retry_context);
/* Disconnect the database to see if the publish times out. */
@@ -374,8 +374,8 @@ TEST subscribe_late_test(void) {
.timeout = 0,
.fail_callback = subscribe_late_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_late_done_callback,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_late_done_callback,
(void *) subscribe_late_context);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -420,8 +420,8 @@ TEST publish_late_test(void) {
.timeout = 0,
.fail_callback = publish_late_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, NULL, NULL,
NULL);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
NULL, NULL, NULL);
task_table_add_task(db, task, &retry, publish_late_done_callback,
(void *) publish_late_context);
/* Install handler for terminating the event loop. */
+50 -42
View File
@@ -12,31 +12,32 @@
SUITE(task_tests);
TEST task_test(void) {
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
TaskBuilder *builder = make_task_builder();
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 2);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
2);
UniqueID arg1 = globally_unique_id();
UniqueID arg1 = UniqueID::from_random();
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "hello", 5);
UniqueID arg2 = globally_unique_id();
UniqueID arg2 = UniqueID::from_random();
TaskSpec_args_add_ref(builder, &arg2, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "world", 5);
/* Finish constructing the spec. This constructs the task ID and the
* return IDs. */
int64_t size;
uint8_t *spec = TaskSpec_finish_construct(builder, &size);
TaskSpec *spec = TaskSpec_finish_construct(builder, &size);
/* Check that the spec was constructed as expected. */
ASSERT(TaskSpec_num_args(spec) == 4);
ASSERT(TaskSpec_num_returns(spec) == 2);
ASSERT(FunctionID_equal(TaskSpec_function(spec), func_id));
ASSERT(ObjectID_equal(TaskSpec_arg_id(spec, 0, 0), arg1));
ASSERT(TaskSpec_arg_id(spec, 0, 0) == arg1);
ASSERT(memcmp(TaskSpec_arg_val(spec, 1), (uint8_t *) "hello",
TaskSpec_arg_length(spec, 1)) == 0);
ASSERT(ObjectID_equal(TaskSpec_arg_id(spec, 2, 0), arg2));
ASSERT(TaskSpec_arg_id(spec, 2, 0) == arg2);
ASSERT(memcmp(TaskSpec_arg_val(spec, 3), (uint8_t *) "world",
TaskSpec_arg_length(spec, 3)) == 0);
@@ -48,22 +49,24 @@ TEST task_test(void) {
TEST deterministic_ids_test(void) {
TaskBuilder *builder = make_task_builder();
/* Define the inputs to the task construction. */
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
UniqueID arg1 = globally_unique_id();
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
UniqueID arg1 = UniqueID::from_random();
uint8_t *arg2 = (uint8_t *) "hello world";
/* Construct a first task. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size1;
TaskSpec *spec1 = TaskSpec_finish_construct(builder, &size1);
/* Construct a second identical task. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size2;
@@ -71,52 +74,57 @@ TEST deterministic_ids_test(void) {
/* Check that these tasks have the same task IDs and the same return IDs. */
ASSERT(TaskID_equal(TaskSpec_task_id(spec1), TaskSpec_task_id(spec2)));
ASSERT(ObjectID_equal(TaskSpec_return(spec1, 0), TaskSpec_return(spec2, 0)));
ASSERT(ObjectID_equal(TaskSpec_return(spec1, 1), TaskSpec_return(spec2, 1)));
ASSERT(ObjectID_equal(TaskSpec_return(spec1, 2), TaskSpec_return(spec2, 2)));
ASSERT(TaskSpec_return(spec1, 0) == TaskSpec_return(spec2, 0));
ASSERT(TaskSpec_return(spec1, 1) == TaskSpec_return(spec2, 1));
ASSERT(TaskSpec_return(spec1, 2) == TaskSpec_return(spec2, 2));
/* Check that the return IDs are all distinct. */
ASSERT(!ObjectID_equal(TaskSpec_return(spec1, 0), TaskSpec_return(spec2, 1)));
ASSERT(!ObjectID_equal(TaskSpec_return(spec1, 0), TaskSpec_return(spec2, 2)));
ASSERT(!ObjectID_equal(TaskSpec_return(spec1, 1), TaskSpec_return(spec2, 2)));
ASSERT(!(TaskSpec_return(spec1, 0) == TaskSpec_return(spec2, 1)));
ASSERT(!(TaskSpec_return(spec1, 0) == TaskSpec_return(spec2, 2)));
ASSERT(!(TaskSpec_return(spec1, 1) == TaskSpec_return(spec2, 2)));
/* Create more tasks that are only mildly different. */
/* Construct a task with a different parent task ID. */
TaskSpec_start_construct(builder, NIL_ID, globally_unique_id(), 0,
NIL_ACTOR_ID, NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), TaskID::from_random(), 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size3;
TaskSpec *spec3 = TaskSpec_finish_construct(builder, &size3);
/* Construct a task with a different parent counter. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 1, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 1,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size4;
TaskSpec *spec4 = TaskSpec_finish_construct(builder, &size4);
/* Construct a task with a different function ID. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, globally_unique_id(), 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false,
FunctionID::from_random(), 3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size5;
TaskSpec *spec5 = TaskSpec_finish_construct(builder, &size5);
/* Construct a task with a different object ID argument. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
ObjectID object_id = globally_unique_id();
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
ObjectID object_id = ObjectID::from_random();
TaskSpec_args_add_ref(builder, &object_id, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size6;
TaskSpec *spec6 = TaskSpec_finish_construct(builder, &size6);
/* Construct a task with a different value argument. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "hello_world", 11);
int64_t size7;
@@ -136,9 +144,8 @@ 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(!ObjectID_equal(
TaskSpec_return(specs[task_index1], return_index1),
TaskSpec_return(specs[task_index2], return_index2)));
ASSERT(!(TaskSpec_return(specs[task_index1], return_index1) ==
TaskSpec_return(specs[task_index2], return_index2)));
}
}
}
@@ -158,15 +165,16 @@ TEST deterministic_ids_test(void) {
TEST send_task(void) {
TaskBuilder *builder = make_task_builder();
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 2);
ObjectID object_id = globally_unique_id();
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
2);
ObjectID object_id = ObjectID::from_random();
TaskSpec_args_add_ref(builder, &object_id, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "Hello", 5);
TaskSpec_args_add_val(builder, (uint8_t *) "World", 5);
object_id = globally_unique_id();
object_id = ObjectID::from_random();
TaskSpec_args_add_ref(builder, &object_id, 1);
int64_t size;
TaskSpec *spec = TaskSpec_finish_construct(builder, &size);