Search in sources :

Example 11 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class FSTableDescriptors method readTableDescriptor.

private static HTableDescriptor readTableDescriptor(FileSystem fs, FileStatus status) throws IOException {
    int len = Ints.checkedCast(status.getLen());
    byte[] content = new byte[len];
    FSDataInputStream fsDataInputStream = fs.open(status.getPath());
    try {
        fsDataInputStream.readFully(content);
    } finally {
        fsDataInputStream.close();
    }
    HTableDescriptor htd = null;
    try {
        htd = HTableDescriptor.parseFrom(content);
    } catch (DeserializationException e) {
        throw new IOException("content=" + Bytes.toShort(content), e);
    }
    return htd;
}
Also used : FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 12 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class QualifierFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link QualifierFilter} instance
 * @return An instance of {@link QualifierFilter} made from <code>bytes</code>
 * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 * @see #toByteArray
 */
public static QualifierFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.QualifierFilter proto;
    try {
        proto = FilterProtos.QualifierFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    final CompareOperator valueCompareOp = CompareOperator.valueOf(proto.getCompareFilter().getCompareOp().name());
    ByteArrayComparable valueComparator = null;
    try {
        if (proto.getCompareFilter().hasComparator()) {
            valueComparator = ProtobufUtil.toComparator(proto.getCompareFilter().getComparator());
        }
    } catch (IOException ioe) {
        throw new DeserializationException(ioe);
    }
    return new QualifierFilter(valueCompareOp, valueComparator);
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) FilterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 13 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class ZKReplicationQueueStorage method getLastSequenceIdWithVersion.

/**
 * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means
 * that the ZNode does not exist.
 */
protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName, String peerId) throws KeeperException {
    Stat stat = new Stat();
    String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId);
    byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat);
    if (data == null) {
        // ZNode does not exist, so just return version -1 to indicate that no node exist.
        return Pair.newPair(HConstants.NO_SEQNUM, -1);
    }
    try {
        return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion());
    } catch (DeserializationException de) {
        LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId + "), data=" + Bytes.toStringBinary(data));
    }
    return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion());
}
Also used : Stat(org.apache.zookeeper.data.Stat) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 14 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class ActiveMasterManager method blockUntilBecomingActiveMaster.

/**
 * Block until becoming the active master.
 *
 * Method blocks until there is not another active master and our attempt
 * to become the new active master is successful.
 *
 * This also makes sure that we are watching the master znode so will be
 * notified if another master dies.
 * @param checkInterval the interval to check if the master is stopped
 * @param startupStatus the monitor status to track the progress
 * @return True if no issue becoming active master else false if another
 *   master was running or if some other problem (zookeeper, stop flag has been
 *   set on this Master)
 */
