Search in sources :

Example 6 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project pinpoint by naver.

the class ThriftRequestProperty method writeTraceHeader.

public void writeTraceHeader(ThriftHeader headerKey, TProtocol oprot) throws TException {
    Object headerValue = this.thriftHeaders.get(headerKey);
    if (headerValue == null) {
        return;
    }
    byte headerType = headerKey.getType();
    TField traceField = new TField(headerKey.name(), headerKey.getType(), headerKey.getId());
    oprot.writeFieldBegin(traceField);
    try {
        if (headerType == TType.STRING) {
            // these will be read as byte buffer although it's probably safe to just use writeString here.
            // see org.apache.thrift.protocol.TProtocolUtil.skip(TProtocol, byte, int)
            oprot.writeBinary(stringToByteBuffer((String) headerValue));
        } else if (headerType == TType.I64) {
            oprot.writeI64((Long) headerValue);
        } else if (headerType == TType.I16) {
            oprot.writeI16((Short) headerValue);
        } else if (headerType == TType.BOOL) {
            oprot.writeBool((Boolean) headerValue);
        } else {
            throw new TProtocolException("Invalid pinpoint header type - " + headerType);
        }
    } finally {
        oprot.writeFieldEnd();
    }
}
Also used : TField(org.apache.thrift.protocol.TField) TProtocolException(org.apache.thrift.protocol.TProtocolException)

Example 7 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project hive by apache.

the class RetryingMetaStoreClient method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Object ret;
    int retriesMade = 0;
    TException caughtException;
    boolean allowReconnect = !method.isAnnotationPresent(NoReconnect.class);
    boolean allowRetry = true;
    Annotation[] directives = method.getDeclaredAnnotations();
    if (directives != null) {
        for (Annotation a : directives) {
            if (a instanceof RetrySemantics.CannotRetry) {
                allowRetry = false;
            }
        }
    }
    while (true) {
        try {
            reloginExpiringKeytabUser();
            if (allowReconnect) {
                if (retriesMade > 0 || hasConnectionLifeTimeReached(method)) {
                    if (this.ugi != null) {
                        // Perform reconnect with the proper user context
                        try {
                            LOG.info("RetryingMetaStoreClient trying reconnect as " + this.ugi);
                            this.ugi.doAs(new PrivilegedExceptionAction<Object>() {

                                @Override
                                public Object run() throws MetaException {
                                    base.reconnect();
                                    return null;
                                }
                            });
                        } catch (UndeclaredThrowableException e) {
                            Throwable te = e.getCause();
                            if (te instanceof PrivilegedActionException) {
                                throw te.getCause();
                            } else {
                                throw te;
                            }
                        }
                        lastConnectionTime = System.currentTimeMillis();
                    } else {
                        LOG.warn("RetryingMetaStoreClient unable to reconnect. No UGI information.");
                        throw new MetaException("UGI information unavailable. Will not attempt a reconnect.");
                    }
                }
            }
            if (metaCallTimeMap == null) {
                ret = method.invoke(base, args);
            } else {
                // need to capture the timing
                long startTime = System.currentTimeMillis();
                ret = method.invoke(base, args);
                long timeTaken = System.currentTimeMillis() - startTime;
                addMethodTime(method, timeTaken);
            }
            break;
        } catch (UndeclaredThrowableException e) {
            throw e.getCause();
        } catch (InvocationTargetException e) {
            Throwable t = e.getCause();
            if (t instanceof TApplicationException) {
                TApplicationException tae = (TApplicationException) t;
                switch(tae.getType()) {
                    case TApplicationException.UNSUPPORTED_CLIENT_TYPE:
                    case TApplicationException.UNKNOWN_METHOD:
                    case TApplicationException.WRONG_METHOD_NAME:
                    case TApplicationException.INVALID_PROTOCOL:
                        throw t;
                    default:
                        // TODO: most other options are probably unrecoverable... throw?
                        caughtException = tae;
                }
            } else if ((t instanceof TProtocolException) || (t instanceof TTransportException)) {
                // TODO: most protocol exceptions are probably unrecoverable... throw?
                caughtException = (TException) t;
            } else if ((t instanceof MetaException) && t.getMessage().matches("(?s).*(JDO[a-zA-Z]*|TProtocol|TTransport)Exception.*") && !t.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
                caughtException = (MetaException) t;
            } else {
                throw t;
            }
        } catch (MetaException e) {
            if (e.getMessage().matches("(?s).*(IO|TTransport)Exception.*") && !e.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
                caughtException = e;
            } else {
                throw e;
            }
        }
        if (retriesMade >= retryLimit || base.isLocalMetaStore() || !allowRetry) {
            throw caughtException;
        }
        retriesMade++;
        LOG.warn("MetaStoreClient lost connection. Attempting to reconnect (" + retriesMade + " of " + retryLimit + ") after " + retryDelaySeconds + "s. " + method.getName(), caughtException);
        Thread.sleep(retryDelaySeconds * 1000);
    }
    return ret;
}
Also used : TException(org.apache.thrift.TException) PrivilegedActionException(java.security.PrivilegedActionException) TTransportException(org.apache.thrift.transport.TTransportException) NoReconnect(org.apache.hadoop.hive.metastore.annotation.NoReconnect) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException) TApplicationException(org.apache.thrift.TApplicationException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) TProtocolException(org.apache.thrift.protocol.TProtocolException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 8 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project storm by apache.

the class ComponentObject method tupleSchemeReadValue.

@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
    _Fields setField = _Fields.findByThriftId(fieldID);
    if (setField != null) {
        switch(setField) {
            case SERIALIZED_JAVA:
                ByteBuffer serialized_java;
                serialized_java = iprot.readBinary();
                return serialized_java;
            case SHELL:
                ShellComponent shell;
                shell = new ShellComponent();
                shell.read(iprot);
                return shell;
            case JAVA_OBJECT:
                JavaObject java_object;
                java_object = new JavaObject();
                java_object.read(iprot);
                return java_object;
            default:
                throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
        }
    } else {
        throw new TProtocolException("Couldn't find a field with field id " + fieldID);
    }
}
Also used : TProtocolException(org.apache.thrift.protocol.TProtocolException) ByteBuffer(java.nio.ByteBuffer)

