2016-10-29 15:22:33 -07:00
|
|
|
#include "object_table.h"
|
|
|
|
#include "redis.h"
|
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
void object_table_lookup(DBHandle *db_handle,
|
|
|
|
ObjectID object_id,
|
|
|
|
RetryInfo *retry,
|
2016-10-29 15:22:33 -07:00
|
|
|
object_table_lookup_done_callback done_callback,
|
|
|
|
void *user_context) {
|
2016-12-01 02:15:21 -08:00
|
|
|
CHECK(db_handle != NULL);
|
2016-11-15 20:33:29 -08:00
|
|
|
init_table_callback(db_handle, object_id, __func__, NULL, retry,
|
2017-03-01 01:17:24 -08:00
|
|
|
(table_done_callback) done_callback,
|
|
|
|
redis_object_table_lookup, user_context);
|
2016-10-29 15:22:33 -07:00
|
|
|
}
|
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
void object_table_add(DBHandle *db_handle,
|
|
|
|
ObjectID object_id,
|
2016-12-18 18:19:02 -08:00
|
|
|
int64_t object_size,
|
2016-12-08 20:57:08 -08:00
|
|
|
unsigned char digest[],
|
2017-02-26 00:32:43 -08:00
|
|
|
RetryInfo *retry,
|
2016-10-29 15:22:33 -07:00
|
|
|
object_table_done_callback done_callback,
|
|
|
|
void *user_context) {
|
2016-12-01 02:15:21 -08:00
|
|
|
CHECK(db_handle != NULL);
|
2016-12-09 00:51:44 -08:00
|
|
|
|
2017-03-01 01:17:24 -08:00
|
|
|
ObjectTableAddData *info =
|
|
|
|
(ObjectTableAddData *) malloc(sizeof(ObjectTableAddData));
|
2016-12-18 18:19:02 -08:00
|
|
|
info->object_size = object_size;
|
2016-12-09 00:51:44 -08:00
|
|
|
memcpy(&info->digest[0], digest, DIGEST_SIZE);
|
|
|
|
init_table_callback(db_handle, object_id, __func__, info, retry,
|
2017-03-01 01:17:24 -08:00
|
|
|
(table_done_callback) done_callback,
|
|
|
|
redis_object_table_add, user_context);
|
2016-10-29 15:22:33 -07:00
|
|
|
}
|
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
void object_table_remove(DBHandle *db_handle,
|
|
|
|
ObjectID object_id,
|
|
|
|
DBClientID *client_id,
|
|
|
|
RetryInfo *retry,
|
2016-12-19 23:18:57 -08:00
|
|
|
object_table_done_callback done_callback,
|
|
|
|
void *user_context) {
|
|
|
|
CHECK(db_handle != NULL);
|
|
|
|
/* Copy the client ID, if one was provided. */
|
2017-02-26 00:32:43 -08:00
|
|
|
DBClientID *client_id_copy = NULL;
|
2016-12-19 23:18:57 -08:00
|
|
|
if (client_id != NULL) {
|
2017-03-01 01:17:24 -08:00
|
|
|
client_id_copy = (DBClientID *) malloc(sizeof(DBClientID));
|
2016-12-19 23:18:57 -08:00
|
|
|
*client_id_copy = *client_id;
|
|
|
|
}
|
|
|
|
init_table_callback(db_handle, object_id, __func__, client_id_copy, retry,
|
2017-03-01 01:17:24 -08:00
|
|
|
(table_done_callback) done_callback,
|
|
|
|
redis_object_table_remove, user_context);
|
2016-12-19 23:18:57 -08:00
|
|
|
}
|
|
|
|
|
2016-12-18 18:19:02 -08:00
|
|
|
void object_table_subscribe_to_notifications(
|
2017-02-26 00:32:43 -08:00
|
|
|
DBHandle *db_handle,
|
2016-12-19 21:07:25 -08:00
|
|
|
bool subscribe_all,
|
2016-10-29 15:22:33 -07:00
|
|
|
object_table_object_available_callback object_available_callback,
|
|
|
|
void *subscribe_context,
|
2017-02-26 00:32:43 -08:00
|
|
|
RetryInfo *retry,
|
2016-12-05 00:26:53 -08:00
|
|
|
object_table_lookup_done_callback done_callback,
|
2016-10-29 15:22:33 -07:00
|
|
|
void *user_context) {
|
2016-12-01 02:15:21 -08:00
|
|
|
CHECK(db_handle != NULL);
|
2017-03-01 01:17:24 -08:00
|
|
|
ObjectTableSubscribeData *sub_data =
|
|
|
|
(ObjectTableSubscribeData *) malloc(sizeof(ObjectTableSubscribeData));
|
2016-10-29 15:22:33 -07:00
|
|
|
sub_data->object_available_callback = object_available_callback;
|
|
|
|
sub_data->subscribe_context = subscribe_context;
|
2016-12-19 21:07:25 -08:00
|
|
|
sub_data->subscribe_all = subscribe_all;
|
2016-10-29 15:22:33 -07:00
|
|
|
|
2017-03-01 01:17:24 -08:00
|
|
|
init_table_callback(db_handle, NIL_OBJECT_ID, __func__, sub_data, retry,
|
|
|
|
(table_done_callback) done_callback,
|
|
|
|
redis_object_table_subscribe_to_notifications,
|
|
|
|
user_context);
|
2016-12-18 18:19:02 -08:00
|
|
|
}
|
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
void object_table_request_notifications(DBHandle *db_handle,
|
2016-12-18 18:19:02 -08:00
|
|
|
int num_object_ids,
|
2017-02-26 00:32:43 -08:00
|
|
|
ObjectID object_ids[],
|
|
|
|
RetryInfo *retry) {
|
2016-12-18 18:19:02 -08:00
|
|
|
CHECK(db_handle != NULL);
|
|
|
|
CHECK(num_object_ids > 0);
|
2017-02-26 00:32:43 -08:00
|
|
|
ObjectTableRequestNotificationsData *data =
|
2017-03-01 01:17:24 -08:00
|
|
|
(ObjectTableRequestNotificationsData *) malloc(
|
|
|
|
sizeof(ObjectTableRequestNotificationsData) +
|
|
|
|
num_object_ids * sizeof(ObjectID));
|
2016-12-18 18:19:02 -08:00
|
|
|
data->num_object_ids = num_object_ids;
|
2017-02-26 00:32:43 -08:00
|
|
|
memcpy(data->object_ids, object_ids, num_object_ids * sizeof(ObjectID));
|
2016-12-18 18:19:02 -08:00
|
|
|
|
|
|
|
init_table_callback(db_handle, NIL_OBJECT_ID, __func__, data, retry, NULL,
|
|
|
|
redis_object_table_request_notifications, NULL);
|
2016-10-29 15:22:33 -07:00
|
|
|
}
|
2016-11-10 18:13:26 -08:00
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
void object_info_subscribe(DBHandle *db_handle,
|
2016-12-09 00:51:44 -08:00
|
|
|
object_info_subscribe_callback subscribe_callback,
|
|
|
|
void *subscribe_context,
|
2017-02-26 00:32:43 -08:00
|
|
|
RetryInfo *retry,
|
2016-12-09 00:51:44 -08:00
|
|
|
object_info_done_callback done_callback,
|
|
|
|
void *user_context) {
|
2017-03-01 01:17:24 -08:00
|
|
|
ObjectInfoSubscribeData *sub_data =
|
|
|
|
(ObjectInfoSubscribeData *) malloc(sizeof(ObjectInfoSubscribeData));
|
2016-12-09 00:51:44 -08:00
|
|
|
sub_data->subscribe_callback = subscribe_callback;
|
|
|
|
sub_data->subscribe_context = subscribe_context;
|
|
|
|
|
|
|
|
init_table_callback(db_handle, NIL_OBJECT_ID, __func__, sub_data, retry,
|
2017-03-01 01:17:24 -08:00
|
|
|
(table_done_callback) done_callback,
|
|
|
|
redis_object_info_subscribe, user_context);
|
2016-12-09 00:51:44 -08:00
|
|
|
}
|
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
void result_table_add(DBHandle *db_handle,
|
|
|
|
ObjectID object_id,
|
2017-03-21 00:16:48 -07:00
|
|
|
TaskID task_id,
|
|
|
|
bool is_put,
|
2017-02-26 00:32:43 -08:00
|
|
|
RetryInfo *retry,
|
2016-11-10 18:13:26 -08:00
|
|
|
result_table_done_callback done_callback,
|
|
|
|
void *user_context) {
|
2017-03-21 00:16:48 -07:00
|
|
|
ResultTableAddInfo *info =
|
|
|
|
(ResultTableAddInfo *) malloc(sizeof(ResultTableAddInfo));
|
|
|
|
info->task_id = task_id;
|
|
|
|
info->is_put = is_put;
|
|
|
|
init_table_callback(db_handle, object_id, __func__, info, retry,
|
2017-03-01 01:17:24 -08:00
|
|
|
(table_done_callback) done_callback,
|
|
|
|
redis_result_table_add, user_context);
|
2016-11-10 18:13:26 -08:00
|
|
|
}
|
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
void result_table_lookup(DBHandle *db_handle,
|
|
|
|
ObjectID object_id,
|
|
|
|
RetryInfo *retry,
|
2016-11-10 18:13:26 -08:00
|
|
|
result_table_lookup_callback done_callback,
|
|
|
|
void *user_context) {
|
2016-11-15 20:33:29 -08:00
|
|
|
init_table_callback(db_handle, object_id, __func__, NULL, retry,
|
2017-03-01 01:17:24 -08:00
|
|
|
(table_done_callback) done_callback,
|
|
|
|
redis_result_table_lookup, user_context);
|
2016-11-10 18:13:26 -08:00
|
|
|
}
|