return true;
}
@Override
protected PriorityMQMessage<E> doTake() throws QueueInvalidStateException, QueueFatalException, QueueTimeoutException, DataStoreFatalException {
DataStoreIterator iterator = ds.getAscendingIterator();
boolean jumped = iterator.jump(priorityKeyUtil.encode(getId(), 0L));
if (!jumped) logger.warn("DataStoreIterator failed to jump to queue's first record {} {}", getId(), 0L);
// if (!jumped) something is wrong, we should zero the size and exit
try {
DataStoreIterator.Record record = iterator.getRecord();
CompositeKey key = priorityKeyUtil.decode(record.getKey());
PriorityMQMessage.Key pkey = new PriorityMQMessage.Key(key.getItemId());
if (key.getQueueId() != getId()) {
logger.error("{} != {}: {} for queue {}", key.getQueueId(), getId(), pkey, this);
throw new DataStoreFatalException("The next item wasn't for this queueId");
}
if (DEBUG) {
logger.trace("doTake[{}]: {}", getId(), pkey);
trxLog.offer(pkey.toCompactString("TAKE:"));
}
return priorityTranscoder.decode(record.getValue());
} catch (DataStoreFatalException e) {
logger.error("Unable to get record from datastore for {}", this);
dumpTrxLog();
if (size.get() != 0) {
logger.warn("This is dangerous, but we're going to zero the queue size.");
size.set(0);
}
this.errorCount.incrementAndGet();
throw e;
} finally {
iterator.close();
}
}