Search in sources :

Example 1 with UnderreplicatedLedgerFormat

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);
    }
}
Also used : UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) ACL(org.apache.zookeeper.data.ACL) Stat(org.apache.zookeeper.data.Stat) ReplicationException(org.apache.bookkeeper.replication.ReplicationException) KeeperException(org.apache.zookeeper.KeeperException) UnderreplicatedLedgerFormat(org.apache.bookkeeper.proto.DataFormats.UnderreplicatedLedgerFormat) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException)

Example 2 with UnderreplicatedLedgerFormat

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;
}
Also used : TimeoutException(java.util.concurrent.TimeoutException) BKException(org.apache.bookkeeper.client.BKException) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnderreplicatedLedgerFormat(org.apache.bookkeeper.proto.DataFormats.UnderreplicatedLedgerFormat)

Aggregations

UnderreplicatedLedgerFormat (org.apache.bookkeeper.proto.DataFormats.UnderreplicatedLedgerFormat)2 UnavailableException (org.apache.bookkeeper.replication.ReplicationException.UnavailableException)2 KeeperException (org.apache.zookeeper.KeeperException)2 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 BKException (org.apache.bookkeeper.client.BKException)1 ReplicationException (org.apache.bookkeeper.replication.ReplicationException)1 CompatibilityException (org.apache.bookkeeper.replication.ReplicationException.CompatibilityException)1 ACL (org.apache.zookeeper.data.ACL)1 Stat (org.apache.zookeeper.data.Stat)1