Skip to content

Commit c606f7f

Browse files
committed
retry with initialize fileInputStream
1 parent 2a6ebf9 commit c606f7f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/main/java/org/embulk/output/snowflake/SnowflakeCopyBatchInsert.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,32 +351,31 @@ public UploadTask(
351351
}
352352

353353
public Void call() throws IOException, SQLException, InterruptedException {
354-
logger.info(
355-
String.format(
356-
"Uploading file id %s to Snowflake (%,d bytes %,d rows)",
357-
snowflakeStageFileName, file.length(), batchRows));
358-
359354
int retries = 0;
360355
try {
361356
long startTime = System.currentTimeMillis();
362357
// put file to snowflake internal storage
363358
SnowflakeOutputConnection con = (SnowflakeOutputConnection) connector.connect(true);
364359

365-
FileInputStream fileInputStream = new FileInputStream(file);
366360
do {
367361
try {
362+
logger.info(
363+
String.format(
364+
"Uploading file id %s to Snowflake (%,d bytes %,d rows)",
365+
snowflakeStageFileName, file.length(), batchRows));
366+
FileInputStream fileInputStream = new FileInputStream(file);
368367
con.runUploadFile(stageIdentifier, snowflakeStageFileName, fileInputStream);
368+
break;
369369
} catch (SQLException e) {
370370
retries++;
371-
if (retries > this.maxUploadRetries) {
371+
if (retries >= this.maxUploadRetries) {
372372
throw e;
373373
}
374374
logger.warn(
375375
String.format(
376376
"Upload error %s file %s retries: %d", e, snowflakeStageFileName, retries));
377377
Thread.sleep(retries * retries * 1000);
378378
}
379-
break;
380379
} while (retries < this.maxUploadRetries);
381380

382381
double seconds = (System.currentTimeMillis() - startTime) / 1000.0;

0 commit comments

Comments
 (0)