protected void insertBatch(Content[] batch, int id) 
    throws IOException {
        retry = 0;
        sleepTime = 500;
        while (retry < maxRetries) {
            try {
                if (retry == 1) { 
                    LOG.info("Retrying document insert");
                }
                List<RequestException> errors = 
                    sessions[id].insertContentCollectErrors(batch);
                if (errors != null) {
                    for (RequestException ex : errors) {
                        Throwable cause = ex.getCause();
                        if (cause != null) {
                            if (cause instanceof QueryException) {
                                LOG.error(
                                    ((QueryException)cause).getFormatString());
                            } else {
                                LOG.error(cause.getMessage());
                            }
                        }
                        if (ex instanceof ContentInsertException) {
                            Content content = 
                                    ((ContentInsertException)ex).getContent();
                            DocumentURI failedUri = 
                                    pendingUris[id].remove(content);
                            failed++;
                            if (failedUri != null) {
                                LOG.warn("Failed document " + failedUri);
                            }
                        }
                    }
                }
                if (retry > 0) { 
                    LOG.debug("Retry successful");
                }
            } catch (Exception e) {
                boolean retryable = true;
                if (e instanceof QueryException) {
                    LOG.error("QueryException:" + ((QueryException)e).getFormatString());
                    retryable = ((QueryException)e).isRetryable();
                } else if (e instanceof RequestServerException) {
                    // log error and continue on RequestServerException
                    // not retryable so trying to connect to the replica
                    LOG.error("RequestServerException:" + e.getMessage());
                } else {
                    LOG.error("Exception:" + e.getMessage());
                }

                // necessary to roll back in certain scenarios.
                if (needCommit) {
                    rollback(id);
                }

                if (retryable && ++retry < maxRetries) {
                    // necessary to close the session too.
                    sessions[id].close();
                    try {
                        InternalUtilities.sleep(sleepTime);
                    } catch (Exception e2) {
                    }
                    sleepTime = sleepTime * 2;
                    if (sleepTime > maxSleepTime) 
                        sleepTime = maxSleepTime;
                    
                    // We need to switch host even for RetryableQueryException
                    // because it could be "sync replicating" (bug:45785)
                    sessions[id] = getSession(id, true);
                    continue;
                } else if (retryable) {
                    LOG.info("Exceeded max retry");
                }
                failed += batch.length;
                // remove the failed content from pendingUris
                for (Content fc : batch) {
                    DocumentURI failedUri = pendingUris[id].remove(fc);
                    LOG.warn("Failed document " + failedUri);
                }
                throw new IOException(e);
            } 
            break;
        }

        if (needCommit) {
            // move uris from pending to commit
            for (DocumentURI uri : pendingUris[id].values()) {
                commitUris[id].add(uri);
            }
        } else {
            succeeded += pendingUris[id].size();
        }
        pendingUris[id].clear();
    }
protected void insertBatch ( Content [ ] batch , int id ) throws IOException { retry = 0 ; sleepTime = 500 ; while ( retry < maxRetries ) { try { if ( retry == 1 ) { LOG . info ( "Retrying document insert" ) ; } List < RequestException > errors = sessions [ id ] . insertContentCollectErrors ( batch ) ; if ( errors != null ) { for ( RequestException ex : errors ) { Throwable cause = ex . getCause ( ) ; if ( cause != null ) { if ( cause instanceof QueryException ) { LOG . error ( ( ( QueryException ) cause ) . getFormatString ( ) ) ; } else { LOG . error ( cause . getMessage ( ) ) ; } } if ( ex instanceof ContentInsertException ) { Content content = ( ( ContentInsertException ) ex ) . getContent ( ) ; DocumentURI failedUri = pendingUris [ id ] . remove ( content ) ; failed ++ ; if ( failedUri != null ) { LOG . warn ( "Failed document " + failedUri ) ; } } } } if ( retry > 0 ) { LOG . debug ( "Retry successful" ) ; } } catch ( Exception e ) { boolean retryable = true ; if ( e instanceof QueryException ) { LOG . error ( "QueryException:" + ( ( QueryException ) e ) . getFormatString ( ) ) ; retryable = ( ( QueryException ) e ) . isRetryable ( ) ; } else if ( e instanceof RequestServerException ) { LOG . error ( "RequestServerException:" + e . getMessage ( ) ) ; } else { LOG . error ( "Exception:" + e . getMessage ( ) ) ; } if ( needCommit ) { rollback ( id ) ; } if ( retryable && ++ retry < maxRetries ) { sessions [ id ] . close ( ) ; try { InternalUtilities . sleep ( sleepTime ) ; } catch ( Exception e2 ) { } sleepTime = sleepTime * 2 ; if ( sleepTime > maxSleepTime ) sleepTime = maxSleepTime ; sessions [ id ] = getSession ( id , true ) ; continue ; } else if ( retryable ) { LOG . info ( "Exceeded max retry" ) ; } failed += batch . length ; for ( Content fc : batch ) { DocumentURI failedUri = pendingUris [ id ] . remove ( fc ) ; LOG . warn ( "Failed document " + failedUri ) ; } throw new IOException ( e ) ; } break ; } if ( needCommit ) { for ( DocumentURI uri : pendingUris [ id ] . values ( ) ) { commitUris [ id ] . add ( uri ) ; } } else { succeeded += pendingUris [ id ] . size ( ) ; } pendingUris [ id ] . clear ( ) ; }
Insert batch, log errors and update stats.

@param batch batch of content to insert
@param id forest Id