Browse Source

logging: scope member file polling and worker traces to media

master
evgeny 5 days ago
parent
commit
e85a8c8310
  1. 8
      src/member_files/member_files.c
  2. 14
      src/member_files/worker.c

8
src/member_files/member_files.c

@ -104,7 +104,7 @@ static void mf_local_deliver(void* arg) {
int member_files_member(struct UTUN_INSTANCE* inst, uint64_t group, uint64_t node, int storage) { int member_files_member(struct UTUN_INSTANCE* inst, uint64_t group, uint64_t node, int storage) {
struct TOPO_GROUP* g = inst && inst->topo_groups ? topo_groups_find(inst->topo_groups, group) : NULL; struct TOPO_GROUP* g = inst && inst->topo_groups ? topo_groups_find(inst->topo_groups, group) : NULL;
if (!g || g->group_type != TOPO_GROUP_TYPE_CHAT || !node || !inst->topo_sqlite_db) { if (!g || g->group_type != TOPO_GROUP_TYPE_CHAT || !node || !inst->topo_sqlite_db) {
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "member_files: ACL missing CHAT group=%llu node=%llu role=%d", DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: ACL missing CHAT group=%llu node=%llu require_storage=%d",
(unsigned long long)group, (unsigned long long)node, storage); return 0; (unsigned long long)group, (unsigned long long)node, storage); return 0;
} }
char sql[256]; char sql[256];
@ -121,11 +121,13 @@ int member_files_member(struct UTUN_INSTANCE* inst, uint64_t group, uint64_t nod
int storage_role = tags && json_flat_get(tags, "storage", role, sizeof(role)) == 0 && !strcmp(role, "yes"); int storage_role = tags && json_flat_get(tags, "storage", role, sizeof(role)) == 0 && !strcmp(role, "yes");
int allowed = rc == SQLITE_ROW && !sqlite3_column_int(st, 1) && !sqlite3_column_int(st, 3) && int allowed = rc == SQLITE_ROW && !sqlite3_column_int(st, 1) && !sqlite3_column_int(st, 3) &&
(!storage || (storage_role && sqlite3_column_bytes(st, 2) == 64)); (!storage || (storage_role && sqlite3_column_bytes(st, 2) == 64));
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, DEBUG_TRACE(DEBUG_CATEGORY_MEDIA,
"member_files: ACL allowed=%d group=%llu node=%llu require_storage=%d row=%d storage=%d source=%d signature=%d deleted=%d", "member_files: ACL allowed=%d group=%llu node=%llu require_storage=%d row=%d storage=%d source=%d signature=%d deleted=%d",
allowed, (unsigned long long)group, (unsigned long long)node, storage, rc == SQLITE_ROW, allowed, (unsigned long long)group, (unsigned long long)node, storage, rc == SQLITE_ROW,
storage_role, sqlite3_column_int(st, 1), sqlite3_column_bytes(st, 2), sqlite3_column_int(st, 3)); storage_role, sqlite3_column_int(st, 1), sqlite3_column_bytes(st, 2), sqlite3_column_int(st, 3));
if (rc != SQLITE_ROW && rc != SQLITE_DONE) DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "member_files: membership step failed rc=%d", rc); if (rc != SQLITE_ROW && rc != SQLITE_DONE) DEBUG_ERROR(DEBUG_CATEGORY_MEDIA,
"member_files: access check failed group=%llu node=%llu require_storage=%d sqlite_rc=%d: %s",
(unsigned long long)group, (unsigned long long)node, storage, rc, sqlite3_errmsg(inst->topo_sqlite_db));
sqlite3_finalize(st); return allowed; sqlite3_finalize(st); return allowed;
} }

14
src/member_files/worker.c

