|
@@ -59,6 +59,7 @@ import org.apache.hadoop.contrib.bkjournal.BKJournalProtos.VersionProto;
|
|
import com.google.protobuf.TextFormat;
|
|
import com.google.protobuf.TextFormat;
|
|
import static com.google.common.base.Charsets.UTF_8;
|
|
import static com.google.common.base.Charsets.UTF_8;
|
|
|
|
|
|
|
|
+import org.apache.commons.io.Charsets;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
@@ -142,6 +143,15 @@ public class BookKeeperJournalManager implements JournalManager {
|
|
public static final String BKJM_ZK_LEDGERS_AVAILABLE_PATH_DEFAULT
|
|
public static final String BKJM_ZK_LEDGERS_AVAILABLE_PATH_DEFAULT
|
|
= "/ledgers/available";
|
|
= "/ledgers/available";
|
|
|
|
|
|
|
|
+ public static final String BKJM_BOOKKEEPER_SPECULATIVE_READ_TIMEOUT_MS
|
|
|
|
+ = "dfs.namenode.bookkeeperjournal.speculativeReadTimeoutMs";
|
|
|
|
+ public static final int BKJM_BOOKKEEPER_SPECULATIVE_READ_TIMEOUT_DEFAULT
|
|
|
|
+ = 2000;
|
|
|
|
+
|
|
|
|
+ public static final String BKJM_BOOKKEEPER_READ_ENTRY_TIMEOUT_SEC
|
|
|
|
+ = "dfs.namenode.bookkeeperjournal.readEntryTimeoutSec";
|
|
|
|
+ public static final int BKJM_BOOKKEEPER_READ_ENTRY_TIMEOUT_DEFAULT = 5;
|
|
|
|
+
|
|
private ZooKeeper zkc;
|
|
private ZooKeeper zkc;
|
|
private final Configuration conf;
|
|
private final Configuration conf;
|
|
private final BookKeeper bkc;
|
|
private final BookKeeper bkc;
|
|
@@ -153,6 +163,8 @@ public class BookKeeperJournalManager implements JournalManager {
|
|
private final int ensembleSize;
|
|
private final int ensembleSize;
|
|
private final int quorumSize;
|
|
private final int quorumSize;
|
|
private final String digestpw;
|
|
private final String digestpw;
|
|
|
|
+ private final int speculativeReadTimeout;
|
|
|
|
+ private final int readEntryTimeout;
|
|
private final CountDownLatch zkConnectLatch;
|
|
private final CountDownLatch zkConnectLatch;
|
|
private final NamespaceInfo nsInfo;
|
|
private final NamespaceInfo nsInfo;
|
|
private boolean initialized = false;
|
|
private boolean initialized = false;
|
|
@@ -172,6 +184,11 @@ public class BookKeeperJournalManager implements JournalManager {
|
|
BKJM_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT);
|
|
BKJM_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT);
|
|
quorumSize = conf.getInt(BKJM_BOOKKEEPER_QUORUM_SIZE,
|
|
quorumSize = conf.getInt(BKJM_BOOKKEEPER_QUORUM_SIZE,
|
|
BKJM_BOOKKEEPER_QUORUM_SIZE_DEFAULT);
|
|
BKJM_BOOKKEEPER_QUORUM_SIZE_DEFAULT);
|
|
|
|
+ speculativeReadTimeout = conf.getInt(
|
|
|
|
+ BKJM_BOOKKEEPER_SPECULATIVE_READ_TIMEOUT_MS,
|
|
|
|
+ BKJM_BOOKKEEPER_SPECULATIVE_READ_TIMEOUT_DEFAULT);
|
|
|
|
+ readEntryTimeout = conf.getInt(BKJM_BOOKKEEPER_READ_ENTRY_TIMEOUT_SEC,
|
|
|
|
+ BKJM_BOOKKEEPER_READ_ENTRY_TIMEOUT_DEFAULT);
|
|
|
|
|
|
ledgerPath = basePath + "/ledgers";
|
|
ledgerPath = basePath + "/ledgers";
|
|
String maxTxIdPath = basePath + "/maxtxid";
|
|
String maxTxIdPath = basePath + "/maxtxid";
|
|
@@ -196,7 +213,10 @@ public class BookKeeperJournalManager implements JournalManager {
|
|
}
|
|
}
|
|
|
|
|
|
prepareBookKeeperEnv();
|
|
prepareBookKeeperEnv();
|
|
- bkc = new BookKeeper(new ClientConfiguration(), zkc);
|
|
|
|
|
|
+ ClientConfiguration clientConf = new ClientConfiguration();
|
|
|
|
+ clientConf.setSpeculativeReadTimeout(speculativeReadTimeout);
|
|
|
|
+ clientConf.setReadEntryTimeout(readEntryTimeout);
|
|
|
|
+ bkc = new BookKeeper(clientConf, zkc);
|
|
} catch (KeeperException e) {
|
|
} catch (KeeperException e) {
|
|
throw new IOException("Error initializing zk", e);
|
|
throw new IOException("Error initializing zk", e);
|
|
} catch (InterruptedException ie) {
|
|
} catch (InterruptedException ie) {
|
|
@@ -385,7 +405,7 @@ public class BookKeeperJournalManager implements JournalManager {
|
|
}
|
|
}
|
|
currentLedger = bkc.createLedger(ensembleSize, quorumSize,
|
|
currentLedger = bkc.createLedger(ensembleSize, quorumSize,
|
|
BookKeeper.DigestType.MAC,
|
|
BookKeeper.DigestType.MAC,
|
|
- digestpw.getBytes());
|
|
|
|
|
|
+ digestpw.getBytes(Charsets.UTF_8));
|
|
} catch (BKException bke) {
|
|
} catch (BKException bke) {
|
|
throw new IOException("Error creating ledger", bke);
|
|
throw new IOException("Error creating ledger", bke);
|
|
} catch (KeeperException ke) {
|
|
} catch (KeeperException ke) {
|
|
@@ -522,10 +542,10 @@ public class BookKeeperJournalManager implements JournalManager {
|
|
LedgerHandle h;
|
|
LedgerHandle h;
|
|
if (l.isInProgress()) { // we don't want to fence the current journal
|
|
if (l.isInProgress()) { // we don't want to fence the current journal
|
|
h = bkc.openLedgerNoRecovery(l.getLedgerId(),
|
|
h = bkc.openLedgerNoRecovery(l.getLedgerId(),
|
|
- BookKeeper.DigestType.MAC, digestpw.getBytes());
|
|
|
|
|
|
+ BookKeeper.DigestType.MAC, digestpw.getBytes(Charsets.UTF_8));
|
|
} else {
|
|
} else {
|
|
h = bkc.openLedger(l.getLedgerId(), BookKeeper.DigestType.MAC,
|
|
h = bkc.openLedger(l.getLedgerId(), BookKeeper.DigestType.MAC,
|
|
- digestpw.getBytes());
|
|
|
|
|
|
+ digestpw.getBytes(Charsets.UTF_8));
|
|
}
|
|
}
|
|
elis = new BookKeeperEditLogInputStream(h, l);
|
|
elis = new BookKeeperEditLogInputStream(h, l);
|
|
elis.skipTo(fromTxId);
|
|
elis.skipTo(fromTxId);
|
|
@@ -732,11 +752,11 @@ public class BookKeeperJournalManager implements JournalManager {
|
|
if (fence) {
|
|
if (fence) {
|
|
lh = bkc.openLedger(l.getLedgerId(),
|
|
lh = bkc.openLedger(l.getLedgerId(),
|
|
BookKeeper.DigestType.MAC,
|
|
BookKeeper.DigestType.MAC,
|
|
- digestpw.getBytes());
|
|
|
|
|
|
+ digestpw.getBytes(Charsets.UTF_8));
|
|
} else {
|
|
} else {
|
|
lh = bkc.openLedgerNoRecovery(l.getLedgerId(),
|
|
lh = bkc.openLedgerNoRecovery(l.getLedgerId(),
|
|
BookKeeper.DigestType.MAC,
|
|
BookKeeper.DigestType.MAC,
|
|
- digestpw.getBytes());
|
|
|
|
|
|
+ digestpw.getBytes(Charsets.UTF_8));
|
|
}
|
|
}
|
|
} catch (BKException bke) {
|
|
} catch (BKException bke) {
|
|
throw new IOException("Exception opening ledger for " + l, bke);
|
|
throw new IOException("Exception opening ledger for " + l, bke);
|