Skip to content

Commit 63b1bd0

Browse files
committedJan 11, 2023
fts: add additional index type to segregate fts indexes from imap indexes
1 parent 51c3f6d commit 63b1bd0

10 files changed

+66
-5
lines changed
 

‎src/doveadm/doveadm-mail-mailbox.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct path_cmd_context {
6363

6464
static const char *mailbox_list_path_type_names[] = {
6565
"dir", "alt-dir", "mailbox", "alt-mailbox",
66-
"control", "index", "index-private", "index-cache", "list-index",
66+
"control", "index", "fts-index", "index-private", "index-cache", "list-index",
6767
};
6868
static_assert_array_size(mailbox_list_path_type_names, MAILBOX_LIST_PATH_TYPE_COUNT);
6969

‎src/lib-storage/index/mbox/mbox-storage.c

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ mbox_list_get_path(struct mailbox_list *list, const char *name,
146146
*path_r = t_strconcat(t_strdup_until(path, p),
147147
"/"MBOX_INDEX_DIR_NAME"/", p+1, NULL);
148148
break;
149+
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
149150
case MAILBOX_LIST_PATH_TYPE_DIR:
150151
case MAILBOX_LIST_PATH_TYPE_ALT_DIR:
151152
case MAILBOX_LIST_PATH_TYPE_MAILBOX:

‎src/lib-storage/list/mailbox-list-fs.c

+8
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ fs_list_get_path(struct mailbox_list *_list, const char *name,
130130
return 1;
131131
}
132132
break;
133+
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
134+
if (set->fts_index_dir != NULL) {
135+
if (*set->fts_index_dir == '\0')
136+
return 0;
137+
*path_r = fs_list_get_path_to(set, set->fts_index_dir, name);
138+
return 1;
139+
}
140+
break;
133141
case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
134142
if (set->index_pvt_dir == NULL)
135143
return 0;

‎src/lib-storage/list/mailbox-list-maildir.c

+9
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ maildir_list_get_path(struct mailbox_list *_list, const char *name,
152152
return 1;
153153
}
154154
break;
155+
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
156+
if (_list->set.fts_index_dir != NULL) {
157+
if (*_list->set.fts_index_dir == '\0')
158+
return 0;
159+
*path_r = maildir_list_get_dirname_path(_list,
160+
_list->set.fts_index_dir, name);
161+
return 1;
162+
}
163+
break;
155164
case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
156165
if (_list->set.index_pvt_dir == NULL)
157166
return 0;

‎src/lib-storage/mail-storage-private.h

+2
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ int mailbox_mark_index_deleted(struct mailbox *box, bool del);
856856
const char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
857857
/* Similar to mailbox_get_path() but for MAILBOX_LIST_PATH_TYPE_INDEX. */
858858
const char *mailbox_get_index_path(struct mailbox *box) ATTR_PURE;
859+
/* Check if mailbox path for type exists. */
860+
int mailbox_path_exists(struct mailbox *box, enum mailbox_list_path_type type);
859861
/* Wrapper to mailbox_list_get_path() */
860862
int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
861863
const char **path_r);

‎src/lib-storage/mail-storage.c

+9
Original file line numberDiff line numberDiff line change
@@ -3008,6 +3008,15 @@ const char *mailbox_get_index_path(struct mailbox *box)
30083008
return box->_index_path;
30093009
}
30103010

3011+
int mailbox_path_exists(struct mailbox *box, enum mailbox_list_path_type type)
3012+
{
3013+
const char *path;
3014+
if (get_path_to(box, type, NULL, &path) < 0)
3015+
return 0;
3016+
3017+
return 1;
3018+
}
3019+
30113020
static void mailbox_get_permissions_if_not_set(struct mailbox *box)
30123021
{
30133022
if (box->_perm.file_create_mode != 0)

‎src/lib-storage/mailbox-list.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns,
210210
}
211211

