This is an automated email from the ASF dual-hosted git repository.
keith-turner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new d59b72a38e Encode if GC candidate is dir or file (#6638)
d59b72a38e is described below
commit d59b72a38e8ffd0cf19e8050c3c806c959cce859
Author: Keith Turner <[email protected]>
AuthorDate: Tue Nov 17 10:24:28 2026 -0500
Encode if GC candidate is dir or file (#6638)
The GC codes examines candidate paths looking for the depth of the
literal `tables` in the path to determine if a candidate is a dir or
file. If a candidate path does not have `tables` then its not possible
to know if a candidate is a dir or a file.
This change encodes if a candidate is a dir or file when writing it to
the metadata table because its known at that point. The encoding
replaces the current value of `skewed` which was only used for 2.1 to
4.0 upgrade but is no longer needed.
The GcCandidate type was only used to read candidates from the metadata
table. Changed the code to also use that type to write to the metadata
table. This change causes a good bit of diffs, but it was needed to
support adding the type.
Added a new GcCandidates type that is responsible for removing in use
candidates. This consolidates code that used to be spread throughout
the GC code. The code is also much simpler than the code it replaced
because the type information in the candidate allows the code to be more
direct.
While working on this noticed a race condition between the delete table
code and GC deletion of in use candidates. The table deletion code was
inserting candidates and then deleting tablet metadata. If the GC ran
after candidate insertion but before deleting tablet metadata, then it
could conclude some candidates are in use and delete them. However,
nothing may ever insert these candidates again and then the files would
never be deleted. Modified the delete table code to insert GC candidates
into a temporary area that is ignored by GC, delete the medata table
entries, and then copy GC candidates to the place where GC reads from.
Made this change in the commit because I thought it was causing a test
to fail, but discovered the test failure was caused by another problem
that I will open an issue about.
---
.../org/apache/accumulo/core/gc/GcCandidate.java | 71 +++-
.../accumulo/core/metadata/schema/Ample.java | 6 +-
.../core/metadata/schema/MetadataSchema.java | 71 +++-
.../accumulo/server/gc/AllVolumesDirectory.java | 53 ---
.../apache/accumulo/server/gc/GcVolumeUtil.java | 45 --
.../server/metadata/GcCandidateFilter.java | 33 --
.../accumulo/server/metadata/RootGcCandidates.java | 4 +-
.../accumulo/server/metadata/ServerAmpleImpl.java | 43 +-
.../accumulo/server/util/MetadataTableUtil.java | 39 +-
.../main/java/org/apache/accumulo/gc/GCRun.java | 172 +++-----
.../accumulo/gc/GarbageCollectionAlgorithm.java | 327 ++-------------
.../accumulo/gc/GarbageCollectionEnvironment.java | 14 +-
.../java/org/apache/accumulo/gc/GcCandidates.java | 180 ++++++++
.../apache/accumulo/gc/GarbageCollectionTest.java | 452 ++++++++++-----------
.../accumulo/gc/SimpleGarbageCollectorTest.java | 77 ----
.../tableOps/bulkVer2/CleanUpBulkImport.java | 4 +-
.../manager/tableOps/merge/MergeTablets.java | 7 +-
.../accumulo/manager/upgrade/Upgrader10to11.java | 4 +-
.../manager/tableOps/merge/MergeTabletsTest.java | 9 +-
.../apache/accumulo/test/ComprehensiveITBase.java | 16 +-
.../test/functional/GarbageCollectorIT.java | 167 +++++++-
21 files changed, 846 insertions(+), 948 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/gc/GcCandidate.java
b/core/src/main/java/org/apache/accumulo/core/gc/GcCandidate.java
index 4fb1320eb5..f2b95766cd 100644
--- a/core/src/main/java/org/apache/accumulo/core/gc/GcCandidate.java
+++ b/core/src/main/java/org/apache/accumulo/core/gc/GcCandidate.java
@@ -19,15 +19,63 @@
package org.apache.accumulo.core.gc;
import java.lang.Object;
+import java.util.Comparator;
import java.util.Objects;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.metadata.StoredTabletFile;
+
public class GcCandidate implements Comparable<GcCandidate> {
- private final long uid;
+ private final Long uid;
private final String path;
+ private final Type type;
+
+ public enum Type {
+ TABLET_FILE, TABLET_DIR, TABLE_DIR, BULK_DIR;
+ }
- public GcCandidate(String path, long uid) {
+ private GcCandidate(String path, long uid, Type type) {
this.path = path;
this.uid = uid;
+ this.type = type;
+ }
+
+ private GcCandidate(String path, Type type) {
+ this.path = path;
+ this.uid = null;
+ this.type = type;
+ }
+
+ public static GcCandidate forType(String path, long uid, Type type) {
+ return new GcCandidate(path, uid, type);
+ }
+
+ public static GcCandidate forTabletFile(StoredTabletFile file) {
+ return new GcCandidate(file.getMetadataPath(), Type.TABLET_FILE);
+ }
+
+ public static GcCandidate forTabletFile(String path, long uid) {
+ return new GcCandidate(path, uid, Type.TABLET_FILE);
+ }
+
+ public static GcCandidate forTabletDir(TableId tableId, String dir) {
+ return new GcCandidate("/" + tableId + "/" + dir, Type.TABLET_DIR);
+ }
+
+ public static GcCandidate forTabletDir(String path, long uid) {
+ return new GcCandidate(path, uid, Type.TABLET_DIR);
+ }
+
+ public static GcCandidate forBulkDir(String bulkDir) {
+ return new GcCandidate(bulkDir, Type.BULK_DIR);
+ }
+
+ public static GcCandidate forTableDir(TableId tableId) {
+ return new GcCandidate("/" + tableId, Type.TABLE_DIR);
+ }
+
+ public Type getType() {
+ return type;
}
public String getPath() {
@@ -40,7 +88,7 @@ public class GcCandidate implements Comparable<GcCandidate> {
@Override
public int hashCode() {
- return Objects.hash(path, uid);
+ return Objects.hash(path, uid, type);
}
@Override
@@ -49,23 +97,28 @@ public class GcCandidate implements Comparable<GcCandidate>
{
return true;
}
if (obj instanceof GcCandidate candidate) {
- return this.uid == candidate.getUid() &&
this.path.equals(candidate.getPath());
+ return Objects.equals(this.uid, candidate.uid) &&
this.path.equals(candidate.getPath())
+ && type == candidate.type;
}
return false;
}
+ private static final Comparator<Long> UID_CMP =
Comparator.nullsFirst(Long::compareTo);
+
@Override
public int compareTo(GcCandidate candidate) {
- var cmp = this.path.compareTo(candidate.getPath());
+ var cmp = type.compareTo(candidate.type);
if (cmp == 0) {
- return Long.compare(this.uid, candidate.getUid());
- } else {
- return cmp;
+ cmp = this.path.compareTo(candidate.getPath());
+ if (cmp == 0) {
+ cmp = UID_CMP.compare(this.uid, candidate.uid);
+ }
}
+ return cmp;
}
@Override
public String toString() {
- return path + ", UUID: " + uid;
+ return "type: " + type + ", path: " + path + ", UUID: " + uid;
}
}
diff --git
a/core/src/main/java/org/apache/accumulo/core/metadata/schema/Ample.java
b/core/src/main/java/org/apache/accumulo/core/metadata/schema/Ample.java
index 7e66f37068..3eb7853dc3 100644
--- a/core/src/main/java/org/apache/accumulo/core/metadata/schema/Ample.java
+++ b/core/src/main/java/org/apache/accumulo/core/metadata/schema/Ample.java
@@ -213,7 +213,7 @@ public interface Ample {
/**
* Unlike {@link #putGcCandidates(TableId, Collection)} this takes file and
dir GC candidates.
*/
- default void putGcFileAndDirCandidates(TableId tableId,
Collection<ReferenceFile> candidates) {
+ default void putGcFileAndDirCandidates(TableId tableId,
Collection<GcCandidate> candidates) {
throw new UnsupportedOperationException();
}
@@ -235,10 +235,10 @@ public interface Ample {
* directory for Tablet File. Otherwise, a {@link ReferencedTabletFile}
object could be used. The
* tabletFilePathToRemove is validated and normalized before creating the
mutation.
*
- * @param tabletFilePathToRemove String full path of the TabletFile
+ * @param candidate String full path of the TabletFile
* @return Mutation with encoded delete marker
*/
- default Mutation createDeleteMutation(ReferenceFile tabletFilePathToRemove) {
+ default Mutation createDeleteMutation(GcCandidate candidate) {
throw new UnsupportedOperationException();
}
diff --git
a/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java
b/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java
index fa7a98ce38..25a747d5a6 100644
---
a/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java
+++
b/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java
@@ -20,6 +20,7 @@ package org.apache.accumulo.core.metadata.schema;
import static java.nio.charset.StandardCharsets.UTF_8;
+import java.util.Map;
import java.util.regex.Pattern;
import org.apache.accumulo.core.client.admin.TimeType;
@@ -31,6 +32,7 @@ import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.fate.FateId;
+import org.apache.accumulo.core.gc.GcCandidate;
import org.apache.accumulo.core.schema.Section;
import org.apache.accumulo.core.util.ColumnFQ;
import org.apache.accumulo.core.util.Pair;
@@ -498,6 +500,48 @@ public class MetadataSchema {
}
+ /**
+ * Holds temporary delete markers used when deleting a table.
+ */
+ public static class TmpDeletesSection {
+ private static final Section section =
+ new Section(RESERVED_PREFIX + "tmpdel", true, RESERVED_PREFIX +
"tmpdem", false);
+
+ private static String prefix(TableId tableId) {
+ return section.getRowPrefix() + tableId + ",";
+ }
+
+ private static String row(TableId tableId, GcCandidate candidate) {
+ return prefix(tableId) + candidate.getPath();
+ }
+
+ private static byte[] EMPTY_BYTES = new byte[0];
+
+ public static Mutation insert(TableId tableId, GcCandidate candidate) {
+ Mutation m = new Mutation(row(tableId, candidate));
+ m.at().family(EMPTY_BYTES).qualifier(EMPTY_BYTES)
+ .put(DeletesSection.encodeType(candidate.getType()));
+ return m;
+ }
+
+ public static GcCandidate decode(Map.Entry<Key,Value> entry) {
+ var path = entry.getKey().getRowData().toString().split(",", 2)[1];
+ var type = DeletesSection.decodeType(entry.getValue().toString());
+ return GcCandidate.forType(path, entry.getKey().getTimestamp(), type);
+ }
+
+ public static Mutation delete(TableId tableId, GcCandidate candidate) {
+ Mutation m = new Mutation(row(tableId, candidate));
+ m.at().family(EMPTY_BYTES).qualifier(EMPTY_BYTES).delete();
+ return m;
+ }
+
+ public static Range getRange(TableId tableId) {
+ return Range.prefix(prefix(tableId));
+ }
+
+ }
+
/**
* Holds delete markers for potentially unused files/directories
*/
@@ -520,14 +564,29 @@ public class MetadataSchema {
return row.substring(encoded_prefix_length);
}
- /**
- * Value to indicate that the row has been skewed/encoded.
- */
- public static class SkewedKeyValue {
- public static final String STR_NAME = "skewed";
- public static final Value NAME = new Value(STR_NAME);
+ private static Value TABLET_DIR_VALUE = new Value("DIR");
+ private static Value TABLET_FILE_VALUE = new Value("FILE");
+ private static Value TABLE_DIR_VALUE = new Value("TDIR");
+ private static Value BULK_DIR_VALUE = new Value("BDIR");
+
+ public static Value encodeType(GcCandidate.Type type) {
+ return switch (type) {
+ case TABLET_DIR -> TABLET_DIR_VALUE;
+ case TABLET_FILE -> TABLET_FILE_VALUE;
+ case TABLE_DIR -> TABLE_DIR_VALUE;
+ case BULK_DIR -> BULK_DIR_VALUE;
+ };
}
+ public static GcCandidate.Type decodeType(String type) {
+ return switch (type) {
+ case "DIR" -> GcCandidate.Type.TABLET_DIR;
+ case "FILE" -> GcCandidate.Type.TABLET_FILE;
+ case "TDIR" -> GcCandidate.Type.TABLE_DIR;
+ case "BDIR" -> GcCandidate.Type.BULK_DIR;
+ default -> throw new IllegalArgumentException("Unknown type " + type);
+ };
+ }
}
/**
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/gc/AllVolumesDirectory.java
b/server/base/src/main/java/org/apache/accumulo/server/gc/AllVolumesDirectory.java
deleted file mode 100644
index e8c6c9d24c..0000000000
---
a/server/base/src/main/java/org/apache/accumulo/server/gc/AllVolumesDirectory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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
- *
- * https://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.
- */
-package org.apache.accumulo.server.gc;
-
-import static org.apache.accumulo.server.gc.GcVolumeUtil.ALL_VOLUMES_PREFIX;
-
-import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.data.TableId;
-import org.apache.accumulo.core.gc.ReferenceFile;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema;
-import org.apache.hadoop.fs.Path;
-
-/**
- * A specially encoded GC Reference to a directory with the {@link
GcVolumeUtil#ALL_VOLUMES_PREFIX}
- */
-public class AllVolumesDirectory extends ReferenceFile {
-
- public AllVolumesDirectory(TableId tableId, String dirName) {
- super(tableId, getDeleteTabletOnAllVolumesUri(tableId, dirName), false,
false);
- }
-
- private static String getDeleteTabletOnAllVolumesUri(TableId tableId, String
dirName) {
- MetadataSchema.TabletsSection.ServerColumnFamily.validateDirCol(dirName);
- return ALL_VOLUMES_PREFIX + Constants.TABLE_DIR + Path.SEPARATOR + tableId
+ Path.SEPARATOR
- + dirName;
- }
-
- @Override
- public String getMetadataPath() {
- return metadataPath;
- }
-
- @Override
- public boolean isDirectory() {
- return true;
- }
-}
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/gc/GcVolumeUtil.java
b/server/base/src/main/java/org/apache/accumulo/server/gc/GcVolumeUtil.java
deleted file mode 100644
index 3f73b85ef4..0000000000
--- a/server/base/src/main/java/org/apache/accumulo/server/gc/GcVolumeUtil.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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
- *
- * https://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.
- */
-package org.apache.accumulo.server.gc;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Collectors;
-
-import org.apache.accumulo.server.fs.VolumeManager;
-import org.apache.hadoop.fs.Path;
-
-public class GcVolumeUtil {
- // AGCAV : Accumulo Garbage Collector All Volumes
- static final String ALL_VOLUMES_PREFIX = "agcav:/";
-
- public static Collection<Path> expandAllVolumesUri(VolumeManager fs, Path
path) {
- if (path.toString().startsWith(ALL_VOLUMES_PREFIX)) {
- String relPath = path.toString().substring(ALL_VOLUMES_PREFIX.length());
- return fs.getVolumes().stream().map(vol -> vol.prefixChild(relPath))
- .collect(Collectors.toList());
- } else {
- return Collections.singleton(path);
- }
- }
-
- public static boolean isAllVolumesUri(Path path) {
- return path.toString().startsWith(ALL_VOLUMES_PREFIX);
- }
-}
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/metadata/GcCandidateFilter.java
b/server/base/src/main/java/org/apache/accumulo/server/metadata/GcCandidateFilter.java
deleted file mode 100644
index 146734395f..0000000000
---
a/server/base/src/main/java/org/apache/accumulo/server/metadata/GcCandidateFilter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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
- *
- * https://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.
- */
-package org.apache.accumulo.server.metadata;
-
-import org.apache.accumulo.core.data.Key;
-import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.iterators.Filter;
-import
org.apache.accumulo.core.metadata.schema.MetadataSchema.DeletesSection.SkewedKeyValue;
-
-public class GcCandidateFilter extends Filter {
-
- @Override
- public boolean accept(Key k, Value v) {
- return v.equals(SkewedKeyValue.NAME);
- }
-
-}
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
b/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
index 7a2a17d08f..b04cfa7ad6 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/metadata/RootGcCandidates.java
@@ -96,8 +96,8 @@ public class RootGcCandidates {
return data.candidates.entrySet().stream().flatMap(entry -> {
String parent = entry.getKey();
SortedSet<String> names = entry.getValue();
- return names.stream()
- .map(name -> new GcCandidate(parent + Path.SEPARATOR + name,
uidGen.nextLong()));
+ return names.stream().map(
+ name -> GcCandidate.forTabletFile(parent + Path.SEPARATOR + name,
uidGen.nextLong()));
}).sorted();
}
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/metadata/ServerAmpleImpl.java
b/server/base/src/main/java/org/apache/accumulo/server/metadata/ServerAmpleImpl.java
index 16f63126e4..6a705e3baf 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/metadata/ServerAmpleImpl.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/metadata/ServerAmpleImpl.java
@@ -29,7 +29,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.accumulo.core.client.BatchWriter;
-import org.apache.accumulo.core.client.IteratorSetting;
import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
@@ -40,12 +39,10 @@ import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.gc.GcCandidate;
-import org.apache.accumulo.core.gc.ReferenceFile;
import org.apache.accumulo.core.metadata.RootTable;
import org.apache.accumulo.core.metadata.ScanServerRefStore;
import org.apache.accumulo.core.metadata.StoredTabletFile;
import org.apache.accumulo.core.metadata.SystemTables;
-import org.apache.accumulo.core.metadata.ValidationUtil;
import org.apache.accumulo.core.metadata.schema.Ample;
import org.apache.accumulo.core.metadata.schema.AmpleImpl;
import org.apache.accumulo.core.metadata.schema.MetadataSchema.BlipSection;
@@ -58,6 +55,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
public class ServerAmpleImpl extends AmpleImpl implements Ample {
@@ -138,7 +136,7 @@ public class ServerAmpleImpl extends AmpleImpl implements
Ample {
try (BatchWriter writer =
context.createBatchWriter(getMetaTable(DataLevel.of(tableId)))) {
for (StoredTabletFile file : candidates) {
- writer.addMutation(createDeleteMutation(file));
+
writer.addMutation(createDeleteMutation(GcCandidate.forTabletFile(file)));
}
} catch (MutationsRejectedException | TableNotFoundException e) {
throw new IllegalStateException(e);
@@ -146,12 +144,14 @@ public class ServerAmpleImpl extends AmpleImpl implements
Ample {
}
@Override
- public void putGcFileAndDirCandidates(TableId tableId,
Collection<ReferenceFile> candidates) {
+ public void putGcFileAndDirCandidates(TableId tableId,
Collection<GcCandidate> candidates) {
if (DataLevel.of(tableId) == DataLevel.ROOT) {
// Directories are unexpected for the root tablet, so convert to stored
tablet file
+ Preconditions.checkState(
+ candidates.stream().allMatch(gcc -> gcc.getType() ==
GcCandidate.Type.TABLET_FILE));
mutateRootGcCandidates(rgcc -> rgcc.add(candidates.stream()
- .map(reference ->
StoredTabletFile.of(URI.create(reference.getMetadataPath())))));
+ .map(candidate ->
StoredTabletFile.of(URI.create(candidate.getPath())))));
return;
}
@@ -254,29 +254,26 @@ public class ServerAmpleImpl extends AmpleImpl implements
Ample {
throw new IllegalStateException(e);
}
scanner.setRange(range);
- scanner.addScanIterator(new IteratorSetting(25, "gcCandidate",
GcCandidateFilter.class));
- return scanner.stream()
- .map(
- entry -> new
GcCandidate(DeletesSection.decodeRow(entry.getKey().getRow().toString()),
- entry.getKey().getTimestamp()))
- .iterator();
+ return scanner.stream().<GcCandidate>mapMulti((entry, consumer) -> {
+ try {
+ var candidate =
+
GcCandidate.forType(DeletesSection.decodeRow(entry.getKey().getRow().toString()),
+ entry.getKey().getTimestamp(),
+ DeletesSection.decodeType(entry.getValue().toString()));
+ consumer.accept(candidate);
+ } catch (RuntimeException e) {
+ log.warn("Ignoring invalid deletion candidate : {}", entry, e);
+ }
+ }).iterator();
} else {
throw new IllegalArgumentException();
}
}
@Override
- public Mutation createDeleteMutation(ReferenceFile tabletFilePathToRemove) {
- return
createDelMutation(ValidationUtil.validate(tabletFilePathToRemove).getMetadataPath());
- }
-
- public Mutation createDeleteMutation(StoredTabletFile pathToRemove) {
- return createDelMutation(pathToRemove.getMetadataPath());
- }
-
- private Mutation createDelMutation(String path) {
- Mutation delFlag = new Mutation(new Text(DeletesSection.encodeRow(path)));
- delFlag.put(EMPTY_TEXT, EMPTY_TEXT, DeletesSection.SkewedKeyValue.NAME);
+ public Mutation createDeleteMutation(GcCandidate candidate) {
+ Mutation delFlag = new Mutation(new
Text(DeletesSection.encodeRow(candidate.getPath())));
+ delFlag.put(EMPTY_TEXT, EMPTY_TEXT,
DeletesSection.encodeType(candidate.getType()));
return delFlag;
}
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
index b73eac0914..8d997c0342 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
@@ -55,7 +55,7 @@ import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.dataImpl.KeyExtent;
-import org.apache.accumulo.core.gc.ReferenceFile;
+import org.apache.accumulo.core.gc.GcCandidate;
import org.apache.accumulo.core.lock.ServiceLock;
import org.apache.accumulo.core.metadata.StoredTabletFile;
import org.apache.accumulo.core.metadata.SystemTables;
@@ -67,6 +67,7 @@ import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.Cu
import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.DataFileColumnFamily;
import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily;
+import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TmpDeletesSection;
import org.apache.accumulo.core.metadata.schema.TabletDeletedException;
import org.apache.accumulo.core.metadata.schema.TabletMetadata;
import org.apache.accumulo.core.metadata.schema.TabletsMetadata;
@@ -75,7 +76,6 @@ import org.apache.accumulo.core.tabletserver.log.LogEntry;
import org.apache.accumulo.core.util.FastFormat;
import org.apache.accumulo.core.util.Pair;
import org.apache.accumulo.server.ServerContext;
-import org.apache.accumulo.server.gc.AllVolumesDirectory;
import org.apache.hadoop.io.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -110,7 +110,12 @@ public class MetadataTableUtil {
Ample ample = context.getAmple();
ms.setRange(new KeyExtent(tableId, null, null).toMetaRange());
- // insert deletes before deleting data from metadata... this makes the
code fault-tolerant
+ // Insert tmp delete markers before deleting data from metadata... this
makes the code
+ // idempotent. TmpDeletes avoids race conditions with GC deleting in use
candidates. The
+ // actual deletes markers must be inserted after the tables metadata is
deleted. If the actual
+ // delete markers are inserted before deleting the tablet metadata, then
the GC may see them
+ // as in use and delete them. Buffering delete markers in memory may not
fit and would not be
+ // idempotent, so write them to a temp area.
if (insertDeletes) {
ms.fetchColumnFamily(DataFileColumnFamily.NAME);
@@ -121,15 +126,17 @@ public class MetadataTableUtil {
if (key.getColumnFamily().equals(DataFileColumnFamily.NAME)) {
StoredTabletFile stf = new
StoredTabletFile(key.getColumnQualifierData().toString());
-
bw.addMutation(ample.createDeleteMutation(ReferenceFile.forFile(tableId, stf)));
+ bw.addMutation(TmpDeletesSection.insert(tableId,
GcCandidate.forTabletFile(stf)));
}
if (ServerColumnFamily.DIRECTORY_COLUMN.hasColumns(key)) {
- var uri = new AllVolumesDirectory(tableId,
cell.getValue().toString());
- bw.addMutation(ample.createDeleteMutation(uri));
+ bw.addMutation(TmpDeletesSection.insert(tableId,
+ GcCandidate.forTabletDir(tableId,
cell.getValue().toString())));
}
}
+ bw.addMutation(TmpDeletesSection.insert(tableId,
GcCandidate.forTableDir(tableId)));
+
bw.flush();
ms.clearColumns();
@@ -158,6 +165,26 @@ public class MetadataTableUtil {
if (m != null) {
bw.addMutation(m);
}
+
+ // must flush tablet metadata deletes before inserting GC candidates to
avoid race conditions
+ // with GC in use candidate deletion.
+ bw.flush();
+
+ ms.setRange(TmpDeletesSection.getRange(tableId));
+ for (Entry<Key,Value> cell : ms) {
+ GcCandidate candidate = TmpDeletesSection.decode(cell);
+ bw.addMutation(ample.createDeleteMutation(candidate));
+ }
+ // flush deletion candidates before deleting tmp candidates to make this
code idempotent.
+ bw.flush();
+
+ // cleanup the tmp deletion candidates
+ for (Entry<Key,Value> cell : ms) {
+ GcCandidate candidate = TmpDeletesSection.decode(cell);
+ bw.addMutation(TmpDeletesSection.delete(tableId, candidate));
+ }
+ bw.flush();
+
}
}
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java
b/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java
index f13cff3bd1..8b02e7909e 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java
@@ -30,14 +30,15 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Set;
-import java.util.SortedMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -69,19 +70,16 @@ import
org.apache.accumulo.core.metadata.schema.TabletsMetadata;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.util.Timer;
import org.apache.accumulo.core.util.threads.ThreadPools;
-import org.apache.accumulo.core.volume.Volume;
import org.apache.accumulo.server.ServerContext;
import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.fs.VolumeUtil;
-import org.apache.accumulo.server.gc.GcVolumeUtil;
-import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Iterators;
/**
* A single garbage collection performed on a table (Root, MD) or all User
tables.
@@ -268,7 +266,7 @@ public class GCRun implements GarbageCollectionEnvironment {
}
@Override
- public void deleteConfirmedCandidates(SortedMap<String,GcCandidate>
confirmedDeletes) {
+ public void deleteConfirmedCandidates(Collection<GcCandidate>
confirmedDeletes) {
final VolumeManager fs = context.getVolumeManager();
var metadataLocation = level == Ample.DataLevel.ROOT
? ZooUtil.getRoot(context.getInstanceID()) + " for " +
SystemTables.ROOT.tableName()
@@ -279,7 +277,7 @@ public class GCRun implements GarbageCollectionEnvironment {
+ " data file candidates marked for deletion in " + metadataLocation
+ ".\n"
+ " Examine the log files to identify them.\n");
log.info("{} SAFEMODE: Listing all data file candidates for deletion",
fileActionPrefix);
- for (GcCandidate candidate : confirmedDeletes.values()) {
+ for (GcCandidate candidate : confirmedDeletes) {
log.info("{} SAFEMODE: {}", fileActionPrefix, candidate);
}
log.info("SAFEMODE: End candidates for deletion");
@@ -288,43 +286,52 @@ public class GCRun implements
GarbageCollectionEnvironment {
List<GcCandidate> processedDeletes = Collections.synchronizedList(new
ArrayList<>());
- minimizeDeletes(confirmedDeletes, processedDeletes, fs, log,
loggingInterval);
-
ThreadPoolExecutor deleteThreadPool = ThreadPools.getServerThreadPools()
.createExecutorService(config, Property.GC_DELETE_THREADS);
final Map<Path,Path> replacements = context.getVolumeReplacements();
+ Map<GcCandidate.Type,List<Runnable>> deleteTasks = new
EnumMap<>(GcCandidate.Type.class);
+
log.info("Batch {} attempting to delete {} gcCandidate files",
batchCount.get(),
confirmedDeletes.size());
Timer timer = Timer.startNew();
- for (final GcCandidate delete : confirmedDeletes.values()) {
+ for (final GcCandidate delete : confirmedDeletes) {
Runnable deleteTask = () -> {
boolean removeFlag = false;
try {
- Path fullPath;
- Path switchedDelete = VolumeUtil.switchVolume(new
Path(delete.getPath()),
- VolumeManager.FileType.TABLE, replacements);
- if (switchedDelete != null) {
- // actually replacing the volumes in the metadata table would be
tricky because the
- // entries would be different rows. So it could not be
- // atomically in one mutation and extreme care would need to be
taken that delete
- // entry was not lost. Instead of doing that, just deal with
- // volume switching when something needs to be deleted. Since the
rest of the code
- // uses suffixes to compare delete entries, there is no danger
- // of deleting something that should not be deleted. Must not
change value of delete
- // variable because that's what's stored in metadata table.
- log.debug("Volume replaced {} -> {}", delete.getPath(),
switchedDelete);
- fullPath = ValidationUtil.validate(switchedDelete);
+ Iterable<Path> paths;
+ if (delete.getType() == GcCandidate.Type.TABLET_DIR
+ || delete.getType() == GcCandidate.Type.TABLE_DIR) {
+ String relPath = "/" + Constants.TABLE_DIR
+ + (delete.getPath().startsWith("/") ? "" : "/") +
delete.getPath();
+ paths = () -> fs.getVolumes().stream().map(vol ->
vol.prefixChild(relPath)).iterator();
} else {
- fullPath = new Path(ValidationUtil.validate(delete.getPath()));
+ Path fullPath;
+ Path switchedDelete = VolumeUtil.switchVolume(new
Path(delete.getPath()),
+ VolumeManager.FileType.TABLE, replacements);
+ if (switchedDelete != null) {
+ // actually replacing the volumes in the metadata table would be
tricky because the
+ // entries would be different rows. So it could not be
+ // atomically in one mutation and extreme care would need to be
taken that delete
+ // entry was not lost. Instead of doing that, just deal with
+ // volume switching when something needs to be deleted. Since
the rest of the code
+ // uses suffixes to compare delete entries, there is no danger
+ // of deleting something that should not be deleted. Must not
change value of delete
+ // variable because that's what's stored in metadata table.
+ log.debug("Volume replaced {} -> {}", delete.getPath(),
switchedDelete);
+ fullPath = ValidationUtil.validate(switchedDelete);
+ } else {
+ fullPath = new Path(ValidationUtil.validate(delete.getPath()));
+ }
+ paths = () -> Iterators.singletonIterator(fullPath);
}
- for (Path pathToDel : GcVolumeUtil.expandAllVolumesUri(fs,
fullPath)) {
+ for (Path pathToDel : paths) {
log.debug("Batch {} {} Deleting {}", batchCount.get(),
fileActionPrefix, pathToDel);
- if (moveToTrash(pathToDel) || fs.deleteRecursively(pathToDel)) {
+ if (moveToTrash(pathToDel) || fs.delete(pathToDel)) {
// delete succeeded, still want to delete
removeFlag = true;
deleted.increment();
@@ -368,7 +375,27 @@ public class GCRun implements GarbageCollectionEnvironment
{
};
- deleteThreadPool.execute(deleteTask);
+ deleteTasks.computeIfAbsent(delete.getType(), t -> new
ArrayList<>()).add(deleteTask);
+ }
+
+ // Need to process deletes in a certain order to ensure that files are
deleted before
+ // directories.
+ for (var type : List.of(GcCandidate.Type.TABLET_FILE,
GcCandidate.Type.TABLET_DIR,
+ GcCandidate.Type.BULK_DIR, GcCandidate.Type.TABLE_DIR)) {
+ List<Future<?>> futures = new ArrayList<>();
+ for (var task : deleteTasks.getOrDefault(type, List.of())) {
+ futures.add(deleteThreadPool.submit(task));
+ }
+ for (var future : futures) {
+ try {
+ future.get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ log.error("{}", e.getMessage(), e);
+ } catch (ExecutionException e) {
+ log.error("{}", e.getMessage(), e);
+ }
+ }
}
deleteThreadPool.shutdown();
@@ -389,29 +416,6 @@ public class GCRun implements GarbageCollectionEnvironment
{
deleteGcCandidates(processedDeletes, GcCandidateType.VALID);
}
- @Override
- public void deleteTableDirIfEmpty(TableId tableID) throws IOException {
- final VolumeManager fs = context.getVolumeManager();
- // if dir exist and is empty, then empty list is returned...
- // hadoop 2.0 will throw an exception if the file does not exist
- for (String dir : context.getTablesDirs()) {
- FileStatus[] tabletDirs;
- try {
- tabletDirs = fs.listStatus(new Path(dir + "/" + tableID));
- } catch (FileNotFoundException ex) {
- continue;
- }
-
- if (tabletDirs.length == 0) {
- Path p = new Path(dir + "/" + tableID);
- log.debug("{} Removing table dir {}", fileActionPrefix, p);
- if (!moveToTrash(p)) {
- fs.delete(p);
- }
- }
- }
- }
-
@Override
public void incrementCandidatesStat(long i) {
candidates.add(i);
@@ -422,70 +426,6 @@ public class GCRun implements GarbageCollectionEnvironment
{
inUse.add(i);
}
- @VisibleForTesting
- static void minimizeDeletes(SortedMap<String,GcCandidate> confirmedDeletes,
- List<GcCandidate> processedDeletes, VolumeManager fs, Logger logger,
- Duration loggingInterval) {
- Set<Path> seenVolumes = new HashSet<>();
-
- // when deleting a dir and all files in that dir, only need to delete the
dir.
- // The dir will sort right before the files... so remove the files in this
case
- // to minimize namenode ops
- Iterator<Map.Entry<String,GcCandidate>> cdIter =
confirmedDeletes.entrySet().iterator();
-
- String lastDirRel = null;
- Path lastDirAbs = null;
- Timer progressTimer = Timer.startNew();
- int progressCount = 0;
- int totalDeletes = confirmedDeletes.size();
- while (cdIter.hasNext()) {
- progressCount++;
- Map.Entry<String,GcCandidate> entry = cdIter.next();
- String relPath = entry.getKey();
- Path absPath = new Path(entry.getValue().getPath());
-
- if (SimpleGarbageCollector.isDir(relPath)) {
- lastDirRel = relPath;
- lastDirAbs = absPath;
- } else if (lastDirRel != null) {
- if (relPath.startsWith(lastDirRel)) {
- Path vol = VolumeManager.FileType.TABLE.getVolume(absPath);
-
- boolean sameVol = false;
-
- if (GcVolumeUtil.isAllVolumesUri(lastDirAbs)) {
- if (seenVolumes.contains(vol)) {
- sameVol = true;
- } else {
- for (Volume cvol : fs.getVolumes()) {
- if (cvol.containsPath(vol)) {
- seenVolumes.add(vol);
- sameVol = true;
- }
- }
- }
- } else {
- sameVol =
Objects.equals(VolumeManager.FileType.TABLE.getVolume(lastDirAbs), vol);
- }
-
- if (sameVol) {
- logger.info("{} Ignoring {} because {} exist", fileActionPrefix,
- entry.getValue().getPath(), lastDirAbs);
- processedDeletes.add(entry.getValue());
- cdIter.remove();
- }
- } else {
- lastDirRel = null;
- lastDirAbs = null;
- }
- }
- if (progressTimer.hasElapsed(loggingInterval)) {
- logger.debug("Minimizing delete {} of {}", progressCount,
totalDeletes);
- progressTimer.restart();
- }
- }
- }
-
/**
* Checks if safemode is set - files will not be deleted.
*
diff --git
a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
index bb19b36313..6dfdd1c57b 100644
---
a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
+++
b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
@@ -20,25 +20,19 @@ package org.apache.accumulo.gc;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
import java.util.stream.Stream;
-import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.gc.GcCandidate;
import org.apache.accumulo.core.gc.Reference;
import org.apache.accumulo.core.metadata.schema.Ample.GcCandidateType;
-import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily;
import org.apache.accumulo.core.trace.TraceUtil;
-import org.apache.hadoop.fs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,227 +45,26 @@ public class GarbageCollectionAlgorithm {
private static final Logger log =
LoggerFactory.getLogger(GarbageCollectionAlgorithm.class);
- /**
- * Normalizes a candidate, directory, or blip path to a table-relative GC
key. File references use
- * {@link #makeRelativeFileReference(String)} because they must be absolute
URIs.
- */
- @VisibleForTesting
- String makeRelative(String path, int expectedLen) {
- // remove prefixed old relative path
- int position = path.startsWith("../") ? 3 : 0;
- int componentCount = 0;
- int start0 = 0;
- int end0 = 0;
- int start1 = 0;
- int end1 = 0;
- int start2 = 0;
- int end2 = 0;
- int start3 = 0;
- int end3 = 0;
- boolean hasColon = false;
-
- // Scan once, ignoring empty components and retaining only the last four
ranges.
- while (position < path.length()) {
- while (position < path.length() && path.charAt(position) == '/') {
- position++;
- }
- if (position == path.length()) {
- break;
- }
-
- int componentStart = position;
- while (position < path.length() && path.charAt(position) != '/') {
- if (path.charAt(position) == ':') {
- hasColon = true;
- }
- position++;
- }
- int componentEnd = position;
-
- start0 = start1;
- end0 = end1;
- start1 = start2;
- end1 = end2;
- start2 = start3;
- end2 = end3;
- start3 = componentStart;
- end3 = componentEnd;
- componentCount++;
- }
-
- int outputStart1;
- int outputEnd1;
- int outputStart2;
- int outputEnd2;
- int outputStart3 = 0;
- int outputEnd3 = 0;
- int outputComponents;
-
- if (componentCount > 3 && hasColon) {
- // full file path like hdfs://foo:6000/accumulo/tables/4/t0/F000.rf
- int tablesLength = end0 - start0;
- if (tablesLength == Constants.TABLE_DIR.length()
- && path.regionMatches(start0, Constants.TABLE_DIR, 0, tablesLength)
- && (expectedLen == 0 || expectedLen == 3)) {
- // return the last 3 components after tables, like 4/t0/F000.rf
- outputStart1 = start1;
- outputEnd1 = end1;
- outputStart2 = start2;
- outputEnd2 = end2;
- outputStart3 = start3;
- outputEnd3 = end3;
- outputComponents = 3;
- } else {
- int directoryTablesLength = end1 - start1;
- if (directoryTablesLength == Constants.TABLE_DIR.length()
- && path.regionMatches(start1, Constants.TABLE_DIR, 0,
directoryTablesLength)
- && (expectedLen == 0 || expectedLen == 2)) {
- // return the last 2 components after tables, like 4/t0
- outputStart1 = start2;
- outputEnd1 = end2;
- outputStart2 = start3;
- outputEnd2 = end3;
- outputComponents = 2;
- } else {
- throw new IllegalArgumentException(
- "Failed to make path relative. Bad reference: " + path);
- }
- }
- } else if (componentCount == 3 && (expectedLen == 0 || expectedLen == 3)
&& !hasColon) {
- // we already have a relative path so return it, like 4/t0/F000.rf
- outputStart1 = start1;
- outputEnd1 = end1;
- outputStart2 = start2;
- outputEnd2 = end2;
- outputStart3 = start3;
- outputEnd3 = end3;
- outputComponents = 3;
- } else if (componentCount == 2 && (expectedLen == 0 || expectedLen == 2)
&& !hasColon) {
- // return the last 2 components of the relative path, like 4/t0
- outputStart1 = start2;
- outputEnd1 = end2;
- outputStart2 = start3;
- outputEnd2 = end3;
- outputComponents = 2;
- } else {
- throw new IllegalArgumentException("Failed to make path relative. Bad
reference: " + path);
- }
-
- String relPath;
- boolean contiguous = outputEnd1 + 1 == outputStart2 &&
path.charAt(outputEnd1) == '/';
- if (outputComponents == 2) {
- if (contiguous) {
- relPath = path.substring(outputStart1, outputEnd2);
- } else {
- relPath = new StringBuilder(outputEnd1 - outputStart1 + outputEnd2 -
outputStart2 + 1)
- .append(path, outputStart1, outputEnd1).append('/')
- .append(path, outputStart2, outputEnd2).toString();
- }
- } else if (contiguous && outputEnd2 + 1 == outputStart3 &&
path.charAt(outputEnd2) == '/') {
- relPath = path.substring(outputStart1, outputEnd3);
- } else {
- relPath = new StringBuilder(
- outputEnd1 - outputStart1 + outputEnd2 - outputStart2 + outputEnd3 -
outputStart3 + 2)
- .append(path, outputStart1, outputEnd1).append('/').append(path,
outputStart2, outputEnd2)
- .append('/').append(path, outputStart3, outputEnd3).toString();
- }
-
- log.trace("{} -> {} expectedLen = {}", path, relPath, expectedLen);
- return relPath;
- }
-
- /**
- * Extracts the table-relative GC key from an absolute file reference URI,
such as
- * hdfs://foo:6000/accumulo/tables/4/t0/F000.rf -> 4/t0/F000.rf.
- */
- private String makeRelativeFileReference(String path) {
- Path referencePath = new Path(path);
- if (!referencePath.isAbsolute() || referencePath.toUri().getScheme() ==
null) {
- throw new IllegalArgumentException("File reference must be an absolute
URI: " + path);
- }
-
- String[] tokens = path.split("/");
- String[] suffix = new String[4];
- int suffixLen = 0;
- for (int i = tokens.length - 1; i >= 0 && suffixLen < suffix.length; i--) {
- if (!tokens[i].isEmpty()) {
- suffix[suffixLen++] = tokens[i];
- }
- }
-
- if (suffixLen != suffix.length || !Constants.TABLE_DIR.equals(suffix[3])) {
- throw new IllegalArgumentException("Failed to make path relative. Bad
reference: " + path);
- }
-
- String relativePath = suffix[2] + "/" + suffix[1] + "/" + suffix[0];
- log.trace("{} -> {}", path, relativePath);
- return relativePath;
- }
-
- private SortedMap<String,GcCandidate> makeRelative(Collection<GcCandidate>
candidates) {
- SortedMap<String,GcCandidate> ret = new TreeMap<>();
-
- for (GcCandidate candidate : candidates) {
- String relPath;
- try {
- relPath = makeRelative(candidate.getPath(), 0);
- } catch (IllegalArgumentException iae) {
- log.warn("Ignoring invalid deletion candidate {}", candidate);
- continue;
- }
- ret.put(relPath, candidate);
- }
-
- return ret;
- }
-
- private void removeCandidatesInUse(GarbageCollectionEnvironment gce,
- SortedMap<String,GcCandidate> candidateMap) throws InterruptedException {
+ private void removeCandidatesInUse(GarbageCollectionEnvironment gce,
GcCandidates candidates)
+ throws InterruptedException {
List<GcCandidate> candidateEntriesToBeDeleted = new ArrayList<>();
Set<TableId> tableIdsBefore = gce.getCandidateTableIDs();
Set<TableId> tableIdsSeen = new HashSet<>(tableIdsBefore.size());
try (Stream<Reference> references = gce.getReferences()) {
references.forEach(ref -> {
- tableIdsSeen.add(ref.getTableId());
-
if (ref.isDirectory()) {
- ServerColumnFamily.validateDirCol(ref.getMetadataPath());
-
- String dir = "/" + ref.getTableId() + "/" + ref.getMetadataPath();
-
- dir = makeRelative(dir, 2);
-
- GcCandidate gcTemp = candidateMap.remove(dir);
- if (gcTemp != null) {
- log.debug("Directory Candidate was still in use by dir ref: {}",
dir);
- // Do not add dir candidates to candidateEntriesToBeDeleted as
they are only created
- // once.
- }
- } else {
- String reference = ref.getMetadataPath();
- String relativePath = makeRelativeFileReference(reference);
+ tableIdsSeen.add(ref.getTableId());
+ }
- // WARNING: This line is EXTREMELY IMPORTANT.
- // You MUST REMOVE candidates that are still in use
- GcCandidate gcTemp = candidateMap.remove(relativePath);
- if (gcTemp != null) {
- log.debug("File Candidate was still in use: {}", relativePath);
+ candidates.remove(ref, candidate -> {
+ log.debug("{} candidate is still in use : {}", candidate.getType(),
candidate.getPath());
+ if (candidate.getType() == GcCandidate.Type.TABLET_FILE &&
!ref.isScan()) {
// Prevent deletion of candidates that are still in use by scans,
because they won't be
// recreated once the scan is finished.
- if (!ref.isScan()) {
- candidateEntriesToBeDeleted.add(gcTemp);
- }
- }
-
- String dir = relativePath.substring(0,
relativePath.lastIndexOf('/'));
- GcCandidate gcT = candidateMap.remove(dir);
- if (gcT != null) {
- log.debug("Directory Candidate was still in use by file ref: {}",
relativePath);
- // Do not add dir candidates to candidateEntriesToBeDeleted as
they are only created
- // once.
+ candidateEntriesToBeDeleted.add(candidate);
}
- }
+ });
});
}
Set<TableId> tableIdsAfter = gce.getCandidateTableIDs();
@@ -280,46 +73,24 @@ public class GarbageCollectionAlgorithm {
gce.deleteGcCandidates(candidateEntriesToBeDeleted, GcCandidateType.INUSE);
}
- private long removeBlipCandidates(GarbageCollectionEnvironment gce,
- SortedMap<String,GcCandidate> candidateMap) throws
TableNotFoundException {
+ private long removeBlipCandidates(GarbageCollectionEnvironment gce,
GcCandidates candidates)
+ throws TableNotFoundException {
long blipCount = 0;
- boolean checkForBulkProcessingFiles = false;
- for (String relativePath : candidateMap.keySet()) {
- if (containsBulkPrefix(relativePath)) {
- checkForBulkProcessingFiles = true;
- break;
- }
- }
-
- if (checkForBulkProcessingFiles) {
- try (Stream<String> blipStream = gce.getBlipPaths()) {
- Iterator<String> blipiter = blipStream.iterator();
- // WARNING: This block is IMPORTANT
- // You MUST REMOVE candidates that are in the same folder as a bulk
- // processing flag!
+ try (Stream<String> blipStream = gce.getBlipPaths()) {
+ Iterator<String> blipiter = blipStream.iterator();
- while (blipiter.hasNext()) {
- blipCount++;
- String blipPath = blipiter.next();
- blipPath = makeRelative(blipPath, 2);
+ // WARNING: This block is IMPORTANT
+ // You MUST REMOVE candidates that are in the same folder as a bulk
+ // processing flag!
- Iterator<String> tailIter =
candidateMap.tailMap(blipPath).keySet().iterator();
+ while (blipiter.hasNext()) {
+ blipCount++;
+ var blipPath = blipiter.next();
+ int count = candidates.removeBlip(blipPath);
- int count = 0;
-
- while (tailIter.hasNext()) {
- if (tailIter.next().startsWith(blipPath)) {
- count++;
- tailIter.remove();
- } else {
- break;
- }
- }
-
- if (count > 0) {
- log.debug("Folder has bulk processing flag: {}", blipPath);
- }
+ if (count > 0) {
+ log.debug("Folder has bulk processing flag: {}", blipPath);
}
}
}
@@ -327,16 +98,6 @@ public class GarbageCollectionAlgorithm {
return blipCount;
}
- private boolean containsBulkPrefix(String path) {
- int prefixLength = Constants.BULK_PREFIX.length();
- for (int i = 0; i <= path.length() - prefixLength; i++) {
- if (path.regionMatches(true, i, Constants.BULK_PREFIX, 0, prefixLength))
{
- return true;
- }
- }
- return false;
- }
-
/**
* Double check no tables were missed during GC
*/
@@ -377,34 +138,7 @@ public class GarbageCollectionAlgorithm {
}
}
- private void cleanUpDeletedTableDirs(GarbageCollectionEnvironment gce,
- SortedMap<String,GcCandidate> candidateMap) throws InterruptedException,
IOException {
- HashSet<TableId> tableIdsWithDeletes = new HashSet<>();
-
- // find the table ids that had dirs deleted
- for (String delete : candidateMap.keySet()) {
- int firstSlash = delete.indexOf('/');
- if (firstSlash > 0 && firstSlash < delete.length() - 1
- && delete.indexOf('/', firstSlash + 1) == -1) {
- // its a directory
- TableId tableId = TableId.of(delete.substring(0, firstSlash));
- tableIdsWithDeletes.add(tableId);
- }
- }
-
- Set<TableId> tableIdsInZookeeper = gce.getTableIDs().keySet();
-
- tableIdsWithDeletes.removeAll(tableIdsInZookeeper);
-
- // tableIdsWithDeletes should now contain the set of deleted tables that
had dirs deleted
-
- for (TableId delTableId : tableIdsWithDeletes) {
- gce.deleteTableDirIfEmpty(delTableId);
- }
- }
-
- private long confirmDeletesTrace(GarbageCollectionEnvironment gce,
- SortedMap<String,GcCandidate> candidateMap)
+ private long confirmDeletesTrace(GarbageCollectionEnvironment gce,
GcCandidates candidateMap)
throws InterruptedException, TableNotFoundException {
long blips = 0;
Span confirmDeletesSpan = TraceUtil.startSpan(this.getClass(),
"confirmDeletes");
@@ -420,20 +154,17 @@ public class GarbageCollectionAlgorithm {
return blips;
}
- private void deleteConfirmedCandidates(GarbageCollectionEnvironment gce,
- SortedMap<String,GcCandidate> candidateMap)
+ private void deleteConfirmedCandidates(GarbageCollectionEnvironment gce,
GcCandidates candidates)
throws InterruptedException, IOException, TableNotFoundException {
Span deleteSpan = TraceUtil.startSpan(this.getClass(), "deleteFiles");
try (Scope deleteScope = deleteSpan.makeCurrent()) {
- gce.deleteConfirmedCandidates(candidateMap);
+ gce.deleteConfirmedCandidates(candidates);
} catch (Exception e) {
TraceUtil.setException(deleteSpan, e, true);
throw e;
} finally {
deleteSpan.end();
}
-
- cleanUpDeletedTableDirs(gce, candidateMap);
}
public long collect(GarbageCollectionEnvironment gce)
@@ -470,12 +201,12 @@ public class GarbageCollectionAlgorithm {
gce.incrementCandidatesStat(origSize);
log.info("Batch {} total deletion candidates: {}", batchCount, origSize);
- SortedMap<String,GcCandidate> candidateMap = makeRelative(currentBatch);
+ GcCandidates candidates = new GcCandidates(currentBatch);
- long blips = confirmDeletesTrace(gce, candidateMap);
- gce.incrementInUseStat(origSize - candidateMap.size());
+ long blips = confirmDeletesTrace(gce, candidates);
+ gce.incrementInUseStat(origSize - candidates.size());
- deleteConfirmedCandidates(gce, candidateMap);
+ deleteConfirmedCandidates(gce, candidates);
return blips;
}
diff --git
a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionEnvironment.java
b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionEnvironment.java
index ae7d780dea..48b61d7025 100644
---
a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionEnvironment.java
+++
b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionEnvironment.java
@@ -18,13 +18,11 @@
*/
package org.apache.accumulo.gc;
-import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.SortedMap;
import java.util.stream.Stream;
import org.apache.accumulo.core.client.TableNotFoundException;
@@ -96,10 +94,9 @@ public interface GarbageCollectionEnvironment {
* Delete the given files from the provided {@link Map} of relative path to
absolute path for each
* file that should be deleted. The candidates should already be confirmed
for deletion.
*
- * @param candidateMap A Map from relative path to absolute path for files
to be deleted.
+ * @param candidates A Map from relative path to absolute path for files to
be deleted.
*/
- void deleteConfirmedCandidates(SortedMap<String,GcCandidate> candidateMap)
- throws TableNotFoundException;
+ void deleteConfirmedCandidates(Collection<GcCandidate> candidates) throws
TableNotFoundException;
/**
* Delete in-use reference candidates
@@ -108,13 +105,6 @@ public interface GarbageCollectionEnvironment {
*/
void deleteGcCandidates(Collection<GcCandidate> GcCandidates,
GcCandidateType type);
- /**
- * Delete a table's directory if it is empty.
- *
- * @param tableID The id of the table whose directory we are to operate on
- */
- void deleteTableDirIfEmpty(TableId tableID) throws IOException;
-
/**
* Increment the number of candidates for deletion for the current garbage
collection run
*
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/GcCandidates.java
b/server/gc/src/main/java/org/apache/accumulo/gc/GcCandidates.java
new file mode 100644
index 0000000000..8f9a3d0f2a
--- /dev/null
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/GcCandidates.java
@@ -0,0 +1,180 @@
+/*
+ * 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
+ *
+ * https://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.
+ */
+package org.apache.accumulo.gc;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.util.AbstractCollection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.function.Consumer;
+
+import org.apache.accumulo.core.gc.GcCandidate;
+import org.apache.accumulo.core.gc.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * Code that supports efficient removal of references from a set of gc
candidates.
+ */
+public class GcCandidates extends AbstractCollection<GcCandidate> {
+
+ private static final Logger log =
LoggerFactory.getLogger(GcCandidates.class);
+
+ private final SortedMap<String,GcCandidate> fileCandidates = new TreeMap<>();
+ private final HashMap<String,GcCandidate> tabletDirCandidates = new
HashMap<>();
+ private final HashMap<String,GcCandidate> bulkDirCandidates = new
HashMap<>();
+ private final HashMap<String,GcCandidate> tableDirCandidates = new
HashMap<>();
+
+ private record LastThree(String maybeATableId, String dir, String name) {
+ }
+
+ private LastThree lastThree(String strPath, int minPathLength) {
+ return lastThree(strPath, true, minPathLength, Integer.MAX_VALUE);
+ }
+
+ private LastThree lastThree(String strPath, boolean expectScheme, int
minPathLength,
+ int maxPathLength) {
+ URI uri = null;
+ try {
+ uri = new URI(strPath);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ if (expectScheme && uri.getScheme() == null) {
+ throw new IllegalArgumentException("Missing scheme in URI " + strPath);
+ }
+
+ // TODO what about other parts of the URI?
+ var path = Path.of(uri.getPath());
+
+ int count = path.getNameCount();
+ if (count < minPathLength) {
+ throw new IllegalArgumentException("Path too short " + strPath);
+ }
+
+ if (count > maxPathLength) {
+ throw new IllegalArgumentException("Path too long " + strPath);
+ }
+
+ if (count == 1) {
+ return new LastThree(null, null, path.getName(count - 1).toString());
+ } else if (count == 2) {
+ return new LastThree(null, path.getName(count - 2).toString(),
+ path.getName(count - 1).toString());
+ } else if (count >= 3) {
+ return new LastThree(path.getName(count - 3).toString(),
path.getName(count - 2).toString(),
+ path.getName(count - 1).toString());
+ } else {
+ throw new IllegalArgumentException("Bad path " + path);
+ }
+ }
+
+ public GcCandidates(Iterable<GcCandidate> candidates) {
+ candidates.forEach(candidate -> {
+ try {
+ switch (candidate.getType()) {
+ case TABLET_FILE -> {
+ var lastThree = lastThree(candidate.getPath(), 2);
+ fileCandidates.put("/" + lastThree.dir + "/" + lastThree.name,
candidate);
+ }
+ case TABLET_DIR -> {
+ var lastThree = lastThree(candidate.getPath(), false, 2, 2);
+ tabletDirCandidates.put("/" + lastThree.dir + "/" +
lastThree.name, candidate);
+ }
+ case BULK_DIR -> {
+ var lastThree = lastThree(candidate.getPath(), 1);
+ bulkDirCandidates.put(lastThree.name, candidate);
+ }
+ case TABLE_DIR -> {
+ var lastThree = lastThree(candidate.getPath(), false, 1, 1);
+ tableDirCandidates.put(lastThree.name, candidate);
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ log.warn("Ignoring invalid deletion candidate {}", candidate);
+ }
+ });
+ }
+
+ @Override
+ public Iterator<GcCandidate> iterator() {
+ return
Iterators.unmodifiableIterator(Iterators.concat(fileCandidates.values().iterator(),
+ tabletDirCandidates.values().iterator(),
bulkDirCandidates.values().iterator(),
+ tableDirCandidates.values().iterator()));
+ }
+
+ public int removeBlip(String blip) {
+ var lastThree = lastThree(blip, false, 2, 2);
+
+ String blipPrefix = "/" + lastThree.name;
+
+ bulkDirCandidates.remove(lastThree.name);
+
+ var tailIter = fileCandidates.tailMap(blipPrefix).keySet().iterator();
+ int removeCount = 0;
+ while (tailIter.hasNext()) {
+ if (tailIter.next().startsWith(blipPrefix)) {
+ tailIter.remove();
+ removeCount++;
+ } else {
+ break;
+ }
+ }
+
+ return removeCount;
+ }
+
+ public void remove(Reference reference, Consumer<GcCandidate>
removedConsumer) {
+
+ Consumer<GcCandidate> nonNullConsumer = gcc -> {
+ if (gcc != null) {
+ removedConsumer.accept(gcc);
+ }
+ };
+
+ if (reference.isDirectory()) {
+ var lastThree = lastThree(reference.getMetadataPath(), false, 1, 1);
+ nonNullConsumer
+ .accept(tabletDirCandidates.remove("/" + reference.getTableId() +
"/" + lastThree.name));
+
nonNullConsumer.accept(tableDirCandidates.remove(reference.getTableId().toString()));
+ } else {
+ var lastThree = lastThree(reference.getMetadataPath(), 2);
+ if (lastThree.maybeATableId != null) {
+ nonNullConsumer.accept(
+ tabletDirCandidates.remove("/" + lastThree.maybeATableId + "/" +
lastThree.dir));
+
nonNullConsumer.accept(tableDirCandidates.remove(lastThree.maybeATableId));
+ }
+ nonNullConsumer.accept(bulkDirCandidates.remove(lastThree.dir));
+ nonNullConsumer.accept(fileCandidates.remove("/" + lastThree.dir + "/" +
lastThree.name));
+ }
+ }
+
+ @Override
+ public int size() {
+ return tabletDirCandidates.size() + fileCandidates.size() +
bulkDirCandidates.size()
+ + tableDirCandidates.size();
+ }
+}
diff --git
a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
index e82642c4d1..21b8cdaa49 100644
--- a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
+++ b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
@@ -31,9 +31,10 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.accumulo.core.client.TableNotFoundException;
@@ -58,7 +59,6 @@ public class GarbageCollectionTest {
HashSet<TableId> tableIds = new HashSet<>();
ArrayList<GcCandidate> fileDeletions = new ArrayList<>();
- ArrayList<TableId> tablesDirsToDelete = new ArrayList<>();
private long timestamp = 0L;
private final Ample.DataLevel level;
@@ -72,14 +72,15 @@ public class GarbageCollectionTest {
}
public GcCandidate addCandidate(String s) {
- var candidate = new GcCandidate(s, timestamp);
+ var candidate = s.endsWith(".rf") ? GcCandidate.forTabletFile(s,
timestamp)
+ : GcCandidate.forTabletDir(s, timestamp);
this.candidates.add(candidate);
this.timestamp = timestamp + 1;
return candidate;
}
- public Long getTimestamp() {
- return timestamp;
+ public void addCandidate(GcCandidate candidate) {
+ this.candidates.add(candidate);
}
@Override
@@ -127,14 +128,9 @@ public class GarbageCollectionTest {
}
@Override
- public void deleteConfirmedCandidates(SortedMap<String,GcCandidate>
candidateMap) {
- fileDeletions.addAll(candidateMap.values());
- this.candidates.removeAll(candidateMap.values());
- }
-
- @Override
- public void deleteTableDirIfEmpty(TableId tableID) {
- tablesDirsToDelete.add(tableID);
+ public void deleteConfirmedCandidates(Collection<GcCandidate>
candidateMap) {
+ fileDeletions.addAll(candidateMap);
+ this.candidates.removeAll(candidateMap);
}
public void addFileReference(String tableId, String endRow, String file) {
@@ -218,7 +214,8 @@ public class GarbageCollectionTest {
private void assertFileDeleted(TestGCE gce, GcCandidate... candidates) {
for (GcCandidate candidate : candidates) {
- assertTrue(gce.fileDeletions.remove(candidate));
+ assertTrue(gce.fileDeletions.remove(candidate),
+ "Did not remove candidate : " + candidate.toString());
}
assertEquals(0, gce.fileDeletions.size(), "Deletes not empty: " +
gce.fileDeletions);
@@ -253,6 +250,8 @@ public class GarbageCollectionTest {
gce.addFileReference("4", null, candOne.getPath());
gce.addFileReference("4", null, candTwo.getPath());
gce.addFileReference("6", null, candFour.getPath());
+ gce.addDirReference("4", null, "t0");
+ gce.addDirReference("6", null, "t1");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
gca.collect(gce);
@@ -269,6 +268,8 @@ public class GarbageCollectionTest {
var candTwo =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F001.rf");
var candThree =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/5/t0/F005.rf");
+ gce.addDirReference("4", null, "t0");
+ gce.addDirReference("5", null, "t0");
gce.addFileReference("4", null, candOne.getPath());
gce.addFileReference("4", null, candTwo.getPath());
gce.addFileReference("4", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0//F002.rf");
@@ -312,33 +313,20 @@ public class GarbageCollectionTest {
GcCandidate[] toBeRemoved = new GcCandidate[20];
- var candOne =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/4/t0/F000.rf");
- var candTwo =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F001.rf");
- var candThree =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/5/t0/F005.rf");
+ BiFunction<String,String,String> genPath =
+ (id, f) ->
String.format("hdfs://foo:6000/accumulo/tables/%s/t%s/F00%s.rf", id, id, f);
+
+ var candOne = gce.addCandidate(genPath.apply("4", "0"));
+ var candTwo = gce.addCandidate(genPath.apply("4", "1"));
+ var candThree = gce.addCandidate(genPath.apply("5", "5"));
int counter = 0;
// items to be removed from candidates
- String[] paths = {"hdfs://foo.com:6000/accumulo/tables/5/t0/F001.rf",
-
- "hdfs://foo:6000/accumulo/tables/5/t0/F000.rf",
- "hdfs://foo.com:6000/accumulo/tables/6/t1/F005.rf",
- "hdfs://foo:6000/accumulo/tables/6/t0/F000.rf",
- "hdfs://foo.com:6000/accumulo/tables/6/t0/F001.rf",
- "hdfs://foo.com:6000/accumulo/tables/7/t0/F005.rf",
- "hdfs://foo:6000/accumulo/tables/7/t0/F000.rf",
- "hdfs://foo.com:6000/accumulo/tables/7/t0/F001.rf",
- "hdfs://foo.com:6000/accumulo/tables/8/t0/F005.rf",
- "hdfs://foo:6000/accumulo/tables/8/t0/F000.rf",
- "hdfs://foo.com:6000/accumulo/tables/8/t0/F001.rf",
- "hdfs://foo.com:6000/accumulo/tables/9/t0/F005.rf",
- "hdfs://foo:6000/accumulo/tables/9/t0/F000.rf",
- "hdfs://foo.com:6000/accumulo/tables/9/t0/F001.rf",
- "hdfs://foo.com:6000/accumulo/tables/10/t0/F005.rf",
- "hdfs://foo:6000/accumulo/tables/10/t0/F000.rf",
- "hdfs://foo.com:6000/accumulo/tables/10/t0/F001.rf",
- "hdfs://foo.com:6000/accumulo/tables/11/t0/F005.rf",
- "hdfs://foo:6000/accumulo/tables/11/t0/F000.rf",
- "hdfs://foo.com:6000/accumulo/tables/11/t0/F001.rf"};
+ List<String> paths = new ArrayList<>();
+ for (int i = 10; i < 30; i++) {
+ paths.add(genPath.apply("" + i, "" + i));
+ }
+
for (String path : paths) {
toBeRemoved[counter] = gce.addCandidate(path);
counter++;
@@ -348,6 +336,8 @@ public class GarbageCollectionTest {
gce.addFileReference("4", null, candTwo.getPath());
gce.addFileReference("4", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0//F002.rf");
gce.addFileReference("5", null, candThree.getPath());
+ gce.addDirReference("4", null, "t4");
+ gce.addDirReference("5", null, "t5");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
@@ -356,7 +346,7 @@ public class GarbageCollectionTest {
assertCandidateRemoved(gce, GcCandidateType.INUSE, candOne, candTwo,
candThree);
// Add the candidate back in for the file removal
- candOne = gce.addCandidate("hdfs://foo:6000/accumulo/tables/4/t0/F000.rf");
+ candOne = gce.addCandidate(genPath.apply("4", "0"));
// Remove the reference to a file in the candidates should cause it to be
removed
gce.removeFileReference("4", null, candOne.getPath());
gca.collect(gce);
@@ -364,21 +354,21 @@ public class GarbageCollectionTest {
assertNoCandidatesRemoved(gce);
// Removing a reference to a file that wasn't in the candidates should do
nothing
- gce.removeFileReference("4", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F002.rf");
+ gce.removeFileReference("4", null, genPath.apply("4", "2"));
gca.collect(gce);
assertFileDeleted(gce);
assertNoCandidatesRemoved(gce);
// Remove the reference to a file in the candidates should cause it to be
removed
- candTwo =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F001.rf");
+ candTwo = gce.addCandidate(genPath.apply("4", "1"));
gce.removeFileReference("4", null, candTwo.getPath());
gca.collect(gce);
assertFileDeleted(gce, candTwo);
assertNoCandidatesRemoved(gce);
// Adding more candidates which do no have references should be removed
- var candFour =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F003.rf");
- var candFive =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F004.rf");
+ var candFour = gce.addCandidate(genPath.apply("4", "3"));
+ var candFive = gce.addCandidate(genPath.apply("4", "4"));
gca.collect(gce);
assertFileDeleted(gce, candFour, candFive);
assertNoCandidatesRemoved(gce);
@@ -399,6 +389,8 @@ public class GarbageCollectionTest {
gce.addFileReference("4", null, candOne.getPath());
gce.addFileReference("4", null, candTwo.getPath());
gce.addFileReference("6", null, candFour.getPath());
+ gce.addDirReference("4", null, "t0");
+ gce.addDirReference("6", null, "t1");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
gca.collect(gce);
@@ -411,8 +403,8 @@ public class GarbageCollectionTest {
public void testAbsoluteReferencesWithRelativeCandidates() throws Exception {
TestGCE gce = new TestGCE();
- var candOne = gce.addCandidate("/4/t0/F000.rf");
- var candTwo = gce.addCandidate("/4/t0/F002.rf");
+ var candOne =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F000.rf");
+ var candTwo =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F002.rf");
var candThree =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F001.rf");
gce.addFileReference("4", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F000.rf");
@@ -420,6 +412,9 @@ public class GarbageCollectionTest {
gce.addFileReference("4", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F002.rf");
gce.addFileReference("5", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F000.rf");
gce.addFileReference("6", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F000.rf");
+ gce.addDirReference("4", null, "t0");
+ gce.addDirReference("5", null, "t1");
+ gce.addDirReference("6", null, "t1");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
@@ -444,7 +439,7 @@ public class GarbageCollectionTest {
assertFileDeleted(gce, cand);
gce.removeFileReference("4", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F001.rf");
- candThree = gce.addCandidate("/4/t0/F001.rf");
+ candThree =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F001.rf");
gca.collect(gce);
assertFileDeleted(gce, candThree);
assertNoCandidatesRemoved(gce);
@@ -463,7 +458,7 @@ public class GarbageCollectionTest {
assertNoCandidatesRemoved(gce);
// Finally re-add the relative candidate to remove the last file
- candTwo = gce.addCandidate("/4/t0/F002.rf");
+ candTwo =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F002.rf");
gca.collect(gce);
assertFileDeleted(gce, candTwo);
assertNoCandidatesRemoved(gce);
@@ -473,15 +468,19 @@ public class GarbageCollectionTest {
public void testBlip() throws Exception {
TestGCE gce = new TestGCE();
- gce.addCandidate("/4/B-0");
- gce.addCandidate("/4/B-0/F002.rf");
+
gce.addCandidate(GcCandidate.forBulkDir("hdfs://foo.com:6000/accumulo/tables/4/B-0"));
+ gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/B-0/F002.rf");
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/B-0/F001.rf");
- gce.addCandidate("/5/b-0");
- gce.addCandidate("/5/b-0/F002.rf");
- gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/5/b-0/F001.rf");
+
gce.addCandidate(GcCandidate.forBulkDir("hdfs://foo.com:6000/accumulo/tables/5/b-1"));
+ gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/5/b-1/F002.rf");
+ gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/5/b-1/F001.rf");
+
gce.addCandidate(GcCandidate.forBulkDir("hdfs://foo.com:6000/accumulo/tables/6/b-2"));
+
+ gce.addDirReference("6", null, "t-0");
+ gce.addFileReference("6", null,
"hdfs://foo.com:6000/accumulo/tables/6/b-2/I1234.rf");
gce.blips.add("/4/B-0");
- gce.blips.add("hdfs://foo.com:6000/accumulo/tables/5/b-0");
+ gce.blips.add("/5/b-1");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
@@ -495,82 +494,98 @@ public class GarbageCollectionTest {
// And we should lose all files in that blip and the blip directory itself
-- relative and
// absolute
gca.collect(gce);
- assertFileDeleted(gce, new GcCandidate("/4/B-0", 0L), new
GcCandidate("/4/B-0/F002.rf", 1L),
- new GcCandidate("hdfs://foo.com:6000/accumulo/tables/4/B-0/F001.rf",
2L));
+ assertFileDeleted(gce,
GcCandidate.forBulkDir("hdfs://foo.com:6000/accumulo/tables/4/B-0"),
+
GcCandidate.forTabletFile("hdfs://foo.com:6000/accumulo/tables/4/B-0/F002.rf",
0L),
+
GcCandidate.forTabletFile("hdfs://foo.com:6000/accumulo/tables/4/B-0/F001.rf",
1L));
- gce.blips.remove("hdfs://foo.com:6000/accumulo/tables/5/b-0");
+ gce.blips.remove("/5/b-1");
// Same as above, we should lose relative and absolute for a relative or
absolute blip
gca.collect(gce);
- assertFileDeleted(gce, new GcCandidate("/5/b-0", 3L), new
GcCandidate("/5/b-0/F002.rf", 4L),
- new GcCandidate("hdfs://foo.com:6000/accumulo/tables/5/b-0/F001.rf",
5L));
+ assertFileDeleted(gce,
GcCandidate.forBulkDir("hdfs://foo.com:6000/accumulo/tables/5/b-1"),
+
GcCandidate.forTabletFile("hdfs://foo.com:6000/accumulo/tables/5/b-1/F002.rf",
2L),
+
GcCandidate.forTabletFile("hdfs://foo.com:6000/accumulo/tables/5/b-1/F001.rf",
3L));
gca.collect(gce);
assertFileDeleted(gce);
+
+ // removing this file ref should allow the bulk dir to be deleted
+ gce.removeFileReference("6", null,
"hdfs://foo.com:6000/accumulo/tables/6/b-2/I1234.rf");
+
+ gca.collect(gce);
+ assertFileDeleted(gce,
GcCandidate.forBulkDir("hdfs://foo.com:6000/accumulo/tables/6/b-2"));
}
@Test
public void testDirectories() throws Exception {
TestGCE gce = new TestGCE();
- gce.addCandidate("/4/t-0");
- gce.addCandidate("/4/t-0/F002.rf");
- gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/5/t-0");
- gce.addCandidate("/6/t-0");
- gce.addCandidate("hdfs://foo:6000/accumulo/tables/7/t-0/");
- gce.addCandidate("/8/t-0");
- gce.addCandidate("hdfs://foo:6000/accumulo/tables/9/t-0");
- gce.addCandidate("/a/t-0");
- gce.addCandidate("hdfs://foo:6000/accumulo/tables/b/t-0");
- gce.addCandidate("/c/t-0");
- gce.addCandidate("hdfs://foo:6000/accumulo/tables/d/t-0");
-
- gce.addDirReference("4", null, "t-0");
- gce.addDirReference("5", null, "t-0");
- gce.addDirReference("6", null, "t-0");
- gce.addDirReference("7", null, "t-0");
-
- gce.addFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-0/F00.rf");
- gce.addFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-0/F00.rf");
-
- gce.addFileReference("a", "m",
"hdfs://foo.com:6000/accumulo/tables/a/t-0/F00.rf");
- gce.addFileReference("b", "m",
"hdfs://foo.com:6000/accumulo/tables/b/t-0/F00.rf");
-
- gce.addFileReference("e", "m",
"hdfs://foo:6000/accumulo/tables/c/t-0/F00.rf");
- gce.addFileReference("f", "m",
"hdfs://foo:6000/accumulo/tables/d/t-0/F00.rf");
+ gce.addCandidate("/4/t-4");
+ gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t-4/F002.rf");
+ gce.addCandidate("/5/t-5");
+ gce.addCandidate("/6/t-6");
+ gce.addCandidate("/7/t-7/");
+ gce.addCandidate("/8/t-8");
+ gce.addCandidate("/9/t-9");
+ gce.addCandidate("/a/t-a");
+ gce.addCandidate("/b/t-b");
+ gce.addCandidate("/c/t-c");
+ gce.addCandidate("/d/t-d");
+
+ gce.addDirReference("4", null, "t-4");
+ gce.addDirReference("5", null, "t-5");
+ gce.addDirReference("6", null, "t-6");
+ gce.addDirReference("7", null, "t-7");
+
+ gce.addDirReference("8", null, "t-82");
+ gce.addDirReference("9", null, "t-92");
+ gce.addDirReference("a", null, "t-a2");
+ gce.addDirReference("b", null, "t-b2");
+ gce.addDirReference("e", null, "t-e2");
+ gce.addDirReference("f", null, "t-f2");
+
+ gce.addFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-8/F00.rf");
+ gce.addFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-9/F00.rf");
+
+ gce.addFileReference("a", "m",
"hdfs://foo.com:6000/accumulo/tables/a/t-a/F00.rf");
+ gce.addFileReference("b", "m",
"hdfs://foo.com:6000/accumulo/tables/b/t-b/F00.rf");
+
+ gce.addFileReference("e", "m",
"hdfs://foo:6000/accumulo/tables/c/t-c/F00.rf");
+ gce.addFileReference("f", "m",
"hdfs://foo:6000/accumulo/tables/d/t-d/F00.rf");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
// A directory reference does not preclude a candidate file beneath that
directory from deletion
gca.collect(gce);
- assertFileDeleted(gce, new GcCandidate("/4/t-0/F002.rf", 1L));
+ assertFileDeleted(gce,
+
GcCandidate.forTabletFile("hdfs://foo.com:6000/accumulo/tables/4/t-4/F002.rf",
1L));
// Removing the dir reference for a table will delete all tablet
directories
gce.removeDirReference("5", null);
gca.collect(gce);
- assertFileDeleted(gce, new
GcCandidate("hdfs://foo.com:6000/accumulo/tables/5/t-0", 2L));
+ assertFileDeleted(gce, GcCandidate.forTabletDir("/5/t-5", 2L));
gce.removeDirReference("4", null);
gca.collect(gce);
- assertFileDeleted(gce, new GcCandidate("/4/t-0", 0L));
+ assertFileDeleted(gce, GcCandidate.forTabletDir("/4/t-4", 0L));
gce.removeDirReference("6", null);
gce.removeDirReference("7", null);
gca.collect(gce);
- assertFileDeleted(gce, new GcCandidate("/6/t-0", 3L),
- new GcCandidate("hdfs://foo:6000/accumulo/tables/7/t-0/", 4L));
-
- gce.removeFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-0/F00.rf");
- gce.removeFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-0/F00.rf");
- gce.removeFileReference("a", "m",
"hdfs://foo.com:6000/accumulo/tables/a/t-0/F00.rf");
- gce.removeFileReference("b", "m",
"hdfs://foo.com:6000/accumulo/tables/b/t-0/F00.rf");
- gce.removeFileReference("e", "m",
"hdfs://foo:6000/accumulo/tables/c/t-0/F00.rf");
- gce.removeFileReference("f", "m",
"hdfs://foo:6000/accumulo/tables/d/t-0/F00.rf");
+ assertFileDeleted(gce, GcCandidate.forTabletDir("/6/t-6", 3L),
+ GcCandidate.forTabletDir("/7/t-7/", 4L));
+
+ gce.removeFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-8/F00.rf");
+ gce.removeFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-9/F00.rf");
+ gce.removeFileReference("a", "m",
"hdfs://foo.com:6000/accumulo/tables/a/t-a/F00.rf");
+ gce.removeFileReference("b", "m",
"hdfs://foo.com:6000/accumulo/tables/b/t-b/F00.rf");
+ gce.removeFileReference("e", "m",
"hdfs://foo:6000/accumulo/tables/c/t-c/F00.rf");
+ gce.removeFileReference("f", "m",
"hdfs://foo:6000/accumulo/tables/d/t-d/F00.rf");
gca.collect(gce);
- assertFileDeleted(gce, new GcCandidate("/8/t-0", 5L),
- new GcCandidate("hdfs://foo:6000/accumulo/tables/9/t-0", 6L), new
GcCandidate("/a/t-0", 7L),
- new GcCandidate("hdfs://foo:6000/accumulo/tables/b/t-0", 8L), new
GcCandidate("/c/t-0", 9L),
- new GcCandidate("hdfs://foo:6000/accumulo/tables/d/t-0", 10L));
+ assertFileDeleted(gce, GcCandidate.forTabletDir("/8/t-8", 5L),
+ GcCandidate.forTabletDir("/9/t-9", 6L),
GcCandidate.forTabletDir("/a/t-a", 7L),
+ GcCandidate.forTabletDir("/b/t-b", 8L),
GcCandidate.forTabletDir("/c/t-c", 9L),
+ GcCandidate.forTabletDir("/d/t-d", 10L));
gca.collect(gce);
assertFileDeleted(gce);
@@ -582,30 +597,36 @@ public class GarbageCollectionTest {
Map<Integer,GcCandidate> candidates = new HashMap<>();
candidates.put(1, gce.addCandidate("/4/t-0"));
- candidates.put(2, gce.addCandidate("/4/t-0/F002.rf"));
- candidates.put(3,
gce.addCandidate("hdfs://foo.com:6000/user/foo/tables/5/t-0"));
- candidates.put(4, gce.addCandidate("/6/t-0"));
- candidates.put(5,
gce.addCandidate("hdfs://foo:6000/user/foo/tables/7/t-0/"));
- candidates.put(6, gce.addCandidate("/8/t-0"));
- candidates.put(7,
gce.addCandidate("hdfs://foo:6000/user/foo/tables/9/t-0"));
- candidates.put(8, gce.addCandidate("/a/t-0"));
- candidates.put(9,
gce.addCandidate("hdfs://foo:6000/user/foo/tables/b/t-0"));
- candidates.put(10, gce.addCandidate("/c/t-0"));
- candidates.put(11,
gce.addCandidate("hdfs://foo:6000/user/foo/tables/d/t-0"));
+ candidates.put(2,
gce.addCandidate("hdfs://foo:6000/user/foo/tables/4/t-0/F002.rf"));
+ candidates.put(3, gce.addCandidate("/5/t-5"));
+ candidates.put(4, gce.addCandidate("/6/t-6"));
+ candidates.put(5, gce.addCandidate("/7/t-7/"));
+ candidates.put(6, gce.addCandidate("/8/t-8"));
+ candidates.put(7, gce.addCandidate("/9/t-9"));
+ candidates.put(8, gce.addCandidate("/a/t-a"));
+ candidates.put(9, gce.addCandidate("/b/t-b"));
+ candidates.put(10, gce.addCandidate("/c/t-c"));
+ candidates.put(11, gce.addCandidate("/d/t-d"));
gce.addDirReference("4", null, "t-0");
- gce.addDirReference("5", null, "t-0");
- gce.addDirReference("6", null, "t-0");
- gce.addDirReference("7", null, "t-0");
+ gce.addDirReference("5", null, "t-5");
+ gce.addDirReference("6", null, "t-6");
+ gce.addDirReference("7", null, "t-7");
+ gce.addDirReference("8", null, "t-82");
+ gce.addDirReference("9", null, "t-92");
+ gce.addDirReference("a", null, "t-a2");
+ gce.addDirReference("b", null, "t-b2");
+ gce.addDirReference("e", null, "t-e2");
+ gce.addDirReference("f", null, "t-f2");
- gce.addFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-0/F00.rf");
- gce.addFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-0/F00.rf");
+ gce.addFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-8/F00.rf");
+ gce.addFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-9/F00.rf");
- gce.addFileReference("a", "m",
"hdfs://foo.com:6000/user/foo/tables/a/t-0/F00.rf");
- gce.addFileReference("b", "m",
"hdfs://foo.com:6000/user/foo/tables/b/t-0/F00.rf");
+ gce.addFileReference("a", "m",
"hdfs://foo.com:6000/user/foo/tables/a/t-a/F00.rf");
+ gce.addFileReference("b", "m",
"hdfs://foo.com:6000/user/foo/tables/b/t-b/F00.rf");
- gce.addFileReference("e", "m",
"hdfs://foo.com:6000/user/foo/tables/c/t-0/F00.rf");
- gce.addFileReference("f", "m",
"hdfs://foo.com:6000/user/foo/tables/d/t-0/F00.rf");
+ gce.addFileReference("e", "m",
"hdfs://foo.com:6000/user/foo/tables/c/t-c/F00.rf");
+ gce.addFileReference("f", "m",
"hdfs://foo.com:6000/user/foo/tables/d/t-d/F00.rf");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
@@ -616,7 +637,7 @@ public class GarbageCollectionTest {
// Removing the dir reference for a table will delete all tablet
directories
gce.removeDirReference("5", null);
// but we need to add a file ref
- gce.addFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-0/F00.rf");
+ gce.addFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-8/F00.rf");
gca.collect(gce);
assertFileDeleted(gce, candidates.get(3));
@@ -629,12 +650,12 @@ public class GarbageCollectionTest {
gca.collect(gce);
assertFileDeleted(gce, candidates.get(4), candidates.get(5));
- gce.removeFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-0/F00.rf");
- gce.removeFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-0/F00.rf");
- gce.removeFileReference("a", "m",
"hdfs://foo.com:6000/user/foo/tables/a/t-0/F00.rf");
- gce.removeFileReference("b", "m",
"hdfs://foo.com:6000/user/foo/tables/b/t-0/F00.rf");
- gce.removeFileReference("e", "m",
"hdfs://foo.com:6000/user/foo/tables/c/t-0/F00.rf");
- gce.removeFileReference("f", "m",
"hdfs://foo.com:6000/user/foo/tables/d/t-0/F00.rf");
+ gce.removeFileReference("8", "m",
"hdfs://foo:6000/accumulo/tables/8/t-8/F00.rf");
+ gce.removeFileReference("9", "m",
"hdfs://foo:6000/accumulo/tables/9/t-9/F00.rf");
+ gce.removeFileReference("a", "m",
"hdfs://foo.com:6000/user/foo/tables/a/t-a/F00.rf");
+ gce.removeFileReference("b", "m",
"hdfs://foo.com:6000/user/foo/tables/b/t-b/F00.rf");
+ gce.removeFileReference("e", "m",
"hdfs://foo.com:6000/user/foo/tables/c/t-c/F00.rf");
+ gce.removeFileReference("f", "m",
"hdfs://foo.com:6000/user/foo/tables/d/t-d/F00.rf");
gca.collect(gce);
assertFileDeleted(gce, candidates.get(6), candidates.get(7),
candidates.get(8),
candidates.get(9), candidates.get(10), candidates.get(11));
@@ -646,9 +667,10 @@ public class GarbageCollectionTest {
private void badRefTest(String ref) {
TestGCE gce = new TestGCE();
- gce.addCandidate("/4/t-0/F002.rf");
+ gce.addCandidate("hdfs://foo:6000/accumulo/tables/8/4/t-0/F002.rf");
gce.addFileReference("4", "m", ref);
+ gce.addDirReference("4", "m", "t-0");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
try {
@@ -662,39 +684,33 @@ public class GarbageCollectionTest {
@Test
public void testBadFileRef1() {
- assertThrows(IllegalArgumentException.class, () -> badRefTest("/F00.rf"));
+ var e = assertThrows(IllegalArgumentException.class, () ->
badRefTest("/F00.rf"));
+ assertTrue(e.getMessage().contains("scheme"));
}
@Test
public void testRelativeFileRefIsInvalid() {
- assertThrows(IllegalArgumentException.class, () ->
badRefTest("/t-0/F00.rf"));
+ var e = assertThrows(IllegalArgumentException.class, () ->
badRefTest("/t-0/F00.rf"));
+ assertTrue(e.getMessage().contains("scheme"));
}
@Test
public void testBadFileRef2() {
- assertThrows(IllegalArgumentException.class, () ->
badRefTest("../F00.rf"));
- }
-
- @Test
- public void testBadFileRef3() {
- assertThrows(IllegalArgumentException.class,
- () -> badRefTest("hdfs://foo.com:6000/accumulo/F00.rf"));
- }
-
- @Test
- public void testBadFileRef4() {
- assertThrows(IllegalArgumentException.class,
- () -> badRefTest("hdfs://foo.com:6000/accumulo/tbls/5/F00.rf"));
+ var e = assertThrows(IllegalArgumentException.class, () ->
badRefTest("../F00.rf"));
+ assertTrue(e.getMessage().contains("scheme"));
}
@Test
public void testBadFileRef5() {
- assertThrows(RuntimeException.class, () -> badRefTest("F00.rf"));
+ var e = assertThrows(RuntimeException.class, () -> badRefTest("F00.rf"));
+ assertTrue(e.getMessage().contains("scheme"));
}
@Test
public void testBadFileRef6() {
- assertThrows(IllegalArgumentException.class, () ->
badRefTest("/accumulo/tbls/5/F00.rf"));
+ var e =
+ assertThrows(IllegalArgumentException.class, () ->
badRefTest("/accumulo/tbls/5/F00.rf"));
+ assertTrue(e.getMessage().contains("scheme"));
}
@Test
@@ -708,12 +724,8 @@ public class GarbageCollectionTest {
gce.addCandidate("//");
gce.addCandidate("///");
gce.addCandidate("////");
- gce.addCandidate("/1/2/3/4");
gce.addCandidate("/a");
- gce.addCandidate("hdfs://foo.com:6000/accumulo/tbls/5/F00.rf");
gce.addCandidate("hdfs://foo.com:6000/");
- gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/");
- gce.addCandidate("hdfs://foo.com:6000/user/foo/tables/a/t-0/t-1/F00.rf");
gca.collect(gce);
System.out.println(gce.fileDeletions);
@@ -732,22 +744,24 @@ public class GarbageCollectionTest {
assertFileDeleted(gce);
gce.candidates.clear();
- var tempCandidate = gce.addCandidate("/1636/default_tablet/someFile");
+ var tempCandidate =
+
gce.addCandidate("hdfs://foo:6000/accumulo/tables/1636/default_tablet/someFile.rf");
gca.collect(gce);
assertFileDeleted(gce, tempCandidate);
gce.addFileReference("1636", null,
- "hdfs://foo:6000/accumulo/tables/1636/default_tablet/someFile");
- gce.addCandidate("/1636/default_tablet/someFile");
+ "hdfs://foo:6000/accumulo/tables/1636/default_tablet/someFile.rf");
+
gce.addCandidate("hdfs://foo:6000/accumulo/tables/1636/default_tablet/someFile.rf");
gca.collect(gce);
assertFileDeleted(gce);
// have an indirect file reference
gce = new TestGCE();
- gce.addFileReference("1636", null,
"hdfs://foo:6000/accumulo/tables/9/default_tablet/someFile");
+ gce.addFileReference("1636", null,
+ "hdfs://foo:6000/accumulo/tables/9/default_tablet/someFile.rf");
gce.addDirReference("1636", null, "default_tablet");
- gce.addCandidate("/9/default_tablet/someFile");
+
gce.addCandidate("hdfs://foo:6000/accumulo/tables/9/default_tablet/someFile.rf");
gca.collect(gce);
assertFileDeleted(gce);
@@ -759,7 +773,7 @@ public class GarbageCollectionTest {
gce.candidates.clear();
gce.addCandidate("/9/default_tablet");
- gce.addCandidate("/9/default_tablet/someFile");
+
gce.addCandidate("hdfs://foo:6000/accumulo/tables/9/default_tablet/someFile.rf");
long blipCount = gca.collect(gce);
assertFileDeleted(gce);
assertEquals(0, blipCount);
@@ -767,7 +781,7 @@ public class GarbageCollectionTest {
gce = new TestGCE();
gce.blips.add("/1636/b-0001");
- gce.addCandidate("/1636/b-0001/I0000");
+ gce.addCandidate("hdfs://foo:6000/accumulo/tables/1636/b-0001/I0000.rf");
blipCount = gca.collect(gce);
assertFileDeleted(gce);
assertEquals(1, blipCount);
@@ -779,9 +793,9 @@ public class GarbageCollectionTest {
gce.blips.add("/1029/b-0003");
gce.blips.add("/1000/b-1001");
gce.blips.add("/1000/b-1002");
- gce.addCandidate("/1029/b-0002/I0006");
- gce.addCandidate("/1000/b-1002/I0007");
- var candidate = gce.addCandidate("/1000/t-0003/I0008");
+ gce.addCandidate("hdfs://foo:6000/accumulo/tables/1029/b-0002/I0006.rf");
+ gce.addCandidate("hdfs://foo:6000/accumulo/tables/1000/b-1002/I0007.rf");
+ var candidate =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/1000/t-0003/I0008.rf");
blipCount = gca.collect(gce);
assertFileDeleted(gce, candidate);
assertEquals(5, blipCount);
@@ -794,15 +808,27 @@ public class GarbageCollectionTest {
TestGCE gce = new TestGCE();
gce.tableIds.add(TableId.of("4"));
+ gce.tableIds.add(TableId.of("8"));
gce.addCandidate("/4/t-0");
- gce.addCandidate("/4/t-0/F002.rf");
- gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/5/t-0");
+ gce.addCandidate(GcCandidate.forTableDir(TableId.of("4")));
+ gce.addCandidate(GcCandidate.forTableDir(TableId.of("5")));
+ gce.addCandidate(GcCandidate.forTableDir(TableId.of("6")));
+ gce.addCandidate(GcCandidate.forTableDir(TableId.of("8")));
+ gce.addCandidate(GcCandidate.forTableDir(TableId.of("9")));
+ gce.addCandidate("hdfs://foo:6000/accumulo/tables/4/t-0/F002.rf");
+ gce.addCandidate("/5/t-0");
gce.addCandidate("/6/t-0");
- gce.addCandidate("hdfs://foo:6000/accumulo/tables/7/t-0/");
+ gce.addCandidate("/7/t-0/");
+ // Table 4 only has a dir ref, this should keep the table dir from being
deleted
gce.addDirReference("4", null, "t-0");
- gce.addDirReference("7", null, "t-0");
+ gce.addDirReference("7", null, "t-1");
+ // Table 8 has a dir and a file ref.
+ gce.addDirReference("8", null, "t-2");
+ gce.addFileReference("8", null,
"hdfs://foo:6000/accumulo/tables/8/t-2/F008.rf");
+ // Table 9 only has a file ref, should keep table dir from being deleted.
+ gce.addFileReference("7", null,
"hdfs://foo:6000/accumulo/tables/9/t-3/F009.rf");
gca.collect(gce);
@@ -810,8 +836,10 @@ public class GarbageCollectionTest {
tids.add(TableId.of("5"));
tids.add(TableId.of("6"));
- assertEquals(tids.size(), gce.tablesDirsToDelete.size());
- assertTrue(tids.containsAll(gce.tablesDirsToDelete));
+ var tableDirsDeleted = gce.fileDeletions.stream()
+ .filter(gcc -> gcc.getType() == GcCandidate.Type.TABLE_DIR)
+ .map(gcc -> gcc.getPath().replace("/",
"")).map(TableId::of).collect(Collectors.toSet());
+ assertEquals(tids, tableDirsDeleted);
assertNoCandidatesRemoved(gce);
}
@@ -824,7 +852,8 @@ public class GarbageCollectionTest {
gce.addCandidate("hdfs://foo.com:6000/user/foo/tables/a/t-0/F00.rf");
gce.addFileReference("a", null,
"hdfs://foo.com:6000/user/foo/tables/a/t-0/F00.rf");
- gce.addFileReference("c", null,
"hdfs://foo.com:6000/user/foo/tables/c/t-0/F00.rf");
+ gce.addDirReference("a", null, "t-0");
+ gce.addDirReference("c", null, "t-1");
// add 2 more table references that will not be seen by the scan
gce.tableIds.addAll(makeUnmodifiableSet("b", "d"));
@@ -838,7 +867,7 @@ public class GarbageCollectionTest {
public void testDeletingInUseReferenceCandidates() throws Exception {
TestGCE gce = new TestGCE();
- var candidate = gce.addCandidate("/4/t0/F000.rf");
+ var candidate =
gce.addCandidate("hdfs://foo.com:6000/accumulo/tables/4/t0/F000.rf");
gce.addFileReference("4", null,
"hdfs://foo:6000/accumulo/tables/4/t0/F000.rf");
gce.addFileReference("4", null,
"hdfs://foo:6000/accumulo/tables/4/t0/F001.rf");
@@ -847,6 +876,10 @@ public class GarbageCollectionTest {
gce.addFileReference("5", null,
"hdfs://foo:6000/accumulo/tables/4/t0/F000.rf");
gce.addFileReference("9", null,
"hdfs://foo:6000/accumulo/tables/9/t0/F003.rf");
gce.addFileReference("6", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F000.rf");
+ gce.addDirReference("4", null, "t0");
+ gce.addDirReference("5", null, "t0");
+ gce.addDirReference("6", null, "t0");
+ gce.addDirReference("9", null, "t0");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
// All candidates currently have references
@@ -854,8 +887,8 @@ public class GarbageCollectionTest {
assertFileDeleted(gce);
assertCandidateRemoved(gce, GcCandidateType.INUSE, candidate);
- var cand1 = gce.addCandidate("/9/t0/F003.rf");
- var cand2 = gce.addCandidate("../144/t0/F003.rf");
+ var cand1 =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/9/t2/F003.rf");
+ var cand2 =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/144/t3/F003.rf");
gce.removeFileReference("9", null,
"hdfs://foo:6000/accumulo/tables/9/t0/F003.rf");
gce.removeFileReference("4", null,
"hdfs://foo:6000/accumulo/tables/4/t0/F003.rf");
@@ -871,18 +904,19 @@ public class GarbageCollectionTest {
GcCandidate[] toBeRemoved = new GcCandidate[4];
- toBeRemoved[0] = gce.addCandidate("/+r/t0/F000.rf");
- toBeRemoved[1] = gce.addCandidate("/+r/t0/F001.rf");
- toBeRemoved[2] = gce.addCandidate("/+r/t0/F002.rf");
- toBeRemoved[3] = gce.addCandidate("/+r/t0/F003.rf");
+ toBeRemoved[0] =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/+r/t0/F000.rf");
+ toBeRemoved[1] =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/+r/t0/F001.rf");
+ toBeRemoved[2] =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/+r/t0/F002.rf");
+ toBeRemoved[3] =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/+r/t0/F003.rf");
gce.addFileReference("+r", null,
"hdfs://foo:6000/accumulo/tables/+r/t0/F000.rf");
gce.addFileReference("+r", null,
"hdfs://foo:6000/accumulo/tables/+r/t0/F001.rf");
gce.addFileReference("+r", null,
"hdfs://foo:6000/accumulo/tables/+r/t0/F002.rf");
gce.addFileReference("+r", null,
"hdfs://foo:6000/accumulo/tables/+r/t0/F003.rf");
- gce.addFileReference("+r", null,
"hdfs://foo:6000/accumulo/tables/4/t0/F000.rf");
- gce.addFileReference("+r", null,
"hdfs://foo:6000/accumulo/tables/+r/t0/F003.rf");
- gce.addFileReference("+r", null,
"hdfs://foo.com:6000/accumulo/tables/4/t0/F000.rf");
+ gce.addFileReference("+r", null,
"hdfs://foo:6000/accumulo/tables/4/t1/F000.rf");
+ gce.addFileReference("+r", null,
"hdfs://foo.com:6000/accumulo/tables/4/t1/F000.rf");
+
+ gce.addDirReference("+r", null, "t0");
GarbageCollectionAlgorithm gca = new GarbageCollectionAlgorithm();
gca.collect(gce);
@@ -912,6 +946,7 @@ public class GarbageCollectionTest {
// Ensure that dir candidates still work
var candOne = gce.addCandidate("6/t-0");
var candTwo = gce.addCandidate("7/T-1");
+ gce.addDirReference("6", "m", "t-1");
gce.addDirReference("6", null, "t-0");
gca.collect(gce);
@@ -929,12 +964,12 @@ public class GarbageCollectionTest {
assertEquals(0, gce.candidates.size());
// Add deletion candidate for a directory.
- var candidate = new GcCandidate("6/t-0/", 10L);
+ var candidate = GcCandidate.forTabletDir("6/t-0/", 10L);
gce.candidates.add(candidate);
// Then create an InUse candidate for a file in that directory.
gce.addFileReference("6", null,
"hdfs://foo:6000/accumulo/tables/6/t-0/F003.rf");
- var removedCandidate = gce.addCandidate("6/t-0/F003.rf");
+ var removedCandidate =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/6/t-0/F003.rf");
gca.collect(gce);
assertCandidateRemoved(gce, GcCandidateType.INUSE, removedCandidate);
@@ -949,9 +984,10 @@ public class GarbageCollectionTest {
TestGCE gce = new TestGCE();
// InUse Scan Refs should not be removed.
- var scanCandidate = gce.addCandidate("/4/t0/F010.rf");
- var candOne = gce.addCandidate("/4/t0/F000.rf");
- var candTwo = gce.addCandidate("/6/t0/F123.rf");
+ var scanCandidate =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/4/t0/F010.rf");
+ var candOne =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/4/t0/F000.rf");
+ var candTwo =
gce.addCandidate("hdfs://foo:6000/accumulo/tables/6/t0/F123.rf");
+ gce.addDirReference("4", null, "t0");
gce.addScanReference("4", null,
"hdfs://foo:6000/accumulo/tables/4/t0/F010.rf");
gce.addFileReference("4", null,
"hdfs://foo:6000/accumulo/tables/4/t0/F000.rf");
@@ -1114,62 +1150,4 @@ public class GarbageCollectionTest {
assertTrue(msg.startsWith("Saw table IDs in ZK that were not in metadata
table: [3]"));
}
-
- /**
- * Tests makeRelative with expectedLen 0 (any), 2 (dir) and 3 (file).
- */
- @Test
- public void testMakeRelative() {
- var gca = new GarbageCollectionAlgorithm();
- String fullFile = "hdfs://foo:6000/accumulo/tables/4/t0/F000.rf";
- String fullDir = "hdfs://foo:6000/accumulo/tables/4/t0";
-
- // full paths
- assertRelative(gca, fullFile, 0, "4/t0/F000.rf");
- assertRelative(gca, fullFile, 3, "4/t0/F000.rf");
- assertRelative(gca, "hdfs://foo.com:6000/accumulo/tables/4//t0//F001.rf",
0, "4/t0/F001.rf");
- assertRelative(gca, fullDir, 0, "4/t0");
- assertRelative(gca, fullDir, 2, "4/t0");
- assertRelative(gca, fullDir + "/", 0, "4/t0");
- assertRelative(gca, fullDir + "//", 2, "4/t0");
-
- // relative paths
- assertRelative(gca, "4/t0/F000.rf", 0, "4/t0/F000.rf");
- assertRelative(gca, "4/t0/F000.rf", 3, "4/t0/F000.rf");
- assertRelative(gca, "../4/t0/F000.rf", 0, "4/t0/F000.rf");
- assertRelative(gca, "/4/t0/F000.rf", 0, "4/t0/F000.rf");
- assertRelative(gca, "4//t0///F000.rf/", 0, "4/t0/F000.rf");
- assertRelative(gca, "4/t0", 0, "4/t0");
- assertRelative(gca, "4/t0", 2, "4/t0");
- assertRelative(gca, "4/b-0", 2, "4/b-0");
- assertRelative(gca, "4/B-0", 2, "4/B-0");
- assertRelative(gca, "//4//t0//", 0, "4/t0");
- assertRelative(gca, "../4/t0", 2, "4/t0");
-
- // wrong expectedLen
- assertInvalid(gca, fullFile, 2);
- assertInvalid(gca, fullDir, 3);
- assertInvalid(gca, "4/t0/F000.rf", 2);
- assertInvalid(gca, "4/t0", 3);
-
- // malformed paths
- assertInvalid(gca, "", 0);
- assertInvalid(gca, "/", 0);
- assertInvalid(gca, "4", 0);
- assertInvalid(gca, "a/b/c/d", 0);
- assertInvalid(gca, "../../4/t0/F000.rf", 0);
- assertInvalid(gca, "hdfs://foo:6000/accumulo/nottables/4/t0/F000.rf", 0);
- assertInvalid(gca, "hdfs://foo:6000/tables", 0);
- assertInvalid(gca, "4:x/t0", 0);
- assertInvalid(gca, "a:/t0/F000.rf", 0);
- }
-
- private static void assertRelative(GarbageCollectionAlgorithm gca, String
path, int len,
- String expected) {
- assertEquals(expected, gca.makeRelative(path, len), path);
- }
-
- private static void assertInvalid(GarbageCollectionAlgorithm gca, String
path, int len) {
- assertThrows(IllegalArgumentException.class, () -> gca.makeRelative(path,
len), path);
- }
}
diff --git
a/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
b/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
index 9cc2e7f8b2..9a10c33a3c 100644
---
a/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
+++
b/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
@@ -18,10 +18,8 @@
*/
package org.apache.accumulo.gc;
-import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.getCurrentArguments;
import static org.easymock.EasyMock.partialMockBuilder;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
@@ -31,26 +29,16 @@ import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileNotFoundException;
-import java.time.Duration;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.TreeMap;
import org.apache.accumulo.core.clientImpl.Credentials;
import org.apache.accumulo.core.conf.ConfigurationCopy;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.conf.SiteConfiguration;
import org.apache.accumulo.core.data.InstanceId;
-import org.apache.accumulo.core.data.TableId;
-import org.apache.accumulo.core.gc.GcCandidate;
-import org.apache.accumulo.core.volume.Volume;
import org.apache.accumulo.server.ServerContext;
import org.apache.accumulo.server.fs.VolumeManager;
-import org.apache.accumulo.server.gc.AllVolumesDirectory;
import org.apache.accumulo.server.security.SystemCredentials;
import org.apache.hadoop.fs.Path;
import org.junit.jupiter.api.BeforeEach;
@@ -139,69 +127,4 @@ public class SimpleGarbageCollectorTest {
assertFalse(SimpleGarbageCollector.isDir(""));
assertFalse(SimpleGarbageCollector.isDir(null));
}
-
- @Test
- public void testMinimizeDeletes() {
- Volume vol1 = createMock(Volume.class);
- expect(vol1.containsPath(anyObject()))
- .andAnswer(() ->
getCurrentArguments()[0].toString().startsWith("hdfs://nn1/accumulo"))
- .anyTimes();
-
- Volume vol2 = createMock(Volume.class);
- expect(vol2.containsPath(anyObject()))
- .andAnswer(() ->
getCurrentArguments()[0].toString().startsWith("hdfs://nn2/accumulo"))
- .anyTimes();
-
- Collection<Volume> vols = Arrays.asList(vol1, vol2);
-
- VolumeManager volMgr2 = createMock(VolumeManager.class);
- expect(volMgr2.getVolumes()).andReturn(vols).anyTimes();
-
- replay(vol1, vol2, volMgr2);
-
- TreeMap<String,GcCandidate> confirmed = new TreeMap<>();
- confirmed.put("5a/t-0001", new
GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0001", 0L));
- confirmed.put("5a/t-0001/F0001.rf",
- new GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0001/F0001.rf", 1L));
- confirmed.put("5a/t-0001/F0002.rf",
- new GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0001/F0002.rf", 2L));
- confirmed.put("5a/t-0002/F0001.rf",
- new GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0002/F0001.rf", 3L));
- var allVolumesDirectory = new AllVolumesDirectory(TableId.of("5b"),
"t-0003");
- confirmed.put("5b/t-0003", new
GcCandidate(allVolumesDirectory.getMetadataPath(), 4L));
- confirmed.put("5b/t-0003/F0001.rf",
- new GcCandidate("hdfs://nn1/accumulo/tables/5b/t-0003/F0001.rf", 5L));
- confirmed.put("5b/t-0003/F0002.rf",
- new GcCandidate("hdfs://nn2/accumulo/tables/5b/t-0003/F0002.rf", 6L));
- confirmed.put("5b/t-0003/F0003.rf",
- new GcCandidate("hdfs://nn3/accumulo/tables/5b/t-0003/F0003.rf", 7L));
- allVolumesDirectory = new AllVolumesDirectory(TableId.of("5b"), "t-0004");
- confirmed.put("5b/t-0004", new
GcCandidate(allVolumesDirectory.getMetadataPath(), 8L));
- confirmed.put("5b/t-0004/F0001.rf",
- new GcCandidate("hdfs://nn1/accumulo/tables/5b/t-0004/F0001.rf", 9L));
-
- List<GcCandidate> processedDeletes = new ArrayList<>();
-
- GCRun.minimizeDeletes(confirmed, processedDeletes, volMgr2, log,
Duration.ofMinutes(1));
-
- TreeMap<String,GcCandidate> expected = new TreeMap<>();
- expected.put("5a/t-0001", new
GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0001", 0L));
- expected.put("5a/t-0002/F0001.rf",
- new GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0002/F0001.rf", 3L));
- allVolumesDirectory = new AllVolumesDirectory(TableId.of("5b"), "t-0003");
- expected.put("5b/t-0003", new
GcCandidate(allVolumesDirectory.getMetadataPath(), 4L));
- expected.put("5b/t-0003/F0003.rf",
- new GcCandidate("hdfs://nn3/accumulo/tables/5b/t-0003/F0003.rf", 7L));
- allVolumesDirectory = new AllVolumesDirectory(TableId.of("5b"), "t-0004");
- expected.put("5b/t-0004", new
GcCandidate(allVolumesDirectory.getMetadataPath(), 8L));
-
- assertEquals(expected, confirmed);
- assertEquals(
- Arrays.asList(new
GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0001/F0001.rf", 1L),
- new GcCandidate("hdfs://nn1/accumulo/tables/5a/t-0001/F0002.rf",
2L),
- new GcCandidate("hdfs://nn1/accumulo/tables/5b/t-0003/F0001.rf",
5L),
- new GcCandidate("hdfs://nn2/accumulo/tables/5b/t-0003/F0002.rf",
6L),
- new GcCandidate("hdfs://nn1/accumulo/tables/5b/t-0004/F0001.rf",
9L)),
- processedDeletes);
- }
}
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/bulkVer2/CleanUpBulkImport.java
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/bulkVer2/CleanUpBulkImport.java
index ea3fb97eff..56bddcba71 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/bulkVer2/CleanUpBulkImport.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/bulkVer2/CleanUpBulkImport.java
@@ -31,7 +31,7 @@ import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.fate.Repo;
import org.apache.accumulo.core.fate.zookeeper.LockRange;
-import org.apache.accumulo.core.gc.ReferenceFile;
+import org.apache.accumulo.core.gc.GcCandidate;
import org.apache.accumulo.core.logging.BulkLogger;
import org.apache.accumulo.core.metadata.schema.Ample;
import org.apache.accumulo.core.metadata.schema.Ample.ConditionalResult.Status;
@@ -64,7 +64,7 @@ public class CleanUpBulkImport extends
AbstractBulkFateOperation {
ample.removeBulkLoadInProgressFlag(
"/" + bulkDir.getParent().getName() + "/" + bulkDir.getName());
ample.putGcFileAndDirCandidates(bulkInfo.tableId,
- Collections.singleton(ReferenceFile.forFile(bulkInfo.tableId,
bulkDir)));
+ Collections.singleton(GcCandidate.forBulkDir(bulkInfo.bulkDir)));
Text firstSplit = bulkInfo.firstSplit == null ? null : new
Text(bulkInfo.firstSplit);
Text lastSplit = bulkInfo.lastSplit == null ? null : new
Text(bulkInfo.lastSplit);
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/merge/MergeTablets.java
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/merge/MergeTablets.java
index de3484c4fa..4b3caf7729 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/merge/MergeTablets.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/merge/MergeTablets.java
@@ -35,7 +35,7 @@ import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.fate.Repo;
-import org.apache.accumulo.core.gc.ReferenceFile;
+import org.apache.accumulo.core.gc.GcCandidate;
import org.apache.accumulo.core.metadata.StoredTabletFile;
import org.apache.accumulo.core.metadata.schema.Ample;
import org.apache.accumulo.core.metadata.schema.DataFileValue;
@@ -45,7 +45,6 @@ import
org.apache.accumulo.core.metadata.schema.TabletOperationId;
import org.apache.accumulo.core.metadata.schema.TabletOperationType;
import org.apache.accumulo.manager.tableOps.AbstractFateOperation;
import org.apache.accumulo.manager.tableOps.FateEnv;
-import org.apache.accumulo.server.gc.AllVolumesDirectory;
import org.apache.accumulo.server.tablets.TabletTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,7 +71,7 @@ public class MergeTablets extends AbstractFateOperation {
var opid = TabletOperationId.from(TabletOperationType.MERGING, fateId);
Set<TabletAvailability> tabletAvailabilities = new HashSet<>();
MetadataTime maxLogicalTime = null;
- List<ReferenceFile> dirs = new ArrayList<>();
+ List<GcCandidate> dirs = new ArrayList<>();
Map<StoredTabletFile,DataFileValue> newFiles = new HashMap<>();
TabletMetadata firstTabletMeta = null;
TabletMetadata lastTabletMeta = null;
@@ -136,7 +135,7 @@ public class MergeTablets extends AbstractFateOperation {
});
// queue all tablets dirs except the last tablets to be added as GC
candidates
- dirs.add(new AllVolumesDirectory(range.tableId(),
tabletMeta.getDirName()));
+ dirs.add(GcCandidate.forTabletDir(range.tableId(),
tabletMeta.getDirName()));
if (dirs.size() > 1000) {
Preconditions.checkState(tabletsSeen > 1);
env.getContext().getAmple().putGcFileAndDirCandidates(range.tableId(), dirs);
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader10to11.java
b/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader10to11.java
index 4c469676c8..f3dff9d4bc 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader10to11.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader10to11.java
@@ -44,6 +44,7 @@ import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
import org.apache.accumulo.core.fate.zookeeper.ZooUtil;
+import org.apache.accumulo.core.gc.GcCandidate;
import org.apache.accumulo.core.manager.state.tables.TableState;
import org.apache.accumulo.core.metadata.SystemTables;
import org.apache.accumulo.core.metadata.schema.MetadataSchema;
@@ -156,7 +157,8 @@ public class Upgrader10to11 implements Upgrader {
private Mutation createDelMutation(String path) {
Mutation delFlag = new Mutation(new
Text(MetadataSchema.DeletesSection.encodeRow(path)));
- delFlag.put(EMPTY_TEXT, EMPTY_TEXT,
MetadataSchema.DeletesSection.SkewedKeyValue.NAME);
+ delFlag.put(EMPTY_TEXT, EMPTY_TEXT,
+
MetadataSchema.DeletesSection.encodeType(GcCandidate.Type.TABLET_FILE));
return delFlag;
}
diff --git
a/server/manager/src/test/java/org/apache/accumulo/manager/tableOps/merge/MergeTabletsTest.java
b/server/manager/src/test/java/org/apache/accumulo/manager/tableOps/merge/MergeTabletsTest.java
index 88f1a0d6bb..e11256d54b 100644
---
a/server/manager/src/test/java/org/apache/accumulo/manager/tableOps/merge/MergeTabletsTest.java
+++
b/server/manager/src/test/java/org/apache/accumulo/manager/tableOps/merge/MergeTabletsTest.java
@@ -69,7 +69,7 @@ import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.fate.FateInstanceType;
-import org.apache.accumulo.core.gc.ReferenceFile;
+import org.apache.accumulo.core.gc.GcCandidate;
import org.apache.accumulo.core.lock.ServiceLock;
import org.apache.accumulo.core.metadata.StoredTabletFile;
import org.apache.accumulo.core.metadata.SuspendingTServer;
@@ -91,7 +91,6 @@ import org.apache.accumulo.core.tabletserver.log.LogEntry;
import org.apache.accumulo.core.util.time.SteadyTime;
import org.apache.accumulo.manager.tableOps.FateEnv;
import org.apache.accumulo.server.ServerContext;
-import org.apache.accumulo.server.gc.AllVolumesDirectory;
import org.apache.accumulo.server.metadata.ConditionalTabletMutatorImpl;
import org.apache.accumulo.server.metadata.ConditionalTabletsMutatorImpl;
import org.apache.hadoop.io.Text;
@@ -508,9 +507,9 @@ public class MergeTabletsTest {
EasyMock.expectLastCall().anyTimes();
// Setup GC candidate write
- List<ReferenceFile> dirs = new ArrayList<>();
- dirs.add(new AllVolumesDirectory(tableId, "td1"));
- dirs.add(new AllVolumesDirectory(tableId, "td2"));
+ List<GcCandidate> dirs = new ArrayList<>();
+ dirs.add(GcCandidate.forTabletDir(tableId, "td1"));
+ dirs.add(GcCandidate.forTabletDir(tableId, "td2"));
ample.putGcFileAndDirCandidates(tableId, dirs);
EasyMock.expectLastCall().once();
diff --git
a/test/src/main/java/org/apache/accumulo/test/ComprehensiveITBase.java
b/test/src/main/java/org/apache/accumulo/test/ComprehensiveITBase.java
index 1b0029aaff..c228700adf 100644
--- a/test/src/main/java/org/apache/accumulo/test/ComprehensiveITBase.java
+++ b/test/src/main/java/org/apache/accumulo/test/ComprehensiveITBase.java
@@ -104,6 +104,7 @@ import
org.apache.accumulo.core.spi.scan.ConfigurableScanServerSelector;
import org.apache.accumulo.minicluster.ServerType;
import org.apache.accumulo.test.harness.SharedMiniClusterBase;
import org.apache.accumulo.test.util.Wait;
+import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.junit.jupiter.api.Test;
@@ -1245,17 +1246,17 @@ public abstract class ComprehensiveITBase extends
SharedMiniClusterBase {
}).collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1,
TreeMap::new));
}
- private static void bulkImport(AccumuloClient client, String table,
+ public static void bulkImport(AccumuloClient client, String table,
FileSystem fs, Path tmpPath,
List<SortedMap<Key,Value>> data) throws Exception {
- String tmp = getCluster().getTemporaryPath().toString();
+ String tmp = tmpPath.toString();
Path dir = new Path(tmp, "comp_bulk_" + UUID.randomUUID());
- getCluster().getFileSystem().mkdirs(dir);
+ fs.mkdirs(dir);
try {
int count = 0;
for (var keyValues : data) {
- try (var output = getCluster().getFileSystem().create(new Path(dir,
"f" + count + ".rf"));
+ try (var output = fs.create(new Path(dir, "f" + count + ".rf"));
var writer = RFile.newWriter().to(output).build()) {
writer.startDefaultLocalityGroup();
for (Map.Entry<Key,Value> entry : keyValues.entrySet()) {
@@ -1267,10 +1268,15 @@ public abstract class ComprehensiveITBase extends
SharedMiniClusterBase {
client.tableOperations().importDirectory(dir.toString()).to(table).load();
} finally {
- getCluster().getFileSystem().delete(dir, true);
+ fs.delete(dir, true);
}
}
+ private static void bulkImport(AccumuloClient client, String table,
+ List<SortedMap<Key,Value>> data) throws Exception {
+ bulkImport(client, table, getCluster().getFileSystem(),
getCluster().getTemporaryPath(), data);
+ }
+
static class TestRecord {
final int row;
final int fam;
diff --git
a/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
b/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
index 69f1a482e7..b4c09c7c57 100644
---
a/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
+++
b/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
@@ -30,11 +30,17 @@ import java.io.UncheckedIOException;
import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -44,6 +50,10 @@ import org.apache.accumulo.core.client.Accumulo;
import org.apache.accumulo.core.client.AccumuloClient;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.admin.CloneConfiguration;
+import org.apache.accumulo.core.client.admin.CompactionConfig;
+import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+import org.apache.accumulo.core.clientImpl.ClientContext;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
@@ -51,7 +61,6 @@ import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
import org.apache.accumulo.core.gc.GcCandidate;
-import org.apache.accumulo.core.gc.ReferenceFile;
import org.apache.accumulo.core.lock.ServiceLock;
import org.apache.accumulo.core.lock.ServiceLockData;
import org.apache.accumulo.core.lock.ServiceLockData.ThriftService;
@@ -60,7 +69,6 @@ import org.apache.accumulo.core.metadata.SystemTables;
import org.apache.accumulo.core.metadata.schema.Ample;
import org.apache.accumulo.core.metadata.schema.Ample.DataLevel;
import org.apache.accumulo.core.metadata.schema.MetadataSchema.DeletesSection;
-import
org.apache.accumulo.core.metadata.schema.MetadataSchema.DeletesSection.SkewedKeyValue;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.TablePermission;
import org.apache.accumulo.gc.SimpleGarbageCollector;
@@ -70,9 +78,11 @@ import
org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl.ProcessInfo;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
import org.apache.accumulo.miniclusterImpl.ProcessNotFoundException;
import org.apache.accumulo.miniclusterImpl.ProcessReference;
+import org.apache.accumulo.test.ComprehensiveIT;
import org.apache.accumulo.test.TestIngest;
import org.apache.accumulo.test.VerifyIngest;
import org.apache.accumulo.test.VerifyIngest.VerifyParams;
+import org.apache.accumulo.test.util.Wait;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RawLocalFileSystem;
@@ -83,7 +93,7 @@ import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Iterators;
+import com.google.common.collect.Sets;
import com.google.common.net.HostAndPort;
public class GarbageCollectorIT extends ConfigurableMacBase {
@@ -249,9 +259,9 @@ public class GarbageCollectorIT extends ConfigurableMacBase
{
bw.addMutation(createDelMutation("", "", "", ""));
bw.addMutation(createDelMutation("", "testDel", "test", "valueTest"));
// path is invalid but value is expected - only way the invalid entry
will come through
- // processing and
- // show up to produce error in output to allow while loop to end
- bw.addMutation(createDelMutation("/", "", "",
SkewedKeyValue.STR_NAME));
+ // processing and show up to produce error in output to allow while
loop to end
+ bw.addMutation(createDelMutation("/", "", "",
+
DeletesSection.encodeType(GcCandidate.Type.TABLET_FILE).toString()));
}
ProcessInfo gc = cluster.exec(SimpleGarbageCollector.class);
@@ -341,8 +351,8 @@ public class GarbageCollectorIT extends ConfigurableMacBase
{
// Create multiple candidate entries
List<GcCandidate> candidates =
- List.of(new
GcCandidate("hdfs://foo.com:6000/user/foo/tables/+r/t-0/F00.rf", 0L),
- new
GcCandidate("hdfs://foo.com:6000/user/foo/tables/+r/t-0/F001.rf", 1L));
+
List.of(GcCandidate.forTabletFile("hdfs://foo.com:6000/user/foo/tables/+r/t-0/F00.rf",
0L),
+
GcCandidate.forTabletFile("hdfs://foo.com:6000/user/foo/tables/+r/t-0/F001.rf",
1L));
List<StoredTabletFile> stfs = candidates.stream()
.map(temp -> StoredTabletFile.of(new
Path(temp.getPath()))).collect(Collectors.toList());
@@ -446,7 +456,7 @@ public class GarbageCollectorIT extends ConfigurableMacBase
{
private int countFiles(String pathStr) throws Exception {
Path path = new Path(pathStr);
- return
Iterators.size(Arrays.asList(cluster.getFileSystem().globStatus(path)).iterator());
+ return cluster.getFileSystem().globStatus(path).length;
}
private void addEntries(AccumuloClient client) throws Exception {
@@ -459,7 +469,7 @@ public class GarbageCollectorIT extends ConfigurableMacBase
{
+ "ffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjj";
var path = URI.create(String.format("file:/%020d/%s", i, longpath));
Mutation delFlag =
- ample.createDeleteMutation(ReferenceFile.forFile(TableId.of("1"),
new Path(path)));
+
ample.createDeleteMutation(GcCandidate.forTabletFile(path.toString(), 100));
bw.addMutation(delFlag);
}
}
@@ -532,4 +542,139 @@ public class GarbageCollectorIT extends
ConfigurableMacBase {
// Cleanup from test
ample.deleteGcCandidates(datalevel, candidates,
Ample.GcCandidateType.VALID);
}
+
+ private Path getTableDir(ClientContext ctx, TableId tableId) throws
Exception {
+ final String pathString =
cluster.getSiteConfiguration().get(Property.INSTANCE_VOLUMES) + "/"
+ + Constants.TABLE_DIR + "/" + tableId;
+ return new Path(pathString);
+ }
+
+ private Set<String> getTabletDirs(ClientContext ctx, String tableName)
throws Exception {
+ var dirs = new HashSet<String>();
+ for (var fileStat : cluster.getFileSystem()
+ .listStatus(getTableDir(ctx, ctx.getTableId(tableName)))) {
+ dirs.add(fileStat.getPath().getName());
+ }
+ return dirs;
+ }
+
+ private Set<String> getTableRows(AccumuloClient client, String table) throws
Exception {
+ try (var scanner = client.createScanner(table)) {
+ return scanner.stream().map(e -> e.getKey().getRowData().toString())
+ .collect(Collectors.toSet());
+ }
+ }
+
+ /**
+ * Tests deletion of tablet, bulk and table dirs.
+ */
+ @Test
+ public void testDirDeletion() throws Exception {
+ var names = getUniqueNames(3);
+ var table1 = names[0];
+ var table2 = names[1];
+ var clone = names[2];
+
+ try (AccumuloClient client =
Accumulo.newClient().from(getClientProperties()).build()) {
+ client.tableOperations().create(table1, new NewTableConfiguration()
+ .setProperties(Map.of(Property.TABLE_MAJC_RATIO.getKey(), "100")));
+ // The GC should not touch table2 files
+ client.tableOperations().create(table2);
+ SortedSet<Text> splits = new TreeSet<>();
+ for (char c = 'a'; c <= 'z'; c++) {
+ splits.add(new Text(c + ""));
+ }
+ client.tableOperations().addSplits(table1, splits);
+ client.tableOperations().addSplits(table2, splits);
+
+ var expectedRows = new HashSet<String>();
+ try (var writer1 = client.createBatchWriter(table1);
+ var writer2 = client.createBatchWriter(table2)) {
+ for (char c = 'a'; c <= 'z'; c++) {
+ Mutation m = new Mutation(c + "");
+ m.put("", "", "" + c);
+ writer1.addMutation(m);
+ writer2.addMutation(m);
+ expectedRows.add("" + c);
+ }
+ }
+
+ client.tableOperations().flush(table1, null, null, true);
+ client.tableOperations().flush(table2, null, null, true);
+
+ var ctx = (ClientContext) client;
+
+ Map<String,String> tabletDirs = new HashMap<>();
+ try (var tablets =
ctx.getAmple().readTablets().forTable(ctx.getTableId(table1)).build()) {
+ for (var tablet : tablets) {
+ if (tablet.getEndRow() != null) {
+ tabletDirs.put(tablet.getEndRow().toString(), tablet.getDirName());
+ }
+ }
+ }
+
+ assertEquals(expectedRows, getTableRows(client, table1));
+ assertEquals(expectedRows, getTableRows(client, table2));
+
+ client.tableOperations().merge(table1, new Text("c"), new Text("g"));
+
+ assertEquals(expectedRows, getTableRows(client, table1));
+ assertEquals(expectedRows, getTableRows(client, table2));
+
+ assertEquals(Set.copyOf(tabletDirs.values()), getTabletDirs(ctx,
table1));
+
+ // bulk import some data
+ TreeMap<Key,Value> bulkData = new TreeMap<>();
+ bulkData.put(Key.builder().row("h1").build(), new Value("h1"));
+ bulkData.put(Key.builder().row("j1").build(), new Value("j1"));
+ ComprehensiveIT.bulkImport(client, table1, cluster.getFileSystem(),
+ cluster.getTemporaryPath(), List.of(bulkData));
+ ComprehensiveIT.bulkImport(client, table2, cluster.getFileSystem(),
+ cluster.getTemporaryPath(), List.of(bulkData));
+ expectedRows.add("h1");
+ expectedRows.add("j1");
+
+ // should now see a bulk dir when listing the dirs for table1
+ var dirDiffs = Sets.difference(getTabletDirs(ctx, table1),
Set.copyOf(tabletDirs.values()));
+ assertEquals(1, dirDiffs.size());
+ assertTrue(dirDiffs.stream().allMatch(dir ->
dir.startsWith(Constants.BULK_PREFIX)));
+
+ // This compaction should cause the tablet dirs that were merged away to
become empty and be
+ // deleted by the GC. Should also cause the bulk dir to be deleted.
+ client.tableOperations().compact(table1, new
CompactionConfig().setWait(true));
+
+ assertEquals(expectedRows, getTableRows(client, table1));
+ assertEquals(expectedRows, getTableRows(client, table2));
+
+ // remove the tablet dirs that were merged away
+ tabletDirs.remove("d");
+ tabletDirs.remove("e");
+ tabletDirs.remove("f");
+
+ // Wait for the tablet dirs to be deleted
+ Wait.waitFor(() ->
Set.copyOf(tabletDirs.values()).equals(getTabletDirs(ctx, table1)));
+
+ assertEquals(expectedRows, getTableRows(client, table1));
+ assertEquals(expectedRows, getTableRows(client, table2));
+
+ var table1Id = ctx.getTableId(table1);
+ // Create a clone to force GC of table files when deleting table
+ client.tableOperations().clone(table1, clone,
CloneConfiguration.builder().build());
+ client.tableOperations().delete(table1);
+
+ assertEquals(expectedRows, getTableRows(client, clone));
+ assertEquals(expectedRows, getTableRows(client, table2));
+
+ // Deleting the clone or compacting it should cause the table dir to be
deleted however,
+ // there is a bug w/ inuse and deleting the clone. See #6645
+ // client.tableOperations().delete(clone);
+ client.tableOperations().compact(clone, new
CompactionConfig().setWait(true));
+
+ // Wait for GC to remove table1 dir
+ Wait.waitFor(() -> !getCluster().getFileSystem().exists(getTableDir(ctx,
table1Id)));
+
+ // GC never should have touched table2, it should still work
+ assertEquals(expectedRows, getTableRows(client, table2));
+ }
+ }
}