Skip to content

Commit a16abaf

Browse files
fenzhuGitHub Enterprise
authored andcommitted
[CARMEL-6061] Skip the storage detection for access-denied paths (#1013)
1 parent 70beb72 commit a16abaf

File tree

1 file changed

+42
-19
lines changed
  • sql/core/src/main/scala/org/apache/spark/sql/execution/command

1 file changed

+42
-19
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,54 @@ case class DescribeDatabaseCommand(
245245
val databasePath = new Path(dbLocation)
246246
val fs = databasePath.getFileSystem(hadoopConf)
247247
val dbPath = fs.makeQualified(databasePath)
248+
val tableList = catalog.listTables(databaseName)
249+
val subDirList = fs.listStatus(dbPath)
250+
251+
val allSubStatus = subDirList.map(fss => (fss, getLen(fss, fs))).sortWith {
252+
(t1, t2) => t1._2 > t2._2
253+
}.partition(_._2 >= 0)
254+
val subStatus = allSubStatus._1
255+
val abnormalSubStatus = allSubStatus._2
256+
248257
result += Row("## Database Storage Summary", "")
249-
val summary = fs.getContentSummary(dbPath)
250-
val subStatus = fs.listStatus(dbPath).sortWith {
251-
(fss1, fss2) => getLen(fss1, fs) > getLen(fss2, fs)
252-
}
253-
val (spaceQuotaStr, spaceQuotaRemStr) = if (summary.getSpaceQuota > 0L) {
254-
(formatSize(summary.getSpaceQuota),
255-
formatSize(summary.getSpaceQuota - summary.getSpaceConsumed))
256-
} else {
257-
("none", "inf")
258+
val (spaceQuotaStr, spaceQuotaRemStr) = try {
259+
val summary = fs.getContentSummary(dbPath)
260+
if (summary.getSpaceQuota > 0L) {
261+
(formatSize(summary.getSpaceQuota),
262+
formatSize(summary.getSpaceQuota - summary.getSpaceConsumed))
263+
} else {
264+
("none", "inf")
265+
}
266+
} catch {
267+
case _: Exception => ("unknown (sub-directory access denied)", "unknown")
258268
}
259-
result += Row("space quota", spaceQuotaStr)
269+
270+
result += Row("total space quota", spaceQuotaStr)
260271
result += Row("remaining space quota", spaceQuotaRemStr)
261-
result += Row("total tables", String.valueOf(subStatus.length))
272+
result += Row("total directories", String.valueOf(subDirList.length))
273+
result += Row("total tables", String.valueOf(tableList.length))
262274

263275
result += Row("", "")
276+
264277
val k = Math.min(15, subStatus.length)
265278
result += Row(s"## Top $k Directories", "Size")
266279
for (i <- 0 until k) {
267-
val len = getLen(subStatus(i), fs)
268-
result += Row(subStatus(i).getPath.toString, formatSize(len))
280+
val len = subStatus(i)._2
281+
result += Row(subStatus(i)._1.getPath.toString, formatSize(len))
269282
}
270283

271-
val tableLocations = catalog.listTables(databaseName).map { t =>
284+
if (allSubStatus._2.nonEmpty) {
285+
result += Row("", "")
286+
val ak = Math.min(15, abnormalSubStatus.length)
287+
result += Row(s"## Top $ak Abnormal Directories (e.g., Access Denied)", "Size")
288+
for (i <- 0 until ak) {
289+
val len = abnormalSubStatus(i)._2
290+
result += Row(abnormalSubStatus(i)._1.getPath.toString, formatSize(len))
291+
}
292+
}
293+
294+
result += Row("", "")
295+
val tableLocations = tableList.map { t =>
272296
val meta = catalog.getTableMetadata(t)
273297
val loc = if (meta.storage.locationUri.isEmpty) {
274298
""
@@ -280,10 +304,9 @@ case class DescribeDatabaseCommand(
280304
}.filter(_.nonEmpty).toSet
281305

282306
val leakStatus = subStatus.filterNot { s =>
283-
tableLocations.contains(fs.makeQualified(s.getPath).toString)
307+
tableLocations.contains(fs.makeQualified(s._1.getPath).toString)
284308
}
285309

286-
result += Row("", "")
287310
val message = if (clear) {
288311
"try to clear"
289312
} else if (leakStatus.nonEmpty) {
@@ -304,14 +327,14 @@ case class DescribeDatabaseCommand(
304327

305328
if (leakStatus.nonEmpty) {
306329
leakStatus.foreach { ls =>
307-
val lp = ls.getPath.toString
330+
val lp = ls._1.getPath.toString
308331
var state = lp
309332
if (clear) {
310333
val ok = performFakeDelete(lp, trashPath, fs)
311334
val prefix = if (ok) "success" else "failure"
312335
state = s"($prefix) " + state
313336
}
314-
result += Row(state, formatSize(getLen(ls, fs)))
337+
result += Row(state, formatSize(ls._2))
315338
}
316339
}
317340
result
@@ -321,7 +344,7 @@ case class DescribeDatabaseCommand(
321344
if (fss.isFile) {
322345
return fss.getLen
323346
}
324-
var dirLength = 0L
347+
var dirLength = -1L
325348
try {
326349
dirLength = fs.getContentSummary(fss.getPath).getLength
327350
} catch {

0 commit comments

Comments
 (0)