added sqlite busy handler: retries on locking conflicts
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "sqlite_database.h"
|
#include "sqlite_database.h"
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <utils/mutex.h>
|
#include <utils/mutex.h>
|
||||||
@@ -289,6 +290,17 @@ static db_driver_t get_driver(private_sqlite_database_t *this)
|
|||||||
return DB_SQLITE;
|
return DB_SQLITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Busy handler implementation
|
||||||
|
*/
|
||||||
|
static int busy_handler(private_sqlite_database_t *this, int count)
|
||||||
|
{
|
||||||
|
/* add an sleep, exponentially longer on every try */
|
||||||
|
usleep(count * count * 1000);
|
||||||
|
/* always retry */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of database_t.destroy
|
* Implementation of database_t.destroy
|
||||||
*/
|
*/
|
||||||
@@ -333,6 +345,8 @@ sqlite_database_t *sqlite_database_create(char *uri)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlite3_busy_handler(this->db, (void*)busy_handler, this);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user