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
This commit is contained in:
Not Zed
2002-09-24 01:16:12 +00:00
committed by Michael Zucci
parent 5ca425852c
commit a65c7bb476
6 changed files with 123 additions and 24 deletions

View File

@ -1,3 +1,23 @@
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.
2002-09-23 Jeffrey Stedfast <fejj@ximian.com>
* camel-folder.c (transfer_message_to): If the original message is

View File

@ -713,6 +713,7 @@ sync_nolock(CamelBlockFile *bs)
d(printf("turning on sync flag\n"));
bs->root->flags |= CAMEL_BLOCK_FILE_SYNC;
bs->root_block->flags |= CAMEL_BLOCK_DIRTY;
return sync_block_nolock(bs, bs->root_block);
}
@ -834,8 +835,10 @@ camel_key_file_finalise(CamelKeyFile *bs)
e_dlist_remove((EDListNode *)p);
UNLOCK(key_file_lock);
if (bs->fp)
if (bs-> fp) {
key_file_count--;
fclose(bs->fp);
}
g_free(bs->path);
#ifdef ENABLE_THREADS

View File

@ -116,7 +116,12 @@ camel_index_construct(CamelIndex *idx, const char *path, int flags)
int
camel_index_rename(CamelIndex *idx, const char *path)
{
return CI_CLASS(idx)->rename(idx, path);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->rename(idx, path);
else {
errno = ENOENT;
return -1;
}
}
void
@ -129,43 +134,84 @@ camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm func, void *data)
int
camel_index_sync(CamelIndex *idx)
{
return CI_CLASS(idx)->sync(idx);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->sync(idx);
else {
errno = ENOENT;
return -1;
}
}
int
camel_index_compress(CamelIndex *idx)
{
return CI_CLASS(idx)->compress(idx);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->compress(idx);
else {
errno = ENOENT;
return -1;
}
}
int
camel_index_delete(CamelIndex *idx)
{
int ret;
if ((idx->state & CAMEL_INDEX_DELETED) == 0) {
ret = CI_CLASS(idx)->delete(idx);
idx->state |= CAMEL_INDEX_DELETED;
} else {
errno = ENOENT;
ret = -1;
}
return ret;
}
int
camel_index_has_name(CamelIndex *idx, const char *name)
{
return CI_CLASS(idx)->has_name(idx, name);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->has_name(idx, name);
else
return FALSE;
}
CamelIndexName *
camel_index_add_name(CamelIndex *idx, const char *name)
{
return CI_CLASS(idx)->add_name(idx, name);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->add_name(idx, name);
else
return NULL;
}
int
camel_index_write_name(CamelIndex *idx, CamelIndexName *idn)
{
return CI_CLASS(idx)->write_name(idx, idn);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->write_name(idx, idn);
else {
errno = ENOENT;
return -1;
}
}
CamelIndexCursor *
camel_index_find_name(CamelIndex *idx, const char *name)
{
return CI_CLASS(idx)->find_name(idx, name);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->find_name(idx, name);
else
return NULL;
}
void
camel_index_delete_name(CamelIndex *idx, const char *name)
{
return CI_CLASS(idx)->delete_name(idx, name);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
CI_CLASS(idx)->delete_name(idx, name);
}
CamelIndexCursor *
@ -174,6 +220,9 @@ camel_index_find(CamelIndex *idx, const char *word)
char *b = (char *)word;
CamelIndexCursor *ret;
if ((idx->state & CAMEL_INDEX_DELETED) != 0)
return NULL;
if (idx->normalise)
b = idx->normalise(idx, word, idx->normalise_data);
@ -188,13 +237,19 @@ camel_index_find(CamelIndex *idx, const char *word)
CamelIndexCursor *
camel_index_words(CamelIndex *idx)
{
return CI_CLASS(idx)->words(idx);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->words(idx);
else
return NULL;
}
CamelIndexCursor *
camel_index_names(CamelIndex *idx)
{
return CI_CLASS(idx)->names(idx);
if ((idx->state & CAMEL_INDEX_DELETED) == 0)
return CI_CLASS(idx)->names(idx);
else
return NULL;
}
/* ********************************************************************** */

View File

@ -110,7 +110,8 @@ struct _CamelIndex {
char *path;
guint32 version;
guint32 flags;
guint32 flags; /* open flags */
guint32 state;
CamelIndexNorm normalise;
void *normalise_data;
@ -121,6 +122,7 @@ struct _CamelIndexClass {
int (*sync)(CamelIndex *idx);
int (*compress)(CamelIndex *idx);
int (*delete)(CamelIndex *idx);
int (*rename)(CamelIndex *idx, const char *path);
@ -135,6 +137,9 @@ struct _CamelIndexClass {
CamelIndexCursor * (*names)(CamelIndex *idx);
};
/* flags, stored in 'state', set with set_state */
#define CAMEL_INDEX_DELETED (1<<0)
CamelType camel_index_get_type (void);
CamelIndex *camel_index_new(const char *path, int flags);
@ -145,6 +150,7 @@ void camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm fun
int camel_index_sync(CamelIndex *idx);
int camel_index_compress(CamelIndex *idx);
int camel_index_delete(CamelIndex *idx);
int camel_index_has_name(CamelIndex *idx, const char *name);
CamelIndexName *camel_index_add_name(CamelIndex *idx, const char *name);

View File

@ -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);
@ -520,6 +525,12 @@ fail:
return ret;
}
static int
text_index_delete(CamelIndex *idx)
{
return camel_text_index_remove(idx->path);
}
static int
text_index_rename(CamelIndex *idx, const char *path)
{
@ -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;

View File

@ -1,3 +1,4 @@
/*
* Copyright (C) 2001 Ximian Inc.
*