Integer keyRangeLength = _findIntParam(request, ClusterMateConstants.HTTP_QUERY_PARAM_KEYRANGE_LENGTH);
if (keyRangeLength == null) {
return (OUT) missingArgument(response, ClusterMateConstants.HTTP_QUERY_PARAM_KEYRANGE_LENGTH);
}
long clusterHash = _findLongParam(request, ClusterMateConstants.HTTP_QUERY_CLUSTER_HASH);
KeyRange range;
try {
range = _keyspace.range(keyRangeStart, keyRangeLength);
} catch (Exception e) {
return (OUT) badRequest(response, "Invalid key-range definition (start '%s', end '%s'): %s",
keyRangeStart, keyRangeLength, e.getMessage());
}
/* 20-Nov-2012, tatu: We can now piggyback auto-registration by sending minimal
* info about caller...
*/
IpAndPort caller = getCallerQueryParam(request);
if (caller != null) {
_cluster.checkMembership(caller, 0L, range);
}
String acceptHeader = request.getHeader(ClusterMateConstants.HTTP_HEADER_ACCEPT);
// what do they request? If not known, serve JSON (assumed to be from browser)
boolean useSmile = (acceptHeader != null)
&& acceptHeader.trim().indexOf(ClusterMateConstants.CONTENT_TYPE_SMILE) >= 0;
long currentTime = _timeMaster.currentTimeMillis();
final long upUntil = currentTime - _cfgSyncGracePeriod.getMillis();
AtomicLong timestamp = new AtomicLong(0L);
long since = (sinceL == null) ? 0L : sinceL.longValue();
/* One more thing: let's sanity check that our key range overlaps request
* range. If not, can avoid (possibly huge) database scan.
*/
NodeState localState = _cluster.getLocalState();
List<E> entries;
KeyRange localRange = localState.totalRange();
if (localRange.overlapsWith(range)) {
entries = _listEntries(range, since, upUntil, _maxToListPerRequest, timestamp);
/*
System.err.println("Sync for "+_localState.getRangeActive()+" (slice of "+range+"); between "+sinceL+" and "+upUntil+", got "+entries.size()+"/"
+_stores.getEntryStore().getEntryCount()+" entries... (time: "+_timeMaster.currentTimeMillis()+")");
*/