Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fts: add additional index type to segregate fts indexes from imap ind… #194

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-mail-mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct path_cmd_context {

static const char *mailbox_list_path_type_names[] = {
"dir", "alt-dir", "mailbox", "alt-mailbox",
"control", "index", "index-private", "index-cache", "list-index",
"control", "index", "fts-index", "index-private", "index-cache", "list-index",
};
static_assert_array_size(mailbox_list_path_type_names, MAILBOX_LIST_PATH_TYPE_COUNT);

Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/index/mbox/mbox-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ mbox_list_get_path(struct mailbox_list *list, const char *name,
*path_r = t_strconcat(t_strdup_until(path, p),
"/"MBOX_INDEX_DIR_NAME"/", p+1, NULL);
break;
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
case MAILBOX_LIST_PATH_TYPE_DIR:
case MAILBOX_LIST_PATH_TYPE_ALT_DIR:
case MAILBOX_LIST_PATH_TYPE_MAILBOX:
Expand Down
8 changes: 8 additions & 0 deletions src/lib-storage/list/mailbox-list-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ fs_list_get_path(struct mailbox_list *_list, const char *name,
return 1;
}
break;
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
if (set->fts_index_dir != NULL) {
if (*set->fts_index_dir == '\0')
return 0;
*path_r = fs_list_get_path_to(set, set->fts_index_dir, name);
return 1;
}
break;
case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
if (set->index_pvt_dir == NULL)
return 0;
Expand Down
9 changes: 9 additions & 0 deletions src/lib-storage/list/mailbox-list-maildir.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ maildir_list_get_path(struct mailbox_list *_list, const char *name,
return 1;
}
break;
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
if (_list->set.fts_index_dir != NULL) {
if (*_list->set.fts_index_dir == '\0')
return 0;
*path_r = maildir_list_get_dirname_path(_list,
_list->set.fts_index_dir, name);
return 1;
}
break;
case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
if (_list->set.index_pvt_dir == NULL)
return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/lib-storage/mail-storage-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,8 @@ int mailbox_mark_index_deleted(struct mailbox *box, bool del);
const char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
/* Similar to mailbox_get_path() but for MAILBOX_LIST_PATH_TYPE_INDEX. */
const char *mailbox_get_index_path(struct mailbox *box) ATTR_PURE;
/* Check if mailbox path for type exists. */
int mailbox_path_exists(struct mailbox *box, enum mailbox_list_path_type type);
/* Wrapper to mailbox_list_get_path() */
int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
const char **path_r);
Expand Down
9 changes: 9 additions & 0 deletions src/lib-storage/mail-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,15 @@ const char *mailbox_get_index_path(struct mailbox *box)
return box->_index_path;
}

int mailbox_path_exists(struct mailbox *box, enum mailbox_list_path_type type)
{
const char *path;
if (get_path_to(box, type, NULL, &path) < 0)
return 0;

return 1;
}

static void mailbox_get_permissions_if_not_set(struct mailbox *box)
{
if (box->_perm.file_create_mode != 0)
Expand Down
23 changes: 21 additions & 2 deletions src/lib-storage/mailbox-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns,
}

if ((class->props & MAILBOX_LIST_PROP_NO_MAILDIR_NAME) != 0 &&
*set->maildir_name != '\0') {
*set->maildir_name != '\0') {
*error_r = "maildir_name not supported by this driver";
return -1;
}
Expand Down Expand Up @@ -210,10 +210,11 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns,
}

e_debug(ns->user->event,
"%s: root=%s, index=%s, indexpvt=%s, control=%s, inbox=%s, alt=%s",
"%s: root=%s, index=%s, fts_index=%s, indexpvt=%s, control=%s, inbox=%s, alt=%s",
list->name,
list->set.root_dir == NULL ? "" : list->set.root_dir,
list->set.index_dir == NULL ? "" : list->set.index_dir,
list->set.fts_index_dir == NULL ? "" : list->set.fts_index_dir,
list->set.index_pvt_dir == NULL ? "" : list->set.index_pvt_dir,
list->set.control_dir == NULL ?
"" : list->set.control_dir,
Expand Down Expand Up @@ -333,6 +334,8 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data,
dest = &set_r->inbox_path;
else if (strcmp(key, "INDEX") == 0)
dest = &set_r->index_dir;
else if (strcmp(key, "FTS_INDEX") == 0)
dest = &set_r->fts_index_dir;
else if (strcmp(key, "INDEXPVT") == 0)
dest = &set_r->index_pvt_dir;
else if (strcmp(key, "INDEXCACHE") == 0)
Expand Down Expand Up @@ -1485,6 +1488,22 @@ bool mailbox_list_set_get_root_path(const struct mailbox_list_settings *set,
path = set->root_dir;
}
break;
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
if (set->fts_index_dir != NULL) {
if (set->fts_index_dir[0] == '\0') {
/* in-memory indexes */
return 0;
}
path = set->fts_index_dir;

/* Preserve the old behavior of using the index directory if
* fts_index_dir is not set. */
} else if (set->index_dir != NULL) {
path = set->index_dir;
} else {
path = set->root_dir;
}
break;
case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
path = set->index_pvt_dir;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/lib-storage/mailbox-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ enum mailbox_list_path_type {
/* Return mailbox list index directory (usually same as
MAILBOX_LIST_PATH_TYPE_INDEX) */
MAILBOX_LIST_PATH_TYPE_LIST_INDEX,
/* Return mailbox fts index directory path */
MAILBOX_LIST_PATH_TYPE_FTS_INDEX,

MAILBOX_LIST_PATH_TYPE_COUNT
};
Expand All @@ -115,6 +117,7 @@ struct mailbox_list_settings {
const char *layout; /* FIXME: shouldn't be here */
const char *root_dir;
const char *index_dir;
const char *fts_index_dir;
const char *index_pvt_dir;
const char *index_cache_dir;
const char *control_dir;
Expand Down
16 changes: 12 additions & 4 deletions src/plugins/fts-flatcurve/fts-backend-flatcurve.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,22 @@ fts_backend_flatcurve_set_mailbox(struct flatcurve_fts_backend *backend,
return -1;
}

if (mailbox_open(box) < 0 ||
mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path) <= 0) {
if (mailbox_open(box) < 0
|| (mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_INDEX) == 0 &&
mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX) == 0)
) {
*error_r = t_strdup_printf("Could not open mailbox: %s: %s",
box->vname,
mailbox_get_last_internal_error(box, NULL));
box->vname,
mailbox_get_last_internal_error(box, NULL));
return -1;
}

if (mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX)) {
mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX, &path);
} else {
mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path);
}

str_append(backend->boxname, box->vname);
str_printfa(backend->db_path, "%s/%s/", path, FTS_FLATCURVE_LABEL);

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/fts/fts-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,9 @@ fts_mailbox_list_created(struct mailbox_list *list)
return;
}

if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_INDEX, &path)) {
/* TODO: Create config item for MAILBOX_LIST_PATH_TYPE... FTS_INDEX||=INDEX */
bool has_fts_index_path = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_FTS_INDEX, &path);
if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_INDEX, &path) && !has_fts_index_path) {
e_debug(list->ns->user->event,
"fts: Indexes disabled for namespace '%s'",
list->ns->prefix);
Expand Down