synchronized void load(Transaction tx) throws IOException { if (loaded.compareAndSet(false, true)) { page = tx.load(pageId, null); if (page.getType() == Page.PAGE_FREE_TYPE) { page.set(null); tx.store(page, messageStoreStatisticsMarshaller, true); } } page = tx.load(pageId, messageStoreStatisticsMarshaller); }
public Transaction tx() { assertLoaded(); return new Transaction(this); }
/** * Frees up a previously allocated page so that it can be re-allocated again. * * @param pageId the page to free up * @throws IOException * If an disk error occurred. * @throws IllegalStateException * if the PageFile is not loaded */ public void free(long pageId) throws IOException { free(load(pageId, null)); }
/** * Configures the page size used by the page file. By default it is 4k. Once a page file is created on disk, * subsequent loads of that file will use the original pageSize. Once the PageFile is loaded, this setting * can no longer be changed. * * @param pageSize the pageSize to set * @throws IllegalStateException once the page file is loaded. */ public void setPageSize(int pageSize) throws IllegalStateException { assertNotLoaded(); this.pageSize = pageSize; }
/** * Allocates a free page that you can write data to. * * @return a newly allocated page. * @throws IOException * If an disk error occurred. * @throws IllegalStateException * if the PageFile is not loaded */ public <T> Page<T> allocate() throws IOException { return allocate(1); }
private long getWriteTransactionId() { if( writeTransactionId==-1 ) { writeTransactionId = pageFile.getNextWriteTransactionId(); } return writeTransactionId; }
/** * Allows you to iterate through all active Pages in this object. Pages with type Page.FREE_TYPE are * not included in this iteration. * * Pages removed with Iterator.remove() will not actually get removed until the transaction commits. * * @throws IllegalStateException * if the PageFile is not loaded */ public Iterator<Page> iterator() { return (Iterator<Page>)iterator(false); }
/** * @param pageCacheSize Sets the maximum number of pages that will get stored in the read page cache. */ public void setPageCacheSize(int pageCacheSize) { assertNotLoaded(); this.pageCacheSize = pageCacheSize; }
private Location findMessageLocation(final String key, final KahaDestination destination) throws IOException { return pageFile.tx().execute(new Transaction.CallableClosure<Location, IOException>() { @Override public Location execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(destination, tx); Long sequence = sd.messageIdIndex.get(tx, key); if (sequence == null) { return null; } return sd.orderIndex.get(tx, sequence).location; } }); }
/** * Sets if the recovery buffer uses to double buffer page writes. Enabled by default. Disabling this * may potentially cause partial page writes which can lead to page file corruption. */ public void setEnableRecoveryFile(boolean doubleBuffer) { assertNotLoaded(); this.enableRecoveryFile = doubleBuffer; }
@Override public void recover(final MessageRecoveryListener listener) throws Exception { synchronized(indexMutex) { pageFile.tx().execute(new Transaction.Closure<Exception>(){ @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); for (Iterator<Entry<Long, MessageRecord>> iterator = sd.orderIndex.iterator(tx); iterator.hasNext();) { Entry<Long, MessageRecord> entry = iterator.next(); listener.recoverMessage( (Message) wireFormat.unmarshal(entry.getValue().data) ); } } }); } }