assertLoaded();
if (count <= 0) {
throw new IllegalArgumentException("The allocation count must be larger than zero");
}
Sequence seq = freeList.removeFirstSequence(count);
// We may need to create new free pages...
if (seq == null) {
Page<T> first = null;
int c = count;
// Perform the id's only once....
long pageId = nextFreePageId.getAndAdd(count);
long writeTxnId = nextTxid.getAndAdd(count);
while (c-- > 0) {
Page<T> page = new Page<T>(pageId++);
page.makeFree(writeTxnId++);
if (first == null) {
first = page;
}
addToCache(page);
DataByteArrayOutputStream out = new DataByteArrayOutputStream(pageSize);
page.write(out);
write(page, out.getData());
// LOG.debug("allocate writing: "+page.getPageId());
}
return first;
}
Page<T> page = new Page<T>(seq.getFirst());
page.makeFree(0);
// LOG.debug("allocated: "+page.getPageId());
return page;
}