Permalink
Browse files

Add "guess" command to mailestctl(1). Which orders mailestd to

start guessing parent messages again to find the parents which have
appeared after the last guessing.
  • Loading branch information...
yasuoka committed Nov 12, 2018
1 parent a16e766 commit d247c340c684300f3ad5b0408f0f910a22bc20c7
Showing with 104 additions and 5 deletions.
  1. +3 −0 README.md
  2. +4 −0 mailestctl.1
  3. +10 −0 mailestctl.c
  4. +78 −3 mailestd.c
  5. +2 −1 mailestd.h
  6. +5 −1 mailestd_local.h
  7. +1 −0 parser.c
  8. +1 −0 parser.h
@@ -119,6 +119,9 @@ ChangeLog
0.9.25 (not yet)
- Fix links in man pages.
- Add "guess" command to mailestctl(1). Which orders mailestd to
start guessing parent messages again to find the parents which have
appeared after the last guessing.
0.9.24
@@ -120,6 +120,10 @@ is usable for the
The
.Xr mailestd 8
daemon will start automatically if it's not running.
.It Cm guess
Guess parant-id again.
Guessing parent-id might have failed if the parent appears after the guess.
This command is useful for such the situation.
.It Cm suspend
Suspend the indexing.
.It Cm resume
@@ -69,6 +69,7 @@ mailestctl_main(int argc, char *argv[])
struct mailestctl_search search;
struct mailestctl_smew smew;
struct mailestctl_update update;
bool wait_resp = false;
cmd = argv[0];
cmdv[cmdc++] = "mailestd";
@@ -146,6 +147,10 @@ mailestctl_main(int argc, char *argv[])
}
if (write(mailestc_sock, &ctl, sizeof(ctl)) < 0)
err(1, "write");
if (wait_resp)
while ((sz =
read(mailestc_sock, msgbuf, sizeof(msgbuf))) > 0)
fwrite(msgbuf, 1, sz, stdout);
break;
case DEBUGI:
@@ -258,6 +263,11 @@ mailestctl_main(int argc, char *argv[])
err(1, "write");
goto wait_resp;
case GUESS:
ctl.command = MAILESTCTL_CMD_GUESS_AGAIN;
wait_resp = true;
goto do_common;
case NONE:
break;
}
@@ -1533,6 +1533,53 @@ mailestd_search(struct mailestd *_this, uint64_t task_id, const char *searchstr,
}
}
static void
mailestd_db_guess_again(struct mailestd *_this, struct task *task)
{
int *res, i, rnum, num = 0;
ESTCOND *cond;
ESTDOC *doc;
struct rfc822 *msg, msg0;
const char *uri;
char buf[80];
if (!_this->paridguess) {
snprintf(buf, sizeof(buf), "\"guess-parid\" is not enabled.\n");
goto out;
}
if (mailestd_db_open_rd(_this) == NULL) {
snprintf(buf, sizeof(buf), "Opening DB is failed");
goto out;
}
cond = est_cond_new();
est_cond_add_attr(cond, ATTR_PARID " " ESTOPSTREQ " notexist");
res = est_db_search(_this->db, cond, &rnum, NULL);
est_cond_delete(cond);
for (i = 0; i < rnum; i++) {
doc = est_db_get_doc(_this->db, res[i], ESTGDNOKWD);
if (doc == NULL)
continue;
uri = est_doc_attr(doc, ESTDATTRURI);
msg0.path = (char *)URI2PATH(uri);
msg = RB_FIND(rfc822_tree, &_this->root, &msg0);
if (msg != NULL && msg->pariddone) {
msg->pariddone = false;
_this->paridnotdone++;
num++;
}
est_doc_delete(doc);
}
if (num > 0)
snprintf(buf, sizeof(buf),
"Guessing parent is scheduled for %d messages.\n", num);
else
snprintf(buf, sizeof(buf),
"No message which needs to find its parent.\n");
out:
mailestd_schedule_inform(_this, task->id, buf, strlen(buf));
}
static void
mailestd_guess_parid(struct mailestd *_this)
{
@@ -1754,6 +1801,19 @@ mailestd_schedule_smew(struct mailestd *_this, const char *msgid,
return (task_worker_add_task(&_this->dbworker, (struct task *)task));
}
static uint64_t
mailestd_schedule_message_dbworker(struct mailestd *_this,
enum MAILESTD_TASK tsk_type)
{
struct task *task;
task = xcalloc(1, sizeof(struct task));
task->type = tsk_type;
task->highprio = true;
return (task_worker_add_task(&_this->dbworker, (struct task *)task));
}
static uint64_t
mailestd_schedule_inform(struct mailestd *_this, uint64_t task_id,
u_char *inform, size_t informsiz)
@@ -2028,6 +2088,7 @@ task_worker_on_proc(struct task_worker *_this)
case MAILESTD_TASK_RFC822_DELDB:
case MAILESTD_TASK_SEARCH:
case MAILESTD_TASK_SMEW:
case MAILESTD_TASK_GUESS_AGAIN:
MAILESTD_ASSERT(thread_this ==
mailestd->dbworker.thread);
task_worker_on_proc_db(_this, &dbctx, task);
@@ -2164,16 +2225,20 @@ task_worker_on_proc_db(struct task_worker *_this,
mailestd_db_smew(mailestd, (struct task_smew *)task);
break;
case MAILESTD_TASK_GUESS_AGAIN:
mailestd_db_guess_again(mailestd, task);
break;
case MAILESTD_TASK_NONE:
if (ctx->resche)
mailestd_reschedule_draft(mailestd);
if (mailestd->db == NULL || !mailestd->db_wr)
/* Keep the read only db connection */
break;
if (mailestd->paridguess && mailestd->paridnotdone > 0) {
mailestd_guess_parid(mailestd);
mailestd->paridnotdone = 0;
}
if (mailestd->db == NULL || !mailestd->db_wr)
/* Keep the read only db connection */
break;
if (ctx->puts + ctx->dels > 0 &&
est_db_used_cache_size(mailestd->db) > MAILESTD_DBFLUSHSIZ){
/*
@@ -2364,6 +2429,15 @@ mailestc_on_event(int fd, short evmask, void *ctx)
if (_this->monitoring_id == 0)
goto on_error;
break;
case MAILESTCTL_CMD_GUESS_AGAIN:
_this->monitoring_cmd = MAILESTCTL_CMD_GUESS_AGAIN;
_this->monitoring_id =
mailestd_schedule_message_dbworker(mailestd,
MAILESTD_TASK_GUESS_AGAIN);
if (_this->monitoring_id == 0)
goto on_error;
break;
}
}
@@ -2465,6 +2539,7 @@ mailestc_task_inform(struct mailestc *_this, uint64_t task_id, u_char *inform,
break;
case MAILESTCTL_CMD_SMEW:
case MAILESTCTL_CMD_SEARCH:
case MAILESTCTL_CMD_GUESS_AGAIN:
if (informsiz == 0)
mailestc_stop(_this);
else
@@ -32,7 +32,8 @@ enum MAILESTCTL_CMD {
MAILESTCTL_CMD_SUSPEND,
MAILESTCTL_CMD_RESUME,
MAILESTCTL_CMD_SEARCH,
MAILESTCTL_CMD_SMEW
MAILESTCTL_CMD_SMEW,
MAILESTCTL_CMD_GUESS_AGAIN
};
enum MAILESTCTL_OUTFORM {
@@ -130,7 +130,8 @@ enum MAILESTD_TASK {
MAILESTD_TASK_RFC822_PUTDB,
MAILESTD_TASK_RFC822_DELDB,
MAILESTD_TASK_RFC822_GUESS,
MAILESTD_TASK_MONITOR_FOLDER
MAILESTD_TASK_MONITOR_FOLDER,
MAILESTD_TASK_GUESS_AGAIN
};
struct task {
@@ -288,6 +289,7 @@ static void mailestd_putdb(struct mailestd *, struct rfc822 *);
static void mailestd_deldb(struct mailestd *, struct rfc822 *);
static void mailestd_search(struct mailestd *, uint64_t, const char *,
ESTCOND *, enum MAILESTCTL_OUTFORM);
static void mailestd_db_guess_again(struct mailestd *, struct task *);
static void mailestd_guess_parid(struct mailestd *);
static void mailestd_db_informer(const char *, void *);
static void mailestd_db_error(struct mailestd *);
@@ -306,6 +308,8 @@ static uint64_t mailestd_schedule_deldb(struct mailestd *, struct gather *,
struct rfc822 *);
static uint64_t mailestd_schedule_search(struct mailestd *, const char *,
ESTCOND *, enum MAILESTCTL_OUTFORM);
static uint64_t mailestd_schedule_message_dbworker(struct mailestd *,
enum MAILESTD_TASK);
static uint64_t mailestd_schedule_inform(struct mailestd *, uint64_t,
u_char *, size_t);
static void mailestd_schedule_message_all(struct mailestd *,
@@ -71,6 +71,7 @@ static const struct token t_main[] = {
{KEYWORD, "update", UPDATE, t_folder},
{KEYWORD, "suspend", SUSPEND, NULL},
{KEYWORD, "resume", RESUME, NULL},
{KEYWORD, "guess", GUESS, NULL},
{KEYWORD, "debug", DEBUGI, NULL},
{KEYWORD, "-debug", DEBUGD, NULL},
{ENDTOKEN, "", NONE, NULL}
@@ -28,6 +28,7 @@ enum actions {
MESSAGE_ID,
SEARCH_SMEW,
PARENT_ID,
GUESS
};
struct parse_result {

0 comments on commit d247c34

Please sign in to comment.