<commit_before>package com.splicemachine.derby.hbase;

import com.splicemachine.si.api.CannotCommitException;
import org.apache.derby.iapi.error.StandardException;
import org.apache.hadoop.hbase.DoNotRetryIOException;

import java.io.IOException;
import java.net.SocketTimeoutException;

/**
 * Class for holding unified logic between hbase-94 and hbase-98
 * exception translation logic.
 *
 * @author <NAME>
 *         Date: 12/3/14
 */
public abstract class SkeletonExceptionTranslator implements ExceptionTranslator{
    @Override
    public boolean needsTransactionalRetry(Throwable t) {
        t = getRootCause(t);
        if(t instanceof CannotCommitException) return true;
        if(isCallTimeoutException(t)) return true;
        if(t instanceof SocketTimeoutException) return true;
        return false;
    }

    @Override
    public boolean canFinitelyRetry(Throwable t) {
        t = getRootCause(t);
        if(isCallTimeoutException(t)) return true;
        else if(isConnectException(t)) return true;
        else if (t instanceof DoNotRetryIOException) return false;
        else if (t instanceof IOException) return true;
        else return false;
    }

    @Override
    public boolean canInfinitelyRetry(Throwable t) {
        t = getRootCause(t);
        return isNotServingRegionException(t)
                || isWrongRegionException(t)
                || isRegionTooBusyException(t);
    }

    protected abstract Throwable getRootCause(Throwable t);
}<commit_msg>DB-2439: Making it so that SE004 error messages will be treated as NotServingRegionExceptions and infinitely retried where applicable<commit_after>package com.splicemachine.derby.hbase;

import com.splicemachine.pipeline.exception.ErrorState;
import com.splicemachine.si.api.CannotCommitException;
import org.apache.derby.iapi.error.StandardException;
import org.apache.hadoop.hbase.DoNotRetryIOException;

import java.io.IOException;
import java.net.SocketTimeoutException;

/**
 * Class for holding unified logic between hbase-94 and hbase-98
 * exception translation logic.
 *
 * @author <NAME>
 *         Date: 12/3/14
 */
public abstract class SkeletonExceptionTranslator implements ExceptionTranslator{
    @Override
    public boolean needsTransactionalRetry(Throwable t) {
        t = getRootCause(t);
        if(t instanceof CannotCommitException) return true;
        if(isCallTimeoutException(t)) return true;
        if(t instanceof SocketTimeoutException) return true;
        return false;
    }

    @Override
    public boolean canFinitelyRetry(Throwable t) {
        t = getRootCause(t);
        if(isCallTimeoutException(t)) return true;
        else if(isConnectException(t)) return true;
        else if (t instanceof DoNotRetryIOException) return false;
        else if (t instanceof IOException) return true;
        else return false;
    }

    @Override
    public boolean canInfinitelyRetry(Throwable t) {
        t = getRootCause(t);
        if(isNotServingRegionException(t)
                || isWrongRegionException(t)
                || isRegionTooBusyException(t)) return true;
        if(t instanceof StandardException){
            StandardException se = (StandardException)t;
            if(ErrorState.SPLICE_REGION_OFFLINE.getSqlState().equals(se.getSqlState())){
                /*
                 * SpliceRegionOffline is an error message that we throw that is a translation
                 * of a NotServingRegionException, WrongRegionException, or FailedServerException.
                 * All of these should be retried up to the query timeout (i.e. infinitely)
                 */
                return true;
            }
        }
        return false;
    }

    protected abstract Throwable getRootCause(Throwable t);
}
{'fraction_non_alphanumeric': 0.07635009310986965, 'fraction_numerical': 0.006650704974727321, 'mean_word_length': 3.030010718113612, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4674706', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1008, 'n_words': 268}