}
readInProgress = true;
}
try {
final ElapsedTimer timer = new ElapsedTimer();
timer.startInterval();
Map<String, SortedMap<Long, Map<String, String>>> returnedData = partitionDataBuffer.getData(feedRequestContexts.keySet(), timeUnit, startTime, endTime);
PERF_READ_LOGGER.debug("Get Regular Data feeds: {} from partition: {}", returnedData, partitionDataBuffer.getBufferEnv().getCurrentBufferPartition());
for (Iterator<Entry<String, FeedRequestContext>> it = feedRequestContexts.entrySet().iterator(); it.hasNext(); ) {
Entry<String, FeedRequestContext> entry = it.next();
String feedID = entry.getKey();
SortedMap<Long, Map<String, String>> data = returnedData.get(feedID);
boolean needPrevPoint = true;
if (data != null && !data.isEmpty()) {
long firstPointTS = data.firstKey();
needPrevPoint = firstPointTS > TimeUnit.NANOSECONDS.convert(startTime, timeUnit);
}
if (!entry.getValue().getLastDataIfNeeded || !needPrevPoint) {
it.remove();
}
}
if (!feedRequestContexts.isEmpty()) {
Set<String> feedIDs = feedRequestContexts.keySet();
Map<String, SortedMap<Long, Map<String, String>>> lastData = partitionDataBuffer.getLastData(feedIDs,
timeUnit, 0, startTime);
for (Entry<String, SortedMap<Long, Map<String, String>>> entry : lastData.entrySet()) {
String feedID = entry.getKey();
SortedMap<Long, Map<String, String>> data = entry.getValue();
if (data != null && !data.isEmpty()) {
SortedMap<Long, Map<String, String>> feedData = returnedData.get(feedID);
if (feedData == null) {
feedData = new TreeMap<Long, Map<String, String>>();
returnedData.put(feedID, feedData);
}
Long ts = data.firstKey();
feedData.put(ts, data.get(ts));
}
}
PERF_READ_LOGGER.debug("Get Last Data feeds: {} from partition: {} ", returnedData, partitionDataBuffer.getBufferEnv().getCurrentBufferPartition());
}
timer.stopInterval();
LOGGER.debug("time to get Data for feeds {}: {}", feedRequestContexts, timer.getIntervalInMillis());
return returnedData;
} finally {
synchronized (movePartitionLock) {
readInProgress = false;
movePartitionLock.notifyAll();