in connector/src/main/scala/com/datastax/spark/connector/cql/RefCountMap.scala [71:86]
final def release(key: T, n: Int = 1): Int = {
refCounts.get(key) match {
case Some(count) if count > n =>
if (refCounts.replace(key, count, count - n))
count - n
else
release(key, n)
case Some(count) if count == n =>
if (refCounts.remove(key, n))
0
else
release(key, n)
case _ =>
throw new IllegalStateException("Release without acquire for key: " + key)
}
}