aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-text-index.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-09-24 09:16:12 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-09-24 09:16:12 +0800
commita65c7bb4769b16dda87c1bdf2cb06784b4090d4a (patch)
tree8e77d9424cf98f558b57a1174c621bb014740ec8 /camel/camel-text-index.c
parent5ca425852cab78a782c1b354555f7c9c380d8e02 (diff)
downloadgsoc2013-evolution-a65c7bb4769b16dda87c1bdf2cb06784b4090d4a.tar
gsoc2013-evolution-a65c7bb4769b16dda87c1bdf2cb06784b4090d4a.tar.gz
gsoc2013-evolution-a65c7bb4769b16dda87c1bdf2cb06784b4090d4a.tar.bz2
gsoc2013-evolution-a65c7bb4769b16dda87c1bdf2cb06784b4090d4a.tar.lz
gsoc2013-evolution-a65c7bb4769b16dda87c1bdf2cb06784b4090d4a.tar.xz
gsoc2013-evolution-a65c7bb4769b16dda87c1bdf2cb06784b4090d4a.tar.zst
gsoc2013-evolution-a65c7bb4769b16dda87c1bdf2cb06784b4090d4a.zip
If we have no data written to a key, dont add it, or its partition header.
2002-09-24 Not Zed <NotZed@Ximian.com> * camel-text-index.c (text_index_compress_nosync): If we have no data written to a key, dont add it, or its partition header. 2002-09-23 Not Zed <NotZed@Ximian.com> * camel-block-file.c (sync_nolock): Mark root block dirty if we're going to sync it. (camel_key_file_finalise): de-count the active list if we close it. * camel-text-index.c (text_index_delete): Implement. (text_index_compress_nosync): Use index_delete when we're finished with the old one, so it is properly deactivated. * camel-index.c (camel_index_delete): Remove api call. Mark index deleted in new state variable. (camel_index_*): Wrap all calls in check for deleted state. svn path=/trunk/; revision=18189
Diffstat (limited to 'camel/camel-text-index.c')
-rw-r--r--camel/camel-text-index.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/camel/camel-text-index.c b/camel/camel-text-index.c
index 3c490804fc..e340511131 100644
--- a/camel/camel-text-index.c
+++ b/camel/camel-text-index.c
@@ -263,6 +263,8 @@ text_index_sync(CamelIndex *idx)
struct _CamelTextIndexRoot *rb;
int ret = 0, wfrag, nfrag, work = FALSE;
+ d(printf("sync: blocks = %p\n", p->blocks));
+
if (p->blocks == NULL)
return 0;
@@ -304,11 +306,12 @@ text_index_sync(CamelIndex *idx)
ret = -1;
/* only do the frag/compress check if we did some new writes on this index */
- if (ret == 0 && work) {
- wfrag = rb->words ? (((rb->keys - rb->words) * 100)/ rb->words) : 0;
- nfrag = rb->names ? ((rb->deleted * 100) / rb->names) : 0;
- d(printf("wfrag = %d, nfrag = %d\n", wfrag, nfrag));
- d(printf(" words = %d, keys = %d\n", rb->words, rb->keys));
+ wfrag = rb->words ? (((rb->keys - rb->words) * 100)/ rb->words) : 0;
+ nfrag = rb->names ? ((rb->deleted * 100) / rb->names) : 0;
+ d(printf("wfrag = %d, nfrag = %d, work = %s, ret = %d\n", wfrag, nfrag, work?"true":"false", ret));
+ d(printf(" words = %d, keys = %d\n", rb->words, rb->keys));
+
+ if (ret == 0) {
if (wfrag > 30 || nfrag > 20)
ret = text_index_compress_nosync(idx);
}
@@ -466,11 +469,13 @@ text_index_compress_nosync(CamelIndex *idx)
if (camel_key_file_write(newp->links, &newdata, newcount, newrecords) == -1)
goto fail;
}
-
- newkeyid = camel_key_table_add(newp->word_index, name, newdata, flags);
- if (newkeyid == 0)
- goto fail;
- camel_partition_table_add(newp->word_hash, name, newkeyid);
+
+ if (newdata != 0) {
+ newkeyid = camel_key_table_add(newp->word_index, name, newdata, flags);
+ if (newkeyid == 0)
+ goto fail;
+ camel_partition_table_add(newp->word_hash, name, newkeyid);
+ }
g_free(name);
name = NULL;
}
@@ -505,13 +510,13 @@ text_index_compress_nosync(CamelIndex *idx)
fail:
CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+ camel_index_delete((CamelIndex *)newidx);
+
camel_object_unref((CamelObject *)newidx);
g_free(name);
g_hash_table_destroy(remap);
/* clean up temp files always */
- camel_text_index_remove(newpath);
-
sprintf(savepath, "%s~.index", oldpath);
unlink(savepath);
sprintf(newpath, "%s.data", savepath);
@@ -521,6 +526,12 @@ fail:
}
static int
+text_index_delete(CamelIndex *idx)
+{
+ return camel_text_index_remove(idx->path);
+}
+
+static int
text_index_rename(CamelIndex *idx, const char *path)
{
struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
@@ -649,6 +660,8 @@ text_index_delete_name(CamelIndex *idx, const char *name)
camel_key_t keyid;
struct _CamelTextIndexRoot *rb = (struct _CamelTextIndexRoot *)p->blocks->root;
+ d(printf("Delete name: %s\n", name));
+
/* probably doesn't really need locking, but oh well */
CAMEL_TEXT_INDEX_LOCK(idx, lock);
@@ -714,6 +727,7 @@ camel_text_index_class_init(CamelTextIndexClass *klass)
iklass->sync = text_index_sync;
iklass->compress = text_index_compress;
+ iklass->delete = text_index_delete;
iklass->rename = text_index_rename;