This is an automated email from the ASF dual-hosted git repository.

shinrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 33bbe34  Ensure queued HostDB requests get rescheduled back to the 
original thread.
33bbe34 is described below

commit 33bbe3432a1a58ff526fe097424c17514d431b3c
Author: Susan Hinrichs <[email protected]>
AuthorDate: Tue Mar 5 17:51:31 2019 +0000

    Ensure queued HostDB requests get rescheduled back to the original thread.
---
 iocore/cache/CacheWrite.cc     | 10 ++--------
 iocore/cache/P_CacheInternal.h |  3 +--
 iocore/hostdb/HostDB.cc        | 12 ++++++++++--
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc
index 178ec08..48d16cb 100644
--- a/iocore/cache/CacheWrite.cc
+++ b/iocore/cache/CacheWrite.cc
@@ -358,7 +358,7 @@ Vol::aggWriteDone(int event, Event *e)
   CacheVC *c = nullptr;
   while ((c = sync.dequeue())) {
     if (UINT_WRAP_LTE(c->write_serial + 2, header->write_serial)) {
-      c->initial_thread->schedule_imm_signal(c, AIO_EVENT_DONE);
+      eventProcessor.schedule_imm_signal(c, ET_CALL, AIO_EVENT_DONE);
     } else {
       sync.push(c); // put it back on the front
       break;
@@ -1019,11 +1019,7 @@ Lagain:
       ink_assert(false);
       while ((c = agg.dequeue())) {
         agg_todo_size -= c->agg_len;
-        if (c->initial_thread != nullptr) {
-          c->initial_thread->schedule_imm_signal(c, AIO_EVENT_DONE);
-        } else {
-          eventProcessor.schedule_imm_signal(c, ET_CALL, AIO_EVENT_DONE);
-        }
+        eventProcessor.schedule_imm_signal(c, ET_CALL, AIO_EVENT_DONE);
       }
       return EVENT_CONT;
     }
@@ -1086,8 +1082,6 @@ Lwait:
   while ((c = tocall.dequeue())) {
     if (event == EVENT_CALL && c->mutex->thread_holding == 
mutex->thread_holding) {
       ret = EVENT_RETURN;
-    } else if (c->initial_thread != nullptr) {
-      c->initial_thread->schedule_imm_signal(c, AIO_EVENT_DONE);
     } else {
       eventProcessor.schedule_imm_signal(c, ET_CALL, AIO_EVENT_DONE);
     }
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index d82aa34..8ed8475 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -440,7 +440,6 @@ struct CacheVC : public CacheVConnection {
   // NOTE: NOTE: NOTE: If vio is NOT the start, then CHANGE the
   // size_to_init initialization
   VIO vio;
-  EThread *initial_thread; // initial thread open_XX was called on
   CacheFragType frag_type;
   CacheHTTPInfo *info;
   CacheHTTPInfoVector *write_vector;
@@ -549,9 +548,9 @@ new_CacheVC(Continuation *cont)
   CacheVC *c          = THREAD_ALLOC(cacheVConnectionAllocator, t);
   c->vector.data.data = &c->vector.data.fast_data[0];
   c->_action          = cont;
-  c->initial_thread   = t->tt == DEDICATED ? nullptr : t;
   c->mutex            = cont->mutex;
   c->start_time       = Thread::get_hrtime();
+  c->setThreadAffinity(t);
   ink_assert(c->trigger == nullptr);
   Debug("cache_new", "new %p", c);
 #ifdef CACHE_STAT_PAGES
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 73c8014..ed7ba5f 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -1578,7 +1578,8 @@ int
 HostDBContinuation::set_check_pending_dns()
 {
   Queue<HostDBContinuation> &q = hostDB.pending_dns_for_hash(hash.hash);
-  HostDBContinuation *c        = q.head;
+  this->setThreadAffinity(this_ethread());
+  HostDBContinuation *c = q.head;
   for (; c; c = (HostDBContinuation *)c->link.next) {
     if (hash.hash == c->hash.hash) {
       Debug("hostdb", "enqueuing additional request");
@@ -1606,8 +1607,15 @@ HostDBContinuation::remove_trigger_pending_dns()
     }
     c = n;
   }
+  EThread *thread = this_ethread();
   while ((c = qq.dequeue())) {
-    c->handleEvent(EVENT_IMMEDIATE, nullptr);
+    // resume all queued HostDBCont in the thread associated with the netvc to 
avoid nethandler locking issues.
+    EThread *affinity_thread = c->getThreadAffinity();
+    if (!affinity_thread || affinity_thread == thread) {
+      c->handleEvent(EVENT_IMMEDIATE, nullptr);
+    } else {
+      eventProcessor.schedule_imm(c);
+    }
   }
 }
 

Reply via email to