This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new 8afd93e78b9 HBASE-28614 Introduce a field to display whether the 
snapshot is expired (#5947)
8afd93e78b9 is described below

commit 8afd93e78b98d13760c1d7149839fb2acf6b7f97
Author: guluo <lupeng_n...@qq.com>
AuthorDate: Wed Jun 5 23:18:51 2024 +0800

    HBASE-28614 Introduce a field to display whether the snapshot is expired 
(#5947)
    
    Signed-off-by: Pankaj Kumar <pankajku...@apache.org>
    Signed-off-by: Viraj Jasani <vjas...@apache.org>
    Signed-off-by: Duo Zhang <zhang...@apache.org>
---
 .../main/resources/hbase-webapps/master/snapshot.jsp  |  5 +++++
 .../resources/hbase-webapps/master/snapshotsStats.jsp |  5 +++++
 .../resources/hbase-webapps/master/userSnapshots.jsp  |  5 +++++
 .../src/main/ruby/shell/commands/list_snapshots.rb    | 19 +++++++++++++++++--
 4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/hbase-server/src/main/resources/hbase-webapps/master/snapshot.jsp 
b/hbase-server/src/main/resources/hbase-webapps/master/snapshot.jsp
index 9b1328a3a32..e85cab95d7e 100644
--- a/hbase-server/src/main/resources/hbase-webapps/master/snapshot.jsp
+++ b/hbase-server/src/main/resources/hbase-webapps/master/snapshot.jsp
@@ -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"
 %>
@@ -98,6 +99,7 @@
         <th>Type</th>
         <th>Format Version</th>
         <th>State</th>
+        <th>Expired</th>
     </tr>
     <tr>
 
@@ -124,6 +126,9 @@
         <% } else { %>
           <td>ok</td>
         <% } %>
+        <td>
+          <%= SnapshotDescriptionUtils.isExpiredSnapshot(snapshotTtl, 
snapshot.getCreationTime(), System.currentTimeMillis()) ? "Yes" : "No" %>
+        </td>
     </tr>
   </table>
   <div class="row">
diff --git 
a/hbase-server/src/main/resources/hbase-webapps/master/snapshotsStats.jsp 
b/hbase-server/src/main/resources/hbase-webapps/master/snapshotsStats.jsp
index becdc68442d..6202d7409b5 100644
--- a/hbase-server/src/main/resources/hbase-webapps/master/snapshotsStats.jsp
+++ b/hbase-server/src/main/resources/hbase-webapps/master/snapshotsStats.jsp
@@ -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"
@@ -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>
@@ -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()) %>
diff --git 
a/hbase-server/src/main/resources/hbase-webapps/master/userSnapshots.jsp 
b/hbase-server/src/main/resources/hbase-webapps/master/userSnapshots.jsp
index 0b741e1089f..97cd477f6d8 100644
--- a/hbase-server/src/main/resources/hbase-webapps/master/userSnapshots.jsp
+++ b/hbase-server/src/main/resources/hbase-webapps/master/userSnapshots.jsp
@@ -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"
@@ -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()); %>
@@ -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>
diff --git a/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb 
b/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb
index 6a173993654..3b34cb993e6 100644
--- a/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb
@@ -18,6 +18,8 @@
 
 require 'time'
 
+java_import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils
+
 module Shell
   module Commands
     class ListSnapshots < Command
@@ -34,12 +36,25 @@ EOF
       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)

Reply via email to