Skip to content

Commit c7b9562

Browse files
committed
HBASE-30252 hbase snapshot info display inaccurate snapshot TTL information messages
1 parent 4aa5509 commit c7b9562

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hbase.snapshot;
1919

20+
import static org.apache.hadoop.hbase.HConstants.DEFAULT_SNAPSHOT_TTL;
21+
2022
import java.io.FileNotFoundException;
2123
import java.io.IOException;
2224
import java.net.URI;
@@ -71,6 +73,10 @@
7173
public final class SnapshotInfo extends AbstractHBaseTool {
7274
private static final Logger LOG = LoggerFactory.getLogger(SnapshotInfo.class);
7375

76+
private static final String EXPIRED_LABEL = "Yes";
77+
private static final String NOT_EXPIRED_LABEL = "No";
78+
private static final String TTL_FOREVER = "FOREVER";
79+
7480
static final class Options {
7581
static final Option SNAPSHOT =
7682
new Option(null, "snapshot", true, "The name of the snapshot to be detailed.");
@@ -391,11 +397,18 @@ public int doWork() throws IOException, InterruptedException {
391397
// List Available Snapshots
392398
if (listSnapshots) {
393399
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
394-
System.out.printf("%-20s | %-20s | %-20s | %s%n", "SNAPSHOT", "CREATION TIME", "TTL IN SEC",
395-
"TABLE NAME");
396-
for (SnapshotDescription desc : getSnapshotList(conf)) {
397-
System.out.printf("%-20s | %20s | %20s | %s%n", desc.getName(),
398-
df.format(new Date(desc.getCreationTime())), desc.getTtl(), desc.getTableNameAsString());
400+
List<SnapshotDescription> snapshotDescriptions = getSnapshotList(conf);
401+
System.out.printf("%-20s | %-20s | %-20s | %-20s | %s%n", "SNAPSHOT", "CREATION TIME",
402+
"TTL(Sec)", "EXPIRED", "TABLE NAME");
403+
long currentTime = System.currentTimeMillis();
404+
for (SnapshotDescription desc : snapshotDescriptions) {
405+
String ttlInfo =
406+
desc.getTtl() == DEFAULT_SNAPSHOT_TTL ? TTL_FOREVER : String.valueOf(desc.getTtl());
407+
String expired = SnapshotDescriptionUtils.isExpiredSnapshot(desc.getTtl(),
408+
desc.getCreationTime(), currentTime) ? EXPIRED_LABEL : NOT_EXPIRED_LABEL;
409+
System.out.printf("%-20s | %20s | %20s | %20s | %s%n", desc.getName(),
410+
df.format(new Date(desc.getCreationTime())), ttlInfo, expired,
411+
desc.getTableNameAsString());
399412
}
400413
return 0;
401414
}
@@ -443,15 +456,23 @@ private boolean loadSnapshotInfo(final String snapshotName) throws IOException {
443456
private void printInfo() {
444457
SnapshotProtos.SnapshotDescription snapshotDesc = snapshotManifest.getSnapshotDescription();
445458
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
459+
String ttlInfo = snapshotDesc.getTtl() == DEFAULT_SNAPSHOT_TTL
460+
? TTL_FOREVER
461+
: String.valueOf(snapshotDesc.getTtl());
462+
String expired = SnapshotDescriptionUtils.isExpiredSnapshot(snapshotDesc.getTtl(),
463+
snapshotDesc.getCreationTime(), System.currentTimeMillis())
464+
? EXPIRED_LABEL
465+
: NOT_EXPIRED_LABEL;
446466
System.out.println("Snapshot Info");
447-
System.out.println("----------------------------------------");
448-
System.out.println(" Name: " + snapshotDesc.getName());
449-
System.out.println(" Type: " + snapshotDesc.getType());
450-
System.out.println(" Table: " + snapshotDesc.getTable());
451-
System.out.println(" Format: " + snapshotDesc.getVersion());
452-
System.out.println("Created: " + df.format(new Date(snapshotDesc.getCreationTime())));
453-
System.out.println(" Ttl: " + snapshotDesc.getTtl());
454-
System.out.println(" Owner: " + snapshotDesc.getOwner());
467+
System.out.println("-----------------------------------------");
468+
System.out.println(" Name: " + snapshotDesc.getName());
469+
System.out.println(" Type: " + snapshotDesc.getType());
470+
System.out.println(" Table: " + snapshotDesc.getTable());
471+
System.out.println(" Format: " + snapshotDesc.getVersion());
472+
System.out.println(" Created: " + df.format(new Date(snapshotDesc.getCreationTime())));
473+
System.out.println("Ttl(Sec): " + ttlInfo);
474+
System.out.println(" Expired: " + expired);
475+
System.out.println(" Owner: " + snapshotDesc.getOwner());
455476
System.out.println();
456477
}
457478

0 commit comments

Comments
 (0)