mirror of
https://github.com/wassname/ray.git
synced 2026-08-11 05:51:40 +08:00
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:
committed by
Robert Nishihara
parent
be1618f041
commit
a30eed452e
@@ -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,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
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
|
||||
@@ -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,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 */
|
||||
|
||||
Reference in New Issue
Block a user