[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3783 - in GNUnet/src: applications/datastore applications/
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3783 - in GNUnet/src: applications/datastore applications/sqstore_mysql applications/sqstore_sqlite include |
Date: |
Wed, 15 Nov 2006 19:13:46 -0800 (PST) |
Author: grothoff
Date: 2006-11-15 19:13:40 -0800 (Wed, 15 Nov 2006)
New Revision: 3783
Modified:
GNUnet/src/applications/datastore/prefetch.c
GNUnet/src/applications/sqstore_mysql/mysql.c
GNUnet/src/applications/sqstore_sqlite/sqlite.c
GNUnet/src/include/gnunet_sqstore_service.h
Log:
improving migration, mysql code cleanup
Modified: GNUnet/src/applications/datastore/prefetch.c
===================================================================
--- GNUnet/src/applications/datastore/prefetch.c 2006-11-15 21:44:04 UTC
(rev 3782)
+++ GNUnet/src/applications/datastore/prefetch.c 2006-11-16 03:13:40 UTC
(rev 3783)
@@ -147,8 +147,7 @@
static void * rcbAcquire(void * unused) {
int load;
while (doneSignal == NO) {
- sq->iterateExpirationTime(0,
- &aquire,
+ sq->iterateMigrationOrder(&aquire,
NULL);
/* sleep here, too - otherwise we start looping immediately
if there is no content in the DB! */
@@ -263,8 +262,8 @@
doneSignal = YES;
PTHREAD_STOP_SLEEP(gather_thread);
SEMAPHORE_UP(acquireMoreSignal);
- SEMAPHORE_DESTROY(acquireMoreSignal);
PTHREAD_JOIN(gather_thread, &unused);
+ SEMAPHORE_DESTROY(acquireMoreSignal);
for (i=0;i<RCB_SIZE;i++)
FREENONNULL(randomContentBuffer[i].value);
MUTEX_DESTROY(lock);
Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c 2006-11-15 21:44:04 UTC
(rev 3782)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c 2006-11-16 03:13:40 UTC
(rev 3783)
@@ -504,9 +504,11 @@
return OK;
}
+
/**
- * Iterate over the items in the datastore in ascending
- * order of priority.
+ * Iterate over the items in the datastore
+ * using the given query to select and order
+ * the items.
*
* @param type entries of which type should be considered?
* Use 0 for any type.
@@ -514,9 +516,10 @@
* @return the number of results, SYSERR if the
* iter is non-NULL and aborted the iteration
*/
-static int iterateLowPriority(unsigned int type,
- Datum_Iterator iter,
- void * closure) {
+static int iterateHelper(unsigned int type,
+ const char * query,
+ Datum_Iterator iter,
+ void * closure) {
MYSQL_RES *sql_res;
MYSQL_ROW sql_row;
Datastore_Datum * datum;
@@ -545,10 +548,8 @@
}
scratch = MALLOC(256);
SNPRINTF(scratch,
- 256, // SQL_BIG_RESULT SQL_BUFFER_RESULT
- "SELECT SQL_NO_CACHE * FROM gn070"
- " %s"
- "ORDER BY prio ASC",
+ 256,
+ query,
typestr);
mysql_query(dbhI.dbf,
scratch);
@@ -576,7 +577,9 @@
return count;
}
if ( (iter != NULL) &&
- (SYSERR == iter(&datum->key, &datum->value, closure) ) ) {
+ (SYSERR == iter(&datum->key,
+ &datum->value,
+ closure) ) ) {
count = SYSERR;
FREE(datum);
break;
@@ -601,6 +604,27 @@
/**
* Iterate over the items in the datastore in ascending
+ * order of priority.
+ *
+ * @param type entries of which type should be considered?
+ * Use 0 for any type.
+ * @param iter never NULL
+ * @return the number of results, SYSERR if the
+ * iter is non-NULL and aborted the iteration
+ */
+static int iterateLowPriority(unsigned int type,
+ Datum_Iterator iter,
+ void * closure) {
+ return iterateHelper(type,
+ "SELECT SQL_NO_CACHE * FROM gn070"
+ " %s"
+ "ORDER BY prio ASC",
+ iter,
+ closure);
+}
+
+/**
+ * Iterate over the items in the datastore in ascending
* order of expiration time.
*
* @param type entries of which type should be considered?
@@ -612,85 +636,30 @@
static int iterateExpirationTime(unsigned int type,
Datum_Iterator iter,
void * closure) {
- MYSQL_RES *sql_res;
- MYSQL_ROW sql_row;
- Datastore_Datum * datum;
- char * scratch;
- char typestr[32];
- int count = 0;
- mysqlHandle dbhI;
+ return iterateHelper(type,
+ "SELECT SQL_NO_CACHE * FROM gn070"
+ " %s"
+ " ORDER BY expire ASC",
+ iter,
+ closure);
+}
- dbhI.cnffile = dbh->cnffile; /* shared */
- if (OK != iopen(&dbhI, NO))
- return SYSERR;
- MUTEX_LOCK(dbhI.DATABASE_Lock_);
- mysql_query(dbhI.dbf,
- "SET AUTOCOMMIT = 0");
- mysql_query(dbhI.dbf,
- "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED");
- if (type==0) {
- typestr[0] = 0;
- } else {
- SNPRINTF(typestr,
- 32,
- "WHERE type=%u", type);
- }
- scratch = MALLOC(256);
- SNPRINTF(scratch, //SQL_BIG_RESULT SQL_BUFFER_RESULT SQL_NO_CACHE
- 256,
- "SELECT SQL_NO_CACHE * FROM gn070"
- " %s"
- " ORDER BY expire ASC",
- typestr);
- mysql_query(dbhI.dbf,
- scratch);
- FREE(scratch);
- if (mysql_error(dbhI.dbf)[0]) {
- LOG_MYSQL(GE_ERROR | GE_ADMIN | GE_BULK,
- "mysql_query",
- &dbhI);
- MUTEX_UNLOCK(dbhI.DATABASE_Lock_);
- iclose(&dbhI);
- return SYSERR;
- }
- if (!(sql_res=mysql_use_result(dbhI.dbf))) {
- MUTEX_UNLOCK(dbhI.DATABASE_Lock_);
- iclose(&dbhI);
- return SYSERR;
- }
- while ((sql_row=mysql_fetch_row(sql_res))) {
- datum = assembleDatum(sql_res,
- sql_row,
- &dbhI);
- if (datum == NULL) {
- MUTEX_UNLOCK(dbhI.DATABASE_Lock_);
- iclose(&dbhI);
- return count;
- }
- if ( (iter != NULL) &&
- (SYSERR == iter(&datum->key,
- &datum->value,
- closure) ) ) {
- count = SYSERR;
- FREE(datum);
- break;
- }
- FREE(datum);
- count++;
- }
- if (mysql_error(dbhI.dbf)[0]) {
- LOG_MYSQL(GE_ERROR | GE_ADMIN | GE_BULK,
- "mysql_query",
- &dbhI);
- mysql_free_result(sql_res);
- MUTEX_UNLOCK(dbhI.DATABASE_Lock_);
- iclose(&dbhI);
- return SYSERR;
- }
- mysql_free_result(sql_res);
- MUTEX_UNLOCK(dbhI.DATABASE_Lock_);
- iclose(&dbhI);
- return count;
+/**
+ * Iterate over the items in the datastore in migration
+ * order.
+ *
+ * @param iter never NULL
+ * @return the number of results, SYSERR if the
+ * iter is non-NULL and aborted the iteration
+ */
+static int iterateMigrationOrder(Datum_Iterator iter,
+ void * closure) {
+ return iterateHelper(0,
+ "SELECT SQL_NO_CACHE * FROM gn070"
+ " %s"
+ " ORDER BY expire DESC",
+ iter,
+ closure);
}
#define MAX_DATUM_SIZE 65536
@@ -1413,6 +1382,7 @@
api.get = &get;
api.iterateLowPriority = &iterateLowPriority;
api.iterateExpirationTime = &iterateExpirationTime;
+ api.iterateMigrationOrder = &iterateMigrationOrder;
api.del = &del;
api.drop = &drop;
api.update = &update;
Modified: GNUnet/src/applications/sqstore_sqlite/sqlite.c
===================================================================
--- GNUnet/src/applications/sqstore_sqlite/sqlite.c 2006-11-15 21:44:04 UTC
(rev 3782)
+++ GNUnet/src/applications/sqstore_sqlite/sqlite.c 2006-11-16 03:13:40 UTC
(rev 3783)
@@ -531,7 +531,8 @@
static int sqlite_iterate(unsigned int type,
Datum_Iterator iter,
void * closure,
- int sortByPriority) {
+ int sortByPriority,
+ int inverseOrder) {
sqlite3_stmt * stmt;
int count;
char scratch[512];
@@ -553,12 +554,21 @@
"SELECT size, type, prio, anonLevel, expire, hash, value FROM gn070"
" WHERE rowid IN (SELECT rowid FROM gn070"
" WHERE ((hash > :1 AND expire == :2 AND prio == :3) OR ");
- if (sortByPriority)
- strcat(scratch,
- "(expire > :4 AND prio == :5) OR prio > :6)");
- else
- strcat(scratch,
- "(prio > :4 AND expire == :5) OR expire > :6)");
+ if (sortByPriority) {
+ if (inverseOrder)
+ strcat(scratch,
+ "(expire < :4 AND prio == :5) OR prio < :6)");
+ else
+ strcat(scratch,
+ "(expire > :4 AND prio == :5) OR prio > :6)");
+ } else {
+ if (inverseOrder)
+ strcat(scratch,
+ "(prio < :4 AND expire == :5) OR expire < :6)");
+ else
+ strcat(scratch,
+ "(prio > :4 AND expire == :5) OR expire > :6)");
+ }
if (type != 0)
strcat(scratch, " AND type = :7");
else
@@ -568,10 +578,17 @@
RESERVED_BLOCK); /* otherwise we iterate over
the stats entry, which would
be bad */
- if (sortByPriority)
- strcat(scratch, " ORDER BY prio ASC, expire ASC, hash ASC");
- else
- strcat(scratch, " ORDER BY expire ASC, prio ASC, hash ASC");
+ if (sortByPriority) {
+ if (inverseOrder)
+ strcat(scratch, " ORDER BY prio DESC, expire DESC, hash ASC");
+ else
+ strcat(scratch, " ORDER BY prio ASC, expire ASC, hash ASC");
+ } else {
+ if (inverseOrder)
+ strcat(scratch, " ORDER BY expire DESC, prio DESC, hash ASC");
+ else
+ strcat(scratch, " ORDER BY expire ASC, prio ASC, hash ASC");
+ }
strcat(scratch, " LIMIT 1)");
if (sq_prepare(dbh,
scratch,
@@ -689,7 +706,7 @@
static int iterateLowPriority(unsigned int type,
Datum_Iterator iter,
void * closure) {
- return sqlite_iterate(type, iter, closure, 1);
+ return sqlite_iterate(type, iter, closure, 1, NO);
}
/**
@@ -704,9 +721,23 @@
static int iterateExpirationTime(unsigned int type,
Datum_Iterator iter,
void * closure) {
- return sqlite_iterate(type, iter, closure, 0);
+ return sqlite_iterate(type, iter, closure, 0, NO);
}
+/**
+ * Iterate over the items in the datastore in migration
+ * order.
+ *
+ * @param iter never NULL
+ * @return the number of results, SYSERR if the
+ * iter is non-NULL and aborted the iteration
+ */
+static int iterateMigrationOrder(Datum_Iterator iter,
+ void * closure) {
+ return sqlite_iterate(0, iter, closure, 0, YES);
+}
+
+
static void sqlite_shutdown() {
unsigned int idx;
@@ -1220,6 +1251,7 @@
api.get = &get;
api.iterateLowPriority = &iterateLowPriority;
api.iterateExpirationTime = &iterateExpirationTime;
+ api.iterateMigrationOrder = &iterateMigrationOrder;
api.del = &del;
api.drop = &drop;
api.update = &update;
Modified: GNUnet/src/include/gnunet_sqstore_service.h
===================================================================
--- GNUnet/src/include/gnunet_sqstore_service.h 2006-11-15 21:44:04 UTC (rev
3782)
+++ GNUnet/src/include/gnunet_sqstore_service.h 2006-11-16 03:13:40 UTC (rev
3783)
@@ -135,7 +135,19 @@
Datum_Iterator iter,
void * closure);
+
/**
+ * Iterate over the items in the datastore in migration
+ * order.
+ *
+ * @param iter never NULL
+ * @return the number of results, SYSERR if the
+ * iter is non-NULL and aborted the iteration
+ */
+ int (*iterateMigrationOrder)(Datum_Iterator iter,
+ void * closure);
+
+ /**
* Delete an item from the datastore.
*
* Note that it is possible for multiple values to match this del
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3783 - in GNUnet/src: applications/datastore applications/sqstore_mysql applications/sqstore_sqlite include,
grothoff <=