Skip to content

Commit

Permalink
HBASE-28614 Introduce a field to display whether the snapshot is expi…
Browse files Browse the repository at this point in the history
…red (#5947)

Signed-off-by: Pankaj Kumar <pankajkumar@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
Signed-off-by: Duo Zhang <zhangduo@apache.org>
(cherry picked from commit 8afd93e)
  • Loading branch information
guluo2016 authored and Apache9 committed Jun 5, 2024
1 parent 236b790 commit 69c4696
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import="org.apache.hadoop.hbase.http.InfoServer"
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.snapshot.SnapshotInfo"
import="org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils"
import="org.apache.hadoop.util.StringUtils"
import="org.apache.hadoop.hbase.TableName"
%>
Expand Down Expand Up @@ -98,6 +99,7 @@
<th>Type</th>
<th>Format Version</th>
<th>State</th>
<th>Expired</th>
</tr>
<tr>

Expand All @@ -124,6 +126,9 @@
<% } else { %>
<td>ok</td>
<% } %>
<td>
<%= SnapshotDescriptionUtils.isExpiredSnapshot(snapshotTtl, snapshot.getCreationTime(), System.currentTimeMillis()) ? "Yes" : "No" %>
</td>
</tr>
</table>
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import="org.apache.hadoop.fs.Path"
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.snapshot.SnapshotInfo"
import="org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils"
import="org.apache.hadoop.hbase.TableName"
import="org.apache.hadoop.util.StringUtils"
import="org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription"
Expand Down Expand Up @@ -68,6 +69,7 @@
<th>Creation Time</th>
<th>Owner</th>
<th>TTL</th>
<th>Expired</th>
<th>Shared Storefile Size</th>
<th>Mob Storefile Size</th>
<th>Archived Storefile Size</th>
Expand All @@ -94,6 +96,9 @@
.format(String.valueOf(snapshotDesc.getTtl()), PrettyPrinter.Unit.TIME_INTERVAL)%>
<% } %>
</td>
<td>
<%= SnapshotDescriptionUtils.isExpiredSnapshot(snapshotDesc.getTtl(), snapshotDesc.getCreationTime(), System.currentTimeMillis()) ? "Yes" : "No" %>
</td>
<td><%= StringUtils.humanReadableInt(stats.getSharedStoreFilesSize()) %></td>
<td><%= StringUtils.humanReadableInt(stats.getMobStoreFilesSize()) %></td>
<td><%= StringUtils.humanReadableInt(stats.getArchivedStoreFileSize()) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<%@ page contentType="text/plain;charset=UTF-8"
import="java.util.List"
import="java.util.Date"
import="org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils"
import="org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription"
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.TableName"
Expand All @@ -38,6 +39,7 @@
<th>Creation Time</th>
<th>Owner</th>
<th>TTL</th>
<th>Expired</th>
</tr>
<% for (SnapshotDescription snapshotDesc : snapshots){ %>
<% TableName snapshotTable = TableName.valueOf(snapshotDesc.getTable()); %>
Expand All @@ -51,6 +53,9 @@
<td>
<%= snapshotDesc.getTtl() == 0 ? "FOREVER": PrettyPrinter.format(String.valueOf(snapshotDesc.getTtl()), PrettyPrinter.Unit.TIME_INTERVAL) %>
</td>
<td>
<%= SnapshotDescriptionUtils.isExpiredSnapshot(snapshotDesc.getTtl(), snapshotDesc.getCreationTime(), System.currentTimeMillis()) ? "Yes" : "No" %>
</td>
</tr>
<% } %>
<p><%= snapshots.size() %> snapshot(s) in set. [<a href="/snapshotsStats.jsp">Snapshot Storefile stats</a>]</p>
Expand Down
19 changes: 17 additions & 2 deletions hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

require 'time'

java_import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils

module Shell
module Commands
class ListSnapshots < Command
Expand All @@ -34,12 +36,25 @@ def help
end

def command(regex = '.*')
formatter.header(['SNAPSHOT', 'TABLE + CREATION TIME'])
formatter.header(['SNAPSHOT', 'TABLE + CREATION TIME + TTL(Sec)'])

list = admin.list_snapshot(regex)
list.each do |snapshot|
creation_time = Time.at(snapshot.getCreationTime / 1000).to_s
formatter.row([snapshot.getName, snapshot.getTableNameAsString + ' (' + creation_time + ')'])
ttl = snapshot.getTtl
if ttl == 0
ttl_info = 'FOREVER'
else
now_timestamp = (Time.now.to_f * 1000).to_i
expired = SnapshotDescriptionUtils.isExpiredSnapshot(ttl, snapshot.getCreationTime(), now_timestamp)
if expired
ttl_info = ttl.to_s + ' (Expired) '
else
ttl_info = ttl.to_s
end
end
info = snapshot.getTableNameAsString + ' (' + creation_time + ') ' + ttl_info
formatter.row([snapshot.getName, info])
end

formatter.footer(list.size)
Expand Down

0 comments on commit 69c4696

Please sign in to comment.