You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2018/08/02 19:38:20 UTC

[GitHub] keith-turner closed pull request #463: fixes #459 Made GC archive WALs

keith-turner closed pull request #463: fixes #459 Made GC archive WALs
URL: https://github.com/apache/accumulo/pull/463
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/base/src/main/java/org/apache/accumulo/server/ServerConstants.java b/server/base/src/main/java/org/apache/accumulo/server/ServerConstants.java
index 2992af6194..e87967c508 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/ServerConstants.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/ServerConstants.java
@@ -147,8 +147,7 @@
   public static final String TABLE_DIR = "tables";
   public static final String RECOVERY_DIR = "recovery";
   public static final String WAL_DIR = "wal";
-  public static final String WALOG_ARCHIVE_DIR = "walogArchive";
-  public static final String FILE_ARCHIVE_DIR = "fileArchive";
+  public static final String ARCHIVE_DIR = "archive";
 
   public static String[] getTablesDirs() {
     return VolumeConfiguration.prefix(getBaseUris(), TABLE_DIR);
@@ -162,10 +161,6 @@
     return VolumeConfiguration.prefix(getBaseUris(), WAL_DIR);
   }
 
-  public static String[] getWalogArchives() {
-    return VolumeConfiguration.prefix(getBaseUris(), WALOG_ARCHIVE_DIR);
-  }
-
   public static Path getInstanceIdLocation(Volume v) {
     // all base dirs should have the same instance id, so can choose any one
     return v.prefixChild(INSTANCE_ID_DIR);
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogs.java b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogs.java
index 405a7a0f86..1773a4378e 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogs.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogs.java
@@ -75,11 +75,15 @@
 
   private final AccumuloServerContext context;
   private final VolumeManager fs;
-  private final boolean useTrash;
+  private final RemovalPolicy removalPolicy;
   private final LiveTServerSet liveServers;
   private final WalStateManager walMarker;
   private final Iterable<TabletLocationState> store;
 
+  enum RemovalPolicy {
+    ARCHIVE, ARCHIVE_TRASH, TRASH, DELETE
+  }
+
   /**
    * Creates a new GC WAL object.
    *
@@ -91,10 +95,10 @@
    *          true to move files to trash rather than delete them
    */
   GarbageCollectWriteAheadLogs(final AccumuloServerContext context, VolumeManager fs,
-      boolean useTrash) throws IOException {
+      RemovalPolicy removalPolicy) throws IOException {
     this.context = context;
     this.fs = fs;
-    this.useTrash = useTrash;
+    this.removalPolicy = removalPolicy;
     this.liveServers = new LiveTServerSet(context, new Listener() {
       @Override
       public void update(LiveTServerSet current, Set<TServerInstance> deleted,
@@ -127,12 +131,12 @@ public void update(LiveTServerSet current, Set<TServerInstance> deleted,
    *          a started LiveTServerSet instance
    */
   @VisibleForTesting
-  GarbageCollectWriteAheadLogs(AccumuloServerContext context, VolumeManager fs, boolean useTrash,
-      LiveTServerSet liveTServerSet, WalStateManager walMarker, Iterable<TabletLocationState> store)
-      throws IOException {
+  GarbageCollectWriteAheadLogs(AccumuloServerContext context, VolumeManager fs,
+      RemovalPolicy removalPolicy, LiveTServerSet liveTServerSet, WalStateManager walMarker,
+      Iterable<TabletLocationState> store) throws IOException {
     this.context = context;
     this.fs = fs;
-    this.useTrash = useTrash;
+    this.removalPolicy = removalPolicy;
     this.liveServers = liveTServerSet;
     this.walMarker = walMarker;
     this.store = store;
@@ -253,8 +257,29 @@ private long removeTabletServerMarkers(Map<UUID,TServerInstance> uidMap,
 
   private long removeFile(Path path) {
     try {
-      if (!useTrash || !fs.moveToTrash(path)) {
-        fs.deleteRecursively(path);
+      switch (removalPolicy) {
+        case TRASH:
+          if (!fs.moveToTrash(path)) {
+            fs.deleteRecursively(path);
+          }
+          break;
+        case ARCHIVE:
+          if (!SimpleGarbageCollector.archiveFile(fs, path)) {
+            fs.deleteRecursively(path);
+          }
+          break;
+        case ARCHIVE_TRASH:
+          if (!SimpleGarbageCollector.archiveFile(fs, path)) {
+            if (!fs.moveToTrash(path)) {
+              fs.deleteRecursively(path);
+            }
+          }
+          break;
+        case DELETE:
+          fs.deleteRecursively(path);
+          break;
+        default:
+          throw new IllegalStateException();
       }
       return 1;
     } catch (FileNotFoundException ex) {
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
index 0aeaaea90c..db99a8a76e 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
@@ -81,6 +81,7 @@
 import org.apache.accumulo.core.zookeeper.ZooUtil;
 import org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason;
 import org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher;
+import org.apache.accumulo.gc.GarbageCollectWriteAheadLogs.RemovalPolicy;
 import org.apache.accumulo.gc.replication.CloseWriteAheadLogReferences;
 import org.apache.accumulo.server.Accumulo;
 import org.apache.accumulo.server.AccumuloServerContext;
@@ -608,8 +609,18 @@ private void run() {
 
       Span waLogs = Trace.start("walogs");
       try {
+        RemovalPolicy removalPolicy = RemovalPolicy.DELETE;
+        if (shouldArchiveFiles()) {
+          if (isUsingTrash()) {
+            removalPolicy = RemovalPolicy.ARCHIVE_TRASH;
+          } else {
+            removalPolicy = RemovalPolicy.ARCHIVE;
+          }
+        } else if (isUsingTrash()) {
+          removalPolicy = RemovalPolicy.TRASH;
+        }
         GarbageCollectWriteAheadLogs walogCollector = new GarbageCollectWriteAheadLogs(this, fs,
-            isUsingTrash());
+            removalPolicy);
         log.info("Beginning garbage collection of write-ahead logs");
         walogCollector.collect(status);
       } catch (Exception e) {
@@ -651,7 +662,7 @@ private void run() {
    */
   boolean archiveOrMoveToTrash(Path path) throws IOException {
     if (shouldArchiveFiles()) {
-      return archiveFile(path);
+      return archiveFile(fs, path);
     } else {
       if (!isUsingTrash())
         return false;
@@ -670,13 +681,11 @@ boolean archiveOrMoveToTrash(Path path) throws IOException {
    *          Path to file that is to be archived
    * @return True if the file was successfully moved to the file archive directory, false otherwise
    */
-  boolean archiveFile(Path fileToArchive) throws IOException {
+  static boolean archiveFile(VolumeManager fs, Path fileToArchive) throws IOException {
     // Figure out what the base path this volume uses on this FileSystem
     Volume sourceVolume = fs.getVolumeByPath(fileToArchive);
     String sourceVolumeBasePath = sourceVolume.getBasePath();
 
-    log.debug("Base path for volume: " + sourceVolumeBasePath);
-
     // Get the path for the file we want to archive
     String sourcePathBasePath = fileToArchive.toUri().getPath();
 
@@ -690,29 +699,26 @@ boolean archiveFile(Path fileToArchive) throws IOException {
       }
     }
 
-    log.debug("Computed relative path for file to archive: " + relativeVolumePath);
-
     // The file archive path on this volume (we can't archive this file to a different volume)
-    Path archivePath = new Path(sourceVolumeBasePath, ServerConstants.FILE_ARCHIVE_DIR);
-
-    log.debug("File archive path: " + archivePath);
-
-    fs.mkdirs(archivePath);
+    Path archivePath = new Path(sourceVolumeBasePath, ServerConstants.ARCHIVE_DIR);
 
     // Preserve the path beneath the Volume's base directory (e.g. tables/1/A_0000001.rf)
     Path fileArchivePath = new Path(archivePath, relativeVolumePath);
 
-    log.debug("Create full path of " + fileArchivePath + " from " + archivePath + " and "
-        + relativeVolumePath);
-
     // Make sure that it doesn't already exist, something is wrong.
     if (fs.exists(fileArchivePath)) {
       log.warn("Tried to archive file, but it already exists: " + fileArchivePath);
       return false;
     }
 
-    log.debug("Moving " + fileToArchive + " to " + fileArchivePath);
-    return fs.rename(fileToArchive, fileArchivePath);
+    fs.mkdirs(fileArchivePath.getParent());
+
+    log.debug("Archiving {} to {}", fileToArchive, fileArchivePath);
+    boolean renamed = fs.rename(fileToArchive, fileArchivePath);
+    if (!renamed) {
+      log.warn("Failed to archive {} to {}", fileToArchive, fileArchivePath);
+    }
+    return renamed;
   }
 
   private void getZooLock(HostAndPort addr) throws KeeperException, InterruptedException {
diff --git a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java
index 58c9089587..4e88bd4016 100644
--- a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java
+++ b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java
@@ -38,6 +38,7 @@
 import org.apache.accumulo.core.replication.ReplicationTable;
 import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.core.util.Pair;
+import org.apache.accumulo.gc.GarbageCollectWriteAheadLogs.RemovalPolicy;
 import org.apache.accumulo.server.AccumuloServerContext;
 import org.apache.accumulo.server.fs.VolumeManager;
 import org.apache.accumulo.server.log.WalStateManager;
@@ -99,8 +100,8 @@ public void testRemoveUnusedLog() throws Exception {
     marker.removeWalMarker(server1, id);
     EasyMock.expectLastCall().once();
     EasyMock.replay(context, fs, marker, tserverSet);
-    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs, false,
-        tserverSet, marker, tabletOnServer1List) {
+    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs,
+        RemovalPolicy.DELETE, tserverSet, marker, tabletOnServer1List) {
       @Override
       protected int removeReplicationEntries(Map<UUID,TServerInstance> candidates)
           throws IOException, KeeperException, InterruptedException {
@@ -129,8 +130,8 @@ public void testKeepClosedLog() throws Exception {
     EasyMock.expect(marker.getAllMarkers()).andReturn(markers).once();
     EasyMock.expect(marker.state(server1, id)).andReturn(new Pair<>(WalState.CLOSED, path));
     EasyMock.replay(context, marker, tserverSet, fs);
-    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs, false,
-        tserverSet, marker, tabletOnServer1List) {
+    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs,
+        RemovalPolicy.DELETE, tserverSet, marker, tabletOnServer1List) {
       @Override
       protected int removeReplicationEntries(Map<UUID,TServerInstance> candidates)
           throws IOException, KeeperException, InterruptedException {
@@ -181,8 +182,8 @@ public void deleteUnreferenceLogOnDeadServer() throws Exception {
     marker.forget(server2);
     EasyMock.expectLastCall().once();
     EasyMock.replay(context, fs, marker, tserverSet, conn, rscanner, mscanner);
-    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs, false,
-        tserverSet, marker, tabletOnServer1List) {
+    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs,
+        RemovalPolicy.DELETE, tserverSet, marker, tabletOnServer1List) {
       @Override
       protected Map<UUID,Path> getSortedWALogs() throws IOException {
         return Collections.emptyMap();
@@ -222,8 +223,8 @@ public void ignoreReferenceLogOnDeadServer() throws Exception {
     EasyMock.expectLastCall().once();
     EasyMock.expect(mscanner.iterator()).andReturn(emptyKV);
     EasyMock.replay(context, fs, marker, tserverSet, conn, rscanner, mscanner);
-    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs, false,
-        tserverSet, marker, tabletOnServer2List) {
+    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs,
+        RemovalPolicy.DELETE, tserverSet, marker, tabletOnServer2List) {
       @Override
       protected Map<UUID,Path> getSortedWALogs() throws IOException {
         return Collections.emptyMap();
@@ -269,8 +270,8 @@ public void replicationDelaysFileCollection() throws Exception {
     EasyMock.expectLastCall().once();
     EasyMock.expect(mscanner.iterator()).andReturn(replicationWork.entrySet().iterator());
     EasyMock.replay(context, fs, marker, tserverSet, conn, rscanner, mscanner);
-    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs, false,
-        tserverSet, marker, tabletOnServer1List) {
+    GarbageCollectWriteAheadLogs gc = new GarbageCollectWriteAheadLogs(context, fs,
+        RemovalPolicy.DELETE, tserverSet, marker, tabletOnServer1List) {
       @Override
       protected Map<UUID,Path> getSortedWALogs() throws IOException {
         return Collections.emptyMap();
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CleanUp.java b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CleanUp.java
index f4f974afd6..f02bcf2122 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CleanUp.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CleanUp.java
@@ -242,7 +242,7 @@ protected void archiveFile(VolumeManager fs, String dir, String tableId) throws
     }
 
     // Get the file archive directory on this volume
-    final Path fileArchiveDir = new Path(basePath, ServerConstants.FILE_ARCHIVE_DIR);
+    final Path fileArchiveDir = new Path(basePath, ServerConstants.ARCHIVE_DIR);
 
     // Make sure it exists just to be safe
     fs.mkdirs(fileArchiveDir);
diff --git a/test/src/main/java/org/apache/accumulo/test/FileArchiveIT.java b/test/src/main/java/org/apache/accumulo/test/FileArchiveIT.java
index af1d06e342..ff4df281c9 100644
--- a/test/src/main/java/org/apache/accumulo/test/FileArchiveIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/FileArchiveIT.java
@@ -107,7 +107,7 @@ public void testUnusuedFilesAreArchived() throws Exception {
     log.info("File relative to accumulo dir: " + filePath);
 
     Path fileArchiveDir = new Path(getCluster().getConfig().getAccumuloDir().toString(),
-        ServerConstants.FILE_ARCHIVE_DIR);
+        ServerConstants.ARCHIVE_DIR);
 
     Assert.assertTrue("File archive directory didn't exist", fs.exists(fileArchiveDir));
 
@@ -167,7 +167,7 @@ public void testDeletedTableIsArchived() throws Exception {
     log.info("File relative to accumulo dir: " + filePath);
 
     Path fileArchiveDir = new Path(getCluster().getConfig().getAccumuloDir().toString(),
-        ServerConstants.FILE_ARCHIVE_DIR);
+        ServerConstants.ARCHIVE_DIR);
 
     Assert.assertTrue("File archive directory didn't exist", fs.exists(fileArchiveDir));
 
@@ -228,7 +228,7 @@ public void testUnusuedFilesAndDeletedTable() throws Exception {
     log.info("File relative to accumulo dir: " + filePath);
 
     Path fileArchiveDir = new Path(getCluster().getConfig().getAccumuloDir().toString(),
-        ServerConstants.FILE_ARCHIVE_DIR);
+        ServerConstants.ARCHIVE_DIR);
 
     Assert.assertTrue("File archive directory didn't exist", fs.exists(fileArchiveDir));
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services