<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12054] CalendarServer/trunk/twext/application/masterchild.py</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12054">12054</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2013-12-12 10:00:01 -0800 (Thu, 12 Dec 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Get rid of restarted() on ChildStatus, also thge abandoned attribute.
When we get a "0" message, log a critical error is things are not as expected.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwextapplicationmasterchildpy">CalendarServer/trunk/twext/application/masterchild.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwextapplicationmasterchildpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twext/application/masterchild.py (12053 => 12054)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twext/application/masterchild.py        2013-12-12 17:57:30 UTC (rev 12053)
+++ CalendarServer/trunk/twext/application/masterchild.py        2013-12-12 18:00:01 UTC (rev 12054)
</span><span class="lines">@@ -59,10 +59,8 @@
</span><span class="cx"> from twext.internet.sendfdport import IStatusWatcher
</span><span class="cx"> from twext.internet.sendfdport import InheritedPort
</span><span class="cx">
</span><del>-log = Logger()
</del><span class="cx">
</span><span class="cx">
</span><del>-
</del><span class="cx"> class MasterOptions(Options):
</span><span class="cx"> """
</span><span class="cx"> Options for a master process.
</span><span class="lines">@@ -200,22 +198,16 @@
</span><span class="cx">
</span><span class="cx"> @staticmethod
</span><span class="cx"> def initialStatus():
</span><del>- log.info("Status: init")
-
</del><span class="cx"> return ChildStatus()
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @staticmethod
</span><span class="cx"> def newConnectionStatus(previousStatus):
</span><del>- log.info("Status: {0} new".format(previousStatus))
-
</del><span class="cx"> return previousStatus + ChildStatus(unacknowledged=1)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @staticmethod
</span><span class="cx"> def statusFromMessage(previousStatus, message):
</span><del>- log.info("Status: {0} {1!r}".format(previousStatus, message))
-
</del><span class="cx"> if message == "-":
</span><span class="cx"> # A connection has gone away in a subprocess; we should start
</span><span class="cx"> # accepting connections again if we paused (see
</span><span class="lines">@@ -229,8 +221,27 @@
</span><span class="cx"> # way of knowing whether the acknowledged connections were acted
</span><span class="cx"> # upon or dropped, so we have to treat that number with a healthy
</span><span class="cx"> # amount of skepticism.)
</span><del>- return previousStatus.restarted()
</del><span class="cx">
</span><ins>+ # Do some sanity checks... no attempt to fix, but log critically
+ # if there are unexpected connection counts, as that means we
+ # don't know what's going on with our connection management.
+
+ def checkForWeirdness(what, expected):
+ n = getattr(previousStatus, what)
+ if n != expected:
+ # Upgrade to critical when logging is updated
+ MasterService.log.critical(
+ "New process has {count} {type} connections, "
+ "expected {expected}."
+ .format(count=n, type=what, expected=expected)
+ )
+
+ checkForWeirdness("acknowledged", 0)
+ checkForWeirdness("unacknowledged", 1)
+ checkForWeirdness("unclosed", 1)
+
+ return previousStatus
+
</ins><span class="cx"> elif message == "+":
</span><span class="cx"> # Acknowledges that the subprocess has taken on the work.
</span><span class="cx"> return (
</span><span class="lines">@@ -244,8 +255,6 @@
</span><span class="cx">
</span><span class="cx"> @staticmethod
</span><span class="cx"> def closeCountFromStatus(previousStatus):
</span><del>- log.info("Status: {0} close".format(previousStatus))
-
</del><span class="cx"> toClose = previousStatus.unclosed
</span><span class="cx"> return (toClose, previousStatus - ChildStatus(unclosed=toClose))
</span><span class="cx">
</span><span class="lines">@@ -542,7 +551,10 @@
</span><span class="cx"> def stopService(self):
</span><span class="cx"> factory = self.wrappedProtocolFactory
</span><span class="cx">
</span><ins>+ # Halt connection inflow
</ins><span class="cx"> factory.inheritedPort.stopReading()
</span><ins>+
+ # Wait for existing connections to close
</ins><span class="cx"> factory.allConnectionsClosed()
</span><span class="cx">
</span><span class="cx"> return super(ChildService, self).stopService()
</span><span class="lines">@@ -573,7 +585,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def connectionLost(self, reason):
</span><del>- self.log.info("CONNECTION LOST")
</del><span class="cx"> self.factory.inheritedPort.reportStatus("-")
</span><span class="cx"> return super(ReportingProtocolWrapper, self).connectionLost(reason)
</span><span class="cx">
</span><span class="lines">@@ -595,20 +606,24 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> showAttributes = (
</span><ins>+ "started",
</ins><span class="cx"> "acknowledged",
</span><span class="cx"> "unacknowledged",
</span><del>- "started",
- "abandoned",
</del><span class="cx"> "unclosed",
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def __init__(self, acknowledged=0, unacknowledged=0, started=0,
- abandoned=0, unclosed=0):
</del><ins>+ def __init__(
+ self, started=0,
+ acknowledged=0, unacknowledged=0,
+ abandoned=0, unclosed=0
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Create a L{ConnectionStatus} with a number of sent connections and a
</span><span class="cx"> number of un-acknowledged connections.
</span><span class="cx">
</span><ins>+ @param started: The number of times this worker has been started.
+
</ins><span class="cx"> @param acknowledged: the number of connections which we know the
</span><span class="cx"> subprocess to be presently processing; i.e. those which have been
</span><span class="cx"> transmitted to the subprocess.
</span><span class="lines">@@ -617,19 +632,12 @@
</span><span class="cx"> the subprocess which have never received a status response (a
</span><span class="cx"> "C{+}" status message).
</span><span class="cx">
</span><del>- @param abandoned: The number of connections which have been sent to
- this worker, but were not acknowledged at the moment that the
- worker restarted.
-
- @param started: The number of times this worker has been started.
-
</del><span class="cx"> @param unclosed: The number of sockets which have been sent to the
</span><span class="cx"> subprocess but not yet closed.
</span><span class="cx"> """
</span><ins>+ self.started = started
</ins><span class="cx"> self.acknowledged = acknowledged
</span><span class="cx"> self.unacknowledged = unacknowledged
</span><del>- self.started = started
- self.abandoned = abandoned
</del><span class="cx"> self.unclosed = unclosed
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -640,14 +648,6 @@
</span><span class="cx"> return self.acknowledged + self.unacknowledged
</span><span class="cx">
</span><span class="cx">
</span><del>- def restarted(self):
- """
- The L{ChildStatus} derived from the current status of a process and
- the fact that it just restarted.
- """
- return self.__class__(0, 0, self.started + 1, self.unacknowledged)
-
-
</del><span class="cx"> def _tuplify(self):
</span><span class="cx"> return tuple(getattr(self, attr) for attr in self.showAttributes)
</span><span class="cx">
</span><span class="lines">@@ -681,8 +681,4 @@
</span><span class="cx"> if not isinstance(other, ChildStatus):
</span><span class="cx"> return NotImplemented
</span><span class="cx">
</span><del>- a = self._tuplify()
- b = other._tuplify()
- difference = [a1 - b1 for (a1, b1) in zip(a, b)]
-
- return self + self.__class__(*difference)
</del><ins>+ return self + self.__class__(*[-x for x in other._tuplify()])
</ins></span></pre>
</div>
</div>
</body>
</html>