Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-28614 Introduce a field to display whether the snapshot is expired #5947

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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