Search in sources :

Example 16 with InvalidProtocolBufferException

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

the class MultiRowRangeFilter method parseFrom.

/**
 * @param pbBytes A pb serialized instance
 * @return An instance of MultiRowRangeFilter
 * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 */
public static MultiRowRangeFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.MultiRowRangeFilter proto;
    try {
        proto = FilterProtos.MultiRowRangeFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    int length = proto.getRowRangeListCount();
    List<FilterProtos.RowRange> rangeProtos = proto.getRowRangeListList();
    List<RowRange> rangeList = new ArrayList<>(length);
    for (FilterProtos.RowRange rangeProto : rangeProtos) {
        RowRange range = new RowRange(rangeProto.hasStartRow() ? rangeProto.getStartRow().toByteArray() : null, rangeProto.getStartRowInclusive(), rangeProto.hasStopRow() ? rangeProto.getStopRow().toByteArray() : null, rangeProto.getStopRowInclusive());
        rangeList.add(range);
    }
    return new MultiRowRangeFilter(rangeList);
}
Also used : InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) ArrayList(java.util.ArrayList) FilterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 17 with InvalidProtocolBufferException

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

the class SingleColumnValueFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link SingleColumnValueFilter} instance
 * @return An instance of {@link SingleColumnValueFilter} made from <code>bytes</code>
 * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 * @see #toByteArray
 */
public static SingleColumnValueFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.SingleColumnValueFilter proto;
    try {
        proto = FilterProtos.SingleColumnValueFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    final CompareOperator compareOp = CompareOperator.valueOf(proto.getCompareOp().name());
    final org.apache.hadoop.hbase.filter.ByteArrayComparable comparator;
    try {
        comparator = ProtobufUtil.toComparator(proto.getComparator());
    } catch (IOException ioe) {
        throw new DeserializationException(ioe);
    }
    return new SingleColumnValueFilter(proto.hasColumnFamily() ? proto.getColumnFamily().toByteArray() : null, proto.hasColumnQualifier() ? proto.getColumnQualifier().toByteArray() : null, compareOp, comparator, proto.getFilterIfMissing(), proto.getLatestVersionOnly());
}
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 18 with InvalidProtocolBufferException

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

