<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Hi David,</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Thanks for feedback.</div> <br> <div class="bloop_sign" id="bloop_sign_1498861935208306944"></div> More replies inline:<br><p class="airmail_on">On June 27, 2017 at 2:45:56 AM, David Fifield (<a href="mailto:david@bamsoftware.com">david@bamsoftware.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>Currently you can do queries with order_by=test_start_time,<br>order_by=probe_cc, etc., but you cannot do order_by=index.<br><br>https://measurements.ooni.torproject.org/api/v1/files?limit=1&order_by=index<br>{<br>  "error_code": 400, <br>  "error_message": "Invalid order_by"<br>}<br><br>As I understand it, the difference between index and test_start_time is<br>that index is always increasing over time (newly uploaded reports always<br>get a higher index than existing reports), while newly uploaded reports<br>can have a test_start_time that is in the past (if the probe was not<br>able to upload for a time, for example).<br><br></div></div></span></blockquote><div><br></div><div>Yes this is correct and it’s actually something that is not uncommon.</div><br><blockquote type="cite" class="clean_bq"><span><div><div>The ability to order_by=index would allow a slight robustness<br>enhancement in ooni-sync, in the case when a new report is uploaded<br>while ooni-sync is running. Currently ooni-sync always does<br>       order=asc&order_by=test_start_time&limit=1000<br>That is, starting with the oldest reports, get a page of 1000 reports at<br>a time. The issue is what happens when a report from the past is<br>uploaded while ooni-sync is downloading. In this case ooni-sync will not<br>notice the new report right away. Here is an example with made-up<br>indexes and dates:<br>    ooni-sync starts downloading page 0 from index=5000 (2016-01-01) to index=5999 (2016-03-31)<br>   new report with index=9999 (2016-02-01) appears, gets inserted into page 0<br>    ooni-sync finishes downloading page 0<br> ooni-sync starts downloading page 1 from index=5999 (2016-03-31) to index=6998 (2016-04-05)<br>   ooni-sync finishes downloading page 1<br>In this example, ooni-sync never downloads the report with index=9999.<br>Also, it sees index=5999 twice, because index=9999 pushed index=5999<br>from page 0 to page 1.<br><br>An order_by=index option would prevent newly uploaded reports from<br>unaligning the pages like that (at least when order_by=asc is used).<br><br></div></div></span></blockquote><div><br></div><div>I perfectly understand the issue you are talking about and in fact we actually already support order_by=“index”, though it should probably be documented.</div><div><br></div><div>One thing to keep in mind, though, is that while we are ok with guaranteeing that index is an ever-increasing number, it’s not useful as a unique identifier of that report.</div><div><br></div><div>That is to say that we can fairly easily ensure index is always increasing, but it’s much harder to ensure that it maps one to one with reports, so you need to ensure that you are keeping track of whether or not you are already downloaded a particular report (which I believe ooni-sync does).</div><div><br></div><div>One thing to keep in mind is that as we roll-over to the new measurements API we are going to be resetting indexes and we shall start counting again from `max(previous_measurements_api_index)`. This means that when the new ooni-measurements API will be deployed you will say since_index=$last_index_you_say and you will actually get back all measurements since ever.</div><div><br></div><div>Or put differently in the new pipeline all new indexes will be offset by the highest last index that we saw.</div><div><br></div><div>The reason why we are going to have to do this is that otherwise we will have to map the current indexes to the new ones (the new database is backed by the pipeline).</div><div><br></div><div>If you anticipate this creating unexpected issues, please let us know and we can maybe find some other solution.</div><div><br></div><br><div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><span>The reasons why this is minor minor minor and hardly worth mentioning:<br>* index=9999 will get downloaded the next time you run ooni-sync<br>* it can't cause ooni-sync to skip any already uploaded reports (it<br>would, with order=desc, but that's why ooni-sync uses order=asc)<br>* ooni-sync will see but won't actually download index=5999 twice<br>* newly uploaded reports are likely to be on the last page anyway</span></blockquote></div><p>Sounds good, let me know if the existing feature will make ooni-sync work better and if what I said above is going to create issues for you.</p><p>~ Arturo</p><p><br></p></body></html>