Search in sources :

Example 21 with InvalidProtocolBufferException

use of org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException in project hbase by apache.

the class SnapshotManifestV2 method loadRegionManifests.

static List<SnapshotRegionManifest> loadRegionManifests(final Configuration conf, final Executor executor, final FileSystem fs, final Path snapshotDir, final SnapshotDescription desc, final int manifestSizeLimit) throws IOException {
    FileStatus[] manifestFiles = CommonFSUtils.listStatus(fs, snapshotDir, new PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().startsWith(SNAPSHOT_MANIFEST_PREFIX);
        }
    });
    if (manifestFiles == null || manifestFiles.length == 0)
        return null;
    final ExecutorCompletionService<SnapshotRegionManifest> completionService = new ExecutorCompletionService<>(executor);
    for (final FileStatus st : manifestFiles) {
        completionService.submit(new Callable<SnapshotRegionManifest>() {

            @Override
            public SnapshotRegionManifest call() throws IOException {
                try (FSDataInputStream stream = fs.open(st.getPath())) {
                    CodedInputStream cin = CodedInputStream.newInstance(stream);
                    cin.setSizeLimit(manifestSizeLimit);
                    return SnapshotRegionManifest.parseFrom(cin);
                }
            }
        });
    }
    ArrayList<SnapshotRegionManifest> regionsManifest = new ArrayList<>(manifestFiles.length);
    try {
        for (int i = 0; i < manifestFiles.length; ++i) {
            regionsManifest.add(completionService.take().get());
        }
    } catch (InterruptedException e) {
        throw new InterruptedIOException(e.getMessage());
    } catch (ExecutionException e) {
        Throwable t = e.getCause();
        if (t instanceof InvalidProtocolBufferException) {
            throw (InvalidProtocolBufferException) t;
        } else {
            throw new IOException("ExecutionException", e.getCause());
        }
    }
    return regionsManifest;
}
Also used : Path(org.apache.hadoop.fs.Path) InterruptedIOException(java.io.InterruptedIOException) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) CodedInputStream(org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) SnapshotRegionManifest(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) ExecutionException(java.util.concurrent.ExecutionException)

Example 22 with InvalidProtocolBufferException

use of org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException in project hbase by apache.

the class ProtobufUtil method toProcedureJson.

/**
 * Helper to convert the protobuf Procedure to JSON String
 * @return Convert the current Protocol Buffers Procedure to JSON String
 */
public static String toProcedureJson(List<ProcedureProtos.Procedure> procProtos) {
    JsonArray procJsons = new JsonArray(procProtos.size());
    for (ProcedureProtos.Procedure procProto : procProtos) {
        try {
            JsonElement procJson = ProtobufMessageConverter.toJsonElement(procProto);
            procJsons.add(procJson);
        } catch (InvalidProtocolBufferException e) {
            procJsons.add(e.toString());
        }
    }
    return procJsons.toString();
}
Also used : JsonArray(org.apache.hbase.thirdparty.com.google.gson.JsonArray) JsonElement(org.apache.hbase.thirdparty.com.google.gson.JsonElement) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) ProcedureProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos)

Example 23 with InvalidProtocolBufferException

use of org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException in project hbase by apache.

the class ProtobufUtil method parseMetaRegionStateFrom.

/**
 * Get the Meta region state from the passed data bytes. Can handle both old and new style
 * server names.
 * @param data protobuf serialized data with meta server name.
 * @param replicaId replica ID for this region
 * @return RegionState instance corresponding to the serialized data.
 * @throws DeserializationException if the data is invalid.
 */
