public virtual void TestDoubleBuffer()
        {
            EditsDoubleBuffer buf = new EditsDoubleBuffer(1024);

            NUnit.Framework.Assert.IsTrue(buf.IsFlushed());
            byte[] data = new byte[100];
            buf.WriteRaw(data, 0, data.Length);
            NUnit.Framework.Assert.AreEqual("Should count new data correctly", data.Length, buf
                                            .CountBufferedBytes());
            NUnit.Framework.Assert.IsTrue("Writing to current buffer should not affect flush state"
                                          , buf.IsFlushed());
            // Swap the buffers
            buf.SetReadyToFlush();
            NUnit.Framework.Assert.AreEqual("Swapping buffers should still count buffered bytes"
                                            , data.Length, buf.CountBufferedBytes());
            NUnit.Framework.Assert.IsFalse(buf.IsFlushed());
            // Flush to a stream
            DataOutputBuffer outBuf = new DataOutputBuffer();

            buf.FlushTo(outBuf);
            NUnit.Framework.Assert.AreEqual(data.Length, outBuf.GetLength());
            NUnit.Framework.Assert.IsTrue(buf.IsFlushed());
            NUnit.Framework.Assert.AreEqual(0, buf.CountBufferedBytes());
            // Write some more
            buf.WriteRaw(data, 0, data.Length);
            NUnit.Framework.Assert.AreEqual("Should count new data correctly", data.Length, buf
                                            .CountBufferedBytes());
            buf.SetReadyToFlush();
            buf.FlushTo(outBuf);
            NUnit.Framework.Assert.AreEqual(data.Length * 2, outBuf.GetLength());
            NUnit.Framework.Assert.AreEqual(0, buf.CountBufferedBytes());
            outBuf.Close();
        }
Beispiel #2
0
 /// <summary>Flush ready buffer to persistent store.</summary>
 /// <remarks>
 /// Flush ready buffer to persistent store. currentBuffer is not flushed as it
 /// accumulates new log records while readyBuffer will be flushed and synced.
 /// </remarks>
 /// <exception cref="System.IO.IOException"/>
 protected internal override void FlushAndSync(bool durable)
 {
     if (fp == null)
     {
         throw new IOException("Trying to use aborted output stream");
     }
     if (doubleBuf.IsFlushed())
     {
         Log.Info("Nothing to flush");
         return;
     }
     Preallocate();
     // preallocate file if necessary
     doubleBuf.FlushTo(fp);
     if (durable && !shouldSkipFsyncForTests && !shouldSyncWritesAndSkipFsync)
     {
         fc.Force(false);
     }
 }
Beispiel #3
0
        /// <exception cref="System.IO.IOException"/>
        protected internal override void FlushAndSync(bool durable)
        {
            // EditLogOutputStream
            System.Diagnostics.Debug.Assert(@out.GetLength() == 0, "Output buffer is not empty"
                                            );
            if (doubleBuf.IsFlushed())
            {
                Log.Info("Nothing to flush");
                return;
            }
            int  numReadyTxns   = doubleBuf.CountReadyTxns();
            long firstTxToFlush = doubleBuf.GetFirstReadyTxId();

            doubleBuf.FlushTo(@out);
            if (@out.GetLength() > 0)
            {
                System.Diagnostics.Debug.Assert(numReadyTxns > 0);
                byte[] data = Arrays.CopyOf(@out.GetData(), @out.GetLength());
                @out.Reset();
                System.Diagnostics.Debug.Assert(@out.GetLength() == 0, "Output buffer is not empty"
                                                );
                backupNode.Journal(journalInfo, 0, firstTxToFlush, numReadyTxns, data);
            }
        }