#include "replicator-connection.h"
struct replicator_connection *replicator;
+struct event *aggregator_event;
+
+static struct event_category event_category_replication = {
+ .name = "replication"
+};
static void client_connected(struct master_service_connection *conn)
{
sets = master_service_settings_get_others(master_service);
set = sets[0];
+ aggregator_event = event_create(NULL);
+ event_add_category(aggregator_event, &event_category_replication);
+
if (set->replicator_port != 0) {
ret = net_gethostbyname(set->replicator_host, &ips, &ips_count);
if (ret != 0) {
notify_connections_destroy_all();
replicator_connection_destroy(&replicator);
+ event_unref(&aggregator_event);
master_service_deinit(&master_service);
return 0;
}
#include "replication-common.h"
#include "replicator-connection.h"
#include "notify-connection.h"
+#include "aggregator-settings.h"
#define MAX_INBUF_SIZE 8192
{
struct notify_connection *conn = context;
+ e_debug(conn->event, "Sending %s result",
+ success ? "success" : "failure");
o_stream_nsend_str(conn->output, success ? "+\n" : "-\n");
notify_connection_unref(conn);
}
"Client sent invalid priority: %s", args[1]);
return -1;
}
+
+ e_debug(conn->event, "Received priority %s request for %s",
+ args[1], args[0]);
+
if (priority != REPLICATION_PRIORITY_SYNC)
replicator_connection_notify(replicator, args[0], priority);
else {
conn->io = io_add(fd, IO_READ, notify_input, conn);
conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
conn->event = event_create(NULL);
+ event_set_append_log_prefix(conn->event, "notify: ");
if (!fifo) {
conn->output = o_stream_create_fd(fd, SIZE_MAX);
o_stream_set_no_error_handling(conn->output, TRUE);
{
i_assert(conn->fd != -1);
+ e_debug(conn->event, "Disconnected");
+
if (!CONNECTION_IS_FIFO(conn))
master_service_client_connection_destroyed(master_service);
#include "llist.h"
#include "strescape.h"
#include "replicator-connection.h"
+#include "aggregator-settings.h"
#define MAX_INBUF_SIZE 1024
#define REPLICATOR_RECONNECT_MSECS 5000
e_error(conn->event, "Replicator sent invalid ID: %u", id);
return -1;
}
+
+ e_debug(conn->event, "Request id %u has %s",
+ id, line[0] == '+' ? "succeeded" : "failed");
hash_table_remove(conn->requests, POINTER_CAST(id));
conn->callback(line[0] == '+', context);
return 0;
return;
if (conn->port == 0) {
+ event_set_append_log_prefix(conn->event,
+ t_strdup_printf("(unix:%s): ", conn->path));
+ e_debug(conn->event, "Connecting to replicator");
fd = net_connect_unix(conn->path);
if (fd == -1)
e_error(conn->event, "net_connect_unix(%s) failed: %m",
unsigned int idx = conn->ip_idx;
conn->ip_idx = (conn->ip_idx + 1) % conn->ips_count;
+ event_set_append_log_prefix(conn->event, t_strdup_printf(
+ "(%s): ", net_ipport2str(&conn->ips[idx], conn->port)));
+ e_debug(conn->event, "Connecting to replicator");
fd = net_connect_ip(&conn->ips[idx], conn->port, NULL);
if (fd != -1)
break;
}
if (fd == -1) {
+ event_set_append_log_prefix(conn->event, "");
if (conn->to == NULL) {
+ e_debug(conn->event, "Reconnecting in %u msecs", REPLICATOR_RECONNECT_MSECS);
conn->to = timeout_add(REPLICATOR_RECONNECT_MSECS,
replicator_connection_connect,
conn);
conn->io = io_add(fd, IO_READ, replicator_input, conn);
conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
conn->output = o_stream_create_fd(fd, SIZE_MAX);
+ e_debug(conn->event, "Sending handshake");
o_stream_set_no_error_handling(conn->output, TRUE);
o_stream_nsend_str(conn->output, REPLICATOR_HANDSHAKE);
o_stream_set_flush_callback(conn->output, replicator_output, conn);
struct hash_iterate_context *iter;
void *key, *value;
+ e_debug(conn->event, "Aborting all requests");
iter = hash_table_iterate_init(conn->requests);
while (hash_table_iterate(iter, conn->requests, &key, &value))
conn->callback(FALSE, value);
if (conn->fd == -1)
return;
+ e_debug(conn->event, "Disconnecting");
replicator_abort_all_requests(conn);
io_remove(&conn->io);
i_stream_destroy(&conn->input);
o_stream_destroy(&conn->output);
net_disconnect(conn->fd);
+ event_set_append_log_prefix(conn->event, "");
conn->fd = -1;
}
}
T_BEGIN {
+ e_debug(conn->event, "Requesting replication of %s priority for user %s",
+ priority_str, username);
replicator_send(conn, priority, t_strdup_printf(
"U\t%s\t%s\n", str_tabescape(username), priority_str));
} T_END;
hash_table_insert(conn->requests, POINTER_CAST(id), context);
T_BEGIN {
+ e_debug(conn->event, "Requesting synchronization with id %u for user %s",
+ id, username);
replicator_send(conn, REPLICATION_PRIORITY_SYNC, t_strdup_printf(
"U\t%s\tsync\t%u\n", str_tabescape(username), id));
} T_END;