Skip to content

Commit

Permalink
add redundant close check
Browse files Browse the repository at this point in the history
  • Loading branch information
elahrvivaz committed Oct 2, 2024
1 parent 6520c78 commit e9995f4
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import java.nio.charset.StandardCharsets
import java.util.Collections
import java.util.concurrent.{Callable, ConcurrentHashMap}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.Try
import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}

/**
* Copies a schema from one cluster (or catalog) to another, using bulk file operations
Expand Down Expand Up @@ -62,6 +62,7 @@ class SchemaCopier(

private val tryFrom = Try(Cluster(fromCluster))
private val tryTo = Try(Cluster(toCluster))
private var closed = false

// note: all other class variables are lazy, so that we can instantiate an instance and then clean up connections on close()

Expand Down Expand Up @@ -414,9 +415,12 @@ class SchemaCopier(
from.tableOps.delete(cloneTable)
}

override def close(): Unit = {
CloseWithLogging(tryFrom.toOption)
CloseWithLogging(tryTo.toOption)
override def close(): Unit = synchronized {
if (!closed) {
closed = true
CloseWithLogging(tryFrom.toOption)
CloseWithLogging(tryTo.toOption)
}
}
}

Expand Down

0 comments on commit e9995f4

Please sign in to comment.