Report persistence stats when starting.

pull/2624/head
Roger A. Light 3 years ago
parent 7ec8417e54
commit 4997b40259

@ -64,6 +64,7 @@ Broker:
- Add built-in websockets support that doesn't use libwebsockets. This is the - Add built-in websockets support that doesn't use libwebsockets. This is the
preferred websockets implementation. preferred websockets implementation.
- Add support for X-Forwarded-For header for built in websockets. - Add support for X-Forwarded-For header for built in websockets.
- Report persistence stats when starting.
Plugins / plugin interface: Plugins / plugin interface:
- Add persist-sqlite plugin. - Add persist-sqlite plugin.

@ -159,3 +159,9 @@ int session_expiry__add_from_persistence(struct mosquitto *context, time_t expir
UNUSED(expiry_time); UNUSED(expiry_time);
return 0; return 0;
} }
void mosquitto_log_printf(int level, const char *fmt, ...)
{
UNUSED(level);
UNUSED(fmt);
}

@ -42,6 +42,11 @@ Contributors:
uint32_t db_version; uint32_t db_version;
const unsigned char magic[15] = {0x00, 0xB5, 0x00, 'm','o','s','q','u','i','t','t','o',' ','d','b'}; const unsigned char magic[15] = {0x00, 0xB5, 0x00, 'm','o','s','q','u','i','t','t','o',' ','d','b'};
static long base_msg_count = 0;
static long retained_count = 0;
static long client_count = 0;
static long subscription_count = 0;
static long client_msg_count = 0;
static int persist__restore_sub(const char *client_id, const char *sub, uint8_t qos, uint32_t identifier, int options); static int persist__restore_sub(const char *client_id, const char *sub, uint8_t qos, uint32_t identifier, int options);
@ -215,6 +220,7 @@ static int persist__client_chunk_restore(FILE *db_fptr)
mosquitto__FREE(chunk.client_id); mosquitto__FREE(chunk.client_id);
mosquitto__FREE(chunk.username); mosquitto__FREE(chunk.username);
if(rc == 0) client_count++;
return rc; return rc;
} }
@ -238,6 +244,7 @@ static int persist__client_msg_chunk_restore(FILE *db_fptr, uint32_t length)
rc = persist__client_msg_restore(&chunk); rc = persist__client_msg_restore(&chunk);
mosquitto__FREE(chunk.client_id); mosquitto__FREE(chunk.client_id);
if(rc == 0) client_msg_count++;
return rc; return rc;
} }
@ -313,6 +320,7 @@ static int persist__base_msg_chunk_restore(FILE *db_fptr, uint32_t length)
mosquitto__FREE(chunk.source.username); mosquitto__FREE(chunk.source.username);
if(rc == MOSQ_ERR_SUCCESS){ if(rc == MOSQ_ERR_SUCCESS){
base_msg_count++;
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
}else{ }else{
mosquitto__FREE(base_msg); mosquitto__FREE(base_msg);
@ -345,6 +353,7 @@ static int persist__retain_chunk_restore(FILE *db_fptr)
retain__store(msg->topic, msg, split_topics, true); retain__store(msg->topic, msg, split_topics, true);
mosquitto__FREE(local_topic); mosquitto__FREE(local_topic);
mosquitto__FREE(split_topics); mosquitto__FREE(split_topics);
retained_count++;
}else{ }else{
/* Can't find the message - probably expired */ /* Can't find the message - probably expired */
} }
@ -371,6 +380,7 @@ static int persist__sub_chunk_restore(FILE *db_fptr)
mosquitto__FREE(chunk.client_id); mosquitto__FREE(chunk.client_id);
mosquitto__FREE(chunk.topic); mosquitto__FREE(chunk.topic);
if(rc == 0) subscription_count++;
return rc; return rc;
} }
@ -405,6 +415,11 @@ int persist__restore(void)
} }
db.msg_store = NULL; db.msg_store = NULL;
base_msg_count = 0;
retained_count = 0;
client_count = 0;
subscription_count = 0;
client_msg_count = 0;
fptr = mosquitto__fopen(db.config->persistence_filepath, "rb", false); fptr = mosquitto__fopen(db.config->persistence_filepath, "rb", false);
if(fptr == NULL) return MOSQ_ERR_SUCCESS; if(fptr == NULL) return MOSQ_ERR_SUCCESS;
@ -510,6 +525,12 @@ int persist__restore(void)
fclose(fptr); fclose(fptr);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld base messages", base_msg_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld retained messages", retained_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld clients", client_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld subscriptions", subscription_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld client messages", client_msg_count);
return rc; return rc;
error: error:
err = strerror(errno); err = strerror(errno);

@ -256,3 +256,9 @@ int session_expiry__add_from_persistence(struct mosquitto *context, time_t expir
UNUSED(expiry_time); UNUSED(expiry_time);
return 0; return 0;
} }
void mosquitto_log_printf(int level, const char *fmt, ...)
{
UNUSED(level);
UNUSED(fmt);
}

@ -229,3 +229,9 @@ int session_expiry__add_from_persistence(struct mosquitto *context, time_t expir
UNUSED(expiry_time); UNUSED(expiry_time);
return 0; return 0;
} }
void mosquitto_log_printf(int level, const char *fmt, ...)
{
UNUSED(level);
UNUSED(fmt);
}

Loading…
Cancel
Save