Skip to content
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

OAK-11431: Remove usage of Guava Files.createTempDir() #2027

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.spi.blob.split;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.blob.FileBlobStore;
import org.apache.jackrabbit.oak.spi.blob.split.DefaultSplitBlobStore;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.apache.jackrabbit.guava.common.io.Files;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -61,7 +58,7 @@ public class SplitBlobStoreTest {

@Before
public void setup() throws IOException {
repository = Files.createTempDir();
repository = Files.createTempDirectory(getClass().getSimpleName() + "-").toFile();
oldBlobStore = new FileBlobStore(repository.getPath() + "/old");
newBlobStore = new FileBlobStore(repository.getPath() + "/new");
splitBlobStore = new DefaultSplitBlobStore(repository.getPath(), oldBlobStore, newBlobStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;

import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.jackrabbit.guava.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.plugins.index.search.FieldNames;
import org.apache.lucene.analysis.Analyzer;
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void updateSuggester(Directory directory, Analyzer analyzer, Index
//create a placeholder non-existing-sub-child which would mark the location when we want to return
//our internal suggestion OakDirectory. After build is done, we'd delete the temp directory
//thereby removing any temp stuff that suggester created in the interim.
tempDir = Files.createTempDir();
tempDir = Files.createTempDirectory(SuggestHelper.class.getSimpleName() + "-").toFile();
File tempSubChild = new File(tempDir, "non-existing-sub-child");

if (reader.getDocCount(FieldNames.SUGGEST) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.jackrabbit.guava.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.felix.cm.file.ConfigurationHandler;
Expand Down Expand Up @@ -68,7 +68,7 @@ public static BlobStoreFixture create(Options options) throws Exception{
S3DataStore s3ds = new S3DataStore();
Properties props = loadConfig(bsopts.getS3ConfigPath());
s3ds.setProperties(props);
File homeDir = Files.createTempDir();
File homeDir = Files.createTempDirectory(BlobStoreFixtureProvider.class.getSimpleName() + "-").toFile();
closer.register(asCloseable(homeDir));
populate(s3ds, asMap(props), false);
s3ds.init(homeDir.getAbsolutePath());
Expand All @@ -78,7 +78,7 @@ public static BlobStoreFixture create(Options options) throws Exception{
String cfgPath = bsopts.getAzureConfigPath();
Properties props = loadConfig(cfgPath);
azureds.setProperties(props);
File homeDir = Files.createTempDir();
File homeDir = Files.createTempDirectory(BlobStoreFixtureProvider.class.getSimpleName() + "-").toFile();
populate(azureds, asMap(props), false);
azureds.init(homeDir.getAbsolutePath());
closer.register(asCloseable(homeDir));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.apache.jackrabbit.oak.commons.PropertiesUtil.populate;
import static org.apache.jackrabbit.oak.plugins.document.LeaseCheckMode.DISABLED;
import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder;
import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder;
import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
Expand All @@ -32,6 +31,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
Expand Down Expand Up @@ -69,7 +69,6 @@
import org.jetbrains.annotations.Nullable;

import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.jackrabbit.guava.common.io.Files;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoURI;

Expand Down Expand Up @@ -298,7 +297,7 @@ public static GarbageCollectableBlobStore bootstrapDataStore(String[] args, Clos
String cfgPath = s3dsConfig.value(options);
Properties props = loadAndTransformProps(cfgPath);
s3ds.setProperties(props);
File homeDir = Files.createTempDir();
File homeDir = Files.createTempDirectory(Utils.class.getSimpleName() + "-").toFile();
closer.register(asCloseable(homeDir));
s3ds.init(homeDir.getAbsolutePath());
delegate = s3ds;
Expand All @@ -307,13 +306,13 @@ public static GarbageCollectableBlobStore bootstrapDataStore(String[] args, Clos
String cfgPath = azureBlobDSConfig.value(options);
Properties props = loadAndTransformProps(cfgPath);
azureds.setProperties(props);
File homeDir = Files.createTempDir();
File homeDir = Files.createTempDirectory(Utils.class.getSimpleName() + "-").toFile();
azureds.init(homeDir.getAbsolutePath());
closer.register(asCloseable(homeDir));
delegate = azureds;
} else if (options.has(nods)){
delegate = new DummyDataStore();
File homeDir = Files.createTempDir();
File homeDir = Files.createTempDirectory(Utils.class.getSimpleName() + "-").toFile();
delegate.init(homeDir.getAbsolutePath());
closer.register(asCloseable(homeDir));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jackrabbit.oak.segment.aws.tool;

import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;
Expand All @@ -26,11 +25,11 @@

import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;

import org.apache.jackrabbit.guava.common.base.Stopwatch;
import org.apache.jackrabbit.guava.common.io.Files;

import org.apache.jackrabbit.oak.segment.SegmentCache;
import org.apache.jackrabbit.oak.segment.aws.tool.AwsToolUtils.SegmentStoreType;
Expand Down Expand Up @@ -220,7 +219,8 @@ public int run() throws IOException {
printArchives(System.out, beforeArchives);
System.out.printf(" -> compacting\n");

try (FileStore store = newFileStore(persistence, Files.createTempDir(), strictVersionCheck, segmentCacheSize,
try (FileStore store = newFileStore(persistence,
Files.createTempDirectory(getClass().getSimpleName() + "-").toFile(), strictVersionCheck, segmentCacheSize,
gcLogInterval, compactorType, concurrency)) {
boolean success = false;
switch (gcType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.segment.aws.fixture;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded;
import com.amazonaws.services.s3.AmazonS3;
import org.apache.jackrabbit.guava.common.io.Files;
import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
import org.apache.jackrabbit.oak.segment.aws.AwsContext;
Expand All @@ -35,6 +33,7 @@
import org.apache.jackrabbit.oak.spi.state.NodeStore;

import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -89,7 +88,7 @@ public NodeStore createNodeStore() {
}

try {
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(Files.createTempDir())
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(Files.createTempDirectory(getClass().getSimpleName() + "-").toFile())
.withCustomPersistence(persistence).build();
NodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
fileStoreMap.put(nodeStore, fileStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.segment.azure.tool;

import com.google.common.io.Files;
import com.microsoft.azure.storage.blob.CloudBlobDirectory;
import org.apache.jackrabbit.oak.segment.azure.AzurePersistence;
import org.apache.jackrabbit.oak.segment.azure.AzureStorageCredentialManager;
Expand All @@ -29,7 +28,9 @@
import org.apache.jackrabbit.oak.segment.tool.check.CheckHelper;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.text.MessageFormat;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -388,7 +389,13 @@ public int run() {
persistence = ToolUtils.decorateWithCache(persistence, persistentCachePath, persistentCacheSizeGb);
}

FileStoreBuilder builder = fileStoreBuilder(Files.createTempDir()).withCustomPersistence(persistence);
FileStoreBuilder builder = null;
try {
builder = fileStoreBuilder(Files.createTempDirectory(getClass().getSimpleName() + "-").toFile()).withCustomPersistence(persistence);
} catch (IOException e) {
e.printStackTrace(err);
return 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe throw an IllegalStateException instead of returning 1 to keep closest to the Guava behavior?


if (ioStatistics) {
builder.withIOMonitor(ioMonitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jackrabbit.oak.segment.azure.tool;

import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;
Expand All @@ -27,7 +26,6 @@
import static org.apache.jackrabbit.oak.segment.azure.tool.ToolUtils.printableStopwatch;

import org.apache.jackrabbit.guava.common.base.Stopwatch;
import org.apache.jackrabbit.guava.common.io.Files;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.BlobListingDetails;
import com.microsoft.azure.storage.blob.CloudBlob;
Expand All @@ -53,6 +51,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -372,7 +371,9 @@ public int run() throws IOException, StorageException, URISyntaxException {
GCGeneration gcGeneration = null;
String root = null;

try (FileStore store = newFileStore(splitPersistence, Files.createTempDir(), strictVersionCheck, segmentCacheSize,
try (FileStore store =newFileStore(splitPersistence,
Files.createTempDirectory(getClass().getSimpleName() + "-").toFile(),
strictVersionCheck, segmentCacheSize,
gcLogInterval, compactorType, concurrency)) {
if (garbageThresholdGb > 0 && garbageThresholdPercentage > 0) {
System.out.printf(" -> minimum garbage threshold set to %d GB or %d%%\n", garbageThresholdGb, garbageThresholdPercentage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.segment.azure.fixture;

import org.apache.jackrabbit.guava.common.io.Files;
import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
Expand All @@ -34,6 +32,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.security.InvalidKeyException;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -73,7 +72,9 @@ public NodeStore createNodeStore() {
}

try {
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(Files.createTempDir()).withCustomPersistence(persistence).build();
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(
Files.createTempDirectory(getClass().getSimpleName() + "-").toFile()).
withCustomPersistence(persistence).build();
NodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
fileStoreMap.put(nodeStore, fileStore);
containerMap.put(nodeStore, container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -42,7 +43,6 @@
import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.jackrabbit.guava.common.io.Files;

public class AzureDataStoreFactory implements BlobStoreFactory {

Expand All @@ -68,7 +68,7 @@ public AzureDataStoreFactory(String configuration, String directory, boolean ign
// Default directory

this.directory = directory;
this.tempHomeDir = Files.createTempDir();
this.tempHomeDir = Files.createTempDirectory(getClass().getSimpleName() + "-").toFile();
this.ignoreMissingBlobs = ignoreMissingBlobs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -39,7 +40,6 @@
import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.jackrabbit.guava.common.io.Files;
import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;

Expand All @@ -65,7 +65,7 @@ public S3DataStoreFactory(String configuration, String directory, boolean ignore
}

this.directory = directory;
this.tempHomeDir = Files.createTempDir();
this.tempHomeDir = Files.createTempDirectory(getClass().getSimpleName() + "-").toFile();
this.ignoreMissingBlobs = ignoreMissingBlobs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.microsoft.azure.storage.blob.CloudBlobDirectory;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.jackrabbit.guava.common.io.Files;
import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
import org.apache.jackrabbit.oak.segment.azure.AzurePersistence;
import org.apache.jackrabbit.oak.segment.azure.AzureStorageCredentialManager;
Expand All @@ -40,6 +39,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.security.InvalidKeyException;

import static org.apache.jackrabbit.oak.segment.SegmentCache.DEFAULT_SEGMENT_CACHE_MB;
Expand Down Expand Up @@ -125,7 +125,7 @@ public NodeStore create(BlobStore blobStore, Closer closer) throws IOException {
throw new IllegalStateException(e);
}

File tmpDir = Files.createTempDir();
File tmpDir = Files.createTempDirectory(getClass().getSimpleName() + "-").toFile();
closer.register(() -> tmpDir.delete());
FileStoreBuilder builder = FileStoreBuilder.fileStoreBuilder(tmpDir)
.withCustomPersistence(azPersistence).withMemoryMapping(false);
Expand Down Expand Up @@ -189,7 +189,7 @@ public boolean hasExternalBlobReferences() throws IOException {
throw new IllegalStateException(e);
}

File tmpDir = Files.createTempDir();
File tmpDir = Files.createTempDirectory(getClass().getSimpleName() + "-").toFile();
FileStoreBuilder builder = FileStoreBuilder.fileStoreBuilder(tmpDir)
.withCustomPersistence(azPersistence).withMemoryMapping(false);

Expand Down
Loading
Loading