if (newUserExtent < getNextOffset() ) { if(newUserExtent == getUserExtent()) { createBackingFile(); getRandomAccessFile().setLength(newExtent); force(true); log.info(getCounters().toString());
/** * {@link #flushWriteCache() flushes} the {@link #writeCache} before syncing * the disk. */ public void force(final boolean metadata) { assertOpen(); synchronized(this) { // flush all pending writes to disk. flushWriteCache(); } try { if(!temporaryStore) { // sync the disk. getChannel().force(metadata); } } catch (IOException ex) { throw new RuntimeException(ex); } storeCounters.nforce++; }
/** * Verify normal operation and basic assumptions when creating a new journal * using {@link BufferMode#Disk}. * * @throws IOException */ public void test_create_disk01() throws IOException { final Properties properties = getProperties(); final Journal journal = new Journal(properties); try { final DiskOnlyStrategy bufferStrategy = (DiskOnlyStrategy) journal .getBufferStrategy(); assertTrue("isStable", bufferStrategy.isStable()); assertFalse("isFullyBuffered", bufferStrategy.isFullyBuffered()); // assertEquals(Options.FILE, properties.getProperty(Options.FILE), // bufferStrategy.file.toString()); assertEquals(Options.INITIAL_EXTENT, Long .parseLong(Options.DEFAULT_INITIAL_EXTENT), bufferStrategy .getInitialExtent()); assertEquals(Options.MAXIMUM_EXTENT, 0L/* soft limit for disk mode */, bufferStrategy .getMaximumExtent()); assertNotNull("raf", bufferStrategy.getRandomAccessFile()); assertEquals(Options.BUFFER_MODE, BufferMode.Disk, bufferStrategy .getBufferMode()); } finally { journal.destroy(); } }
throw new IllegalArgumentException(ERR_BUFFER_NULL); if (isReadOnly()) throw new IllegalStateException(ERR_READ_ONLY); addr = allocate(nbytes); final long offset = getOffset(addr); flushWriteCache(); writeOnDisk(data, offset, true/*append*/); writeOnDisk(data,offset, true/*append*/);
createBackingFile(); overflow(offset, nbytes); storeCounters.ndiskWrite += FileChannelUtility.writeAll(getChannel(), data, pos);
/** * Note: This MAY be <code>null</code>. If {@link BufferMode#Temporary} * is used then it WILL be <code>null</code> until the {@link #writeCache} * is flushed to disk for the first time. */ final public FileChannel getChannel() { final RandomAccessFile raf = getRandomAccessFile(); if (raf == null) return null; return raf.getChannel(); }
FileChannelUtility.writeAll(getChannel(), data, pos); force(forceOnCommit == ForceEnum.ForceMetadata);
throw new IllegalArgumentException(ERR_ADDRESS_IS_NULL); final long offset = getOffset(addr); final int nbytes = getByteCount(addr);
synchronized public long transferTo(final RandomAccessFile out) throws IOException { if (out == null) throw new IllegalArgumentException(); /* * Note: Force the write cache to the disk so that all the data we want * to transfer from channel to channel are actually on the source * channel! * * Note: This also handles the case for a Temporary store where the * backing file has not even been created yet. */ flushWriteCache(); return super.transferFromDiskTo(this, out); }
buf = new DiskOnlyStrategy(maximumExtent, //
@Override final public void force(boolean metadata) { buf.force(metadata); }
/** * Verify normal operation and basic assumptions when creating a new journal * using {@link BufferMode#Disk}. * * @throws IOException */ public void test_create_disk01() throws IOException { final Properties properties = getProperties(); final Journal journal = new Journal(properties); try { final DiskOnlyStrategy bufferStrategy = (DiskOnlyStrategy) journal .getBufferStrategy(); assertTrue("isStable", bufferStrategy.isStable()); assertFalse("isFullyBuffered", bufferStrategy.isFullyBuffered()); // assertEquals(Options.FILE, properties.getProperty(Options.FILE), // bufferStrategy.file.toString()); assertEquals(Options.INITIAL_EXTENT, Long .parseLong(Options.DEFAULT_INITIAL_EXTENT), bufferStrategy .getInitialExtent()); assertEquals(Options.MAXIMUM_EXTENT, 0L/* soft limit for disk mode */, bufferStrategy .getMaximumExtent()); assertNotNull("raf", bufferStrategy.getRandomAccessFile()); assertEquals(Options.BUFFER_MODE, BufferMode.Disk, bufferStrategy .getBufferMode()); } finally { journal.destroy(); } }
throw new IllegalArgumentException(ERR_BUFFER_NULL); if (isReadOnly()) throw new IllegalStateException(ERR_READ_ONLY); addr = allocate(nbytes); final long offset = getOffset(addr); flushWriteCache(); writeOnDisk(data, offset, true/*append*/); writeOnDisk(data,offset, true/*append*/);
createBackingFile(); overflow(offset, nbytes); storeCounters.ndiskWrite += FileChannelUtility.writeAll(getChannel(), data, pos);
/** * Note: This MAY be <code>null</code>. If {@link BufferMode#Temporary} * is used then it WILL be <code>null</code> until the {@link #writeCache} * is flushed to disk for the first time. */ final public FileChannel getChannel() { final RandomAccessFile raf = getRandomAccessFile(); if (raf == null) return null; return raf.getChannel(); }
FileChannelUtility.writeAll(getChannel(), data, pos); force(forceOnCommit == ForceEnum.ForceMetadata);
throw new IllegalArgumentException(ERR_ADDRESS_IS_NULL); final long offset = getOffset(addr); final int nbytes = getByteCount(addr);
/** * Need to override commit to ensure the writeCache is flushed prior to * writing the root block. * * For the DiskOnlyStrategy flushing the writeCache also ensures the backing * file is created if the file is temporary. * * Note that the internal call to flush the writeCache must be synchronized * or concurrent writers to the cache will cause problems. */ @Override public void commit() { if (writeCache != null) { synchronized (this) { flushWriteCache(); } } super.commit(); }