Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A44B1CBF5 for ; Mon, 17 Mar 2014 16:16:25 +0000 (UTC) Received: (qmail 23684 invoked by uid 500); 17 Mar 2014 16:16:24 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 23638 invoked by uid 500); 17 Mar 2014 16:16:24 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 23629 invoked by uid 99); 17 Mar 2014 16:16:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Mar 2014 16:16:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Mar 2014 16:16:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7F76B2388A2C; Mon, 17 Mar 2014 16:15:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1578452 - in /hbase/branches/0.96/hbase-server/src: main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java Date: Mon, 17 Mar 2014 16:15:59 -0000 To: commits@hbase.apache.org From: mbertozzi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140317161559.7F76B2388A2C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mbertozzi Date: Mon Mar 17 16:15:58 2014 New Revision: 1578452 URL: http://svn.apache.org/r1578452 Log: HBASE-10766 SnapshotCleaner allows to delete referenced files (Bharath Vissapragada) Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java?rev=1578452&r1=1578451&r2=1578452&view=diff ============================================================================== --- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java (original) +++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java Mon Mar 17 16:15:58 2014 @@ -183,18 +183,29 @@ public class SnapshotFileCache implement } private synchronized void refreshCache() throws IOException { - // get the status of the snapshots directory - FileStatus status; + // get the status of the snapshots directory and /.tmp + FileStatus dirStatus, tempStatus; try { - status = fs.getFileStatus(snapshotDir); + dirStatus = fs.getFileStatus(snapshotDir); } catch (FileNotFoundException e) { if (this.cache.size() > 0) { LOG.error("Snapshot directory: " + snapshotDir + " doesn't exist"); } return; } + + try { + Path snapshotTmpDir = new Path(snapshotDir, SnapshotDescriptionUtils.SNAPSHOT_TMP_DIR_NAME); + tempStatus = fs.getFileStatus(snapshotTmpDir); + } catch (FileNotFoundException e) { + tempStatus = dirStatus; + } + // if the snapshot directory wasn't modified since we last check, we are done - if (status.getModificationTime() <= lastModifiedTime) return; + if (dirStatus.getModificationTime() <= lastModifiedTime && + tempStatus.getModificationTime() <= lastModifiedTime) { + return; + } // directory was modified, so we need to reload our cache // there could be a slight race here where we miss the cache, check the directory modification @@ -202,7 +213,8 @@ public class SnapshotFileCache implement // However, snapshot directories are only created once, so this isn't an issue. // 1. update the modified time - this.lastModifiedTime = status.getModificationTime(); + this.lastModifiedTime = Math.min(dirStatus.getModificationTime(), + tempStatus.getModificationTime()); // 2.clear the cache this.cache.clear(); Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java?rev=1578452&r1=1578451&r2=1578452&view=diff ============================================================================== --- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java (original) +++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java Mon Mar 17 16:15:58 2014 @@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFac import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils; @@ -87,8 +86,8 @@ public class TestSnapshotFileCache { Path file2 = new Path(family, "file2"); // create two hfiles under the snapshot - fs.create(file1); - fs.create(file2); + fs.createNewFile(file1); + fs.createNewFile(file2); FSUtils.logFileSystemState(fs, rootDir, LOG); @@ -138,7 +137,7 @@ public class TestSnapshotFileCache { Path region = new Path(snapshot, "7e91021"); Path family = new Path(region, "fam"); Path file1 = new Path(family, "file1"); - fs.create(file1); + fs.createNewFile(file1); // create an 'in progress' snapshot SnapshotDescription desc = SnapshotDescription.newBuilder().setName("working").build(); @@ -146,7 +145,7 @@ public class TestSnapshotFileCache { region = new Path(snapshot, "7e91021"); family = new Path(region, "fam"); Path file2 = new Path(family, "file2"); - fs.create(file2); + fs.createNewFile(file2); FSUtils.logFileSystemState(fs, rootDir, LOG); @@ -173,12 +172,12 @@ public class TestSnapshotFileCache { Path region = new Path(snapshot, "7e91021"); Path family = new Path(region, "fam"); Path file1 = new Path(family, "file1"); - fs.create(file1); + fs.createNewFile(file1); // and another file in the logs directory Path logs = TakeSnapshotUtils.getSnapshotHLogsDir(snapshot, "server"); Path log = new Path(logs, "me.hbase.com%2C58939%2C1350424310315.1350424315552"); - fs.create(log); + fs.createNewFile(log); FSUtils.logFileSystemState(fs, rootDir, LOG); @@ -203,8 +202,8 @@ public class TestSnapshotFileCache { Path file2 = new Path(family, "file2"); // create two hfiles under the snapshot - fs.create(file1); - fs.create(file2); + fs.createNewFile(file1); + fs.createNewFile(file2); FSUtils.logFileSystemState(fs, rootDir, LOG); @@ -213,12 +212,34 @@ public class TestSnapshotFileCache { // now delete the snapshot and add a file with a different name fs.delete(snapshot, true); Path file3 = new Path(family, "new_file"); - fs.create(file3); + fs.createNewFile(file3); FSUtils.logFileSystemState(fs, rootDir, LOG); assertTrue("Cache didn't find new file:" + file3, cache.contains(file3.getName())); } + @Test + public void testSnapshotTempDirReload() throws IOException { + long period = Long.MAX_VALUE; + // This doesn't refresh cache until we invoke it explicitly + Path snapshotDir = new Path(SnapshotDescriptionUtils.getSnapshotsDir(rootDir), + SnapshotDescriptionUtils.SNAPSHOT_TMP_DIR_NAME); + SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, period, 10000000, + "test-snapshot-file-cache-refresh", new SnapshotFiles()); + + // Add a new snapshot + Path snapshot1 = new Path(snapshotDir, "snapshot1"); + Path file1 = new Path(new Path(new Path(snapshot1, "7e91021"), "fam"), "file1"); + fs.createNewFile(file1); + assertTrue(cache.contains(file1.getName())); + + // Add another snapshot + Path snapshot2 = new Path(snapshotDir, "snapshot2"); + Path file2 = new Path(new Path(new Path(snapshot2, "7e91021"), "fam2"), "file2"); + fs.createNewFile(file2); + assertTrue(cache.contains(file2.getName())); + } + class SnapshotFiles implements SnapshotFileCache.SnapshotFileInspector { public Collection filesUnderSnapshot(final Path snapshotDir) throws IOException { Collection files = new HashSet();