@ -42,13 +42,14 @@ typedef struct {
typedef struct {
typedef struct {
const char * name ;
const char * name ;
GQueue record_lists ;
} medredis_table_t ;
} medredis_table_t ;
static medredis_con_t * con = NULL ;
static medredis_con_t * con = NULL ;
static char medredis_srem_key_lua [ 41 ] ; // sha-1 hex string
static char medredis_srem_key_lua [ 41 ] ; // sha-1 hex string
static medredis_table_t medredis_table_trash = { . name = " trash " } ;
static medredis_table_t medredis_table_trash = { . name = " trash " , . record_lists = G_QUEUE_INIT } ;
static medredis_table_t medredis_table_backup = { . name = " backup " } ;
static medredis_table_t medredis_table_backup = { . name = " backup " , . record_lists = G_QUEUE_INIT } ;
/**********************************************************************/
/**********************************************************************/
static void medredis_free_reply ( redisReply * * reply ) {
static void medredis_free_reply ( redisReply * * reply ) {
@ -810,13 +811,30 @@ err:
/**********************************************************************/
/**********************************************************************/
static int medredis_cleanup_entries ( GQueue * records , medredis_table_t * table ) {
static int medredis_cleanup_entries ( GQueue * records , medredis_table_t * table ) {
char buffer [ 512 ] ;
if ( medmysql_insert_records ( records , table - > name ) ! = 0 ) {
if ( medmysql_insert_records ( records , table - > name ) ! = 0 ) {
L_CRITICAL ( " Failed to cleanup redis records \n " ) ;
L_CRITICAL ( " Failed to cleanup redis records \n " ) ;
goto err ;
goto err ;
}
}
// take ownership of the contents of the `records` queue and swap out contents with
// an empty queue
GQueue * copy = g_queue_new ( ) ;
GQueue tmp = * copy ; // empty queue
* copy = * records ; // take ownership
* records = tmp ; // replace with empty queue
g_queue_push_tail ( & table - > record_lists , copy ) ;
return 0 ;
err :
return - 1 ;
}
/**********************************************************************/
static int medredis_batch_end_records ( GQueue * records ) {
char buffer [ 512 ] ;
for ( GList * l = records - > head ; l ; l = l - > next ) {
for ( GList * l = records - > head ; l ; l = l - > next ) {
med_entry_t * e = l - > data ;
med_entry_t * e = l - > data ;
if ( ! e - > redis )
if ( ! e - > redis )
@ -859,6 +877,27 @@ err:
return - 1 ;
return - 1 ;
}
}
/**********************************************************************/
static int medredis_batch_end_table ( medredis_table_t * table ) {
while ( table - > record_lists . length ) {
GQueue * records = g_queue_pop_head ( & table - > record_lists ) ;
int ret = medredis_batch_end_records ( records ) ;
g_queue_free_full ( records , med_entry_free ) ;
if ( ret )
return - 1 ;
}
return 0 ;
}
/**********************************************************************/
int medredis_batch_end ( void ) {
if ( medredis_batch_end_table ( & medredis_table_trash ) )
return - 1 ;
if ( medredis_batch_end_table ( & medredis_table_backup ) )
return - 1 ;
return 0 ;
}
/**********************************************************************/
/**********************************************************************/
int medredis_trash_entries ( GQueue * records ) {
int medredis_trash_entries ( GQueue * records ) {
return medredis_cleanup_entries ( records , & medredis_table_trash ) ;
return medredis_cleanup_entries ( records , & medredis_table_trash ) ;