Example 9 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project storm by apache.

the class HBMessageData method tupleSchemeReadValue.

@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
    _Fields setField = _Fields.findByThriftId(fieldID);
    if (setField != null) {
        switch(setField) {
            case PATH:
                String path;
                path = iprot.readString();
                return path;
            case PULSE:
                HBPulse pulse;
                pulse = new HBPulse();
                pulse.read(iprot);
                return pulse;
            case BOOLVAL:
                Boolean boolval;
                boolval = iprot.readBool();
                return boolval;
            case RECORDS:
                HBRecords records;
                records = new HBRecords();
                records.read(iprot);
                return records;
            case NODES:
                HBNodes nodes;
                nodes = new HBNodes();
                nodes.read(iprot);
                return nodes;
            case MESSAGE_BLOB:
                ByteBuffer message_blob;
                message_blob = iprot.readBinary();
                return message_blob;
            default:
                throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
        }
    } else {
        throw new TProtocolException("Couldn't find a field with field id " + fieldID);
    }
}
Also used : TProtocolException(org.apache.thrift.protocol.TProtocolException) ByteBuffer(java.nio.ByteBuffer)

Example 10 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project jstorm by alibaba.

the class Grouping method tupleSchemeReadValue.

@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
    _Fields setField = _Fields.findByThriftId(fieldID);
    if (setField != null) {
        switch(setField) {
            case FIELDS:
                List<String> fields;
                {
                    org.apache.thrift.protocol.TList _list12 = iprot.readListBegin();
                    fields = new ArrayList<String>(_list12.size);
                    String _elem13;
                    for (int _i14 = 0; _i14 < _list12.size; ++_i14) {
                        _elem13 = iprot.readString();
                        fields.add(_elem13);
                    }
                    iprot.readListEnd();
                }
                return fields;
            case SHUFFLE:
                NullStruct shuffle;
                shuffle = new NullStruct();
                shuffle.read(iprot);
                return shuffle;
            case ALL:
                NullStruct all;
                all = new NullStruct();
                all.read(iprot);
                return all;
            case NONE:
                NullStruct none;
                none = new NullStruct();
                none.read(iprot);
                return none;
            case DIRECT:
                NullStruct direct;
                direct = new NullStruct();
                direct.read(iprot);
                return direct;
            case CUSTOM_OBJECT:
                JavaObject custom_object;
                custom_object = new JavaObject();
                custom_object.read(iprot);
                return custom_object;
            case CUSTOM_SERIALIZED:
                ByteBuffer custom_serialized;
                custom_serialized = iprot.readBinary();
                return custom_serialized;
            case LOCAL_OR_SHUFFLE:
                NullStruct local_or_shuffle;
                local_or_shuffle = new NullStruct();
                local_or_shuffle.read(iprot);
                return local_or_shuffle;
            case LOCAL_FIRST:
                NullStruct localFirst;
                localFirst = new NullStruct();
                localFirst.read(iprot);
                return localFirst;
            default:
                throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
        }
    } else {
        throw new TProtocolException("Couldn't find a field with field id " + fieldID);
    }
}
Also used : TProtocolException(org.apache.thrift.protocol.TProtocolException) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TProtocolException (org.apache.thrift.protocol.TProtocolException)15 ByteBuffer (java.nio.ByteBuffer)8 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)3 PartitionValuesRequest (org.apache.hadoop.hive.metastore.api.PartitionValuesRequest)3 TApplicationException (org.apache.thrift.TApplicationException)3 TException (org.apache.thrift.TException)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 ThriftHiveMetastore.set_ugi_args (org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_args)2 ThriftHiveMetastore.set_ugi_result (org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_result)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 TMessage (org.apache.thrift.protocol.TMessage)2 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 NoReconnect (org.apache.hadoop.hive.metastore.annotation.NoReconnect)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 TField (org.apache.thrift.protocol.TField)1