Search in sources :

Example 1 with FSEditLogOp

use of org.apache.hadoop.hdfs.server.namenode.FSEditLogOp in project hadoop by apache.

the class OfflineEditsBinaryLoader method loadEdits.

/**
   * Loads edits file, uses visitor to process all elements
   */
@Override
public void loadEdits() throws IOException {
    try {
        visitor.start(inputStream.getVersion(true));
        while (true) {
            try {
                FSEditLogOp op = inputStream.readOp();
                if (op == null)
                    break;
                if (fixTxIds) {
                    if (nextTxId <= 0) {
                        nextTxId = op.getTransactionId();
                        if (nextTxId <= 0) {
                            nextTxId = 1;
                        }
                    }
                    op.setTransactionId(nextTxId);
                    nextTxId++;
                }
                visitor.visitOp(op);
            } catch (IOException e) {
                if (!recoveryMode) {
                    // Tell the visitor to clean up, then re-throw the exception
                    LOG.error("Got IOException at position " + inputStream.getPosition());
                    visitor.close(e);
                    throw e;
                }
                LOG.error("Got IOException while reading stream!  Resyncing.", e);
                inputStream.resync();
            } catch (RuntimeException e) {
                if (!recoveryMode) {
                    // Tell the visitor to clean up, then re-throw the exception
                    LOG.error("Got RuntimeException at position " + inputStream.getPosition());
                    visitor.close(e);
                    throw e;
                }
                LOG.error("Got RuntimeException while reading stream!  Resyncing.", e);
                inputStream.resync();
            }
        }
        visitor.close(null);
    } finally {
        IOUtils.cleanup(LOG, inputStream);
    }
}
Also used : IOException(java.io.IOException) FSEditLogOp(org.apache.hadoop.hdfs.server.namenode.FSEditLogOp)

Example 2 with FSEditLogOp

use of org.apache.hadoop.hdfs.server.namenode.FSEditLogOp in project hadoop by apache.

the class QJMTestUtil method createTxnData.

public static byte[] createTxnData(int startTxn, int numTxns) throws Exception {
    DataOutputBuffer buf = new DataOutputBuffer();
    FSEditLogOp.Writer writer = new FSEditLogOp.Writer(buf);
    for (long txid = startTxn; txid < startTxn + numTxns; txid++) {
        FSEditLogOp op = NameNodeAdapter.createMkdirOp("tx " + txid);
        op.setTransactionId(txid);
        writer.writeOp(op);
    }
    return Arrays.copyOf(buf.getData(), buf.getLength());
}
Also used : DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) FSEditLogOp(org.apache.hadoop.hdfs.server.namenode.FSEditLogOp)

Example 3 with FSEditLogOp

use of org.apache.hadoop.hdfs.server.namenode.FSEditLogOp in project hadoop by apache.

the class QJMTestUtil method verifyEdits.

/**
   * Verify that the given list of streams contains exactly the range of
   * transactions specified, inclusive.
   */
public static void verifyEdits(List<EditLogInputStream> streams, int firstTxnId, int lastTxnId) throws IOException {
    Iterator<EditLogInputStream> iter = streams.iterator();
    assertTrue(iter.hasNext());
    EditLogInputStream stream = iter.next();
    for (int expected = firstTxnId; expected <= lastTxnId; expected++) {
        FSEditLogOp op = stream.readOp();
        while (op == null) {
            assertTrue("Expected to find txid " + expected + ", " + "but no more streams available to read from", iter.hasNext());
            stream = iter.next();
            op = stream.readOp();
        }
        assertEquals(FSEditLogOpCodes.OP_MKDIR, op.opCode);
        assertEquals(expected, op.getTransactionId());
    }
    assertNull(stream.readOp());
    assertFalse("Expected no more txns after " + lastTxnId + " but more streams are available", iter.hasNext());
}
Also used : EditLogInputStream(org.apache.hadoop.hdfs.server.namenode.EditLogInputStream) FSEditLogOp(org.apache.hadoop.hdfs.server.namenode.FSEditLogOp)

Example 4 with FSEditLogOp

use of org.apache.hadoop.hdfs.server.namenode.FSEditLogOp in project hadoop by apache.

the class QJMTestUtil method createGabageTxns.

