|
@@ -29,7 +29,6 @@ import org.mockito.Mockito;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
import java.util.List;
|
|
|
-import java.util.Random;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
|
@@ -38,7 +37,6 @@ import org.apache.hadoop.hdfs.server.namenode.EditLogOutputStream;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSEditLogTestUtil;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.JournalManager;
|
|
|
-import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
|
|
|
|
|
|
import org.apache.bookkeeper.proto.BookieServer;
|
|
|
import org.apache.zookeeper.CreateMode;
|
|
@@ -80,17 +78,10 @@ public class TestBookKeeperJournalManager {
|
|
|
zkc.close();
|
|
|
}
|
|
|
|
|
|
- private NamespaceInfo newNSInfo() {
|
|
|
- Random r = new Random();
|
|
|
- return new NamespaceInfo(r.nextInt(), "testCluster", "TestBPID", -1);
|
|
|
- }
|
|
|
-
|
|
|
@Test
|
|
|
public void testSimpleWrite() throws Exception {
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-simplewrite"), nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-simplewrite"));
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1 ; i <= 100; i++) {
|
|
|
FSEditLogOp op = FSEditLogTestUtil.getNoOpInstance();
|
|
@@ -108,10 +99,8 @@ public class TestBookKeeperJournalManager {
|
|
|
|
|
|
@Test
|
|
|
public void testNumberOfTransactions() throws Exception {
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
-
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-txncount"), nsi);
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-txncount"));
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1 ; i <= 100; i++) {
|
|
|
FSEditLogOp op = FSEditLogTestUtil.getNoOpInstance();
|
|
@@ -127,10 +116,8 @@ public class TestBookKeeperJournalManager {
|
|
|
|
|
|
@Test
|
|
|
public void testNumberOfTransactionsWithGaps() throws Exception {
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-gaps"), nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-gaps"));
|
|
|
long txid = 1;
|
|
|
for (long i = 0; i < 3; i++) {
|
|
|
long start = txid;
|
|
@@ -164,10 +151,8 @@ public class TestBookKeeperJournalManager {
|
|
|
|
|
|
@Test
|
|
|
public void testNumberOfTransactionsWithInprogressAtEnd() throws Exception {
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-inprogressAtEnd"), nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-inprogressAtEnd"));
|
|
|
long txid = 1;
|
|
|
for (long i = 0; i < 3; i++) {
|
|
|
long start = txid;
|
|
@@ -205,10 +190,8 @@ public class TestBookKeeperJournalManager {
|
|
|
*/
|
|
|
@Test
|
|
|
public void testWriteRestartFrom1() throws Exception {
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-restartFrom1"), nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-restartFrom1"));
|
|
|
long txid = 1;
|
|
|
long start = txid;
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(txid);
|
|
@@ -262,15 +245,11 @@ public class TestBookKeeperJournalManager {
|
|
|
@Test
|
|
|
public void testTwoWriters() throws Exception {
|
|
|
long start = 1;
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
-
|
|
|
BookKeeperJournalManager bkjm1 = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-dualWriter"), nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-dualWriter"));
|
|
|
BookKeeperJournalManager bkjm2 = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-dualWriter"), nsi);
|
|
|
-
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-dualWriter"));
|
|
|
+
|
|
|
EditLogOutputStream out1 = bkjm1.startLogSegment(start);
|
|
|
try {
|
|
|
bkjm2.startLogSegment(start);
|
|
@@ -284,11 +263,8 @@ public class TestBookKeeperJournalManager {
|
|
|
|
|
|
@Test
|
|
|
public void testSimpleRead() throws Exception {
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-simpleread"),
|
|
|
- nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-simpleread"));
|
|
|
final long numTransactions = 10000;
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1 ; i <= numTransactions; i++) {
|
|
@@ -311,11 +287,8 @@ public class TestBookKeeperJournalManager {
|
|
|
|
|
|
@Test
|
|
|
public void testSimpleRecovery() throws Exception {
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-simplerecovery"),
|
|
|
- nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-simplerecovery"));
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1 ; i <= 100; i++) {
|
|
|
FSEditLogOp op = FSEditLogTestUtil.getNoOpInstance();
|
|
@@ -361,10 +334,8 @@ public class TestBookKeeperJournalManager {
|
|
|
conf.setInt(BookKeeperJournalManager.BKJM_BOOKKEEPER_QUORUM_SIZE,
|
|
|
ensembleSize);
|
|
|
long txid = 1;
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-allbookiefailure"),
|
|
|
- nsi);
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-allbookiefailure"));
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(txid);
|
|
|
|
|
|
for (long i = 1 ; i <= 3; i++) {
|
|
@@ -445,12 +416,8 @@ public class TestBookKeeperJournalManager {
|
|
|
conf.setInt(BookKeeperJournalManager.BKJM_BOOKKEEPER_QUORUM_SIZE,
|
|
|
ensembleSize);
|
|
|
long txid = 1;
|
|
|
-
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf,
|
|
|
- BKJMUtil.createJournalURI("/hdfsjournal-onebookiefailure"),
|
|
|
- nsi);
|
|
|
-
|
|
|
+ BKJMUtil.createJournalURI("/hdfsjournal-onebookiefailure"));
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(txid);
|
|
|
for (long i = 1 ; i <= 3; i++) {
|
|
|
FSEditLogOp op = FSEditLogTestUtil.getNoOpInstance();
|
|
@@ -497,9 +464,7 @@ public class TestBookKeeperJournalManager {
|
|
|
@Test
|
|
|
public void testEmptyInprogressNode() throws Exception {
|
|
|
URI uri = BKJMUtil.createJournalURI("/hdfsjournal-emptyInprogress");
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
- BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri,
|
|
|
- nsi);
|
|
|
+ BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1; i <= 100; i++) {
|
|
@@ -516,7 +481,7 @@ public class TestBookKeeperJournalManager {
|
|
|
String inprogressZNode = bkjm.inprogressZNode(101);
|
|
|
zkc.setData(inprogressZNode, new byte[0], -1);
|
|
|
|
|
|
- bkjm = new BookKeeperJournalManager(conf, uri, nsi);
|
|
|
+ bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
try {
|
|
|
bkjm.recoverUnfinalizedSegments();
|
|
|
fail("Should have failed. There should be no way of creating"
|
|
@@ -524,7 +489,7 @@ public class TestBookKeeperJournalManager {
|
|
|
} catch (IOException e) {
|
|
|
// correct behaviour
|
|
|
assertTrue("Exception different than expected", e.getMessage().contains(
|
|
|
- "Invalid/Incomplete data in znode"));
|
|
|
+ "Invalid ledger entry,"));
|
|
|
} finally {
|
|
|
bkjm.close();
|
|
|
}
|
|
@@ -538,9 +503,7 @@ public class TestBookKeeperJournalManager {
|
|
|
@Test
|
|
|
public void testCorruptInprogressNode() throws Exception {
|
|
|
URI uri = BKJMUtil.createJournalURI("/hdfsjournal-corruptInprogress");
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
- BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri,
|
|
|
- nsi);
|
|
|
+ BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1; i <= 100; i++) {
|
|
@@ -558,7 +521,7 @@ public class TestBookKeeperJournalManager {
|
|
|
String inprogressZNode = bkjm.inprogressZNode(101);
|
|
|
zkc.setData(inprogressZNode, "WholeLottaJunk".getBytes(), -1);
|
|
|
|
|
|
- bkjm = new BookKeeperJournalManager(conf, uri, nsi);
|
|
|
+ bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
try {
|
|
|
bkjm.recoverUnfinalizedSegments();
|
|
|
fail("Should have failed. There should be no way of creating"
|
|
@@ -566,7 +529,8 @@ public class TestBookKeeperJournalManager {
|
|
|
} catch (IOException e) {
|
|
|
// correct behaviour
|
|
|
assertTrue("Exception different than expected", e.getMessage().contains(
|
|
|
- "has no field named"));
|
|
|
+ "Invalid ledger entry,"));
|
|
|
+
|
|
|
} finally {
|
|
|
bkjm.close();
|
|
|
}
|
|
@@ -580,9 +544,7 @@ public class TestBookKeeperJournalManager {
|
|
|
@Test
|
|
|
public void testEmptyInprogressLedger() throws Exception {
|
|
|
URI uri = BKJMUtil.createJournalURI("/hdfsjournal-emptyInprogressLedger");
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
- BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri,
|
|
|
- nsi);
|
|
|
+ BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1; i <= 100; i++) {
|
|
@@ -597,7 +559,7 @@ public class TestBookKeeperJournalManager {
|
|
|
out.close();
|
|
|
bkjm.close();
|
|
|
|
|
|
- bkjm = new BookKeeperJournalManager(conf, uri, nsi);
|
|
|
+ bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
bkjm.recoverUnfinalizedSegments();
|
|
|
out = bkjm.startLogSegment(101);
|
|
|
for (long i = 1; i <= 100; i++) {
|
|
@@ -619,9 +581,7 @@ public class TestBookKeeperJournalManager {
|
|
|
public void testRefinalizeAlreadyFinalizedInprogress() throws Exception {
|
|
|
URI uri = BKJMUtil
|
|
|
.createJournalURI("/hdfsjournal-refinalizeInprogressLedger");
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
- BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri,
|
|
|
- nsi);
|
|
|
+ BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
|
|
|
EditLogOutputStream out = bkjm.startLogSegment(1);
|
|
|
for (long i = 1; i <= 100; i++) {
|
|
@@ -641,7 +601,7 @@ public class TestBookKeeperJournalManager {
|
|
|
byte[] inprogressData = zkc.getData(inprogressZNode, false, null);
|
|
|
|
|
|
// finalize
|
|
|
- bkjm = new BookKeeperJournalManager(conf, uri, nsi);
|
|
|
+ bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
bkjm.recoverUnfinalizedSegments();
|
|
|
bkjm.close();
|
|
|
|
|
@@ -653,7 +613,7 @@ public class TestBookKeeperJournalManager {
|
|
|
CreateMode.PERSISTENT);
|
|
|
|
|
|
// should work fine
|
|
|
- bkjm = new BookKeeperJournalManager(conf, uri, nsi);
|
|
|
+ bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
bkjm.recoverUnfinalizedSegments();
|
|
|
bkjm.close();
|
|
|
}
|
|
@@ -666,10 +626,7 @@ public class TestBookKeeperJournalManager {
|
|
|
@Test
|
|
|
public void testEditLogFileNotExistsWhenReadingMetadata() throws Exception {
|
|
|
URI uri = BKJMUtil.createJournalURI("/hdfsjournal-editlogfile");
|
|
|
- NamespaceInfo nsi = newNSInfo();
|
|
|
- BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri,
|
|
|
- nsi);
|
|
|
-
|
|
|
+ BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri);
|
|
|
try {
|
|
|
// start new inprogress log segment with txid=1
|
|
|
// and write transactions till txid=50
|