@ -34,7 +34,7 @@ static void work_finish(struct mf_work* j) {
while (*link && *link != j) link = &(*link)->next; while (*link && *link != j) link = &(*link)->next;
if (*link) *link = j->next; if (*link) *link = j->next;
w->count--; w->count--;
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker callback owner=%p task=%p remaining=%u pid=%ld", DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker callback owner=%p task=%p remaining=%u pid=%ld",
(void*)w, (void*)j, w->count, (long)getpid()); (void*)w, (void*)j, w->count, (long)getpid());
mf_done_fn done = j->done; void* arg = j->arg; mf_done_fn done = j->done; void* arg = j->arg;
u_free(j); done(arg, 0); u_free(j); done(arg, 0);
@ -57,11 +57,11 @@ static void* disk_thread(void* arg) {
struct mf_work* j = w->queue; w->queue = j->queued_next; struct mf_work* j = w->queue; w->queue = j->queued_next;
if (!w->queue) w->tail = NULL; if (!w->queue) w->tail = NULL;
pthread_mutex_unlock(&w->mutex); pthread_mutex_unlock(&w->mutex);
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker execute owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid()); DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker execute owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid());
j->work(j->data); j->work(j->data);
pthread_mutex_lock(&w->mutex); pthread_mutex_lock(&w->mutex);
j->completed = 1; j->completed = 1;
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker posting owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid()); DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker posting owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid());
uasync_post_reserved(w->ua, j->completion); uasync_post_reserved(w->ua, j->completion);
pthread_cond_broadcast(&w->condition); pthread_cond_broadcast(&w->condition);
} }
@ -85,7 +85,7 @@ struct mf_worker* mf_worker_create(struct UASYNC* ua) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "member_files: disk thread failed rc=%d", rc); DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "member_files: disk thread failed rc=%d", rc);
pthread_cond_destroy(&w->condition); pthread_mutex_destroy(&w->mutex); u_free(w); return NULL; pthread_cond_destroy(&w->condition); pthread_mutex_destroy(&w->mutex); u_free(w); return NULL;
} }
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "member_files: worker created owner=%p pid=%ld ua=%p limit=64", DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "member_files: worker created owner=%p pid=%ld ua=%p limit=64",
(void*)w, w->creator_pid, (void*)ua); (void*)w, w->creator_pid, (void*)ua);
DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "member_files: disk thread started queue_limit=64"); return w; DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "member_files: disk thread started queue_limit=64"); return w;
} }
@ -102,12 +102,12 @@ void mf_worker_unreserve(struct mf_work* j) { if (j) { u_free(j->completion); u_
void mf_worker_submit_reserved(struct mf_worker* w, struct mf_work* j, void mf_worker_submit_reserved(struct mf_worker* w, struct mf_work* j,
mf_work_fn work, void* data, mf_done_fn done, void* arg) { mf_work_fn work, void* data, mf_done_fn done, void* arg) {
if (w->creator_pid != (long)getpid()) DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, if (w->creator_pid != (long)getpid()) DEBUG_ERROR(DEBUG_CATEGORY_MEDIA,
"member_files: worker inherited after fork creator_pid=%ld current_pid=%ld; disk thread is missing", "member_files: worker inherited after fork creator_pid=%ld current_pid=%ld; disk thread is missing",
w->creator_pid, (long)getpid()); w->creator_pid, (long)getpid());
j->owner = w; j->work = work; j->data = data; j->done = done; j->arg = arg; j->owner = w; j->work = work; j->data = data; j->done = done; j->arg = arg;
j->next = w->jobs; w->jobs = j; w->count++; j->next = w->jobs; w->jobs = j; w->count++;
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker queued owner=%p task=%p current_pid=%ld creator_pid=%ld active=%u", DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker queued owner=%p task=%p current_pid=%ld creator_pid=%ld active=%u",
(void*)w, (void*)j, (long)getpid(), w->creator_pid, w->count); (void*)w, (void*)j, (long)getpid(), w->creator_pid, w->count);
pthread_mutex_lock(&w->mutex); pthread_mutex_lock(&w->mutex);
if (w->tail) w->tail->queued_next = j; if (w->tail) w->tail->queued_next = j;
@ -137,7 +137,7 @@ void mf_worker_drain(struct mf_worker* w) {
void mf_worker_destroy(struct mf_worker* w) { void mf_worker_destroy(struct mf_worker* w) {
if (!w) return; if (!w) return;
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "member_files: worker stop owner=%p current_pid=%ld creator_pid=%ld active=%u", DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "member_files: worker stop owner=%p current_pid=%ld creator_pid=%ld active=%u",
(void*)w, (long)getpid(), w->creator_pid, w->count); (void*)w, (long)getpid(), w->creator_pid, w->count);
mf_worker_drain(w); mf_worker_drain(w);
pthread_mutex_lock(&w->mutex); w->stopping = 1; pthread_cond_signal(&w->condition); pthread_mutex_unlock(&w->mutex); pthread_mutex_lock(&w->mutex); w->stopping = 1; pthread_cond_signal(&w->condition); pthread_mutex_unlock(&w->mutex);

Loading…
Cancel
Save