[dovecot-cvs] dovecot/src/lib-index mail-cache-lookup.c, 1.3,
1.4 mail-cache-transaction.c, 1.4, 1.5 mail-index-sync.c, 1.22,
1.23 mail-index-transaction.c, 1.12, 1.13 mail-index.h, 1.117, 1.118
cras at procontrol.fi
cras at procontrol.fi
Mon Jun 21 17:44:49 EEST 2004
Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv16327/lib-index
Modified Files:
mail-cache-lookup.c mail-cache-transaction.c mail-index-sync.c
mail-index-transaction.c mail-index.h
Log Message:
Cache doesn't crash anymore if we're asking it about messages that exist
only in uncommitted transactions.
Index: mail-cache-lookup.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-lookup.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mail-cache-lookup.c 20 Jun 2004 09:13:14 -0000 1.3
+++ mail-cache-lookup.c 21 Jun 2004 14:44:47 -0000 1.4
@@ -175,7 +175,11 @@
if (view->cache->disabled)
return NULL;
- /* FIXME: check cache_offset in transaction */
+ if (seq > mail_index_view_get_message_count(view->view)) {
+ /* it's being appended in some transaction */
+ return NULL;
+ }
+
if (mail_index_lookup_full(view->view, seq, &map, &rec) < 0)
return NULL;
Index: mail-cache-transaction.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-transaction.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mail-cache-transaction.c 21 Jun 2004 14:20:08 -0000 1.4
+++ mail-cache-transaction.c 21 Jun 2004 14:44:47 -0000 1.5
@@ -220,7 +220,7 @@
struct mail_cache_record *cache_rec, *next;
const struct mail_index_record *rec;
struct mail_index_map *map;
- uint32_t write_offset, update_offset;
+ uint32_t messages_count, write_offset, update_offset;
const void *buf;
size_t size, buf_size;
int ret;
@@ -230,9 +230,15 @@
size = sizeof(*cache_rec) + buf_size;
ctx->cache_rec.size = uint32_to_nbo(size);
- // FIXME: check cache_offset in transaction
- ret = mail_index_lookup_full(ctx->view->view, ctx->prev_seq,
- &map, &rec);
+ messages_count = mail_index_view_get_message_count(ctx->view->view);
+ if (ctx->prev_seq <= messages_count) {
+ ret = mail_index_lookup_full(ctx->view->view, ctx->prev_seq,
+ &map, &rec);
+ } else {
+ ret = mail_index_transaction_lookup(ctx->trans,
+ ctx->prev_seq, &rec);
+ map = cache->index->map;
+ }
if (ret < 0)
return -1;
Index: mail-index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mail-index-sync.c 20 Jun 2004 09:13:14 -0000 1.22
+++ mail-index-sync.c 21 Jun 2004 14:44:47 -0000 1.23
@@ -6,6 +6,7 @@
#include "mail-index-sync-private.h"
#include "mail-transaction-log.h"
#include "mail-transaction-util.h"
+#include "mail-cache.h"
#include <stdlib.h>
Index: mail-index-transaction.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mail-index-transaction.c 20 Jun 2004 09:13:14 -0000 1.12
+++ mail-index-transaction.c 21 Jun 2004 14:44:47 -0000 1.13
@@ -136,6 +136,30 @@
mail_index_transaction_free(t);
}
+static struct mail_index_record *
+mail_index_lookup_append(struct mail_index_transaction *t, uint32_t seq)
+{
+ size_t pos;
+
+ i_assert(seq >= t->first_new_seq && seq <= t->last_new_seq);
+
+ pos = (seq - t->first_new_seq) * t->view->index->record_size;
+ return buffer_get_space_unsafe(t->appends, pos,
+ t->view->index->record_size);
+}
+
+int mail_index_transaction_lookup(struct mail_index_transaction *t,
+ uint32_t seq,
+ const struct mail_index_record **rec_r)
+{
+ if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
+ *rec_r = mail_index_lookup_append(t, seq);
+ return 1;
+ } else {
+ return mail_index_lookup(t->view, seq, rec_r);
+ }
+}
+
void mail_index_append(struct mail_index_transaction *t, uint32_t uid,
uint32_t *seq_r)
{
@@ -161,18 +185,6 @@
rec->uid = uid;
}
-static struct mail_index_record *
-mail_index_lookup_append_rec(struct mail_index_transaction *t, uint32_t seq)
-{
- size_t pos;
-
- i_assert(seq >= t->first_new_seq && seq <= t->last_new_seq);
-
- pos = (seq - t->first_new_seq) * t->view->index->record_size;
- return buffer_get_space_unsafe(t->appends, pos,
- t->view->index->record_size);
-}
-
void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq)
{
struct mail_transaction_expunge exp, *data;
@@ -303,7 +315,7 @@
if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
/* just appended message, modify it directly */
- rec = mail_index_lookup_append_rec(t, seq);
+ rec = mail_index_lookup_append(t, seq);
mail_index_record_modify_flags(rec, modify_type,
flags, keywords);
return;
@@ -487,7 +499,7 @@
if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
/* just appended message, modify it directly */
- rec = mail_index_lookup_append_rec(t, seq);
+ rec = mail_index_lookup_append(t, seq);
rec->cache_offset = offset;
} else {
mail_index_update_seq_buffer(&t->cache_updates, seq,
@@ -507,7 +519,7 @@
if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
/* just appended message, modify it directly */
/* FIXME: do data_id mapping conversion */
- rec = mail_index_lookup_append_rec(t, seq);
+ rec = mail_index_lookup_append(t, seq);
memcpy(PTR_OFFSET(rec, index->extra_records[data_id].offset),
data, index->extra_records[data_id].size);
} else {
@@ -528,9 +540,3 @@
for (; size > 0; size--)
t->hdr_mask[offset++] = 1;
}
-
-const struct mail_index_record *
-mail_index_lookup_append(struct mail_index_transaction *t, uint32_t seq)
-{
- return mail_index_lookup_append_rec(t, seq);
-}
Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -d -r1.117 -r1.118
--- mail-index.h 20 Jun 2004 04:17:42 -0000 1.117
+++ mail-index.h 21 Jun 2004 14:44:47 -0000 1.118
@@ -278,10 +278,11 @@
void mail_index_update_extra_rec(struct mail_index_transaction *t,
uint32_t seq, uint32_t data_id,
const void *data);
-/* Returns given appended message, with all updates that have been done
- to it since the append. */
-const struct mail_index_record *
-mail_index_lookup_append(struct mail_index_transaction *t, uint32_t seq);
+/* Like mail_index_lookup(), but if seq > view's message count, it's referring
+ to message appended with given transaction. */
+int mail_index_transaction_lookup(struct mail_index_transaction *t,
+ uint32_t seq,
+ const struct mail_index_record **rec_r);
/* Returns the last error code. */
enum mail_index_error mail_index_get_last_error(struct mail_index *index);
More information about the dovecot-cvs
mailing list