212212
e_debug(ns->user->event,
213-
"%s: root=%s, index=%s, indexpvt=%s, control=%s, inbox=%s, alt=%s",
213+
"%s: root=%s, index=%s, fts_index=%s, indexpvt=%s, control=%s, inbox=%s, alt=%s",
214214
list->name,
215215
list->set.root_dir == NULL ? "" : list->set.root_dir,
216216
list->set.index_dir == NULL ? "" : list->set.index_dir,
217+
list->set.fts_index_dir == NULL ? "" : list->set.fts_index_dir,
217218
list->set.index_pvt_dir == NULL ? "" : list->set.index_pvt_dir,
218219
list->set.control_dir == NULL ?
219220
"" : list->set.control_dir,
@@ -333,6 +334,8 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data,
333334
dest = &set_r->inbox_path;
334335
else if (strcmp(key, "INDEX") == 0)
335336
dest = &set_r->index_dir;
337+
else if (strcmp(key, "FTS_INDEX") == 0)
338+
dest = &set_r->fts_index_dir;
336339
else if (strcmp(key, "INDEXPVT") == 0)
337340
dest = &set_r->index_pvt_dir;
338341
else if (strcmp(key, "INDEXCACHE") == 0)
@@ -1485,6 +1488,22 @@ bool mailbox_list_set_get_root_path(const struct mailbox_list_settings *set,
14851488
path = set->root_dir;
14861489
}
14871490
break;
1491+
case MAILBOX_LIST_PATH_TYPE_FTS_INDEX:
1492+
if (set->fts_index_dir != NULL) {
1493+
if (set->fts_index_dir[0] == '\0') {
1494+
/* in-memory indexes */
1495+
return 0;
1496+
}
1497+
path = set->fts_index_dir;
1498+
1499+
/* Preserve the old behavior of using the index directory if
1500+
* fts_index_dir is not set. */
1501+
} else if (set->index_dir != NULL) {
1502+
path = set->index_dir;
1503+
} else {
1504+
path = set->root_dir;
1505+
}
1506+
break;
14881507
case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
14891508
path = set->index_pvt_dir;
14901509
break;

‎src/lib-storage/mailbox-list.h

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ enum mailbox_list_path_type {
9595
/* Return mailbox list index directory (usually same as
9696
MAILBOX_LIST_PATH_TYPE_INDEX) */
9797
MAILBOX_LIST_PATH_TYPE_LIST_INDEX,
98+
/* Return mailbox fts index directory path */
99+
MAILBOX_LIST_PATH_TYPE_FTS_INDEX,
98100

99101
MAILBOX_LIST_PATH_TYPE_COUNT
100102
};
@@ -115,6 +117,7 @@ struct mailbox_list_settings {
115117
const char *layout; /* FIXME: shouldn't be here */
116118
const char *root_dir;
117119
const char *index_dir;
120+
const char *fts_index_dir;
118121
const char *index_pvt_dir;
119122
const char *index_cache_dir;
120123
const char *control_dir;

‎src/plugins/fts-flatcurve/fts-backend-flatcurve.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,22 @@ fts_backend_flatcurve_set_mailbox(struct flatcurve_fts_backend *backend,
125125
return -1;
126126
}
127127

128-
if (mailbox_open(box) < 0 ||
129-
mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path) <= 0) {
128+
if (mailbox_open(box) < 0
129+
|| (mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_INDEX) == 0 &&
130+
mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX) == 0)
131+
) {
130132
*error_r = t_strdup_printf("Could not open mailbox: %s: %s",
131133
box->vname,
132134
mailbox_get_last_internal_error(box, NULL));
133135
return -1;
134136
}
135137

138+
if (mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX)) {
139+
mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX, &path);
140+
} else {
141+
mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path);
142+
}
143+
136144
str_append(backend->boxname, box->vname);
137145
str_printfa(backend->db_path, "%s/%s/", path, FTS_FLATCURVE_LABEL);
138146

‎src/plugins/fts/fts-storage.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,9 @@ fts_mailbox_list_created(struct mailbox_list *list)
959959
return;
960960
}
961961

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

0 commit comments

Comments
 (0)