use of org.apache.bookkeeper.proto.DataFormats.UnderreplicatedLedgerFormat in project bookkeeper by apache.
the class ZkLedgerUnderreplicationManager method markLedgerUnderreplicated.
@Override
public void markLedgerUnderreplicated(long ledgerId, String missingReplica) throws ReplicationException.UnavailableException {
if (LOG.isDebugEnabled()) {
LOG.debug("markLedgerUnderreplicated(ledgerId={}, missingReplica={})", ledgerId, missingReplica);
}
try {
List<ACL> zkAcls = ZkUtils.getACLs(conf);
String znode = getUrLedgerZnode(ledgerId);
while (true) {
UnderreplicatedLedgerFormat.Builder builder = UnderreplicatedLedgerFormat.newBuilder();
try {
builder.addReplica(missingReplica);
ZkUtils.createFullPathOptimistic(zkc, znode, TextFormat.printToString(builder.build()).getBytes(UTF_8), zkAcls, CreateMode.PERSISTENT);
} catch (KeeperException.NodeExistsException nee) {
Stat s = zkc.exists(znode, false);
if (s == null) {
continue;
}
try {
byte[] bytes = zkc.getData(znode, false, s);
builder.clear();
TextFormat.merge(new String(bytes, UTF_8), builder);
UnderreplicatedLedgerFormat data = builder.build();
if (data.getReplicaList().contains(missingReplica)) {
// nothing to add
return;
}
builder.addReplica(missingReplica);
zkc.setData(znode, TextFormat.printToString(builder.build()).getBytes(UTF_8), s.getVersion());
} catch (KeeperException.NoNodeException nne) {
continue;
} catch (KeeperException.BadVersionException bve) {
continue;
} catch (TextFormat.ParseException pe) {
throw new ReplicationException.UnavailableException("Invalid data found", pe);
}
}
break;
}
} catch (KeeperException ke) {
throw new ReplicationException.UnavailableException("Error contacting zookeeper", ke);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new ReplicationException.UnavailableException("Interrupted while contacting zookeeper", ie);
}
}
use of org.apache.bookkeeper.proto.DataFormats.UnderreplicatedLedgerFormat in project bookkeeper by apache.
the class AuditorLedgerCheckerTest method waitForLedgerMissingReplicas.
/**
* Wait for ledger to be underreplicated, and to be missing all replicas specified.
*/
private boolean waitForLedgerMissingReplicas(Long ledgerId, long secondsToWait, String... replicas) throws Exception {
for (int i = 0; i < secondsToWait; i++) {
try {
UnderreplicatedLedgerFormat data = urLedgerMgr.getLedgerUnreplicationInfo(ledgerId);
boolean all = true;
for (String r : replicas) {
all = all && data.getReplicaList().contains(r);
}
if (all) {
return true;
}
} catch (Exception e) {
// may not find node
}
Thread.sleep(1000);
}
return false;
}
Aggregations