commit 7314596e198da7581eed449c80d688195b1ed5df Author: Karsten Loesing karsten.loesing@gmx.net Date: Fri Jan 13 08:36:18 2012 +0100
Tell users when we don't have enough data to answer their request.
Fixes #4895. --- .../torproject/ernie/web/RelaySearchServlet.java | 35 ++++++++++++++++++++ web/WEB-INF/relay-search.jsp | 3 ++ 2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/src/org/torproject/ernie/web/RelaySearchServlet.java b/src/org/torproject/ernie/web/RelaySearchServlet.java index 512e25f..fe7e62b 100644 --- a/src/org/torproject/ernie/web/RelaySearchServlet.java +++ b/src/org/torproject/ernie/web/RelaySearchServlet.java @@ -52,6 +52,8 @@ public class RelaySearchServlet extends HttpServlet { private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ private long minValidAfterMillis; + private DataSource ds;
private Logger logger; @@ -74,6 +76,27 @@ public class RelaySearchServlet extends HttpServlet { } catch (NamingException e) { this.logger.log(Level.WARNING, "Could not look up data source", e); } + + /* Look up first consensus in the database. */ + try { + long requestedConnection = System.currentTimeMillis(); + Connection conn = this.ds.getConnection(); + String query = "SELECT MIN(validafter) AS first FROM consensus"; + Statement statement = conn.createStatement(); + ResultSet rs = statement.executeQuery(query); + if (rs.next()) { + this.minValidAfterMillis = rs.getTimestamp(1).getTime(); + } + rs.close(); + statement.close(); + conn.close(); + this.logger.info("Returned a database connection to the pool " + + "after " + (System.currentTimeMillis() + - requestedConnection) + " millis."); + } catch (SQLException e) { + this.logger.log(Level.WARNING, "Could not look up first consensus " + + "valid-after time in the database.", e); + } }
public void doGet(HttpServletRequest request, @@ -304,6 +327,12 @@ public class RelaySearchServlet extends HttpServlet { boolean addOr = false; timeIntervalBuilder.append("AND ("); for (long searchTimestamp : searchDayTimestamps) { + if (searchTimestamp < this.minValidAfterMillis) { + request.setAttribute("outsideInterval", "Returned search " + + "results may be incomplete, as our data only dates back " + + "to " + dateTimeFormat.format(this.minValidAfterMillis) + + ". Older archives are not available."); + } timeIntervalBuilder.append((addOr ? "OR " : "") + "(validafter >= '" + dateTimeFormat.format(searchTimestamp) + "' AND " @@ -312,6 +341,12 @@ public class RelaySearchServlet extends HttpServlet { addOr = true; } for (long searchTimestamp : searchMonthTimestamps) { + if (searchTimestamp < this.minValidAfterMillis) { + request.setAttribute("outsideInterval", "Returned search " + + "results may be incomplete, as our data only dates back " + + "to " + dateTimeFormat.format(this.minValidAfterMillis) + + ". Older archives are not available."); + } Calendar firstOfNextMonth = Calendar.getInstance( TimeZone.getTimeZone("UTC")); firstOfNextMonth.setTimeInMillis(searchTimestamp); diff --git a/web/WEB-INF/relay-search.jsp b/web/WEB-INF/relay-search.jsp index 260b7dc..b90938a 100644 --- a/web/WEB-INF/relay-search.jsp +++ b/web/WEB-INF/relay-search.jsp @@ -39,6 +39,9 @@ (e.g., "80.190"). You can also provide at most three months or days in ISO 8601 format (e.g., "2010-09" or "2010-09-17").</p> </c:if> + <c:if test="${not empty outsideInterval}"> + <p>${outsideInterval}</p> + </c:if> <c:if test="${not empty searchNotice}"> <p>${searchNotice}</p> </c:if>
tor-commits@lists.torproject.org