public static RegionState parseMetaRegionStateFrom(final byte[] data, int replicaId) throws DeserializationException {
    RegionState.State state = RegionState.State.OPEN;
    ServerName serverName;
    if (data != null && data.length > 0 && ProtobufUtil.isPBMagicPrefix(data)) {
        try {
            int prefixLen = ProtobufUtil.lengthOfPBMagic();
            ZooKeeperProtos.MetaRegionServer rl = ZooKeeperProtos.MetaRegionServer.parser().parseFrom(data, prefixLen, data.length - prefixLen);
            if (rl.hasState()) {
                state = RegionState.State.convert(rl.getState());
            }
            HBaseProtos.ServerName sn = rl.getServer();
            serverName = ServerName.valueOf(sn.getHostName(), sn.getPort(), sn.getStartCode());
        } catch (InvalidProtocolBufferException e) {
            throw new DeserializationException("Unable to parse meta region location");
        }
    } else {
        // old style of meta region location?
        serverName = parseServerNameFrom(data);
    }
    if (serverName == null) {
        state = RegionState.State.OFFLINE;
    }
    return new RegionState(RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId), state, serverName);
}
Also used : RegionState(org.apache.hadoop.hbase.master.RegionState) ServerName(org.apache.hadoop.hbase.ServerName) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) ZooKeeperProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 24 with InvalidProtocolBufferException

use of org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException in project hbase by apache.

the class QuotaTableUtil method extractQuotaSnapshot.

/**
 * Extracts the {@link SpaceViolationPolicy} and {@link TableName} from the provided
 * {@link Result} and adds them to the given {@link Map}. If the result does not contain
 * the expected information or the serialized policy in the value is invalid, this method
 * will throw an {@link IllegalArgumentException}.
 *
 * @param result A row from the quota table.
 * @param snapshots A map of snapshots to add the result of this method into.
 */
public static void extractQuotaSnapshot(Result result, Map<TableName, SpaceQuotaSnapshot> snapshots) {
    byte[] row = Objects.requireNonNull(result).getRow();
    if (row == null || row.length == 0) {
        throw new IllegalArgumentException("Provided result had a null row");
    }
    final TableName targetTableName = getTableFromRowKey(row);
    Cell c = result.getColumnLatestCell(QUOTA_FAMILY_USAGE, QUOTA_QUALIFIER_POLICY);
    if (c == null) {
        throw new IllegalArgumentException("Result did not contain the expected column " + QUOTA_POLICY_COLUMN + ", " + result.toString());
    }
    ByteString buffer = UnsafeByteOperations.unsafeWrap(c.getValueArray(), c.getValueOffset(), c.getValueLength());
    try {
        QuotaProtos.SpaceQuotaSnapshot snapshot = QuotaProtos.SpaceQuotaSnapshot.parseFrom(buffer);
        snapshots.put(targetTableName, SpaceQuotaSnapshot.toSpaceQuotaSnapshot(snapshot));
    } catch (InvalidProtocolBufferException e) {
        throw new IllegalArgumentException("Result did not contain a valid SpaceQuota protocol buffer message", e);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) Cell(org.apache.hadoop.hbase.Cell) QuotaProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos)

Example 25 with InvalidProtocolBufferException

use of org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException in project hbase by apache.

the class QuotaTableUtil method getNamespaceSnapshotSize.

/**
 * Fetches the computed size of all snapshots against tables in a namespace for space quotas.
 */
static long getNamespaceSnapshotSize(Connection conn, String namespace) throws IOException {
    try (Table quotaTable = conn.getTable(QuotaTableUtil.QUOTA_TABLE_NAME)) {
        Result r = quotaTable.get(createGetNamespaceSnapshotSize(namespace));
        if (r.isEmpty()) {
            return 0L;
        }
        r.advance();
        return parseSnapshotSize(r.current());
    } catch (InvalidProtocolBufferException e) {
        throw new IOException("Could not parse snapshot size value for namespace " + namespace, e);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

InvalidProtocolBufferException (org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException)25 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)15 IOException (java.io.IOException)12 FilterProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos)12 CompareOperator (org.apache.hadoop.hbase.CompareOperator)8 ArrayList (java.util.ArrayList)4 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)3 Path (org.apache.hadoop.fs.Path)2 Cell (org.apache.hadoop.hbase.Cell)2 Result (org.apache.hadoop.hbase.client.Result)2 Table (org.apache.hadoop.hbase.client.Table)2 ComparatorProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ComparatorProtos)2 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)2 JsonArray (org.apache.hbase.thirdparty.com.google.gson.JsonArray)2 JsonElement (org.apache.hbase.thirdparty.com.google.gson.JsonElement)2 CodedInputStream (org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream)2 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1 InterruptedIOException (java.io.InterruptedIOException)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1