diff --git hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon index 4b1c192..a624226 100644 --- hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon +++ hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon @@ -477,7 +477,7 @@ AssignmentManager assignmentManager = master.getAssignmentManager(); <% new Date(snapshotDesc.getCreationTime()) %> -

<% snapshots.size() %> snapshot(s) in set.

+

<% snapshots.size() %> snapshot(s) in set. [Snapshot Storefile stats]

diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java index c944fc4..658f4d0 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java @@ -27,6 +27,8 @@ import java.util.Date; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -126,6 +128,7 @@ public final class SnapshotInfo extends Configured implements Tool { private AtomicLong hfilesArchiveSize = new AtomicLong(); private AtomicLong hfilesSize = new AtomicLong(); private AtomicLong hfilesMobSize = new AtomicLong(); + private AtomicLong nonSharedHfilesArchiveSize = new AtomicLong(); private AtomicLong logSize = new AtomicLong(); private final HBaseProtos.SnapshotDescription snapshot; @@ -207,6 +210,17 @@ public final class SnapshotInfo extends Configured implements Tool { /** @return the total size of the store files in the mob store*/ public long getMobStoreFilesSize() { return hfilesMobSize.get(); } + /** @return the total size of the store files in the archive which is not shared + * with other snapshots and tables + * + * this is only calculated when + * {@link getSnapshotStats(Configuration,SnapshotDescription, ConcurrentHashMap)} + * is called with a non-null ConcurrentHashMap + */ + public long getNonSharedArchivedStoreFilesSize() { + return nonSharedHfilesArchiveSize.get(); + } + /** @return the percentage of the shared store files */ public float getSharedStoreFilePercentage() { return ((float) hfilesSize.get() / (getStoreFilesSize())) * 100; @@ -227,10 +241,12 @@ public final class SnapshotInfo extends Configured implements Tool { * @param region region encoded Name * @param family family name * @param storeFile store file name + * @param filesMap store files map for all snapshots, it may be null * @return the store file information */ FileInfo addStoreFile(final HRegionInfo region, final String family, - final SnapshotRegionManifest.StoreFile storeFile) throws IOException { + final SnapshotRegionManifest.StoreFile storeFile, + ConcurrentHashMap filesMap) throws IOException { HFileLink link = HFileLink.build(conf, snapshotTable, region.getEncodedName(), family, storeFile.getName()); boolean isCorrupted = false; @@ -241,6 +257,24 @@ public final class SnapshotInfo extends Configured implements Tool { size = fs.getFileStatus(link.getArchivePath()).getLen(); hfilesArchiveSize.addAndGet(size); hfilesArchiveCount.incrementAndGet(); + + // If store file is not shared with other snapshots and tables, + // increase nonSharedHfilesArchiveSize + if (filesMap != null) { + Path filePath = link.getArchivePath(); + Integer c = filesMap.get(filePath); + + if ((c != null) && (c == 1)) { + Path parentDir = filePath.getParent(); + Path backRefDir = HFileLink.getBackReferencesDir(parentDir, filePath.getName()); + try { + if (FSUtils.listStatus(fs, backRefDir) == null) { + nonSharedHfilesArchiveSize.addAndGet(size); + } + } catch (IOException e) { + } + } + } } else if (inArchive = fs.exists(link.getMobPath())) { size = fs.getFileStatus(link.getMobPath()).getLen(); hfilesMobSize.addAndGet(size); @@ -432,7 +466,7 @@ public final class SnapshotInfo extends Configured implements Tool { final SnapshotRegionManifest.StoreFile storeFile) throws IOException { if (storeFile.hasReference()) return; - SnapshotStats.FileInfo info = stats.addStoreFile(regionInfo, family, storeFile); + SnapshotStats.FileInfo info = stats.addStoreFile(regionInfo, family, storeFile, null); if (showFiles) { String state = info.getStateToString(); System.out.printf("%8s %s/%s/%s/%s %s%n", @@ -501,6 +535,19 @@ public final class SnapshotInfo extends Configured implements Tool { */ public static SnapshotStats getSnapshotStats(final Configuration conf, final SnapshotDescription snapshot) throws IOException { + return getSnapshotStats(conf, snapshot, null); + } + + /** + * Returns the snapshot stats + * @param conf the {@link Configuration} to use + * @param snapshot {@link SnapshotDescription} to get stats from + * @param filesMap store files map for all snapshots, it may be null + * @return the snapshot stats + */ + public static SnapshotStats getSnapshotStats(final Configuration conf, + final SnapshotDescription snapshot, + final ConcurrentHashMap filesMap) throws IOException { HBaseProtos.SnapshotDescription snapshotDesc = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshot); Path rootDir = FSUtils.getRootDir(conf); FileSystem fs = FileSystem.get(rootDir.toUri(), conf); @@ -513,7 +560,7 @@ public final class SnapshotInfo extends Configured implements Tool { public void storeFile(final HRegionInfo regionInfo, final String family, final SnapshotRegionManifest.StoreFile storeFile) throws IOException { if (!storeFile.hasReference()) { - stats.addStoreFile(regionInfo, family, storeFile); + stats.addStoreFile(regionInfo, family, storeFile, filesMap); } } }); @@ -545,6 +592,101 @@ public final class SnapshotInfo extends Configured implements Tool { } /** + * Gets the store files map for snapshot + * @param conf the {@link Configuration} to use + * @param snapshot {@link SnapshotDescription} to get stats from + * @param exec the {@link ExecutorService} to use + * @param filesMap the map to put the mapping entries + * @param uniqueHFilesArchiveSize {@link AtomicLong} the accumulated store file size in archive + * @param uniqueHFilesSize {@link AtomicLong} the accumulated store file size shared + * @param uniqueHFilesMobSize {@link AtomicLong} the accumulated mob store file size shared + * @return the snapshot stats + */ + private static void getSnapshotFilesMap(final Configuration conf, + final SnapshotDescription snapshot, final ExecutorService exec, + final ConcurrentHashMap filesMap, + final AtomicLong uniqueHFilesArchiveSize, final AtomicLong uniqueHFilesSize, + final AtomicLong uniqueHFilesMobSize) throws IOException { + HBaseProtos.SnapshotDescription snapshotDesc = ProtobufUtil.createHBaseProtosSnapshotDesc( + snapshot); + Path rootDir = FSUtils.getRootDir(conf); + final FileSystem fs = FileSystem.get(rootDir.toUri(), conf); + + Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotDesc, rootDir); + SnapshotManifest manifest = SnapshotManifest.open(conf, fs, snapshotDir, snapshotDesc); + SnapshotReferenceUtil.concurrentVisitReferencedFiles(conf, fs, manifest, + new SnapshotReferenceUtil.SnapshotVisitor() { + @Override public void storeFile(final HRegionInfo regionInfo, final String family, + final SnapshotRegionManifest.StoreFile storeFile) throws IOException { + if (!storeFile.hasReference()) { + HFileLink link = HFileLink + .build(conf, TableName.valueOf(snapshot.getTable()), regionInfo.getEncodedName(), + family, storeFile.getName()); + long size; + Integer count; + Path p; + AtomicLong al; + int c = 0; + + if (fs.exists(link.getArchivePath())) { + p = link.getArchivePath(); + al = uniqueHFilesArchiveSize; + size = fs.getFileStatus(p).getLen(); + } else if (fs.exists(link.getMobPath())) { + p = link.getMobPath(); + al = uniqueHFilesMobSize; + size = fs.getFileStatus(p).getLen(); + } else { + p = link.getOriginPath(); + al = uniqueHFilesSize; + size = link.getFileStatus(fs).getLen(); + } + + // If it has been counted, do not double count + count = filesMap.get(p); + if (count != null) { + c = count.intValue(); + } else { + al.addAndGet(size); + } + + filesMap.put(p, ++c); + } + } + }); + } + + /** + * Returns the map of store files based on path for all snapshots + * @param conf the {@link Configuration} to use + * @param uniqueHFilesArchiveSize pass out the size for store files in archive + * @param uniqueHFilesSize pass out the size for store files shared + * @param uniqueHFilesMobSize pass out the size for mob store files shared + * @return the map of store files + */ + public static ConcurrentHashMap getSnapshotsFilesMap(final Configuration conf, + AtomicLong uniqueHFilesArchiveSize, AtomicLong uniqueHFilesSize, + AtomicLong uniqueHFilesMobSize) throws IOException { + List snapshotList = getSnapshotList(conf); + ConcurrentHashMap fileMap = new ConcurrentHashMap(); + + if (snapshotList.size() == 0) return fileMap; + + ExecutorService exec = SnapshotManifest.createExecutor(conf, "VerifySnapshot"); + + try { + for (final SnapshotDescription snapshot : snapshotList) { + getSnapshotFilesMap(conf, snapshot, exec, fileMap, uniqueHFilesArchiveSize, + uniqueHFilesSize, uniqueHFilesMobSize); + } + } finally { + exec.shutdown(); + } + + return fileMap; + } + + /** * The guts of the {@link #main} method. * Call this method to avoid the {@link #main(String[])} System.exit. * @param args diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java index 0532ba7..5f24da3 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java @@ -179,6 +179,26 @@ public final class SnapshotReferenceUtil { public static void concurrentVisitReferencedFiles(final Configuration conf, final FileSystem fs, final SnapshotManifest manifest, final StoreFileVisitor visitor) throws IOException { + + final Path snapshotDir = manifest.getSnapshotDir(); + List regionManifests = manifest.getRegionManifests(); + if (regionManifests == null || regionManifests.size() == 0) { + LOG.debug("No manifest files present: " + snapshotDir); + return; + } + + ExecutorService exec = SnapshotManifest.createExecutor(conf, "VerifySnapshot"); + + try { + concurrentVisitReferencedFiles(conf, fs, manifest, exec, visitor); + } finally { + exec.shutdown(); + } + } + + public static void concurrentVisitReferencedFiles(final Configuration conf, final FileSystem fs, + final SnapshotManifest manifest, final ExecutorService exec, final StoreFileVisitor visitor) + throws IOException { final SnapshotDescription snapshotDesc = manifest.getSnapshotDescription(); final Path snapshotDir = manifest.getSnapshotDir(); @@ -188,36 +208,31 @@ public final class SnapshotReferenceUtil { return; } - ExecutorService exec = SnapshotManifest.createExecutor(conf, "VerifySnapshot"); final ExecutorCompletionService completionService = - new ExecutorCompletionService(exec); + new ExecutorCompletionService(exec); + + for (final SnapshotRegionManifest regionManifest : regionManifests) { + completionService.submit(new Callable() { + @Override public Void call() throws IOException { + visitRegionStoreFiles(regionManifest, visitor); + return null; + } + }); + } try { - for (final SnapshotRegionManifest regionManifest: regionManifests) { - completionService.submit(new Callable() { - @Override - public Void call() throws IOException { - visitRegionStoreFiles(regionManifest, visitor); - return null; - } - }); + for (int i = 0; i < regionManifests.size(); ++i) { + completionService.take().get(); } - try { - for (int i = 0; i < regionManifests.size(); ++i) { - completionService.take().get(); - } - } catch (InterruptedException e) { - throw new InterruptedIOException(e.getMessage()); - } catch (ExecutionException e) { - if (e.getCause() instanceof CorruptedSnapshotException) { - throw new CorruptedSnapshotException(e.getCause().getMessage(), snapshotDesc); - } else { - IOException ex = new IOException(); - ex.initCause(e.getCause()); - throw ex; - } + } catch (InterruptedException e) { + throw new InterruptedIOException(e.getMessage()); + } catch (ExecutionException e) { + if (e.getCause() instanceof CorruptedSnapshotException) { + throw new CorruptedSnapshotException(e.getCause().getMessage(), snapshotDesc); + } else { + IOException ex = new IOException(); + ex.initCause(e.getCause()); + throw ex; } - } finally { - exec.shutdown(); } } diff --git hbase-server/src/main/resources/hbase-webapps/master/snapshotsStats.jsp hbase-server/src/main/resources/hbase-webapps/master/snapshotsStats.jsp new file mode 100644 index 0000000..e258023 --- /dev/null +++ hbase-server/src/main/resources/hbase-webapps/master/snapshotsStats.jsp @@ -0,0 +1,151 @@ +<%-- +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +--%> +<%@ page contentType="text/html;charset=UTF-8" + import="java.util.concurrent.atomic.AtomicLong" + import="java.util.concurrent.ConcurrentHashMap" + import="java.util.Date" + import="java.util.List" + import="org.apache.hadoop.fs.Path" + import="org.apache.hadoop.conf.Configuration" + import="org.apache.hadoop.hbase.client.Admin" + import="org.apache.hadoop.hbase.master.HMaster" + import="org.apache.hadoop.hbase.snapshot.SnapshotInfo" + import="org.apache.hadoop.hbase.client.SnapshotDescription" + import="org.apache.hadoop.util.StringUtils" + import="org.apache.hadoop.hbase.TableName" + import="org.apache.hadoop.hbase.HBaseConfiguration" %> +<% + HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER); + Configuration conf = master.getConfiguration(); + AtomicLong totalSharedSize = new AtomicLong(); + AtomicLong totalArchivedSize = new AtomicLong(); + AtomicLong totalMobSize = new AtomicLong(); + long totalSize = 0; + long totalUnsharedArchivedSize = 0; + + ConcurrentHashMap filesMap = null; + + List snapshots = null; + try (Admin admin = master.getConnection().getAdmin()) { + snapshots = master.isInitialized() ? admin.listSnapshots() : null; + } + + if (snapshots != null && snapshots.size() > 0) { + filesMap = SnapshotInfo.getSnapshotsFilesMap(master.getConfiguration(), + totalArchivedSize, totalSharedSize, totalMobSize); + totalSize = totalSharedSize.get() + totalArchivedSize.get() + totalMobSize.get(); + } +%> + + + + + + HBase Master Snapshots: <%= master.getServerName() %> + + + + + + + + + + +
+
+ +
+ + + + + + + + + + <%for (SnapshotDescription snapshotDesc : snapshots) { %> + + + <% + TableName snapshotTable = TableName.valueOf(snapshotDesc.getTable()); + SnapshotInfo.SnapshotStats stats = SnapshotInfo.getSnapshotStats(master.getConfiguration(), + snapshotDesc, filesMap); + totalUnsharedArchivedSize += stats.getNonSharedArchivedStoreFilesSize(); + %> + + + + + + + <% } %> +

<%= snapshots.size() %> snapshot(s) in set.

+

Total Storefile Size: <%= StringUtils.humanReadableInt(totalSize) %>

+

Total Shared Storefile Size: <%= StringUtils.humanReadableInt(totalSharedSize.get()) %>, + Total Mob Storefile Size: <%= StringUtils.humanReadableInt(totalMobSize.get()) %>, + Total Archived Storefile Size: <%= StringUtils.humanReadableInt(totalArchivedSize.get()) %> + (<%= StringUtils.humanReadableInt(totalUnsharedArchivedSize) %>)

+

Shared Storefile Size is the Storefile size shared between snapshots and active tables. + Mob Storefile Size is the Mob Storefile size shared between snapshots and active tables. + Archived Storefile Size is the Storefile size in Archive. + The format of Archived Storefile Size is NNN(MMM). NNN is the total Storefile + size in Archive, MMM is the total Storefile size in Archive that is specific + to the snapshot (not shared with other snapshots and tables)

+
Snapshot NameTableCreation TimeShared Storefile SizeMob Storefile SizeArchived Storefile Size
<%= snapshotDesc.getName() %><%= snapshotTable.getNameAsString() %> + <%= new Date(snapshotDesc.getCreationTime()) %><%= StringUtils.humanReadableInt(stats.getSharedStoreFilesSize()) %><%= StringUtils.humanReadableInt(stats.getMobStoreFilesSize()) %><%= StringUtils.humanReadableInt(stats.getArchivedStoreFileSize()) %> + (<%= StringUtils.humanReadableInt(stats.getNonSharedArchivedStoreFilesSize()) %>)
+
+ + + + + +