Change event logs to store one Redis ZSET per worker. (#705)

* Changing to zset

* Fixed bug.

* Fixed another bug.

* Modified task_profiles.

* Removed extra file.

* Modified task_profiles test.

* WIP

* WIP

* Undid changes

* Updated

* WIP

* Made changes according to comments.

* Removed unneeded print.

* Removed ujson usage.

* failing test

* tests passing

* Fixed linting errors and modified style.

* Fixed bug.

* Fixed linting

* Fixed according to comments.

* Redis crashing?

* Fixed linting

* Fixed linting
This commit is contained in:
alanamarzoev
2017-07-09 01:42:29 +02:00
committed by Robert Nishihara
parent cd12ea7e09
commit 8464d77c76
10 changed files with 88 additions and 31 deletions
+8 -3
View File
@@ -9,6 +9,8 @@
#include "state/redis.h"
#include "io.h"
#include <iostream>
#include <string>
static const char *log_levels[5] = {"DEBUG", "INFO", "WARN", "ERROR", "FATAL"};
static const char *log_fmt =
@@ -90,9 +92,12 @@ void RayLogger_log_event(DBHandle *db,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length) {
int status = redisAsyncCommand(db->context, NULL, NULL, "RPUSH %b %b", key,
key_length, value, value_length);
int64_t value_length,
double timestamp) {
std::string timestamp_string = std::to_string(timestamp);
int status = redisAsyncCommand(db->context, NULL, NULL, "ZADD %b %s %b", key,
key_length, timestamp_string.c_str(), value,
value_length);
if ((status == REDIS_ERR) || db->context->err) {
LOG_REDIS_DEBUG(db->context, "error while logging message to event log");
}
+2 -1
View File
@@ -52,6 +52,7 @@ void RayLogger_log_event(DBHandle *db,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length);
int64_t value_length,
double time);
#endif /* LOGGING_H */
@@ -47,6 +47,7 @@ table GetTaskReply {
table EventLogMessage {
key: string;
value: string;
timestamp: double;
}
// This struct is used to register a new worker with the local scheduler.
+4 -3
View File
@@ -913,9 +913,10 @@ void process_message(event_loop *loop,
/* Parse the message. */
auto message = flatbuffers::GetRoot<EventLogMessage>(input);
if (state->db != NULL) {
RayLogger_log_event(
state->db, (uint8_t *) message->key()->data(), message->key()->size(),
(uint8_t *) message->value()->data(), message->value()->size());
RayLogger_log_event(state->db, (uint8_t *) message->key()->data(),
message->key()->size(),
(uint8_t *) message->value()->data(),
message->value()->size(), message->timestamp());
}
} break;
case MessageType_RegisterClientRequest: {
@@ -73,11 +73,13 @@ void local_scheduler_log_event(LocalSchedulerConnection *conn,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length) {
int64_t value_length,
double timestamp) {
flatbuffers::FlatBufferBuilder fbb;
auto key_string = fbb.CreateString((char *) key, key_length);
auto value_string = fbb.CreateString((char *) value, value_length);
auto message = CreateEventLogMessage(fbb, key_string, value_string);
auto message =
CreateEventLogMessage(fbb, key_string, value_string, timestamp);
fbb.Finish(message);
write_message(conn->conn, MessageType_EventLogMessage, fbb.GetSize(),
fbb.GetBufferPointer());
+3 -1
View File
@@ -76,13 +76,15 @@ void local_scheduler_disconnect_client(LocalSchedulerConnection *conn);
* @param key_length The length of the key.
* @param value The value to store.
* @param value_length The length of the value.
* @param timestamp The time that the event is logged.
* @return Void.
*/
void local_scheduler_log_event(LocalSchedulerConnection *conn,
uint8_t *key,
int64_t key_length,
uint8_t *value,
int64_t value_length);
int64_t value_length,
double timestamp);
/**
* Get next task for this client. This will block until the scheduler assigns
@@ -89,13 +89,14 @@ static PyObject *PyLocalSchedulerClient_log_event(PyObject *self,
int key_length;
const char *value;
int value_length;
if (!PyArg_ParseTuple(args, "s#s#", &key, &key_length, &value,
&value_length)) {
double timestamp;
if (!PyArg_ParseTuple(args, "s#s#d", &key, &key_length, &value, &value_length,
&timestamp)) {
return NULL;
}
local_scheduler_log_event(
((PyLocalSchedulerClient *) self)->local_scheduler_connection,
(uint8_t *) key, key_length, (uint8_t *) value, value_length);
(uint8_t *) key, key_length, (uint8_t *) value, value_length, timestamp);
Py_RETURN_NONE;
}