Skip to content

Commit fc98927

Browse files
author
Sanchit Garg
committed
PLUGIN-1924: Handle 412 Precondition Failed error
1 parent c1464f9 commit fc98927

20 files changed

Lines changed: 57 additions & 21 deletions

File tree

cassandra-plugins/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>io.cdap.plugin</groupId>
2323
<artifactId>hydrator-plugins</artifactId>
24-
<version>2.11.5</version>
24+
<version>2.11.6-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>Cassandra Plugins</name>

core-plugins/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>hydrator-plugins</artifactId>
2525
<groupId>io.cdap.plugin</groupId>
26-
<version>2.11.5</version>
26+
<version>2.11.6-SNAPSHOT</version>
2727
</parent>
2828

2929
<name>Hydrator Core Plugins</name>
@@ -299,6 +299,11 @@
299299
<groupId>org.mockito</groupId>
300300
<artifactId>mockito-core</artifactId>
301301
</dependency>
302+
<dependency>
303+
<groupId>com.google.api-client</groupId>
304+
<artifactId>google-api-client</artifactId>
305+
<version>1.32.1</version>
306+
</dependency>
302307
</dependencies>
303308

304309
<build>

core-plugins/src/main/java/io/cdap/plugin/batch/action/FileMoveAction.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.cdap.plugin.batch.action;
1818

19+
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
1920
import com.google.common.annotations.VisibleForTesting;
2021
import io.cdap.cdap.api.annotation.Description;
2122
import io.cdap.cdap.api.annotation.Macro;
@@ -70,7 +71,22 @@ public void run(ActionContext context) throws Exception {
7071
Path dest = new Path(config.destPath);
7172

7273
FileSystem fileSystem = source.getFileSystem(new Configuration());
73-
fileSystem.mkdirs(dest.getParent());
74+
try {
75+
fileSystem.mkdirs(dest.getParent());
76+
LOG.debug("mkdirs(): ensured destination parent directory exists: {}", dest.getParent());
77+
} catch (GoogleJsonResponseException e) {
78+
if (e.getStatusCode() == 412 || (e.getStatusMessage() != null && e.getStatusMessage()
79+
.contains("412 Precondition Failed"))) {
80+
// Expected GCS directory marker race condition — safe to ignore
81+
LOG.info("Directory already exists in GCS, skipping creation: {}", dest.getParent());
82+
} else {
83+
String errorReason = String.format("Failed to create parent directory for dest path: %s, Status Code: %s, " +
84+
"Message: %s", dest.getParent(), e.getStatusCode(), e.getMessage());
85+
throw new IOException(errorReason, e);
86+
}
87+
} catch (IOException e) {
88+
throw e;
89+
}
7490

7591
if (fileSystem.getFileStatus(source).isFile()) { //moving single file
7692

@@ -119,7 +135,22 @@ public boolean accept(Path path) {
119135
throw new IllegalArgumentException(String.format("destPath %s needs to be a directory since sourcePath is a " +
120136
"directory", config.destPath));
121137
}
122-
fileSystem.mkdirs(dest); //create destination directory if necessary
138+
try {
139+
fileSystem.mkdirs(dest); //create destination directory if necessary
140+
LOG.debug("mkdirs(): ensured destination parent directory exists: {}", dest.getParent());
141+
} catch (GoogleJsonResponseException e) {
142+
if (e.getStatusCode() == 412 || (e.getStatusMessage() != null && e.getStatusMessage()
143+
.contains("412 Precondition Failed"))) {
144+
// Expected GCS directory marker race condition — safe to ignore
145+
LOG.info("Directory already exists in GCS, skipping creation: {}", dest.getParent());
146+
} else {
147+
String errorReason = String.format("Failed to create parent directory for dest path: %s, Status Code: %s, " +
148+
"Message: %s", dest.getParent(), e.getStatusCode(), e.getMessage());
149+
throw new IOException(errorReason, e);
150+
}
151+
} catch (IOException e) {
152+
throw e;
153+
}
123154

124155
for (FileStatus file : listFiles) {
125156
source = file.getPath();

database-plugins/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<artifactId>hydrator-plugins</artifactId>
2222
<groupId>io.cdap.plugin</groupId>
23-
<version>2.11.5</version>
23+
<version>2.11.6-SNAPSHOT</version>
2424
</parent>
2525

2626
<name>Database Plugins</name>

format-avro/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>hydrator-plugins</artifactId>
2323
<groupId>io.cdap.plugin</groupId>
24-
<version>2.11.5</version>
24+
<version>2.11.6-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

format-blob/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>hydrator-plugins</artifactId>
2323
<groupId>io.cdap.plugin</groupId>
24-
<version>2.11.5</version>
24+
<version>2.11.6-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

format-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>hydrator-plugins</artifactId>
2323
<groupId>io.cdap.plugin</groupId>
24-
<version>2.11.5</version>
24+
<version>2.11.6-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

format-delimited/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>hydrator-plugins</artifactId>
2323
<groupId>io.cdap.plugin</groupId>
24-
<version>2.11.5</version>
24+
<version>2.11.6-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

format-json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>hydrator-plugins</artifactId>
2323
<groupId>io.cdap.plugin</groupId>
24-
<version>2.11.5</version>
24+
<version>2.11.6-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

format-orc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>hydrator-plugins</artifactId>
2323
<groupId>io.cdap.plugin</groupId>
24-
<version>2.11.5</version>
24+
<version>2.11.6-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

0 commit comments

Comments
 (0)