boolean blockUntilBecomingActiveMaster(int checkInterval, MonitoredTask startupStatus) {
    String backupZNode = ZNodePaths.joinZNode(this.watcher.getZNodePaths().backupMasterAddressesZNode, this.sn.toString());
    while (!(master.isAborted() || master.isStopped())) {
        startupStatus.setStatus("Trying to register in ZK as active master");
        // Write out our ServerName as versioned bytes.
        try {
            if (MasterAddressTracker.setMasterAddress(this.watcher, this.watcher.getZNodePaths().masterAddressZNode, this.sn, infoPort)) {
                // master directory since we are the active now)
                if (ZKUtil.checkExists(this.watcher, backupZNode) != -1) {
                    LOG.info("Deleting ZNode for " + backupZNode + " from backup master directory");
                    ZKUtil.deleteNodeFailSilent(this.watcher, backupZNode);
                }
                // Save the znode in a file, this will allow to check if we crash in the launch scripts
                ZNodeClearer.writeMyEphemeralNodeOnDisk(this.sn.toString());
                // We are the master, return
                startupStatus.setStatus("Successfully registered as active master.");
                this.clusterHasActiveMaster.set(true);
                activeMasterServerName = sn;
                LOG.info("Registered as active master=" + this.sn);
                return true;
            }
            // Invalidate the active master name so that subsequent requests do not get any stale
            // master information. Will be re-fetched if needed.
            activeMasterServerName = null;
            // There is another active master running elsewhere or this is a restart
            // and the master ephemeral node has not expired yet.
            this.clusterHasActiveMaster.set(true);
            String msg;
            byte[] bytes = ZKUtil.getDataAndWatch(this.watcher, this.watcher.getZNodePaths().masterAddressZNode);
            if (bytes == null) {
                msg = ("A master was detected, but went down before its address " + "could be read.  Attempting to become the next active master");
            } else {
                ServerName currentMaster;
                try {
                    currentMaster = ProtobufUtil.parseServerNameFrom(bytes);
                } catch (DeserializationException e) {
                    LOG.warn("Failed parse", e);
                    // Hopefully next time around we won't fail the parse.  Dangerous.
                    continue;
                }
                if (ServerName.isSameAddress(currentMaster, this.sn)) {
                    msg = ("Current master has this master's address, " + currentMaster + "; master was restarted? Deleting node.");
                    // Hurry along the expiration of the znode.
                    ZKUtil.deleteNode(this.watcher, this.watcher.getZNodePaths().masterAddressZNode);
                    // We may have failed to delete the znode at the previous step, but
                    // we delete the file anyway: a second attempt to delete the znode is likely to fail
                    // again.
                    ZNodeClearer.deleteMyEphemeralNodeOnDisk();
                } else {
                    msg = "Another master is the active master, " + currentMaster + "; waiting to become the next active master";
                }
            }
            LOG.info(msg);
            startupStatus.setStatus(msg);
        } catch (KeeperException ke) {
            master.abort("Received an unexpected KeeperException, aborting", ke);
            return false;
        }
        synchronized (this.clusterHasActiveMaster) {
            while (clusterHasActiveMaster.get() && !master.isStopped()) {
                try {
                    clusterHasActiveMaster.wait(checkInterval);
                } catch (InterruptedException e) {
                    // We expect to be interrupted when a master dies,
                    // will fall out if so
                    LOG.debug("Interrupted waiting for master to die", e);
                }
            }
            if (clusterShutDown.get()) {
                this.master.stop("Cluster went down before this master became active");
            }
        }
    }
    return false;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) KeeperException(org.apache.zookeeper.KeeperException)

Example 15 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class ReplicationPeerConfigUtil method parsePeerFrom.

/**
 * @param bytes Content of a peer znode.
 * @return ClusterKey parsed from the passed bytes.
 * @throws DeserializationException deserialization exception
 */
public static ReplicationPeerConfig parsePeerFrom(final byte[] bytes) throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(bytes)) {
        int pbLen = ProtobufUtil.lengthOfPBMagic();
        ReplicationProtos.ReplicationPeer.Builder builder = ReplicationProtos.ReplicationPeer.newBuilder();
        ReplicationProtos.ReplicationPeer peer;
        try {
            ProtobufUtil.mergeFrom(builder, bytes, pbLen, bytes.length - pbLen);
            peer = builder.build();
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
        return convert(peer);
    } else {
        if (bytes == null || bytes.length <= 0) {
            throw new DeserializationException("Bytes to deserialize should not be empty.");
        }
        return ReplicationPeerConfig.newBuilder().setClusterKey(Bytes.toString(bytes)).build();
    }
}
Also used : ReplicationProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ReplicationProtos) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)83 IOException (java.io.IOException)57 InvalidProtocolBufferException (org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException)15 FilterProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos)13 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)12 KeeperException (org.apache.zookeeper.KeeperException)12 ArrayList (java.util.ArrayList)11 ServerName (org.apache.hadoop.hbase.ServerName)9 Cell (org.apache.hadoop.hbase.Cell)8 CompareOperator (org.apache.hadoop.hbase.CompareOperator)8 InterruptedIOException (java.io.InterruptedIOException)7 CellVisibility (org.apache.hadoop.hbase.security.visibility.CellVisibility)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Tag (org.apache.hadoop.hbase.Tag)6 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)6 Map (java.util.Map)5 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)5 TableName (org.apache.hadoop.hbase.TableName)5 FilterList (org.apache.hadoop.hbase.filter.FilterList)5 List (java.util.List)4