[vhffs-dev] [927] now check if the lookup return the good cache entry, using temporarily a hash function which return always the same value to check if hash collisions are correctly handled now |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [927] now check if the lookup return the good cache entry, using temporarily a hash function which return always the same value to check if hash collisions are correctly handled now
- From: subversion@xxxxxxxxxxxxx
- Date: Wed, 19 Sep 2007 17:00:54 +0200
Revision: 927
Author: gradator
Date: 2007-09-19 15:00:53 +0000 (Wed, 19 Sep 2007)
Log Message:
-----------
now check if the lookup return the good cache entry, using temporarily a hash function which return always the same value to check if hash collisions are correctly handled now
Modified Paths:
--------------
trunk/vhffs-fs/vhffsfs.c
Modified: trunk/vhffs-fs/vhffsfs.c
===================================================================
--- trunk/vhffs-fs/vhffsfs.c 2007-09-19 12:21:59 UTC (rev 926)
+++ trunk/vhffs-fs/vhffsfs.c 2007-09-19 15:00:53 UTC (rev 927)
@@ -9,6 +9,8 @@
#define VHFFSFS_MAXCONNDB 5
#define VHFFSFS_EMPTYDIR "/tmp/emptydir"
+#define WITH_CACHE_DEBUG 1
+
#define WITH_CHECKQUOTA 1
#define WITH_CHECKQUOTA_RPC 1
@@ -132,6 +134,11 @@
pthread_mutex_unlock(&vhffsfs.cachelock);
}
+guint vhffsfs_cache_hash(gconstpointer p) {
+ //just to test hash collisions
+ return 100;
+}
+
void vhffsfs_cache_add(char *query, PGresult *result) {
vhffsfs_cache_query *vcq;
vhffsfs_cache_lock();
@@ -140,7 +147,9 @@
vhffsfs_cache_unlock();
return;
}
- //printf("CACHE: ADDING: '%s'\n", query);
+#ifdef WITH_CACHE_DEBUG
+ printf("CACHE: ADDING: '%s'\n", query);
+#endif
vcq = malloc(sizeof(vhffsfs_cache_query));
vcq->query = strdup(query);
vcq->result = result;
@@ -156,12 +165,13 @@
vhffsfs_cache_lock();
vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
// non existing or still referenced
- if(!vcq || vcq->ref > 0) {
+ if(!vcq || vcq->ref > 0 || strcmp(vcq->query, query) ) {
vhffsfs_cache_unlock();
return;
}
- //printf("CACHE: DELETING: '%s'\n", query);
- //g_ptr_array_remove_fast(vhffsfs.cachekeys, vcq->query);
+#ifdef WITH_CACHE_DEBUG
+ printf("CACHE: DELETING: '%s'\n", query);
+#endif
g_ptr_array_remove_fast(vhffsfs.cachekeys, vcq->query);
g_hash_table_remove(vhffsfs.cachequeries, vcq->query);
free(vcq->query);
@@ -173,22 +183,28 @@
PGresult *vhffsfs_cache_lookup(char *query) {
vhffsfs_cache_lock();
vhffsfs_cache_query *vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
- if(vcq) {
+ if(vcq && !strcmp(vcq->query,query) ) {
// timeout
if(vhffsfs_cache_timeout(vcq->arrival, VHFFSFS_CACHE_QUERY_TIMEOUT)) {
- //fprintf(stdout, "CACHE: TIMEOUT: '%s'\n", query);
+#ifdef WITH_CACHE_DEBUG
+ fprintf(stdout, "CACHE: TIMEOUT: '%s'\n", query);
+#endif
vhffsfs_cache_unlock();
vhffsfs_cache_del(query);
return NULL;
}
// cache hit
- //fprintf(stdout, "CACHE: HIT: '%s'\n", query);
+#ifdef WITH_CACHE_DEBUG
+ fprintf(stdout, "CACHE: HIT: '%s'\n", query);
+#endif
vcq->ref++;
vhffsfs_cache_unlock();
return vcq->result;
}
// cache miss
- //fprintf(stdout, "CACHE: MISS: '%s'\n", query);
+#ifdef WITH_CACHE_DEBUG
+ fprintf(stdout, "CACHE: MISS: '%s'\n", query);
+#endif
vhffsfs_cache_unlock();
return NULL;
}
@@ -233,7 +249,9 @@
vhffsfs_cache_lock();
vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
if(vcq && vhffsfs_cache_timeout(vcq->arrival, VHFFSFS_CACHE_QUERY_TIMEOUT)) {
- //fprintf(stdout, "CACHE: TIMEOUT: '%s'\n", query);
+#ifdef WITH_CACHE_DEBUG
+ fprintf(stdout, "CACHE: TIMEOUT: '%s'\n", query);
+#endif
vhffsfs_cache_unlock();
vhffsfs_cache_del(query);
}
@@ -1623,7 +1641,7 @@
vhffsfs.minimumrightfile = 00400;
vhffsfs.minimumrightdir = 02700;
#ifdef WITH_CACHE
- vhffsfs.cachequeries = g_hash_table_new(g_str_hash, g_str_equal);
+ vhffsfs.cachequeries = g_hash_table_new(vhffsfs_cache_hash, g_str_equal);
vhffsfs.cachekeys = g_ptr_array_sized_new(4096);
pthread_mutex_init(&vhffsfs.cachelock, NULL);
vhffsfs.cachethreadstarted = 0;