|
@@ -36,6 +36,7 @@ import java.util.PriorityQueue;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.fs.FileUtil;
|
|
|
import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.JournalManager.CorruptionException;
|
|
@@ -43,6 +44,7 @@ import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.TestEditLog.AbortSpec;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
+import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import com.google.common.base.Joiner;
|
|
@@ -51,12 +53,19 @@ import com.google.common.collect.ImmutableList;
|
|
|
public class TestFileJournalManager {
|
|
|
static final Log LOG = LogFactory.getLog(TestFileJournalManager.class);
|
|
|
|
|
|
+ private Configuration conf;
|
|
|
+
|
|
|
static {
|
|
|
// No need to fsync for the purposes of tests. This makes
|
|
|
// the tests run much faster.
|
|
|
EditLogFileOutputStream.setShouldSkipFsyncForTesting(true);
|
|
|
}
|
|
|
|
|
|
+ @Before
|
|
|
+ public void setUp() {
|
|
|
+ conf = new Configuration();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Find out how many transactions we can read from a
|
|
|
* FileJournalManager, starting at a given transaction ID.
|
|
@@ -115,7 +124,7 @@ public class TestFileJournalManager {
|
|
|
|
|
|
long numJournals = 0;
|
|
|
for (StorageDirectory sd : storage.dirIterable(NameNodeDirType.EDITS)) {
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(6*TXNS_PER_ROLL, getNumberOfTransactions(jm, 1, true, false));
|
|
|
numJournals++;
|
|
|
}
|
|
@@ -135,7 +144,7 @@ public class TestFileJournalManager {
|
|
|
5, new AbortSpec(5, 0));
|
|
|
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(5*TXNS_PER_ROLL + TXNS_PER_FAIL,
|
|
|
getNumberOfTransactions(jm, 1, true, false));
|
|
|
}
|
|
@@ -158,16 +167,16 @@ public class TestFileJournalManager {
|
|
|
5, new AbortSpec(5, 1));
|
|
|
Iterator<StorageDirectory> dirs = storage.dirIterator(NameNodeDirType.EDITS);
|
|
|
StorageDirectory sd = dirs.next();
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(6*TXNS_PER_ROLL, getNumberOfTransactions(jm, 1, true, false));
|
|
|
|
|
|
sd = dirs.next();
|
|
|
- jm = new FileJournalManager(sd, storage);
|
|
|
+ jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(5*TXNS_PER_ROLL + TXNS_PER_FAIL, getNumberOfTransactions(jm, 1,
|
|
|
true, false));
|
|
|
|
|
|
sd = dirs.next();
|
|
|
- jm = new FileJournalManager(sd, storage);
|
|
|
+ jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(6*TXNS_PER_ROLL, getNumberOfTransactions(jm, 1, true, false));
|
|
|
}
|
|
|
|
|
@@ -191,17 +200,17 @@ public class TestFileJournalManager {
|
|
|
new AbortSpec(5, 2));
|
|
|
Iterator<StorageDirectory> dirs = storage.dirIterator(NameNodeDirType.EDITS);
|
|
|
StorageDirectory sd = dirs.next();
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(5*TXNS_PER_ROLL + TXNS_PER_FAIL, getNumberOfTransactions(jm, 1,
|
|
|
true, false));
|
|
|
|
|
|
sd = dirs.next();
|
|
|
- jm = new FileJournalManager(sd, storage);
|
|
|
+ jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(5*TXNS_PER_ROLL + TXNS_PER_FAIL, getNumberOfTransactions(jm, 1,
|
|
|
true, false));
|
|
|
|
|
|
sd = dirs.next();
|
|
|
- jm = new FileJournalManager(sd, storage);
|
|
|
+ jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(5*TXNS_PER_ROLL + TXNS_PER_FAIL, getNumberOfTransactions(jm, 1,
|
|
|
true, false));
|
|
|
}
|
|
@@ -226,7 +235,7 @@ public class TestFileJournalManager {
|
|
|
10, new AbortSpec(10, 0));
|
|
|
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
String sdRootPath = sd.getRoot().getAbsolutePath();
|
|
|
FileUtil.chmod(sdRootPath, "-w", true);
|
|
|
try {
|
|
@@ -251,7 +260,7 @@ public class TestFileJournalManager {
|
|
|
10, new AbortSpec(10, 0));
|
|
|
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
long expectedTotalTxnCount = TXNS_PER_ROLL*10 + TXNS_PER_FAIL;
|
|
|
assertEquals(expectedTotalTxnCount, getNumberOfTransactions(jm, 1,
|
|
|
true, false));
|
|
@@ -277,7 +286,7 @@ public class TestFileJournalManager {
|
|
|
10);
|
|
|
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
|
|
|
// 10 rolls, so 11 rolled files, 110 txids total.
|
|
|
final int TOTAL_TXIDS = 10 * 11;
|
|
@@ -315,7 +324,7 @@ public class TestFileJournalManager {
|
|
|
assertEquals(1, files.length);
|
|
|
assertTrue(files[0].delete());
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(startGapTxId-1, getNumberOfTransactions(jm, 1, true, true));
|
|
|
|
|
|
assertEquals(0, getNumberOfTransactions(jm, startGapTxId, true, true));
|
|
@@ -348,7 +357,7 @@ public class TestFileJournalManager {
|
|
|
|
|
|
corruptAfterStartSegment(files[0]);
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
assertEquals(10*TXNS_PER_ROLL+1,
|
|
|
getNumberOfTransactions(jm, 1, true, false));
|
|
|
}
|
|
@@ -363,7 +372,7 @@ public class TestFileJournalManager {
|
|
|
NNStorage.getFinalizedEditsFileName(1001, 1100));
|
|
|
|
|
|
// passing null for NNStorage because this unit test will not use it
|
|
|
- FileJournalManager fjm = new FileJournalManager(sd, null);
|
|
|
+ FileJournalManager fjm = new FileJournalManager(conf, sd, null);
|
|
|
assertEquals("[1,100],[101,200],[1001,1100]", getLogsAsString(fjm, 1));
|
|
|
assertEquals("[101,200],[1001,1100]", getLogsAsString(fjm, 101));
|
|
|
assertEquals("[1001,1100]", getLogsAsString(fjm, 201));
|
|
@@ -427,7 +436,7 @@ public class TestFileJournalManager {
|
|
|
10);
|
|
|
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
|
|
|
EditLogInputStream elis = getJournalInputStream(jm, 5, true);
|
|
|
FSEditLogOp op = elis.readOp();
|
|
@@ -448,7 +457,7 @@ public class TestFileJournalManager {
|
|
|
10, false);
|
|
|
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
|
|
|
|
|
|
- FileJournalManager jm = new FileJournalManager(sd, storage);
|
|
|
+ FileJournalManager jm = new FileJournalManager(conf, sd, storage);
|
|
|
|
|
|
// If we exclude the in-progess stream, we should only have 100 tx.
|
|
|
assertEquals(100, getNumberOfTransactions(jm, 1, false, false));
|