if (offset == file->sync_offset) {
*highest_modseq_r = file->sync_highest_modseq;
- return 0;
+ return 1;
}
cache = modseq_cache_get_offset(file, offset);
} else if (cache->offset == offset) {
/* exact cache hit */
*highest_modseq_r = cache->highest_modseq;
- return 0;
+ return 1;
} else {
/* use cache to skip over some records */
cur_offset = cache->offset;
"Failed to map transaction log %s for getting modseq "
"at offset=%"PRIuUOFF_T" with start_offset=%"PRIuUOFF_T": %s",
file->filepath, offset, cur_offset, reason);
- return -1;
+ return ret;
}
i_assert(cur_offset >= file->buffer_offset);
i_assert(cur_offset + file->buffer->used >= offset);
while (cur_offset < offset) {
if (log_get_synced_record(file, &cur_offset, &hdr, error_r) < 0)
- return- 1;
+ return 0;
mail_transaction_update_modseq(hdr, hdr + 1, &cur_modseq,
MAIL_TRANSACTION_LOG_HDR_VERSION(&file->hdr));
}
file->modseq_cache[0].highest_modseq = cur_modseq;
*highest_modseq_r = cur_modseq;
- return 0;
+ return 1;
}
static int
void mail_transaction_update_modseq(const struct mail_transaction_header *hdr,
const void *data, uint64_t *cur_modseq,
unsigned int version);
+/* Returns 1 if ok, 0 if file is corrupted or offset range is invalid,
+ -1 if I/O error */
int mail_transaction_log_file_get_highest_modseq_at(
struct mail_transaction_log_file *file,
uoff_t offset, uint64_t *highest_modseq_r,
view->broken = FALSE;
if (mail_transaction_log_file_get_highest_modseq_at(view->cur,
- view->cur_offset, &view->prev_modseq, reason_r) < 0)
+ view->cur_offset, &view->prev_modseq, reason_r) <= 0)
return -1;
i_assert(view->cur_offset <= view->cur->sync_offset);
view->broken = FALSE;
if (mail_transaction_log_file_get_highest_modseq_at(view->cur,
- view->cur_offset, &view->prev_modseq, &reason) < 0) {
+ view->cur_offset, &view->prev_modseq, &reason) <= 0) {
mail_index_set_error(view->log->index,
"Failed to get modseq in %s for all-view: %s",
view->log->filepath, reason);
uint64_t modseq_at;
const char *error;
/* initial_offset */
- test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_next_offset[1], &modseq, &error) == 0);
+ test_assert(mail_transaction_log_file_get_highest_modseq_at(
+ file, modseq_next_offset[1], &modseq, &error) == 1);
test_assert(modseq == 1);
/* sync_offset fast path */
- test_assert(mail_transaction_log_file_get_highest_modseq_at(file, file->sync_offset, &modseq, &error) == 0);
+ test_assert(mail_transaction_log_file_get_highest_modseq_at(
+ file, file->sync_offset, &modseq, &error) == 1);
test_assert(modseq == max_modseq);
/* do some random testing with cache */
for (unsigned int i = 0; i < LOG_FILE_MODSEQ_CACHE_SIZE*10; i++) {
modseq = i_rand_minmax(1, max_modseq);
- test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_next_offset[modseq], &modseq_at, &error) == 0);
+ test_assert(mail_transaction_log_file_get_highest_modseq_at(
+ file, modseq_next_offset[modseq], &modseq_at, &error) == 1);
test_assert(modseq_at == modseq);
- test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_alt_next_offset[modseq], &modseq_at, &error) == 0);
+ test_assert(mail_transaction_log_file_get_highest_modseq_at(
+ file, modseq_alt_next_offset[modseq], &modseq_at, &error) == 1);
test_assert(modseq_at == modseq);
}
/* go through all modseqs - do this after randomness testing or
modseq_alt_next_offset[] matching isn't triggered */
for (modseq = 1; modseq <= max_modseq; modseq++) {
- test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_next_offset[modseq], &modseq_at, &error) == 0);
+ test_assert(mail_transaction_log_file_get_highest_modseq_at(
+ file, modseq_next_offset[modseq], &modseq_at, &error) == 1);
test_assert(modseq_at == modseq);
}
const char **error_r ATTR_UNUSED)
{
*highest_modseq_r = 0;
- return 0;
+ return 1;
}
void mail_transaction_update_modseq(const struct mail_transaction_header *hdr ATTR_UNUSED,