bool new_msg;
};
-struct mail_cache_compress_lock {
- struct dotlock *dotlock;
-};
-
static void
mail_cache_merge_bitmask(struct mail_cache_copy_context *ctx,
const struct mail_cache_iterate_field *field)
static int
mail_cache_compress_full(struct mail_cache *cache,
struct mail_index_transaction *trans,
- uint32_t compress_file_seq,
- struct mail_cache_compress_lock **lock_r)
+ uint32_t compress_file_seq)
{
struct dotlock *dotlock = NULL;
bool unlock = FALSE;
i_assert(!cache->compressing);
i_assert(cache->index->log_sync_locked);
- *lock_r = NULL;
-
- if (MAIL_INDEX_IS_IN_MEMORY(cache->index) || cache->index->readonly) {
- *lock_r = i_new(struct mail_cache_compress_lock, 1);
+ if (MAIL_INDEX_IS_IN_MEMORY(cache->index) || cache->index->readonly)
return 0;
- }
/* compression isn't very efficient with small read()s */
if (cache->map_with_read) {
if (mail_cache_unlock(cache) < 0)
ret = -1;
}
+ if (dotlock != NULL)
+ file_dotlock_delete(&dotlock);
if (ret < 0) {
- if (dotlock != NULL)
- file_dotlock_delete(&dotlock);
/* the fields may have been updated in memory already.
reverse those changes by re-reading them from file. */
(void)mail_cache_header_fields_read(cache);
- } else {
- *lock_r = i_new(struct mail_cache_compress_lock, 1);
- (*lock_r)->dotlock = dotlock;
}
return ret;
}
int mail_cache_compress_with_trans(struct mail_cache *cache,
struct mail_index_transaction *trans,
- uint32_t compress_file_seq,
- struct mail_cache_compress_lock **lock_r)
+ uint32_t compress_file_seq)
{
- return mail_cache_compress_full(cache, trans, compress_file_seq, lock_r);
+ return mail_cache_compress_full(cache, trans, compress_file_seq);
}
int mail_cache_compress(struct mail_cache *cache, uint32_t compress_file_seq)
{
struct mail_index_view *view;
struct mail_index_transaction *trans;
- struct mail_cache_compress_lock *lock;
bool lock_log;
int ret;
MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
if (ret < 0)
;
- else if ((ret = mail_cache_compress_full(cache, trans, compress_file_seq, &lock)) < 0)
+ else if ((ret = mail_cache_compress_full(cache, trans, compress_file_seq)) < 0)
mail_index_transaction_rollback(&trans);
else {
if (mail_index_transaction_commit(&trans) < 0)
ret = -1;
- mail_cache_compress_unlock(&lock);
}
mail_index_view_close(&view);
if (lock_log) {
return ret;
}
-void mail_cache_compress_unlock(struct mail_cache_compress_lock **_lock)
-{
- struct mail_cache_compress_lock *lock = *_lock;
-
- *_lock = NULL;
-
- if (lock->dotlock != NULL)
- file_dotlock_delete(&lock->dotlock);
- i_free(lock);
-}
-
bool mail_cache_need_compress(struct mail_cache *cache)
{
return cache->need_compress_file_seq != 0 &&
struct mail_cache;
struct mail_cache_view;
struct mail_cache_transaction_ctx;
-struct mail_cache_compress_lock;
enum mail_cache_decision_type {
/* Not needed currently */
done always regardless of file_seq. */
int mail_cache_compress_with_trans(struct mail_cache *cache,
struct mail_index_transaction *trans,
- uint32_t compress_file_seq,
- struct mail_cache_compress_lock **lock_r);
+ uint32_t compress_file_seq);
int mail_cache_compress(struct mail_cache *cache, uint32_t compress_file_seq);
-void mail_cache_compress_unlock(struct mail_cache_compress_lock **lock);
/* Returns TRUE if there is at least something in the cache. */
bool mail_cache_exists(struct mail_cache *cache);
/* Open and read cache header. Returns 0 if ok, -1 if error/corrupted. */
{
struct mail_index_sync_ctx *ctx = *_ctx;
struct mail_index *index = ctx->index;
- struct mail_cache_compress_lock *cache_lock = NULL;
const char *reason = NULL;
uint32_t next_uid;
bool want_rotate, index_undeleted, delete_index;
trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_FSYNC;
cache_trans = mail_index_transaction_begin(ctx->view, trans_flags);
if (mail_cache_compress_with_trans(index->cache, cache_trans,
- index->cache->need_compress_file_seq,
- &cache_lock) < 0)
+ index->cache->need_compress_file_seq) < 0)
mail_index_transaction_rollback(&cache_trans);
else {
/* can't really do anything if index commit fails */
(void)mail_index_transaction_commit(&cache_trans);
- mail_cache_compress_unlock(&cache_lock);
/* Make sure the newly committed cache record offsets
are updated to the current index. This is important
if the dovecot.index gets recreated below, because
index_rebuild_generate_uidvalidity_t *cb)
{
struct index_rebuild_context *ctx = *_ctx;
- struct mail_cache_compress_lock *lock = NULL;
*_ctx = NULL;
/* initialize cache file with the old field decisions */
(void)mail_cache_compress_with_trans(ctx->box->cache, ctx->trans,
- (uint32_t)-1, &lock);
- if (lock != NULL) {
- /* FIXME: this is a bit too early. ideally we should return it
- from this function and unlock only after the transaction is
- committed, but it would be an API change and this rebuilding
- isn't happening normally anyway. */
- mail_cache_compress_unlock(&lock);
- }
+ (uint32_t)-1);
index_rebuild_header(ctx, cb);
index_rebuild_box_name_header(ctx);
if (ctx->backup_index != NULL) {