Skip to content

Commit

Permalink
dsync: Use header hashing version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Jun 23, 2017
1 parent e17e53f commit f3c24c2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 21 deletions.
9 changes: 3 additions & 6 deletions src/doveadm/dsync/dsync-brain-mailbox.c
Expand Up @@ -218,8 +218,6 @@ dsync_brain_sync_mailbox_init_remote(struct dsync_brain *brain,
import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128;
if (brain->no_notify)
import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_NO_NOTIFY;
if (brain->hdr_hash_v2)
import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_HDR_HASH_V2;
if (brain->empty_hdr_workaround)
import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_EMPTY_HDR_WORKAROUND;

Expand All @@ -237,7 +235,7 @@ dsync_brain_sync_mailbox_init_remote(struct dsync_brain *brain,
brain->sync_max_size,
brain->sync_flag,
brain->import_commit_msgs_interval,
import_flags);
import_flags, brain->hdr_hash_version);
}

int dsync_brain_sync_mailbox_open(struct dsync_brain *brain,
Expand Down Expand Up @@ -329,8 +327,6 @@ int dsync_brain_sync_mailbox_open(struct dsync_brain *brain,
exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_TIMESTAMPS;
if (brain->sync_max_size > 0)
exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_VSIZES;
if (brain->hdr_hash_v2)
exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_HDR_HASH_V2;
if (remote_dsync_box->messages_count == 0) {
/* remote mailbox is empty - we don't really need to export
header hashes since they're not going to match anything
Expand All @@ -341,7 +337,8 @@ int dsync_brain_sync_mailbox_open(struct dsync_brain *brain,
brain->box_exporter = brain->backup_recv ? NULL :
dsync_mailbox_export_init(brain->box, brain->log_scan,
last_common_uid,
exporter_flags);
exporter_flags,
brain->hdr_hash_version);
dsync_brain_sync_mailbox_init_remote(brain, remote_dsync_box);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/dsync/dsync-brain-private.h
Expand Up @@ -63,6 +63,7 @@ struct dsync_brain {
const char *sync_flag;
char alt_char;
unsigned int import_commit_msgs_interval;
unsigned int hdr_hash_version;

unsigned int lock_timeout;
int lock_fd;
Expand Down Expand Up @@ -116,7 +117,6 @@ struct dsync_brain {
bool require_full_resync:1;
bool verbose_proctitle:1;
bool no_notify:1;
bool hdr_hash_v2:1;
bool failed:1;
bool empty_hdr_workaround:1;
};
Expand Down
16 changes: 14 additions & 2 deletions src/doveadm/dsync/dsync-brain.c
Expand Up @@ -424,6 +424,18 @@ dsync_brain_lock(struct dsync_brain *brain, const char *remote_hostname)
return brain->lock_fd == -1 ? -1 : 0;
}

static void
dsync_brain_set_hdr_hash_version(struct dsync_brain *brain,
const struct dsync_ibc_settings *ibc_set)
{
if (ibc_set->hdr_hash_v3)
brain->hdr_hash_version = 3;
else if (ibc_set->hdr_hash_v2)
brain->hdr_hash_version = 3;
else
brain->hdr_hash_version = 1;
}

static bool dsync_brain_master_recv_handshake(struct dsync_brain *brain)
{
const struct dsync_ibc_settings *ibc_set;
Expand All @@ -439,7 +451,7 @@ static bool dsync_brain_master_recv_handshake(struct dsync_brain *brain)
return FALSE;
}
}
brain->hdr_hash_v2 = ibc_set->hdr_hash_v2;
dsync_brain_set_hdr_hash_version(brain, ibc_set);

brain->state = brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_STATE ?
DSYNC_STATE_MASTER_SEND_LAST_COMMON :
Expand All @@ -457,7 +469,7 @@ static bool dsync_brain_slave_recv_handshake(struct dsync_brain *brain)

if (dsync_ibc_recv_handshake(brain->ibc, &ibc_set) == 0)
return FALSE;
brain->hdr_hash_v2 = ibc_set->hdr_hash_v2;
dsync_brain_set_hdr_hash_version(brain, ibc_set);

if (ibc_set->lock_timeout > 0) {
brain->lock_timeout = ibc_set->lock_timeout;
Expand Down
6 changes: 4 additions & 2 deletions src/doveadm/dsync/dsync-ibc-stream.c
Expand Up @@ -26,13 +26,14 @@
#define DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE (1024*128)

#define DSYNC_PROTOCOL_VERSION_MAJOR 3
#define DSYNC_PROTOCOL_VERSION_MINOR 4
#define DSYNC_HANDSHAKE_VERSION "VERSION\tdsync\t3\t4\n"
#define DSYNC_PROTOCOL_VERSION_MINOR 5
#define DSYNC_HANDSHAKE_VERSION "VERSION\tdsync\t3\t5\n"

#define DSYNC_PROTOCOL_MINOR_HAVE_ATTRIBUTES 1
#define DSYNC_PROTOCOL_MINOR_HAVE_SAVE_GUID 2
#define DSYNC_PROTOCOL_MINOR_HAVE_FINISH 3
#define DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V2 4
#define DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V3 5

enum item_type {
ITEM_NONE,
Expand Down Expand Up @@ -881,6 +882,7 @@ dsync_ibc_stream_recv_handshake(struct dsync_ibc *_ibc,
if (dsync_deserializer_decode_try(decoder, "empty_hdr_workaround", &value))
set->brain_flags |= DSYNC_BRAIN_FLAG_EMPTY_HDR_WORKAROUND;
set->hdr_hash_v2 = ibc->minor_version >= DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V2;
set->hdr_hash_v3 = ibc->minor_version >= DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V3;

*set_r = set;
return DSYNC_IBC_RECV_RET_OK;
Expand Down
1 change: 1 addition & 0 deletions src/doveadm/dsync/dsync-ibc.h
Expand Up @@ -68,6 +68,7 @@ struct dsync_ibc_settings {
enum dsync_brain_sync_type sync_type;
enum dsync_brain_flags brain_flags;
bool hdr_hash_v2;
bool hdr_hash_v3;
unsigned int lock_timeout;
unsigned int import_commit_msgs_interval;
};
Expand Down
6 changes: 3 additions & 3 deletions src/doveadm/dsync/dsync-mailbox-export.c
Expand Up @@ -498,7 +498,8 @@ struct dsync_mailbox_exporter *
dsync_mailbox_export_init(struct mailbox *box,
struct dsync_transaction_log_scan *log_scan,
uint32_t last_common_uid,
enum dsync_mailbox_exporter_flags flags)
enum dsync_mailbox_exporter_flags flags,
unsigned int hdr_hash_version)
{
struct dsync_mailbox_exporter *exporter;
pool_t pool;
Expand All @@ -520,8 +521,7 @@ dsync_mailbox_export_init(struct mailbox *box,
(flags & DSYNC_MAILBOX_EXPORTER_FLAG_TIMESTAMPS) != 0;
exporter->export_virtual_sizes =
(flags & DSYNC_MAILBOX_EXPORTER_FLAG_VSIZES) != 0;
exporter->hdr_hash_version =
(flags & DSYNC_MAILBOX_EXPORTER_FLAG_HDR_HASH_V2) != 0 ? 2 : 1;
exporter->hdr_hash_version = hdr_hash_version;
exporter->no_hdr_hashes =
(flags & DSYNC_MAILBOX_EXPORTER_FLAG_NO_HDR_HASHES) != 0;
p_array_init(&exporter->requested_uids, pool, 16);
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/dsync/dsync-mailbox-export.h
Expand Up @@ -6,7 +6,6 @@ enum dsync_mailbox_exporter_flags {
DSYNC_MAILBOX_EXPORTER_FLAG_MAILS_HAVE_GUIDS = 0x02,
DSYNC_MAILBOX_EXPORTER_FLAG_MINIMAL_DMAIL_FILL = 0x04,
DSYNC_MAILBOX_EXPORTER_FLAG_TIMESTAMPS = 0x08,
DSYNC_MAILBOX_EXPORTER_FLAG_HDR_HASH_V2 = 0x10,
DSYNC_MAILBOX_EXPORTER_FLAG_NO_HDR_HASHES = 0x20,
DSYNC_MAILBOX_EXPORTER_FLAG_VSIZES = 0x40,
};
Expand All @@ -15,7 +14,8 @@ struct dsync_mailbox_exporter *
dsync_mailbox_export_init(struct mailbox *box,
struct dsync_transaction_log_scan *log_scan,
uint32_t last_common_uid,
enum dsync_mailbox_exporter_flags flags);
enum dsync_mailbox_exporter_flags flags,
unsigned int hdr_hash_version);
/* Returns 1 if attribute was returned, 0 if no more attributes, -1 on error */
int dsync_mailbox_export_next_attr(struct dsync_mailbox_exporter *exporter,
const struct dsync_mailbox_attribute **attr_r);
Expand Down
6 changes: 3 additions & 3 deletions src/doveadm/dsync/dsync-mailbox-import.c
Expand Up @@ -226,7 +226,8 @@ dsync_mailbox_import_init(struct mailbox *box,
uoff_t sync_max_size,
const char *sync_flag,
unsigned int commit_msgs_interval,
enum dsync_mailbox_import_flags flags)
enum dsync_mailbox_import_flags flags,
unsigned int hdr_hash_version)
{
struct dsync_mailbox_importer *importer;
struct mailbox_status status;
Expand Down Expand Up @@ -289,8 +290,7 @@ dsync_mailbox_import_init(struct mailbox *box,
(flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS) != 0;
importer->mails_use_guid128 =
(flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128) != 0;
importer->hdr_hash_version =
(flags & DSYNC_MAILBOX_IMPORT_FLAG_HDR_HASH_V2) != 0 ? 2 : 1;
importer->hdr_hash_version = hdr_hash_version;
importer->empty_hdr_workaround =
(flags & DSYNC_MAILBOX_IMPORT_FLAG_EMPTY_HDR_WORKAROUND) != 0;

Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/dsync/dsync-mailbox-import.h
Expand Up @@ -11,7 +11,6 @@ enum dsync_mailbox_import_flags {
DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS = 0x10,
DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128 = 0x20,
DSYNC_MAILBOX_IMPORT_FLAG_NO_NOTIFY = 0x40,
DSYNC_MAILBOX_IMPORT_FLAG_HDR_HASH_V2 = 0x80,
DSYNC_MAILBOX_IMPORT_FLAG_EMPTY_HDR_WORKAROUND = 0x100
};

Expand All @@ -37,7 +36,8 @@ dsync_mailbox_import_init(struct mailbox *box,
uoff_t sync_max_size,
const char *sync_flag,
unsigned int commit_msgs_interval,
enum dsync_mailbox_import_flags flags);
enum dsync_mailbox_import_flags flags,
unsigned int hdr_hash_version);
int dsync_mailbox_import_attribute(struct dsync_mailbox_importer *importer,
const struct dsync_mailbox_attribute *attr);
int dsync_mailbox_import_change(struct dsync_mailbox_importer *importer,
Expand Down

0 comments on commit f3c24c2

Please sign in to comment.