-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LocalTmpStorageConfig for all services (#17588)
This is an interface for getting local temporary storage in all the services. Users can directly inject an object of LocalTmpStorageConfig and use the temporary directory in it as a scratch pad. The lifecycle of temporary files has to be managed by the users.
- Loading branch information
Showing
11 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
processing/src/main/java/org/apache/druid/storage/local/LocalTmpStorageConfig.java
This file contains 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,58 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://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.druid.storage.local; | ||
|
||
import com.google.inject.Provider; | ||
import org.apache.druid.java.util.common.FileUtils; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* {@link LocalTmpStorageConfig} is a provider for temporary directories. A default implementation is binded in all services except | ||
* Peon. For peons, a custom implementation is binded in CliPeon which uses the working directory of the peon to create | ||
* a temporary storage. This interface will be guice injectable in all services. | ||
* The cleaning up of the temporary files/directories created in this storage is handled by the caller. | ||
*/ | ||
public interface LocalTmpStorageConfig | ||
{ | ||
/** | ||
* Get a temporary directory. | ||
* | ||
* @return a temporary directory | ||
*/ | ||
File getTmpDir(); | ||
|
||
class DefaultLocalTmpStorageConfigProvider implements Provider<LocalTmpStorageConfig> | ||
{ | ||
private final String prefix; | ||
|
||
public DefaultLocalTmpStorageConfigProvider(String prefix) | ||
{ | ||
this.prefix = prefix; | ||
} | ||
|
||
@Override | ||
public LocalTmpStorageConfig get() | ||
{ | ||
File result = FileUtils.createTempDir(prefix); | ||
return () -> result; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
processing/src/test/java/org/apache/druid/storage/local/LocalTmpStorageConfigTest.java
This file contains 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,42 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://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.druid.storage.local; | ||
|
||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.UUID; | ||
|
||
public class LocalTmpStorageConfigTest | ||
{ | ||
@Test | ||
public void testDefaultLocalTmpStorage() | ||
{ | ||
String tmpString = UUID.randomUUID().toString(); | ||
Injector injector = Guice.createInjector( | ||
binder -> binder.bind(LocalTmpStorageConfig.class) | ||
.toProvider(new LocalTmpStorageConfig.DefaultLocalTmpStorageConfigProvider(tmpString)) | ||
); | ||
LocalTmpStorageConfig localTmpStorageConfig = injector.getInstance(LocalTmpStorageConfig.class); | ||
Assert.assertTrue(localTmpStorageConfig.getTmpDir().getAbsolutePath().contains(tmpString)); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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