[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8084 - GNUnet/src/applications/sqstore_postgres
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8084 - GNUnet/src/applications/sqstore_postgres |
Date: |
Sat, 3 Jan 2009 02:05:51 -0700 (MST) |
Author: grothoff
Date: 2009-01-03 02:05:50 -0700 (Sat, 03 Jan 2009)
New Revision: 8084
Modified:
GNUnet/src/applications/sqstore_postgres/Makefile.am
GNUnet/src/applications/sqstore_postgres/postgres.c
GNUnet/src/applications/sqstore_postgres/postgres_test2.c
Log:
fixes
Modified: GNUnet/src/applications/sqstore_postgres/Makefile.am
===================================================================
--- GNUnet/src/applications/sqstore_postgres/Makefile.am 2009-01-03
08:18:13 UTC (rev 8083)
+++ GNUnet/src/applications/sqstore_postgres/Makefile.am 2009-01-03
09:05:50 UTC (rev 8084)
@@ -41,7 +41,7 @@
postgres_test2_SOURCES = \
postgres_test2.c
-postgres_test2_LDADD = \
+postgres_test2_LDADD = -lpq \
$(top_builddir)/src/server/libgnunetcore.la \
$(top_builddir)/src/util/libgnunetutil.la
Modified: GNUnet/src/applications/sqstore_postgres/postgres.c
===================================================================
--- GNUnet/src/applications/sqstore_postgres/postgres.c 2009-01-03 08:18:13 UTC
(rev 8083)
+++ GNUnet/src/applications/sqstore_postgres/postgres.c 2009-01-03 09:05:50 UTC
(rev 8084)
@@ -126,7 +126,6 @@
command,
args,
line);
- /* FIXME: report error! */
return GNUNET_SYSERR;
}
if (PQresultStatus (ret) != expected_status)
@@ -180,6 +179,7 @@
init_connection ()
{
char * conninfo;
+ PGresult * ret;
/* Open database and precompile statements */
conninfo = NULL;
@@ -204,40 +204,52 @@
dbh = NULL;
return GNUNET_SYSERR;
}
- pq_exec ("DROP TABLE gn080", __LINE__);
- /* FIXME: this could fail if the table already
- exists -- add check! */
- if ( (GNUNET_OK !=
- pq_exec ("CREATE TABLE gn080 ("
- " size INTEGER NOT NULL DEFAULT 0,"
- " type INTEGER NOT NULL DEFAULT 0,"
- " prio INTEGER NOT NULL DEFAULT 0,"
- " anonLevel INTEGER NOT NULL DEFAULT 0,"
- " expire BIGINT NOT NULL DEFAULT 0,"
- " hash BYTEA NOT NULL DEFAULT '',"
- " vhash BYTEA NOT NULL DEFAULT '',"
- " value BYTEA NOT NULL DEFAULT '')"
- "WITH OIDS", __LINE__)) ||
- (GNUNET_OK !=
- pq_exec ("CREATE INDEX idx_hash ON gn080 (hash)", __LINE__)) ||
- (GNUNET_OK !=
- pq_exec ("CREATE INDEX idx_hash_vhash ON gn080 (hash,vhash)",
__LINE__)) ||
- (GNUNET_OK !=
- pq_exec ("CREATE INDEX idx_prio ON gn080 (prio)", __LINE__)) ||
- (GNUNET_OK !=
- pq_exec ("CREATE INDEX idx_expire ON gn080 (expire)", __LINE__)) ||
- (GNUNET_OK !=
- pq_exec ("CREATE INDEX idx_comb3 ON gn080 (prio,anonLevel)", __LINE__))
||
- (GNUNET_OK !=
- pq_exec ("CREATE INDEX idx_comb4 ON gn080 (prio,hash,anonLevel)",
__LINE__)) ||
- (GNUNET_OK !=
- pq_exec ("CREATE INDEX idx_comb7 ON gn080 (expire,hash)", __LINE__)) )
+
+ ret = PQexec (dbh,
+ "CREATE TABLE gn080 ("
+ " size INTEGER NOT NULL DEFAULT 0,"
+ " type INTEGER NOT NULL DEFAULT 0,"
+ " prio INTEGER NOT NULL DEFAULT 0,"
+ " anonLevel INTEGER NOT NULL DEFAULT 0,"
+ " expire BIGINT NOT NULL DEFAULT 0,"
+ " hash BYTEA NOT NULL DEFAULT '',"
+ " vhash BYTEA NOT NULL DEFAULT '',"
+ " value BYTEA NOT NULL DEFAULT '')"
+ "WITH OIDS");
+ if ( (ret == NULL) ||
+ ( (PQresultStatus (ret) != PGRES_COMMAND_OK) &&
+ (0 != strcmp("42P07", /* duplicate table */
+ PQresultErrorField (ret, PG_DIAG_SQLSTATE))) ) )
{
+ check_result (ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn080", __LINE__);
PQfinish (dbh);
dbh = NULL;
return GNUNET_SYSERR;
}
-
+ if (PQresultStatus (ret) == PGRES_COMMAND_OK)
+ {
+ if ( (GNUNET_OK !=
+ pq_exec ("CREATE INDEX idx_hash ON gn080 (hash)", __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec ("CREATE INDEX idx_hash_vhash ON gn080 (hash,vhash)",
__LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec ("CREATE INDEX idx_prio ON gn080 (prio)", __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec ("CREATE INDEX idx_expire ON gn080 (expire)", __LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec ("CREATE INDEX idx_comb3 ON gn080 (prio,anonLevel)",
__LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec ("CREATE INDEX idx_comb4 ON gn080 (prio,hash,anonLevel)",
__LINE__)) ||
+ (GNUNET_OK !=
+ pq_exec ("CREATE INDEX idx_comb7 ON gn080 (expire,hash)",
__LINE__)) )
+ {
+ PQclear(ret);
+ PQfinish (dbh);
+ dbh = NULL;
+ return GNUNET_SYSERR;
+ }
+ }
+ PQclear(ret);
if ( (GNUNET_OK !=
pq_prepare("getvt",
"SELECT size, type, prio, anonLevel, expire, hash, value,
oid FROM gn080 "
Modified: GNUnet/src/applications/sqstore_postgres/postgres_test2.c
===================================================================
--- GNUnet/src/applications/sqstore_postgres/postgres_test2.c 2009-01-03
08:18:13 UTC (rev 8083)
+++ GNUnet/src/applications/sqstore_postgres/postgres_test2.c 2009-01-03
09:05:50 UTC (rev 8084)
@@ -32,13 +32,6 @@
* Priorities and expiration dates are set using a pseudo-random value
* within a realistic range.
* <p>
- *
- * Note that the disk overhead calculations are not very sane for
- * MySQL: we take the entire /var/lib/mysql directory (best we can
- * do for ISAM), which may contain other data and which never
- * shrinks. The scanning of the entire mysql directory during
- * each report is also likely to be the cause of a minor
- * slowdown compared to postgres.<p>
*/
#include "platform.h"
@@ -46,6 +39,7 @@
#include "gnunet_protocols.h"
#include "gnunet_sqstore_service.h"
#include "core.h"
+#include <postgresql/libpq-fe.h>
#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__,
__LINE__); goto FAILURE;} } while (0)
@@ -79,7 +73,7 @@
* at 90% wait, 10% CPU). This is with MySQL 5.0.
*
*/
-#define MAX_SIZE 1024LL * 1024 * 16
+#define MAX_SIZE 1024LL * 1024 * 16 * 100
/**
* Report progress outside of major reports? Should probably be GNUNET_YES if
@@ -104,14 +98,6 @@
*/
#define ITERATIONS 100
-/**
- * Name of the database on disk.
- * You may have to adjust this path and the access
- * permission to the respective directory in order
- * to obtain all of the performance information.
- */
-#define DB_NAME "/tmp/gnunet-postgres-sqstore-test/data/fs/"
-
static unsigned long long stored_bytes;
static unsigned long long stored_entries;
@@ -200,11 +186,9 @@
int i;
int j;
unsigned long long size;
- int have_file;
- struct stat sbuf;
-
- have_file = 0 == stat (DB_NAME, &sbuf);
-
+ PGresult * res;
+ PGconn * dbh = PQconnectdb("dbname=gnunetcheck");
+
for (i = 0; i < ITERATIONS; i++)
{
#if REPORT_ID
@@ -224,9 +208,24 @@
else
api->iterateExpirationTime (0, &iterateDelete, api);
+ res = PQexec (dbh, "VACUUM FULL gn080");
+ PQclear(res);
size = 0;
- if (have_file)
- GNUNET_disk_file_size (NULL, DB_NAME, &size, GNUNET_NO);
+ res = PQexec (dbh, "SELECT pg_database_size('gnunetcheck')");
+ if (PQresultStatus (res) != PGRES_TUPLES_OK)
+ {
+ fprintf(stderr,
+ "Failed with error: %s",
+ PQerrorMessage(dbh));
+ PQclear(res);
+ abort();
+ }
+ ASSERT (1 ==
+ sscanf(PQgetvalue(res, 0, 0),
+ "%llu",
+ &size));
+ PQclear (res);
+ size *= 1024;
printf (
#if REPORT_ID
"\n"
@@ -242,6 +241,7 @@
break;
}
api->drop ();
+ PQfinish (dbh);
return GNUNET_OK;
FAILURE:
@@ -282,4 +282,4 @@
return 0;
}
-/* end of mysqltest2.c */
+/* end of postgres_test2.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8084 - GNUnet/src/applications/sqstore_postgres,
gnunet <=