Search in sources :

Example 11 with CodedInputStream

use of org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream 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 12 with CodedInputStream

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

the class ProtobufUtil method mergeFrom.

/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers where the message size is not known
 * @param builder current message builder
 * @param in InputStream containing protobuf data
 * @throws IOException
 */
public static void mergeFrom(Message.Builder builder, InputStream in) throws IOException {
    final CodedInputStream codedInput = CodedInputStream.newInstance(in);
    codedInput.setSizeLimit(Integer.MAX_VALUE);
    builder.mergeFrom(codedInput);
    codedInput.checkLastTagWas(0);
}
Also used : CodedInputStream(org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream)

Example 13 with CodedInputStream

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

the class ProtobufUtil method mergeDelimitedFrom.

/**
 * This version of protobuf's mergeDelimitedFrom avoid the hard-coded 64MB limit for decoding
 * buffers
 * @param builder current message builder
 * @param in Inputsream with delimited protobuf data
 * @throws IOException
 */
public static void mergeDelimitedFrom(Message.Builder builder, InputStream in) throws IOException {
    // This used to be builder.mergeDelimitedFrom(in);
    // but is replaced to allow us to bump the protobuf size limit.
    final int firstByte = in.read();
    if (firstByte != -1) {
        final int size = CodedInputStream.readRawVarint32(firstByte, in);
        final InputStream limitedInput = ByteStreams.limit(in, size);
        final CodedInputStream codedInput = CodedInputStream.newInstance(limitedInput);
        codedInput.setSizeLimit(size);
        builder.mergeFrom(codedInput);
        codedInput.checkLastTagWas(0);
    }
}
Also used : CodedInputStream(org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream) InputStream(java.io.InputStream) CodedInputStream(org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream)

Aggregations

CodedInputStream (org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream)13 IOException (java.io.IOException)3 InputStream (java.io.InputStream)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 Path (org.apache.hadoop.fs.Path)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 RequestHeader (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader)2 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)2 InvalidProtocolBufferException (org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException)2 Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)2 Span (io.opentelemetry.api.trace.Span)1 Context (io.opentelemetry.context.Context)1 Scope (io.opentelemetry.context.Scope)1 TextMapGetter (io.opentelemetry.context.propagation.TextMapGetter)1 FileNotFoundException (java.io.FileNotFoundException)1 InterruptedIOException (java.io.InterruptedIOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1