/**
   * Generate byte array representing a set of GarbageMkdirOp
   */
public static byte[] createGabageTxns(long startTxId, int numTxns) throws IOException {
    DataOutputBuffer buf = new DataOutputBuffer();
    FSEditLogOp.Writer writer = new FSEditLogOp.Writer(buf);
    for (long txid = startTxId; txid < startTxId + numTxns; txid++) {
        FSEditLogOp op = new TestEditLog.GarbageMkdirOp();
        op.setTransactionId(txid);
        writer.writeOp(op);
    }
    return Arrays.copyOf(buf.getData(), buf.getLength());
}
Also used : DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) FSEditLogOp(org.apache.hadoop.hdfs.server.namenode.FSEditLogOp)

Example 5 with FSEditLogOp

use of org.apache.hadoop.hdfs.server.namenode.FSEditLogOp in project hadoop by apache.

the class OfflineEditsXmlLoader method endElement.

@Override
public void endElement(String uri, String name, String qName) {
    String str = XMLUtils.unmangleXmlString(cbuf.toString(), false).trim();
    cbuf = new StringBuffer();
    switch(state) {
        case EXPECT_EDITS_TAG:
            throw new InvalidXmlException("expected <EDITS/>");
        case EXPECT_VERSION:
            if (!name.equals("EDITS_VERSION")) {
                throw new InvalidXmlException("expected </EDITS_VERSION>");
            }
            try {
                int version = Integer.parseInt(str);
                visitor.start(version);
            } catch (IOException e) {
                // Can't throw IOException from a SAX method, sigh.
                throw new RuntimeException(e);
            }
            state = ParseState.EXPECT_RECORD;
            break;
        case EXPECT_RECORD:
            if (name.equals("EDITS")) {
                state = ParseState.EXPECT_END;
            } else if (!name.equals("RECORD")) {
                throw new InvalidXmlException("expected </EDITS> or </RECORD>");
            }
            break;
        case EXPECT_OPCODE:
            if (!name.equals("OPCODE")) {
                throw new InvalidXmlException("expected </OPCODE>");
            }
            opCode = FSEditLogOpCodes.valueOf(str);
            state = ParseState.EXPECT_DATA;
            break;
        case EXPECT_DATA:
            throw new InvalidXmlException("expected <DATA/>");
        case HANDLE_DATA:
            stanza.setValue(str);
            if (stanzaStack.empty()) {
                if (!name.equals("DATA")) {
                    throw new InvalidXmlException("expected </DATA>");
                }
                state = ParseState.EXPECT_RECORD;
                FSEditLogOp op = opCache.get(opCode);
                opCode = null;
                try {
                    op.decodeXml(stanza);
                    stanza = null;
                } finally {
                    if (stanza != null) {
                        System.err.println("fromXml error decoding opcode " + opCode + "\n" + stanza.toString());
                        stanza = null;
                    }
                }
                if (fixTxIds) {
                    if (nextTxId <= 0) {
                        nextTxId = op.getTransactionId();
                        if (nextTxId <= 0) {
                            nextTxId = 1;
                        }
                    }
                    op.setTransactionId(nextTxId);
                    nextTxId++;
                }
                try {
                    visitor.visitOp(op);
                } catch (IOException e) {
                    // Can't throw IOException from a SAX method, sigh.
                    throw new RuntimeException(e);
                }
                state = ParseState.EXPECT_RECORD;
            } else {
                stanza = stanzaStack.pop();
            }
            break;
        case EXPECT_END:
            throw new InvalidXmlException("not expecting anything after </EDITS>");
    }
}
Also used : InvalidXmlException(org.apache.hadoop.hdfs.util.XMLUtils.InvalidXmlException) IOException(java.io.IOException) FSEditLogOp(org.apache.hadoop.hdfs.server.namenode.FSEditLogOp)

Aggregations

FSEditLogOp (org.apache.hadoop.hdfs.server.namenode.FSEditLogOp)6 IOException (java.io.IOException)2 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)2 EditLogInputStream (org.apache.hadoop.hdfs.server.namenode.EditLogInputStream)1 InvalidXmlException (org.apache.hadoop.hdfs.util.XMLUtils.InvalidXmlException)1