stream2000 commented on PR #9749:
URL: https://github.com/apache/hudi/pull/9749#issuecomment-1767491739
> could you write a test or provide a some sample code to trigger this
issue? I'm a little unclear if this is solving a race condition or something
else
@jonvex We can trigger the issue by the following code( not stable) :
```scala
test("Test concurrent overwrite") {
withTempDir { tmp =>
import spark.implicits._
val day = "2021-08-02"
val threadCount = 12
val df = Seq((1, "a1", 10, 1000, day, 12)).toDF("id", "name", "value",
"ts", "day", "hh")
val executors = Executors.newFixedThreadPool(threadCount)
var futures: Array[Future[_]] = new Array(threadCount /2 )
for (i <- 0 until threadCount / 2 ) {
val overwriteTask = new Runnable {
override def run(): Unit = {
val tableName = "table_name" + i
val tablePath = s"${tmp.getCanonicalPath}/$tableName"
// Write a table by spark dataframe.
df.write.format("hudi")
.option(HoodieWriteConfig.TBL_NAME.key, tableName)
.option(TABLE_TYPE.key, MOR_TABLE_TYPE_OPT_VAL)
.option(RECORDKEY_FIELD.key, "id")
.option(PRECOMBINE_FIELD.key, "ts")
.option(PARTITIONPATH_FIELD.key, "day,hh")
.option(HoodieWriteConfig.INSERT_PARALLELISM_VALUE.key, "1")
.option(HoodieWriteConfig.UPSERT_PARALLELISM_VALUE.key, "1")
.option(HoodieWriteConfig.ALLOW_OPERATION_METADATA_FIELD.key,
"true")
.mode(SaveMode.Overwrite)
.save(tablePath)
}
}
futures(i) = executors.submit(overwriteTask)
}
futures.foreach(f => f.get())
futures = new Array(threadCount)
for (i <- 0 until threadCount) {
val overwriteTask = new Runnable {
override def run(): Unit = {
val tableName = "table_name" + (12 - i)
val tablePath = s"${tmp.getCanonicalPath}/$tableName"
// Write a table by spark dataframe.
df.write.format("hudi")
.option(HoodieWriteConfig.TBL_NAME.key, tableName)
.option(TABLE_TYPE.key, MOR_TABLE_TYPE_OPT_VAL)
.option(RECORDKEY_FIELD.key, "id")
.option(PRECOMBINE_FIELD.key, "ts")
.option(PARTITIONPATH_FIELD.key, "day,hh")
.option(HoodieWriteConfig.INSERT_PARALLELISM_VALUE.key, "1")
.option(HoodieWriteConfig.UPSERT_PARALLELISM_VALUE.key, "1")
.option(HoodieWriteConfig.ALLOW_OPERATION_METADATA_FIELD.key,
"true")
.mode(SaveMode.Append)
.save(tablePath)
}
}
futures(i) = executors.submit(overwriteTask)
}
futures.foreach(f => f.get())
}
}
```
And we will get exception stack trace sometimes like this:
```txt
Caused by: org.apache.hudi.exception.TableNotFoundException: Hoodie table
not found in path
/private/var/folders/q1/_zbtr5t97rz27jb_f3ph8chm0000gp/T/spark-d9e6236f-4d31-4ea1-a60a-df21c5d1d545/table_name12/.hoodie
at
org.apache.hudi.exception.TableNotFoundException.checkTableValidity(TableNotFoundException.java:57)
at
org.apache.hudi.common.table.HoodieTableMetaClient.<init>(HoodieTableMetaClient.java:149)
at
org.apache.hudi.common.table.HoodieTableMetaClient.newMetaClient(HoodieTableMetaClient.java:735)
at
org.apache.hudi.common.table.HoodieTableMetaClient.access$000(HoodieTableMetaClient.java:91)
at
org.apache.hudi.common.table.HoodieTableMetaClient$Builder.build(HoodieTableMetaClient.java:826)
at
org.apache.hudi.HoodieSparkSqlWriter$.$anonfun$getHoodieTableConfig$1(HoodieSparkSqlWriter.scala:1165)
at scala.Option.getOrElse(Option.scala:189)
at
org.apache.hudi.HoodieSparkSqlWriter$.getHoodieTableConfig(HoodieSparkSqlWriter.scala:1166)
at
org.apache.hudi.HoodieSparkSqlWriter$.writeInternal(HoodieSparkSqlWriter.scala:172)
at
org.apache.hudi.HoodieSparkSqlWriter$.write(HoodieSparkSqlWriter.scala:133)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]