the class ValueFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link ValueFilter} instance
 * @return An instance of {@link ValueFilter} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static ValueFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.ValueFilter proto;
    try {
        proto = FilterProtos.ValueFilter.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 ValueFilter(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 19 with InvalidProtocolBufferException

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

the class ProtobufLogReader method readNext.

@Override
protected boolean readNext(Entry entry) throws IOException {
    // OriginalPosition might be < 0 on local fs; if so, it is useless to us.
    long originalPosition = this.inputStream.getPos();
    if (trailerPresent && originalPosition > 0 && originalPosition == this.walEditsStopOffset) {
        LOG.trace("Reached end of expected edits area at offset {}", originalPosition);
        return false;
    }
    WALKey.Builder builder = WALKey.newBuilder();
    long size = 0;
    boolean resetPosition = false;
    try {
        long available = -1;
        try {
            int firstByte = this.inputStream.read();
            if (firstByte == -1) {
                throw new EOFException();
            }
            size = CodedInputStream.readRawVarint32(firstByte, this.inputStream);
            // available may be < 0 on local fs for instance.  If so, can't depend on it.
            available = this.inputStream.available();
            if (available > 0 && available < size) {
                throw new EOFException("Available stream not enough for edit, " + "inputStream.available()= " + this.inputStream.available() + ", " + "entry size= " + size + " at offset = " + this.inputStream.getPos());
            }
            ProtobufUtil.mergeFrom(builder, ByteStreams.limit(this.inputStream, size), (int) size);
        } catch (InvalidProtocolBufferException ipbe) {
            resetPosition = true;
            throw (EOFException) new EOFException("Invalid PB, EOF? Ignoring; originalPosition=" + originalPosition + ", currentPosition=" + this.inputStream.getPos() + ", messageSize=" + size + ", currentAvailable=" + available).initCause(ipbe);
        }
        if (!builder.isInitialized()) {
            // If we can get the KV count, we could, theoretically, try to get next record.
            throw new EOFException("Partial PB while reading WAL, " + "probably an unexpected EOF, ignoring. current offset=" + this.inputStream.getPos());
        }
        WALKey walKey = builder.build();
        entry.getKey().readFieldsFromPb(walKey, this.byteStringUncompressor);
        if (!walKey.hasFollowingKvCount() || 0 == walKey.getFollowingKvCount()) {
            LOG.trace("WALKey has no KVs that follow it; trying the next one. current offset={}", this.inputStream.getPos());
            seekOnFs(originalPosition);
            return false;
        }
        int expectedCells = walKey.getFollowingKvCount();
        long posBefore = this.inputStream.getPos();
        try {
            int actualCells = entry.getEdit().readFromCells(cellDecoder, expectedCells);
            if (expectedCells != actualCells) {
                resetPosition = true;
                // other info added in catch
                throw new EOFException("Only read " + actualCells);
            }
        } catch (Exception ex) {
            String posAfterStr = "<unknown>";
            try {
                posAfterStr = this.inputStream.getPos() + "";
            } catch (Throwable t) {
                LOG.trace("Error getting pos for error message - ignoring", t);
            }
            String message = " while reading " + expectedCells + " WAL KVs; started reading at " + posBefore + " and read up to " + posAfterStr;
            IOException realEofEx = extractHiddenEof(ex);
            throw (EOFException) new EOFException("EOF " + message).initCause(realEofEx != null ? realEofEx : ex);
        }
        if (trailerPresent && this.inputStream.getPos() > this.walEditsStopOffset) {
            LOG.error("Read WALTrailer while reading WALEdits. wal: " + this.path + ", inputStream.getPos(): " + this.inputStream.getPos() + ", walEditsStopOffset: " + this.walEditsStopOffset);
            throw new EOFException("Read WALTrailer while reading WALEdits");
        }
    } catch (EOFException eof) {
        // If originalPosition is < 0, it is rubbish and we cannot use it (probably local fs)
        if (originalPosition < 0) {
            LOG.debug("Encountered a malformed edit, but can't seek back to last good position " + "because originalPosition is negative. last offset={}", this.inputStream.getPos(), eof);
            throw eof;
        }
        // If stuck at the same place and we got an exception, lets go back at the beginning.
        if (inputStream.getPos() == originalPosition) {
            if (resetPosition) {
                LOG.debug("Encountered a malformed edit, seeking to the beginning of the WAL since " + "current position and original position match at {}", originalPosition);
                seekOnFs(0);
            } else {
                LOG.debug("EOF at position {}", originalPosition);
            }
        } else {
            // Else restore our position to original location in hope that next time through we will
            // read successfully.
            LOG.debug("Encountered a malformed edit, seeking back to last good position in file, " + "from {} to {}", inputStream.getPos(), originalPosition, eof);
            seekOnFs(originalPosition);
        }
        return false;
    }
    return true;
}
Also used : WALKey(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALKey) EOFException(java.io.EOFException) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 20 with InvalidProtocolBufferException

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

the class SnapshotManifest method readDataManifest.

/*
   * Read the SnapshotDataManifest file
   */
private SnapshotDataManifest readDataManifest() throws IOException {
    try (FSDataInputStream in = workingDirFs.open(new Path(workingDir, DATA_MANIFEST_NAME))) {
        CodedInputStream cin = CodedInputStream.newInstance(in);
        cin.setSizeLimit(manifestSizeLimit);
        return SnapshotDataManifest.parseFrom(cin);
    } catch (FileNotFoundException e) {
        return null;
    } catch (InvalidProtocolBufferException e) {
        throw new CorruptedSnapshotException("unable to parse data manifest " + e.getMessage(), e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CodedInputStream(org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream) FileNotFoundException(java.io.FileNotFoundException) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

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