Esempio n. 1
0
File: node.c Progetto: ageric/merlin
static int node_binlog_add(merlin_node *node, merlin_event *pkt)
{
	int result;

	/*
	 * we skip stashing some packet types in the binlog. Typically
	 * those that get generated immediately upon reconnect anyway
	 * since they would just cause unnecessary overhead and might
	 * trigger a lot of unnecessary actions if stashed.
	 */
	if (pkt->hdr.type == CTRL_PACKET) {
		if (pkt->hdr.code == CTRL_ACTIVE || pkt->hdr.code == CTRL_INACTIVE)
			return 0;
	}

	if (!node->binlog) {
		char *path;

		/* +20 to safely accommodate for "/.module.binlog\0" */
		path = calloc(1, strlen(binlog_dir) + strlen(node->name) + 20);
		sprintf(path, "%s/%s.%s.binlog",
		        binlog_dir, is_module ? "module" : "daemon", node->name);
		linfo("Creating binary backlog for %s. On-disk location: %s",
			  node->name, path);

		/* 10MB in memory, 100MB on disk */
		node->binlog = binlog_create(path, 10 << 20, 100 << 20, BINLOG_UNLINK);
		if (!node->binlog) {
			lerr("Failed to create binary backlog for %s: %s",
				 node->name, strerror(errno));
			return -1;
		}
		free(path);
	}

	result = binlog_add(node->binlog, pkt, packet_size(pkt));
	if (result < 0) {
		binlog_wipe(node->binlog, BINLOG_UNLINK);
		/* XXX should mark node as unsynced here */
		node->stats.events.dropped += node->stats.events.logged + 1;
		node->stats.bytes.dropped += node->stats.bytes.logged + packet_size(pkt);
		node->stats.events.logged = 0;
		node->stats.bytes.logged = 0;
	} else {
		node->stats.events.logged++;
		node->stats.bytes.logged += packet_size(pkt);
	}

	node_log_event_count(node, 0);

	return result;
}
Esempio n. 2
0
int ipc_binlog_add(merlin_event *pkt)
{
	if (!ipc_binlog) {
		char *path;

		asprintf(&path, "/opt/monitor/op5/merlin/binlogs/ipc.%s.binlog",
				 is_module ? "module" : "daemon");

		/* 1MB in memory, 100MB on disk */
		ipc_binlog = binlog_create(path, 1 << 20, 100 << 20, BINLOG_UNLINK);
		free(path);

		if (!ipc_binlog)
			return -1;
	}

	binlog_add(ipc_binlog, pkt, packet_size(pkt));
	return 0;
}