public void preload(DataStoreIterator iterator) throws DataStoreFatalException, QueueFatalException {
boolean useBackQueue = true;
while (iterator.next()) {
DataStoreIterator.Record record = iterator.getRecord();
CompositeKey key = keyUtil.decode(record.getKey());
// use the transcoder to decode the value
E element = null;
try {
element = transcoder.decode(record.getValue());
//logger.trace("preloaded {}:{}", key, element);
} catch (Throwable t) {
throw new QueueFatalException("Unable to decode element with transcoder for queueId " + getId() + ". Perhaps incorrect transcoder?", t);
}
// assume the first item is the first itemId
if (firstItemId < 0) {
firstItemId = key.getItemId();
} else {
// if this current itemId does not follow the lastItemId
// then this indicates we have a gap and this current itemId
// is really the first itemId
if (key.getItemId() > lastItemId+1) {
// this should only be allowed to happen once, if it happens
// more than once, then this indicates there is a gap of records
// that is incorrect and this means this queue is likely bad
if (!useBackQueue) {
throw new QueueFatalException("Gap of itemIds for queueId=" + getId() + ". Perhaps bad queue?");
}
// the current itemId is actually our first item
firstItemId = key.getItemId();
// start adding things to the "front" queue
useBackQueue = false;
} else if (key.getItemId() < lastItemId+1) {
throw new DataStoreFatalException("ItemId out of order while loading queue itemId=" + key.getItemId() + " < " + (lastItemId+1));
} else {
// key is in the correct order, no issue
}
}
if (useBackQueue) {
backQueue.add(element);
//logger.trace("added {} to backQueue", element);
} else {
frontQueue.add(element);
//logger.trace("added {} to frontQueue", element);
}
// set this lastItemId to the current itemId
lastItemId = key.getItemId();
}
}