-
Notifications
You must be signed in to change notification settings - Fork 489
Deprecate GC_TRASH_IGNORE, add tests to confirm Trash works #3436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorTrashBase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * 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.test.functional; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Iterator; | ||
|
|
||
| import org.apache.accumulo.core.client.AccumuloClient; | ||
| import org.apache.accumulo.core.data.TableId; | ||
| import org.apache.accumulo.core.metadata.StoredTabletFile; | ||
| import org.apache.accumulo.core.metadata.TabletFile; | ||
| import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType; | ||
| import org.apache.accumulo.core.metadata.schema.TabletsMetadata; | ||
| import org.apache.accumulo.server.ServerContext; | ||
| import org.apache.accumulo.test.util.Wait; | ||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.LocatedFileStatus; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.RemoteIterator; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| // base class for ITs that test our legacy trash property and Hadoop's trash policy with accumulo gc | ||
| public class GarbageCollectorTrashBase extends ConfigurableMacBase { | ||
|
dlmarion marked this conversation as resolved.
|
||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(GarbageCollectorTrashBase.class); | ||
|
|
||
| protected ArrayList<StoredTabletFile> getFilesForTable(ServerContext ctx, AccumuloClient client, | ||
| String tableName) { | ||
| String tid = client.tableOperations().tableIdMap().get(tableName); | ||
| TabletsMetadata tms = | ||
| ctx.getAmple().readTablets().forTable(TableId.of(tid)).fetch(ColumnType.FILES).build(); | ||
| ArrayList<StoredTabletFile> files = new ArrayList<>(); | ||
| tms.forEach(tm -> { | ||
| files.addAll(tm.getFiles()); | ||
| }); | ||
| LOG.debug("Tablet files: {}", files); | ||
| return files; | ||
| } | ||
|
|
||
| protected ArrayList<StoredTabletFile> loadData(ServerContext ctx, AccumuloClient client, | ||
| String tableName) throws Exception { | ||
| // create some files | ||
| for (int i = 0; i < 5; i++) { | ||
| ReadWriteIT.ingest(client, 10, 10, 10, 0, tableName); | ||
| client.tableOperations().flush(tableName); | ||
| } | ||
| return getFilesForTable(ctx, client, tableName); | ||
| } | ||
|
|
||
| protected boolean userTrashDirExists(FileSystem fs) { | ||
| return !fs.getTrashRoots(false).isEmpty(); | ||
| } | ||
|
|
||
| protected void makeTrashDir(FileSystem fs) throws IOException { | ||
| if (!userTrashDirExists(fs)) { | ||
| Path homeDir = fs.getHomeDirectory(); | ||
| Path trashDir = new Path(homeDir, ".Trash"); | ||
|
ctubbsii marked this conversation as resolved.
|
||
| assertTrue(fs.mkdirs(trashDir)); | ||
| } | ||
| assertTrue(userTrashDirExists(fs)); | ||
|
|
||
| } | ||
|
|
||
| protected void waitForFilesToBeGCd(final ArrayList<StoredTabletFile> files) throws Exception { | ||
| Wait.waitFor(() -> files.stream().noneMatch(stf -> { | ||
| try { | ||
| return super.getCluster().getMiniDfs().getFileSystem().exists(stf.getPath()); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("error", e); | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| protected long countFilesInTrash(FileSystem fs, TableId tid) | ||
| throws FileNotFoundException, IOException { | ||
| Collection<FileStatus> dirs = fs.getTrashRoots(true); | ||
| if (dirs.isEmpty()) { | ||
| return -1; | ||
| } | ||
| long count = 0; | ||
| Iterator<FileStatus> iter = dirs.iterator(); | ||
| while (iter.hasNext()) { | ||
| FileStatus stat = iter.next(); | ||
| LOG.debug("Trash root: {}", stat.getPath()); | ||
| RemoteIterator<LocatedFileStatus> riter = fs.listFiles(stat.getPath(), true); | ||
| while (riter.hasNext()) { | ||
| LocatedFileStatus lfs = riter.next(); | ||
| if (lfs.isDirectory()) { | ||
| continue; | ||
| } | ||
| TabletFile tf = new TabletFile(lfs.getPath()); | ||
| LOG.debug("File in trash: {}, tableId: {}", lfs.getPath(), tf.getTableId()); | ||
| if (tid.equals(tf.getTableId())) { | ||
| count++; | ||
| } | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| } | ||
88 changes: 88 additions & 0 deletions
88
test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorTrashDefaultIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * 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.test.functional; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.accumulo.core.client.Accumulo; | ||
| import org.apache.accumulo.core.client.AccumuloClient; | ||
| import org.apache.accumulo.core.client.admin.CompactionConfig; | ||
| import org.apache.accumulo.core.conf.Property; | ||
| import org.apache.accumulo.core.data.TableId; | ||
| import org.apache.accumulo.core.metadata.StoredTabletFile; | ||
| import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.CommonConfigurationKeysPublic; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| // verify trash is not used with Hadoop default configuration as Trash is not | ||
| // enabled by default. | ||
| public class GarbageCollectorTrashDefaultIT extends GarbageCollectorTrashBase { | ||
|
dlmarion marked this conversation as resolved.
|
||
|
|
||
| @Override | ||
| protected Duration defaultTimeout() { | ||
| return Duration.ofMinutes(5); | ||
| } | ||
|
|
||
| @Override | ||
| public void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) { | ||
| // By default Hadoop trash is disabled - fs.trash.interval defaults to 0 | ||
|
dlmarion marked this conversation as resolved.
|
||
| Map<String,String> hadoopOverrides = new HashMap<>(); | ||
| hadoopOverrides.put(CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY, "0"); | ||
| cfg.setHadoopConfOverrides(hadoopOverrides); | ||
| cfg.useMiniDFS(true); | ||
|
|
||
| cfg.setProperty(Property.GC_CYCLE_START, "1"); | ||
| cfg.setProperty(Property.GC_CYCLE_DELAY, "1"); | ||
| @SuppressWarnings("removal") | ||
| Property p = Property.GC_TRASH_IGNORE; | ||
| cfg.setProperty(p, "false"); // default, use trash if configured | ||
| cfg.setProperty(Property.GC_PORT, "0"); | ||
| cfg.setProperty(Property.TSERV_MAXMEM, "5K"); | ||
| cfg.setProperty(Property.TABLE_MAJC_RATIO, "5.0"); | ||
| cfg.setProperty(Property.TSERV_MAJC_DELAY, "1"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTrashHadoopDisabledAccumuloEnabled() throws Exception { | ||
| String table = this.getUniqueNames(1)[0]; | ||
| final FileSystem fs = super.getCluster().getFileSystem(); | ||
| super.makeTrashDir(fs); | ||
| try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) { | ||
| ArrayList<StoredTabletFile> files = super.loadData(super.getServerContext(), c, table); | ||
| assertFalse(files.isEmpty()); | ||
| c.tableOperations().compact(table, new CompactionConfig()); | ||
| TableId tid = TableId.of(c.tableOperations().tableIdMap().get(table)); | ||
| // The default value for fs.trash.interval is 0, which means that | ||
| // trash is disabled in the Hadoop configuration. Enabling trash in | ||
| // Accumulo (GC_TRASH_IGNORE = false) still requires enabling trash in Hadoop | ||
| super.waitForFilesToBeGCd(files); | ||
| assertEquals(0, super.countFilesInTrash(fs, tid)); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.