Ejemplo n.º 1
0
 /// <exception cref="System.IO.IOException"/>
 public override void AddTransactionsToLog(EditLogOutputStream elos, FSEditLogOp.OpInstanceCache
                                           cache)
 {
     AddDeleteOpcode(elos, cache, 0, "/foo");
     AddDeleteOpcode(elos, cache, 1, "/supercalifragalisticexpialadocius.supercalifragalisticexpialadocius"
                     );
 }
Ejemplo n.º 2
0
 /// <exception cref="System.IO.IOException"/>
 internal static void AddDeleteOpcode(EditLogOutputStream elos, FSEditLogOp.OpInstanceCache
                                      cache, long txId, string path)
 {
     FSEditLogOp.DeleteOp op = FSEditLogOp.DeleteOp.GetInstance(cache);
     op.SetTransactionId(txId);
     op.SetPath(path);
     op.SetTimestamp(0);
     elos.Write(op);
 }
Ejemplo n.º 3
0
 /// <exception cref="System.IO.IOException"/>
 public override void AddTransactionsToLog(EditLogOutputStream elos, FSEditLogOp.OpInstanceCache
                                           cache)
 {
     for (long txid = 1; txid <= MaxTxid; txid++)
     {
         if (txid == BadTxid)
         {
             byte[] garbage = new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x2)), unchecked (
                                               (int)(0x3)) };
             elos.WriteRaw(garbage, 0, garbage.Length);
         }
         else
         {
             FSEditLogOp.DeleteOp op;
             op = FSEditLogOp.DeleteOp.GetInstance(cache);
             op.SetTransactionId(txid);
             op.SetPath("/foo." + txid);
             op.SetTimestamp(txid);
             elos.Write(op);
         }
     }
 }
Ejemplo n.º 4
0
        /// <exception cref="System.IO.IOException"/>
        internal static void RunEditLogTest(TestNameNodeRecovery.EditLogTestSetup elts)
        {
            FilePath TestLogName = new FilePath(TestDir, "test_edit_log");

            FSEditLogOp.OpInstanceCache cache = new FSEditLogOp.OpInstanceCache();
            EditLogFileOutputStream     elfos = null;
            EditLogFileInputStream      elfis = null;

            try
            {
                elfos = new EditLogFileOutputStream(new Configuration(), TestLogName, 0);
                elfos.Create(NameNodeLayoutVersion.CurrentLayoutVersion);
                elts.AddTransactionsToLog(elfos, cache);
                elfos.SetReadyToFlush();
                elfos.FlushAndSync(true);
                elfos.Close();
                elfos = null;
                elfis = new EditLogFileInputStream(TestLogName);
                elfis.SetMaxOpSize(elts.GetMaxOpSize());
                // reading through normally will get you an exception
                ICollection <long> validTxIds = elts.GetValidTxIds();
                FSEditLogOp        op         = null;
                long prevTxId = 0;
                try
                {
                    while (true)
                    {
                        op = elfis.NextOp();
                        if (op == null)
                        {
                            break;
                        }
                        Log.Debug("read txid " + op.txid);
                        if (!validTxIds.Contains(op.GetTransactionId()))
                        {
                            NUnit.Framework.Assert.Fail("read txid " + op.GetTransactionId() + ", which we did not expect to find."
                                                        );
                        }
                        validTxIds.Remove(op.GetTransactionId());
                        prevTxId = op.GetTransactionId();
                    }
                    if (elts.GetLastValidTxId() != -1)
                    {
                        NUnit.Framework.Assert.Fail("failed to throw IoException as expected");
                    }
                }
                catch (IOException)
                {
                    if (elts.GetLastValidTxId() == -1)
                    {
                        NUnit.Framework.Assert.Fail("expected all transactions to be valid, but got exception "
                                                    + "on txid " + prevTxId);
                    }
                    else
                    {
                        NUnit.Framework.Assert.AreEqual(prevTxId, elts.GetLastValidTxId());
                    }
                }
                if (elts.GetLastValidTxId() != -1)
                {
                    // let's skip over the bad transaction
                    op       = null;
                    prevTxId = 0;
                    try
                    {
                        while (true)
                        {
                            op = elfis.NextValidOp();
                            if (op == null)
                            {
                                break;
                            }
                            prevTxId = op.GetTransactionId();
                            NUnit.Framework.Assert.IsTrue(validTxIds.Remove(op.GetTransactionId()));
                        }
                    }
                    catch (Exception e)
                    {
                        NUnit.Framework.Assert.Fail("caught IOException while trying to skip over bad " +
                                                    "transaction.   message was " + e.Message + "\nstack trace\n" + StringUtils.StringifyException
                                                        (e));
                    }
                }
                // We should have read every valid transaction.
                NUnit.Framework.Assert.IsTrue(validTxIds.IsEmpty());
            }
            finally
            {
                IOUtils.Cleanup(Log, elfos, elfis);
            }
        }
Ejemplo n.º 5
0
 /// <exception cref="System.IO.IOException"/>
 public override void AddTransactionsToLog(EditLogOutputStream elos, FSEditLogOp.OpInstanceCache
                                           cache)
 {
     PadEditLog(elos, paddingLength);
     AddDeleteOpcode(elos, cache, 0, "/foo");
 }
Ejemplo n.º 6
0
 /// <exception cref="System.IO.IOException"/>
 public override void AddTransactionsToLog(EditLogOutputStream elos, FSEditLogOp.OpInstanceCache
                                           cache)
 {
     PadEditLog(elos, paddingLength);
 }
Ejemplo n.º 7
0
 /// <summary>Set up the edit log.</summary>
 /// <exception cref="System.IO.IOException"/>
 public abstract void AddTransactionsToLog(EditLogOutputStream elos, FSEditLogOp.OpInstanceCache
                                           cache);