This is an automated email from the ASF dual-hosted git repository. ddanielr pushed a commit to branch 2.1 in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push: new fd3e837033 Replace ReferenceDirectory with static named constructor (#4741) fd3e837033 is described below commit fd3e83703371ec2a8fde7942f9b194f8aa912dca Author: John K <69256191+meatballspaghe...@users.noreply.github.com> AuthorDate: Thu Jul 25 17:07:04 2024 -0400 Replace ReferenceDirectory with static named constructor (#4741) - Delete ReferenceDirectory class. It is only being used in GarbageCollectionAlgorithm, GCRun, and GarbageCollectionTest. - Replace ReferenceDirectory functionality with addition of forDirectory named static constructor in ReferenceFile. Migrate necessary components from ReferenceDirectory class to forDirectory constructor, including DirCol validation and boolean isDirectory = true. - Replace references to ReferenceDirectory with components migrated to ReferenceFile, including forDirectory constructor. - Delete recast variable dirReference in GarbageCollectionAlgorithm, which is no longer necessary now that all references use Reference interface. - Finalize isDirectory boolean in ReferenceFile. To support this, modify ReferenceFile constructor to add isDirectory boolean to signature. With this change, update references to this constructor in other methods/classes. --- .../accumulo/core/gc/ReferenceDirectory.java | 56 ---------------------- .../org/apache/accumulo/core/gc/ReferenceFile.java | 17 +++++-- .../accumulo/server/gc/AllVolumesDirectory.java | 2 +- .../main/java/org/apache/accumulo/gc/GCRun.java | 3 +- .../accumulo/gc/GarbageCollectionAlgorithm.java | 6 +-- .../apache/accumulo/gc/GarbageCollectionTest.java | 3 +- 6 files changed, 18 insertions(+), 69 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/gc/ReferenceDirectory.java b/core/src/main/java/org/apache/accumulo/core/gc/ReferenceDirectory.java deleted file mode 100644 index 5491020aa4..0000000000 --- a/core/src/main/java/org/apache/accumulo/core/gc/ReferenceDirectory.java +++ /dev/null @@ -1,56 +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.core.gc; - -import org.apache.accumulo.core.data.TableId; -import org.apache.accumulo.core.metadata.schema.MetadataSchema; - -/** - * A GC reference to a Tablet directory, like t-0003. - */ -public class ReferenceDirectory extends ReferenceFile { - private final String tabletDir; // t-0003 - - public ReferenceDirectory(TableId tableId, String dirName) { - super(tableId, dirName, false); - MetadataSchema.TabletsSection.ServerColumnFamily.validateDirCol(dirName); - this.tabletDir = dirName; - } - - @Override - public boolean isDirectory() { - return true; - } - - public String getTabletDir() { - return tabletDir; - } - - /** - * A Tablet directory should have a metadata entry equal to the dirName. - */ - @Override - public String getMetadataEntry() { - if (!tabletDir.equals(metadataEntry)) { - throw new IllegalStateException( - "Tablet dir " + tabletDir + " is not equal to metadataEntry: " + metadataEntry); - } - return metadataEntry; - } -} diff --git a/core/src/main/java/org/apache/accumulo/core/gc/ReferenceFile.java b/core/src/main/java/org/apache/accumulo/core/gc/ReferenceFile.java index b9eece90d5..8a2b63cfcb 100644 --- a/core/src/main/java/org/apache/accumulo/core/gc/ReferenceFile.java +++ b/core/src/main/java/org/apache/accumulo/core/gc/ReferenceFile.java @@ -21,6 +21,7 @@ package org.apache.accumulo.core.gc; import java.util.Objects; import org.apache.accumulo.core.data.TableId; +import org.apache.accumulo.core.metadata.schema.MetadataSchema; /** * A GC reference used for streaming and delete markers. This type is a file. Subclass is a @@ -30,27 +31,35 @@ public class ReferenceFile implements Reference, Comparable<ReferenceFile> { // parts of an absolute URI, like "hdfs://1.2.3.4/accumulo/tables/2a/t-0003" public final TableId tableId; // 2a public final boolean isScan; + public final boolean isDirectory; // the exact string that is stored in the metadata protected final String metadataEntry; - protected ReferenceFile(TableId tableId, String metadataEntry, boolean isScan) { + protected ReferenceFile(TableId tableId, String metadataEntry, boolean isScan, + boolean isDirectory) { this.tableId = Objects.requireNonNull(tableId); this.metadataEntry = Objects.requireNonNull(metadataEntry); this.isScan = isScan; + this.isDirectory = isDirectory; } public static ReferenceFile forFile(TableId tableId, String metadataEntry) { - return new ReferenceFile(tableId, metadataEntry, false); + return new ReferenceFile(tableId, metadataEntry, false, false); } public static ReferenceFile forScan(TableId tableId, String metadataEntry) { - return new ReferenceFile(tableId, metadataEntry, true); + return new ReferenceFile(tableId, metadataEntry, true, false); + } + + public static ReferenceFile forDirectory(TableId tableId, String dirName) { + MetadataSchema.TabletsSection.ServerColumnFamily.validateDirCol(dirName); + return new ReferenceFile(tableId, dirName, false, true); } @Override public boolean isDirectory() { - return false; + return isDirectory; } @Override 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 index aff8dd5d03..d13b3ec89f 100644 --- 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 @@ -32,7 +32,7 @@ import org.apache.hadoop.fs.Path; public class AllVolumesDirectory extends ReferenceFile { public AllVolumesDirectory(TableId tableId, String dirName) { - super(tableId, getDeleteTabletOnAllVolumesUri(tableId, dirName), false); + super(tableId, getDeleteTabletOnAllVolumesUri(tableId, dirName), false, false); } private static String getDeleteTabletOnAllVolumesUri(TableId tableId, String dirName) { 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 cd1753b67f..a4b328438f 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 @@ -51,7 +51,6 @@ import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.fate.zookeeper.ZooReader; import org.apache.accumulo.core.gc.GcCandidate; import org.apache.accumulo.core.gc.Reference; -import org.apache.accumulo.core.gc.ReferenceDirectory; import org.apache.accumulo.core.gc.ReferenceFile; import org.apache.accumulo.core.manager.state.tables.TableState; import org.apache.accumulo.core.metadata.MetadataTable; @@ -215,7 +214,7 @@ public class GCRun implements GarbageCollectionEnvironment { // if dirName is populated, then we have a tablet directory aka srv:dir if (tm.getDirName() != null) { // add the tablet directory to the stream - var tabletDir = new ReferenceDirectory(tableId, tm.getDirName()); + var tabletDir = ReferenceFile.forDirectory(tableId, tm.getDirName()); fileStream = Stream.concat(fileStream, Stream.of(tabletDir)); } return fileStream; 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 6800b9a84d..419d10728f 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 @@ -40,7 +40,6 @@ 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.gc.ReferenceDirectory; 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; @@ -153,10 +152,9 @@ public class GarbageCollectionAlgorithm { tableIdsSeen.add(ref.getTableId()); if (ref.isDirectory()) { - var dirReference = (ReferenceDirectory) ref; - ServerColumnFamily.validateDirCol(dirReference.getTabletDir()); + ServerColumnFamily.validateDirCol(ref.getMetadataEntry()); - String dir = "/" + dirReference.tableId + "/" + dirReference.getTabletDir(); + String dir = "/" + ref.getTableId() + "/" + ref.getMetadataEntry(); dir = makeRelative(dir, 2); 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 8e9a2d1e07..74b6318029 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 @@ -41,7 +41,6 @@ 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.gc.ReferenceDirectory; import org.apache.accumulo.core.gc.ReferenceFile; import org.apache.accumulo.core.manager.state.tables.TableState; import org.apache.accumulo.core.metadata.MetadataTable; @@ -161,7 +160,7 @@ public class GarbageCollectionTest { public void addDirReference(String tableId, String endRow, String dir) { TableId tid = TableId.of(tableId); - references.put(tableId + ":" + endRow, new ReferenceDirectory(tid, dir)); + references.put(tableId + ":" + endRow, ReferenceFile.forDirectory(tid, dir)); tableIds.add(tid); }