question: private void seekingWriteAll ( TableId table , List < InsertAllRequest . RowToInsert > elements , String topic , Set < Schema > schemas ) throws BigQueryConnectException , InterruptedException { logger . debug ( "Seeking best batch size..." ) ; int currentIndex = 0 ; int successfulCallCount = 0 ; while ( currentIndex < elements . size ( ) ) { int endIndex = Math . min ( currentIndex + currentBatchSize , elements . size ( ) ) ; List < InsertAllRequest . RowToInsert > currentBatchElements = elements . subList ( currentIndex , endIndex ) ; try { writer . writeRows ( table , currentBatchElements , topic , schemas ) ; successfulCallCount ++ ; currentIndex = endIndex ; if ( currentBatchSize == MAXIMUM_BATCH_SIZE ) { seeking = false ; logger . debug ( "Best batch size found (max): {}" , currentBatchSize ) ; establishedWriteAll ( table , elements . subList ( currentIndex , elements . size ( ) ) , topic , schemas ) ; return ; } if ( currentIndex < elements . size ( ) ) { increaseBatchSize ( table ) ; } } catch ( BigQueryException exception ) { if ( isBatchSizeError ( exception ) ) { decreaseBatchSize ( table ) ; if ( successfulCallCount > 0 ) { seeking = false ; logger . debug ( "Best batch size found (error if higher): {}" , currentBatchSize ) ; establishedWriteAll ( table , elements . subList ( currentIndex , elements . size ( ) ) , topic , schemas ) ; return ; } } else { throw new BigQueryConnectException ( String . format ( "Failed to write to BigQuery table %s" , table ) , exception ) ; } } } if ( successfulCallCount == 1 ) { seeking = false ; logger . debug ( "Best batch size found (all elements): {}" , currentBatchSize ) ; } }
target:  A writeAll intended to quickly find the largest viable batchSize. <p>We start with the currentBatchSize and adjust up or down as necessary. Seek mode ends when one of the following occurs: 1. we get an error after at least 1 success. This is slightly inefficient if our currentBatchSize is too big, but we will only make 1 extra request in that case. Successes do not carry over from previous seekingWriteAll requests. 2. we write all the given elements in one batch request without error. 3. we write MAXIMUM_BATCH_SIZE elements in one batch request without error. (unlikely)