-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add LocalTmpStorage for all services #17588
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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; | ||
|
||
public interface LocalTmpStorage | ||
{ | ||
/** | ||
* Get a temporary directory. | ||
* | ||
* @return a temporary directory | ||
*/ | ||
File getTmpDir(); | ||
|
||
class DefaultLocalTmpStorageProvider implements Provider<LocalTmpStorage> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't seem like the system will prepare to clean up these files - wouldn't that will fill up the disk/create garabge? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tmpdir provided from this is just a location. Whether things are cleaned up or not is a question of the implementation. In general, most of the code that deals with tmp files cleans them up after itself and if it's not cleaning up after itself, that should either be intentional and have a design reason or it is a bug in the code that's dealing with the file, not a bug in the code that's delivering the location of the directory. |
||
{ | ||
private final String prefix; | ||
|
||
public DefaultLocalTmpStorageProvider(String prefix) | ||
{ | ||
this.prefix = prefix; | ||
} | ||
|
||
@Override | ||
public LocalTmpStorage get() | ||
{ | ||
File tmpStorage = FileUtils.createTempDir(prefix); | ||
return () -> tmpStorage; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,7 @@ | |
import org.apache.druid.server.lookup.cache.LookupLoadingSpec; | ||
import org.apache.druid.server.metrics.DataSourceTaskIdHolder; | ||
import org.apache.druid.server.metrics.ServiceStatusMonitor; | ||
import org.apache.druid.storage.local.LocalTmpStorage; | ||
import org.apache.druid.tasklogs.TaskPayloadManager; | ||
import org.eclipse.jetty.server.Server; | ||
|
||
|
@@ -355,6 +356,17 @@ public BroadcastDatasourceLoadingSpec getBroadcastDatasourcesToLoad(final Task t | |
{ | ||
return task.getBroadcastDatasourceLoadingSpec(); | ||
} | ||
|
||
@Provides | ||
@LazySingleton | ||
public LocalTmpStorage getLocalTmpStorage() | ||
{ | ||
File tmpDir = new File(taskDirPath, "tmp"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cheddar : should we create the temporary storage per attempt? or should we share it across attempts for re-use of temp data? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's share it. The old default for cases where this would've been used is just |
||
if (!tmpDir.mkdirs()) { | ||
log.warn("Failed to create tmp directory [%s]", tmpDir); | ||
} | ||
return () -> tmpDir; | ||
} | ||
}, | ||
new QueryablePeonModule(), | ||
new IndexingServiceInputSourceModule(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty similar to
TempDirProducer
; to service this usecase maybe that could be enhanced with a lazy init and agetRoot
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TempDirProducer
appears to have semantics around cleaning up withclose()
. That class is different from this class, this class is basically just aConfig
. It could be called aConfig
, but Rohan doesn't like the word config, so it got this name instead.LocalTmpStorage
is just delivering a location, nothing more, nothing less, it provides something that can be injected to get at a system-configured tmp storage location and is not intended to actually do anything beyond that. It probably deserves javadoc that describes that this class shouldn't be doing anything other than delivering configuration as it's just there to be an injectable configuration object.It could absolutely make sense to have
TempDirProducer
depend on aLocalTmpStorage
in order to get the tmp dir location that it's supposed to use.