You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "abhishekrb19 (via GitHub)" <gi...@apache.org> on 2024/05/20 18:34:00 UTC
[PR] Fix task bootstrapping. (druid)
abhishekrb19 opened a new pull request, #16475:
URL: https://github.com/apache/druid/pull/16475
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
<!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
Fixes #XXXX.
<!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
<!-- If you are a committer, follow the PR action item checklist for committers:
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
### Description
<!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
<!-- Describe your patch: what did you change in code? How did you fix the problem? -->
<!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
#### Fixed the bug ...
#### Renamed the class ...
#### Added a forbidden-apis entry ...
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
- Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
- Method organization and design (how the logic is split between methods, parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
-->
<!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
<!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
#### Release note
<!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users.
If your change doesn't have end user impact, you can skip this section.
For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
-->
<hr>
##### Key changed/added classes in this PR
* `MyFoo`
* `OurBar`
* `TheirBaz`
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1607477999
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -118,32 +128,158 @@
SegmentLocalCacheManager(
SegmentLoaderConfig config,
@Nonnull StorageLocationSelectorStrategy strategy,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
- this(config.toStorageLocations(), config, strategy, mapper);
+ this(config.toStorageLocations(), config, strategy, indexIO, mapper);
}
/**
* creates instance with default storage location selector strategy
*
* This ctor is mainly for test cases, including test cases in other modules
*/
- @VisibleForTesting
public SegmentLocalCacheManager(
SegmentLoaderConfig config,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
this.config = config;
+ this.indexIO = indexIO;
this.jsonMapper = mapper;
this.locations = config.toStorageLocations();
this.strategy = new LeastBytesUsedStorageLocationSelectorStrategy(locations);
log.info("Using storage location strategy: [%s]", this.strategy.getClass().getSimpleName());
}
- static String getSegmentDir(DataSegment segment)
+ @Override
+ public boolean canHandleSegments()
+ {
+ return !(locations == null || locations.isEmpty());
+ }
+
+ @Override
+ public List<DataSegment> getCachedSegments() throws IOException
+ {
+ if (!canHandleSegments()) {
+ throw DruidException.defensive(
+ "canHandleSegments() is false. getCachedSegments() must be invoked only when canHandleSegments() returns true."
+ );
+ }
+ final File baseDir = getInfoDir();
+
+ List<DataSegment> cachedSegments = new ArrayList<>();
+ File[] segmentsToLoad = baseDir.listFiles();
+
+ int ignored = 0;
+
+ for (int i = 0; i < segmentsToLoad.length; i++) {
+ File file = segmentsToLoad[i];
+ log.info("Loading segment cache file [%d/%d][%s].", i + 1, segmentsToLoad.length, file);
+ try {
+ final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
+
+ if (!segment.getId().toString().equals(file.getName())) {
+ log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), segment.getId());
+ ignored++;
+ } else if (isSegmentCached(segment)) {
+ cachedSegments.add(segment);
+ } else {
+ final SegmentId segmentId = segment.getId();
+ log.warn("Unable to find cache file for segment[%s]. Deleting lookup entry.", segmentId);
+ if (!removeInfoFile(segment)) {
+ log.warn(
+ "Unable to delete cache file[%s] for segment[%s].",
+ getInfoFileName(segment), segmentId);
+ }
+ }
+ }
+ catch (Exception e) {
+ log.makeAlert(e, "Failed to load segment from segmentInfo file")
+ .addData("file", file)
+ .emit();
+ }
+ }
+
+ if (ignored > 0) {
+ log.makeAlert("Ignored misnamed segment cache files on startup.")
+ .addData("numIgnored", ignored)
+ .emit();
+ }
+
+ return cachedSegments;
+ }
+
+ @Override
+ public void storeInfoFile(DataSegment segment) throws IOException
+ {
+ final File segmentInfoCacheFile = new File(getInfoDir(), segment.getId().toString());
+ if (!segmentInfoCacheFile.exists()) {
+ jsonMapper.writeValue(segmentInfoCacheFile, segment);
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7380)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1607627352
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.Interval;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ segmentFile.createNewFile();
Review Comment:
## Ignored error status of call
Method loadSegment ignores exceptional return value of File.createNewFile.
[Show more details](https://github.com/apache/druid/security/code-scanning/7381)
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.Interval;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ segmentFile.createNewFile();
+ factoryJson.createNewFile();
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7384)
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.Interval;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ segmentFile.createNewFile();
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7383)
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.Interval;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ segmentFile.createNewFile();
+ factoryJson.createNewFile();
Review Comment:
## Ignored error status of call
Method loadSegment ignores exceptional return value of File.createNewFile.
[Show more details](https://github.com/apache/druid/security/code-scanning/7382)
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.Interval;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ segmentFile.createNewFile();
+ factoryJson.createNewFile();
+ }
+ catch (IOException e) {
+ throw new SegmentLoadingException(
+ e,
+ "Failed to create files under dir[%s]",
+ destDir.getAbsolutePath()
+ );
+ }
+
+ try {
+ byte[] bytes = new byte[size];
+ ThreadLocalRandom.current().nextBytes(bytes);
+ Files.write(bytes, segmentFile);
+ Files.write("{\"type\":\"testSegmentFactory\"}".getBytes(StandardCharsets.UTF_8), factoryJson);
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7386)
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.Interval;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ segmentFile.createNewFile();
+ factoryJson.createNewFile();
+ }
+ catch (IOException e) {
+ throw new SegmentLoadingException(
+ e,
+ "Failed to create files under dir[%s]",
+ destDir.getAbsolutePath()
+ );
+ }
+
+ try {
+ byte[] bytes = new byte[size];
+ ThreadLocalRandom.current().nextBytes(bytes);
+ Files.write(bytes, segmentFile);
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7385)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #16475:
URL: https://github.com/apache/druid/pull/16475#issuecomment-2121825590
@abhishekrb19 , thanks for the detailed description. IIUC, this PR is basically doing the following:
- Inject the correct value of storage locations into `SegmentLoadDropHandler`
- Refactor and cleanup classes
Is there any other bug fix or feature included in this PR too?
Just wanted to confirm before I start the actual review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1609643174
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -96,13 +104,15 @@ public SegmentLocalCacheManager(
List<StorageLocation> locations,
Review Comment:
Don't see why we need to inject `List<StorageLocation>` if we are already injecting the `SegmentLoaderConfig`. In fact, I think we should probably just get rid of the provider method `StorageNodeModule.provideStorageLocations()` and just inject the `SegmentLoaderConfig` in all the relevant places.
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -490,9 +416,8 @@ void removeSegment(
if (scheduleDrop) {
log.info(
- "Completely removing [%s] in [%,d] millis",
- segment.getId(),
- config.getDropSegmentDelayMillis()
+ "Completely removing segment[%s] in [%,dms].",
Review Comment:
Nit: Maybe keep `ms` outside the square brackets for readability.
`Did something in [100ms]`
vs
`Did something in [100]ms`
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -209,99 +196,43 @@ public boolean isStarted()
return started;
}
- private void loadLocalCache() throws IOException
+ private void bootstrapCachedSegments() throws IOException
Review Comment:
We don't really need two separate methods anymore. The content here can be merged into `addSegments()` itself. The final method can then be called `bootstrapCachedSegments()`.
##########
server/src/main/java/org/apache/druid/server/SegmentManager.java:
##########
@@ -241,8 +240,9 @@ private TableDataSource getTableDataSource(DataSourceAnalysis analysis)
.orElseThrow(() -> new ISE("Cannot handle datasource: %s", analysis.getBaseDataSource()));
}
+ @VisibleForTesting
Review Comment:
Let's remove this method if it is only needed for testing. The tests can call the actual method with `null`s for the 4th arg.
##########
server/src/main/java/org/apache/druid/server/SegmentManager.java:
##########
@@ -262,8 +262,12 @@ public boolean loadSegment(final DataSegment segment, boolean lazy, SegmentLazyL
*
* @throws SegmentLoadingException if the segment cannot be loaded
*/
- public boolean loadSegment(final DataSegment segment, boolean lazy, SegmentLazyLoadFailCallback loadFailed,
- ExecutorService loadSegmentIntoPageCacheExec) throws SegmentLoadingException
+ public boolean loadSegment(
+ final DataSegment segment,
+ boolean lazy,
+ SegmentLazyLoadFailCallback loadFailed,
+ ExecutorService loadSegmentIntoPageCacheExec
+ ) throws SegmentLoadingException, IOException
Review Comment:
Rather than passing a boolean `lazy` and an executor, this class should have two separate methods `loadSegment(segment, callback)` and `loadSegmentOnBootstrap(segment, callback)` (or `bootstrapLoadedSegment`, whichever seems better).
There are two executors for loading segments into page cache, one to be used while bootstrapping and the other for later. Both these executors should belong to the `SegmentLocalCacheManager`. You might need to update the `SegmentCacheManager` interface too to have two separate methods `loadSegmentIntoPageCache` and `loadSegmentIntoPageCacheOnBootrstrap`.
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -209,99 +196,43 @@ public boolean isStarted()
return started;
}
- private void loadLocalCache() throws IOException
+ private void bootstrapCachedSegments() throws IOException
{
- final long start = System.currentTimeMillis();
- File baseDir = config.getInfoDir();
- FileUtils.mkdirp(baseDir);
-
- List<DataSegment> cachedSegments = new ArrayList<>();
- File[] segmentsToLoad = baseDir.listFiles();
- int ignored = 0;
- for (int i = 0; i < segmentsToLoad.length; i++) {
- File file = segmentsToLoad[i];
- log.info("Loading segment cache file [%d/%d][%s].", i + 1, segmentsToLoad.length, file);
- try {
- final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
-
- if (!segment.getId().toString().equals(file.getName())) {
- log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), segment.getId());
- ignored++;
- } else if (segmentCacheManager.isSegmentCached(segment)) {
- cachedSegments.add(segment);
- } else {
- log.warn("Unable to find cache file for %s. Deleting lookup entry", segment.getId());
-
- File segmentInfoCacheFile = new File(baseDir, segment.getId().toString());
- if (!segmentInfoCacheFile.delete()) {
- log.warn("Unable to delete segmentInfoCacheFile[%s]", segmentInfoCacheFile);
- }
- }
- }
- catch (Exception e) {
- log.makeAlert(e, "Failed to load segment from segmentInfo file")
- .addData("file", file)
- .emit();
- }
- }
-
- if (ignored > 0) {
- log.makeAlert("Ignored misnamed segment cache files on startup.")
- .addData("numIgnored", ignored)
- .emit();
- }
-
+ final Stopwatch stopwatch = Stopwatch.createStarted();
+ final List<DataSegment> cachedSegments = segmentManager.getCachedSegments();
addSegments(
cachedSegments,
- () -> log.info("Cache load took %,d ms", System.currentTimeMillis() - start)
+ () -> {
+ log.info("Cache load of [%d] bootstrap segments completed.", cachedSegments.size());
+ }
);
- }
-
- private void loadSegment(DataSegment segment, DataSegmentChangeCallback callback, boolean lazy)
- throws SegmentLoadingException
- {
- loadSegment(segment, callback, lazy, null);
+ stopwatch.stop();
+ log.info("Cache load of [%d] bootstrap segments took [%,dms]", cachedSegments.size(), stopwatch.millisElapsed());
}
/**
- * Load a single segment. If the segment is loaded successfully, this function simply returns. Otherwise it will
- * throw a SegmentLoadingException
- *
- * @throws SegmentLoadingException if it fails to load the given segment
+ * Load a single segment. If the segment is loaded successfully, this function simply returns. Otherwise, it will
Review Comment:
If you want to avoid repetition, I would rather we delete the second sentence here but retain the `@throws` tag.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1614210822
##########
server/src/main/java/org/apache/druid/server/SegmentManager.java:
##########
@@ -262,8 +262,12 @@ public boolean loadSegment(final DataSegment segment, boolean lazy, SegmentLazyL
*
* @throws SegmentLoadingException if the segment cannot be loaded
*/
- public boolean loadSegment(final DataSegment segment, boolean lazy, SegmentLazyLoadFailCallback loadFailed,
- ExecutorService loadSegmentIntoPageCacheExec) throws SegmentLoadingException
+ public boolean loadSegment(
+ final DataSegment segment,
+ boolean lazy,
+ SegmentLazyLoadFailCallback loadFailed,
+ ExecutorService loadSegmentIntoPageCacheExec
+ ) throws SegmentLoadingException, IOException
Review Comment:
Cleaned up the existing patterns a bit. `loadSegment()` doesn't require an async load fail callback as there's no lazy loading done in this flow. Only `loadSegmentOnBootstrap()` requires that based on `lazyLoadOnStart`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1616550799
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,382 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.granularity.Granularity;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.query.QueryMetrics;
+import org.apache.druid.query.filter.Filter;
+import org.apache.druid.segment.Cursor;
+import org.apache.druid.segment.DimensionHandler;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Metadata;
+import org.apache.druid.segment.QueryableIndex;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.StorageAdapter;
+import org.apache.druid.segment.VirtualColumns;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ColumnHolder;
+import org.apache.druid.segment.data.Indexed;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.SegmentId;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.DateTime;
+import org.joda.time.Interval;
+import org.junit.Assert;
+import org.mockito.Mockito;
+
+import javax.annotation.Nullable;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ Assert.assertTrue(segmentFile.createNewFile());
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7401)
##########
server/src/test/java/org/apache/druid/server/TestSegmentUtils.java:
##########
@@ -0,0 +1,382 @@
+/*
+ * 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.server;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.granularity.Granularity;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.query.QueryMetrics;
+import org.apache.druid.query.filter.Filter;
+import org.apache.druid.segment.Cursor;
+import org.apache.druid.segment.DimensionHandler;
+import org.apache.druid.segment.IndexIO;
+import org.apache.druid.segment.Metadata;
+import org.apache.druid.segment.QueryableIndex;
+import org.apache.druid.segment.Segment;
+import org.apache.druid.segment.SegmentLazyLoadFailCallback;
+import org.apache.druid.segment.StorageAdapter;
+import org.apache.druid.segment.VirtualColumns;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ColumnHolder;
+import org.apache.druid.segment.data.Indexed;
+import org.apache.druid.segment.loading.LoadSpec;
+import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.apache.druid.segment.loading.SegmentizerFactory;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.SegmentId;
+import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.joda.time.DateTime;
+import org.joda.time.Interval;
+import org.junit.Assert;
+import org.mockito.Mockito;
+
+import javax.annotation.Nullable;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
+
+
+public class TestSegmentUtils
+{
+ @JsonTypeName("test")
+ public static class TestLoadSpec implements LoadSpec
+ {
+
+ private final int size;
+ private final String name;
+
+ @JsonCreator
+ public TestLoadSpec(
+ @JsonProperty("size") int size,
+ @JsonProperty("name") String name
+ )
+ {
+ this.size = size;
+ this.name = name;
+ }
+
+ @Override
+ public LoadSpecResult loadSegment(File destDir) throws SegmentLoadingException
+ {
+ File segmentFile = new File(destDir, "segment");
+ File factoryJson = new File(destDir, "factory.json");
+ try {
+ FileUtils.mkdirp(destDir);
+ Assert.assertTrue(segmentFile.createNewFile());
+ Assert.assertTrue(factoryJson.createNewFile());
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7402)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1614223972
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -96,13 +104,15 @@ public SegmentLocalCacheManager(
List<StorageLocation> locations,
Review Comment:
Yeah, the `CliPeon` does the same as the locations are dynamically configured for tasks. All the different storage location strategies rely on `List<StorageLocation>` too, so I'm not sure if there's an easy way to coalesce the configs without breaking something.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping & simplify segment load/drop flows (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 merged PR #16475:
URL: https://github.com/apache/druid/pull/16475
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1607188433
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -118,32 +128,158 @@
SegmentLocalCacheManager(
SegmentLoaderConfig config,
@Nonnull StorageLocationSelectorStrategy strategy,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
- this(config.toStorageLocations(), config, strategy, mapper);
+ this(config.toStorageLocations(), config, strategy, indexIO, mapper);
}
/**
* creates instance with default storage location selector strategy
*
* This ctor is mainly for test cases, including test cases in other modules
*/
- @VisibleForTesting
public SegmentLocalCacheManager(
SegmentLoaderConfig config,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
this.config = config;
+ this.indexIO = indexIO;
this.jsonMapper = mapper;
this.locations = config.toStorageLocations();
this.strategy = new LeastBytesUsedStorageLocationSelectorStrategy(locations);
log.info("Using storage location strategy: [%s]", this.strategy.getClass().getSimpleName());
}
- static String getSegmentDir(DataSegment segment)
+ @Override
+ public boolean canHandleSegments()
+ {
+ return !(locations == null || locations.isEmpty());
+ }
+
+ @Override
+ public List<DataSegment> getCachedSegments() throws IOException
+ {
+ if (!canHandleSegments()) {
+ throw DruidException.defensive(
+ "canHandleSegments() is false. getCachedSegments() must be invoked only when canHandleSegments() returns true."
+ );
+ }
+ final File baseDir = getInfoDir();
+
+ List<DataSegment> cachedSegments = new ArrayList<>();
+ File[] segmentsToLoad = baseDir.listFiles();
+
+ int ignored = 0;
+
+ for (int i = 0; i < segmentsToLoad.length; i++) {
+ File file = segmentsToLoad[i];
+ log.info("Loading segment cache file [%d/%d][%s].", i + 1, segmentsToLoad.length, file);
+ try {
+ final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
+
+ if (!segment.getId().toString().equals(file.getName())) {
+ log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), segment.getId());
+ ignored++;
+ } else if (isSegmentCached(segment)) {
+ cachedSegments.add(segment);
+ } else {
+ final SegmentId segmentId = segment.getId();
+ log.warn("Unable to find cache file for segment[%s]. Deleting lookup entry.", segmentId);
+ if (!removeInfoFile(segment)) {
+ log.warn(
+ "Unable to delete cache file[%s] for segment[%s].",
+ getInfoFileName(segment), segmentId);
+ }
+ }
+ }
+ catch (Exception e) {
+ log.makeAlert(e, "Failed to load segment from segmentInfo file")
+ .addData("file", file)
+ .emit();
+ }
+ }
+
+ if (ignored > 0) {
+ log.makeAlert("Ignored misnamed segment cache files on startup.")
+ .addData("numIgnored", ignored)
+ .emit();
+ }
+
+ return cachedSegments;
+ }
+
+ @Override
+ public void storeInfoFile(DataSegment segment) throws IOException
+ {
+ final File segmentInfoCacheFile = new File(getInfoDir(), segment.getId().toString());
+ if (!segmentInfoCacheFile.exists()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7376)
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -118,32 +128,158 @@
SegmentLocalCacheManager(
SegmentLoaderConfig config,
@Nonnull StorageLocationSelectorStrategy strategy,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
- this(config.toStorageLocations(), config, strategy, mapper);
+ this(config.toStorageLocations(), config, strategy, indexIO, mapper);
}
/**
* creates instance with default storage location selector strategy
*
* This ctor is mainly for test cases, including test cases in other modules
*/
- @VisibleForTesting
public SegmentLocalCacheManager(
SegmentLoaderConfig config,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
this.config = config;
+ this.indexIO = indexIO;
this.jsonMapper = mapper;
this.locations = config.toStorageLocations();
this.strategy = new LeastBytesUsedStorageLocationSelectorStrategy(locations);
log.info("Using storage location strategy: [%s]", this.strategy.getClass().getSimpleName());
}
- static String getSegmentDir(DataSegment segment)
+ @Override
+ public boolean canHandleSegments()
+ {
+ return !(locations == null || locations.isEmpty());
+ }
+
+ @Override
+ public List<DataSegment> getCachedSegments() throws IOException
+ {
+ if (!canHandleSegments()) {
+ throw DruidException.defensive(
+ "canHandleSegments() is false. getCachedSegments() must be invoked only when canHandleSegments() returns true."
+ );
+ }
+ final File baseDir = getInfoDir();
+
+ List<DataSegment> cachedSegments = new ArrayList<>();
+ File[] segmentsToLoad = baseDir.listFiles();
+
+ int ignored = 0;
+
+ for (int i = 0; i < segmentsToLoad.length; i++) {
+ File file = segmentsToLoad[i];
+ log.info("Loading segment cache file [%d/%d][%s].", i + 1, segmentsToLoad.length, file);
+ try {
+ final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
+
+ if (!segment.getId().toString().equals(file.getName())) {
+ log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), segment.getId());
+ ignored++;
+ } else if (isSegmentCached(segment)) {
+ cachedSegments.add(segment);
+ } else {
+ final SegmentId segmentId = segment.getId();
+ log.warn("Unable to find cache file for segment[%s]. Deleting lookup entry.", segmentId);
+ if (!removeInfoFile(segment)) {
+ log.warn(
+ "Unable to delete cache file[%s] for segment[%s].",
+ getInfoFileName(segment), segmentId);
+ }
+ }
+ }
+ catch (Exception e) {
+ log.makeAlert(e, "Failed to load segment from segmentInfo file")
+ .addData("file", file)
+ .emit();
+ }
+ }
+
+ if (ignored > 0) {
+ log.makeAlert("Ignored misnamed segment cache files on startup.")
+ .addData("numIgnored", ignored)
+ .emit();
+ }
+
+ return cachedSegments;
+ }
+
+ @Override
+ public void storeInfoFile(DataSegment segment) throws IOException
+ {
+ final File segmentInfoCacheFile = new File(getInfoDir(), segment.getId().toString());
+ if (!segmentInfoCacheFile.exists()) {
+ jsonMapper.writeValue(segmentInfoCacheFile, segment);
+ }
+ }
+
+ @Override
+ public boolean removeInfoFile(DataSegment segment) throws IOException
+ {
+ return new File(getInfoDir(), segment.getId().toString()).delete();
+ }
+
+ @Override
+ public ReferenceCountingSegment getSegment(DataSegment segment, boolean lazy, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException
+ {
+ final File segmentFiles = getSegmentFiles(segment);
+ final File factoryJson = new File(segmentFiles, "factory.json");
+ final SegmentizerFactory factory;
+
+ if (factoryJson.exists()) {
+ try {
+ factory = jsonMapper.readValue(factoryJson, SegmentizerFactory.class);
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7379)
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -118,32 +128,158 @@
SegmentLocalCacheManager(
SegmentLoaderConfig config,
@Nonnull StorageLocationSelectorStrategy strategy,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
- this(config.toStorageLocations(), config, strategy, mapper);
+ this(config.toStorageLocations(), config, strategy, indexIO, mapper);
}
/**
* creates instance with default storage location selector strategy
*
* This ctor is mainly for test cases, including test cases in other modules
*/
- @VisibleForTesting
public SegmentLocalCacheManager(
SegmentLoaderConfig config,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
this.config = config;
+ this.indexIO = indexIO;
this.jsonMapper = mapper;
this.locations = config.toStorageLocations();
this.strategy = new LeastBytesUsedStorageLocationSelectorStrategy(locations);
log.info("Using storage location strategy: [%s]", this.strategy.getClass().getSimpleName());
}
- static String getSegmentDir(DataSegment segment)
+ @Override
+ public boolean canHandleSegments()
+ {
+ return !(locations == null || locations.isEmpty());
+ }
+
+ @Override
+ public List<DataSegment> getCachedSegments() throws IOException
+ {
+ if (!canHandleSegments()) {
+ throw DruidException.defensive(
+ "canHandleSegments() is false. getCachedSegments() must be invoked only when canHandleSegments() returns true."
+ );
+ }
+ final File baseDir = getInfoDir();
+
+ List<DataSegment> cachedSegments = new ArrayList<>();
+ File[] segmentsToLoad = baseDir.listFiles();
+
+ int ignored = 0;
+
+ for (int i = 0; i < segmentsToLoad.length; i++) {
+ File file = segmentsToLoad[i];
+ log.info("Loading segment cache file [%d/%d][%s].", i + 1, segmentsToLoad.length, file);
+ try {
+ final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
+
+ if (!segment.getId().toString().equals(file.getName())) {
+ log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), segment.getId());
+ ignored++;
+ } else if (isSegmentCached(segment)) {
+ cachedSegments.add(segment);
+ } else {
+ final SegmentId segmentId = segment.getId();
+ log.warn("Unable to find cache file for segment[%s]. Deleting lookup entry.", segmentId);
+ if (!removeInfoFile(segment)) {
+ log.warn(
+ "Unable to delete cache file[%s] for segment[%s].",
+ getInfoFileName(segment), segmentId);
+ }
+ }
+ }
+ catch (Exception e) {
+ log.makeAlert(e, "Failed to load segment from segmentInfo file")
+ .addData("file", file)
+ .emit();
+ }
+ }
+
+ if (ignored > 0) {
+ log.makeAlert("Ignored misnamed segment cache files on startup.")
+ .addData("numIgnored", ignored)
+ .emit();
+ }
+
+ return cachedSegments;
+ }
+
+ @Override
+ public void storeInfoFile(DataSegment segment) throws IOException
+ {
+ final File segmentInfoCacheFile = new File(getInfoDir(), segment.getId().toString());
+ if (!segmentInfoCacheFile.exists()) {
+ jsonMapper.writeValue(segmentInfoCacheFile, segment);
+ }
+ }
+
+ @Override
+ public boolean removeInfoFile(DataSegment segment) throws IOException
+ {
+ return new File(getInfoDir(), segment.getId().toString()).delete();
+ }
+
+ @Override
+ public ReferenceCountingSegment getSegment(DataSegment segment, boolean lazy, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException
+ {
+ final File segmentFiles = getSegmentFiles(segment);
+ final File factoryJson = new File(segmentFiles, "factory.json");
+ final SegmentizerFactory factory;
+
+ if (factoryJson.exists()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7378)
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -118,32 +128,158 @@
SegmentLocalCacheManager(
SegmentLoaderConfig config,
@Nonnull StorageLocationSelectorStrategy strategy,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
- this(config.toStorageLocations(), config, strategy, mapper);
+ this(config.toStorageLocations(), config, strategy, indexIO, mapper);
}
/**
* creates instance with default storage location selector strategy
*
* This ctor is mainly for test cases, including test cases in other modules
*/
- @VisibleForTesting
public SegmentLocalCacheManager(
SegmentLoaderConfig config,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
this.config = config;
+ this.indexIO = indexIO;
this.jsonMapper = mapper;
this.locations = config.toStorageLocations();
this.strategy = new LeastBytesUsedStorageLocationSelectorStrategy(locations);
log.info("Using storage location strategy: [%s]", this.strategy.getClass().getSimpleName());
}
- static String getSegmentDir(DataSegment segment)
+ @Override
+ public boolean canHandleSegments()
+ {
+ return !(locations == null || locations.isEmpty());
+ }
+
+ @Override
+ public List<DataSegment> getCachedSegments() throws IOException
+ {
+ if (!canHandleSegments()) {
+ throw DruidException.defensive(
+ "canHandleSegments() is false. getCachedSegments() must be invoked only when canHandleSegments() returns true."
+ );
+ }
+ final File baseDir = getInfoDir();
+
+ List<DataSegment> cachedSegments = new ArrayList<>();
+ File[] segmentsToLoad = baseDir.listFiles();
+
+ int ignored = 0;
+
+ for (int i = 0; i < segmentsToLoad.length; i++) {
+ File file = segmentsToLoad[i];
+ log.info("Loading segment cache file [%d/%d][%s].", i + 1, segmentsToLoad.length, file);
+ try {
+ final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
+
+ if (!segment.getId().toString().equals(file.getName())) {
+ log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), segment.getId());
+ ignored++;
+ } else if (isSegmentCached(segment)) {
+ cachedSegments.add(segment);
+ } else {
+ final SegmentId segmentId = segment.getId();
+ log.warn("Unable to find cache file for segment[%s]. Deleting lookup entry.", segmentId);
+ if (!removeInfoFile(segment)) {
+ log.warn(
+ "Unable to delete cache file[%s] for segment[%s].",
+ getInfoFileName(segment), segmentId);
+ }
+ }
+ }
+ catch (Exception e) {
+ log.makeAlert(e, "Failed to load segment from segmentInfo file")
+ .addData("file", file)
+ .emit();
+ }
+ }
+
+ if (ignored > 0) {
+ log.makeAlert("Ignored misnamed segment cache files on startup.")
+ .addData("numIgnored", ignored)
+ .emit();
+ }
+
+ return cachedSegments;
+ }
+
+ @Override
+ public void storeInfoFile(DataSegment segment) throws IOException
+ {
+ final File segmentInfoCacheFile = new File(getInfoDir(), segment.getId().toString());
+ if (!segmentInfoCacheFile.exists()) {
+ jsonMapper.writeValue(segmentInfoCacheFile, segment);
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7377)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on PR #16475:
URL: https://github.com/apache/druid/pull/16475#issuecomment-2121910215
>
> IIUC, this PR is basically doing the following:
>
> * Inject the correct value of storage locations into `SegmentLoadDropHandler`
> * Refactor and cleanup classes
>
That's about right, except that we're not injecting storage locations into `SegmentLoadDropHandler` to fix it. Instead, `SegmentLoadDropHandler` relies on `SegmentManager` and `SegmentCacheManager` to provide the needed information. With this patch, `SegmentCacheManager` essentially serves as the source of truth for low-level segment info file operations.
> Is there any other bug fix or feature included in this PR too? Just wanted to confirm before I start the actual review.
There's no other bug fix or feature in this PR. I do have another related change that touches some of this code, but given the size of this PR, I will add it separately to make reviewing easier. 🙂
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #16475:
URL: https://github.com/apache/druid/pull/16475#issuecomment-2122047299
Makes sense. Thanks for the clarification, @abhishekrb19 !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Fix task bootstrapping. (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16475:
URL: https://github.com/apache/druid/pull/16475#discussion_r1614229992
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -112,44 +123,192 @@
log.info("Size of thread pool to load segments into page cache on download [%d]",
config.getNumThreadsToLoadSegmentsIntoPageCacheOnDownload());
}
+
+ if (config.getNumThreadsToLoadSegmentsIntoPageCacheOnBootstrap() != 0) {
+ loadSegmentsIntoPageCacheOnBootstrapExec = Execs.multiThreaded(
+ config.getNumThreadsToLoadSegmentsIntoPageCacheOnBootstrap(),
+ "Load-Segments-Into-Page-Cache-On-Bootstrap-%s"
+ );
+ log.info("Size of thread pool to load segments into page cache on bootstrap [%d]",
+ config.getNumThreadsToLoadSegmentsIntoPageCacheOnBootstrap());
+ }
}
@VisibleForTesting
SegmentLocalCacheManager(
SegmentLoaderConfig config,
@Nonnull StorageLocationSelectorStrategy strategy,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
- this(config.toStorageLocations(), config, strategy, mapper);
+ this(config.toStorageLocations(), config, strategy, indexIO, mapper);
}
/**
* creates instance with default storage location selector strategy
*
* This ctor is mainly for test cases, including test cases in other modules
*/
- @VisibleForTesting
public SegmentLocalCacheManager(
SegmentLoaderConfig config,
+ IndexIO indexIO,
@Json ObjectMapper mapper
)
{
this.config = config;
+ this.indexIO = indexIO;
this.jsonMapper = mapper;
this.locations = config.toStorageLocations();
this.strategy = new LeastBytesUsedStorageLocationSelectorStrategy(locations);
log.info("Using storage location strategy: [%s]", this.strategy.getClass().getSimpleName());
}
- static String getSegmentDir(DataSegment segment)
+ @Override
+ public boolean canHandleSegments()
{
- return DataSegmentPusher.getDefaultStorageDir(segment, false);
+ return !(locations == null || locations.isEmpty());
}
@Override
- public boolean isSegmentCached(final DataSegment segment)
+ public List<DataSegment> getCachedSegments() throws IOException
+ {
+ if (!canHandleSegments()) {
+ throw DruidException.defensive(
+ "canHandleSegments() is false. getCachedSegments() must be invoked only when canHandleSegments() returns true."
+ );
+ }
+ final File baseDir = getInfoDir();
+ FileUtils.mkdirp(baseDir);
+
+ List<DataSegment> cachedSegments = new ArrayList<>();
+ File[] segmentsToLoad = baseDir.listFiles();
+
+ int ignored = 0;
+
+ for (int i = 0; i < segmentsToLoad.length; i++) {
+ File file = segmentsToLoad[i];
+ log.info("Loading segment cache file [%d/%d][%s].", i + 1, segmentsToLoad.length, file);
+ try {
+ final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
+ if (!segment.getId().toString().equals(file.getName())) {
+ log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), segment.getId());
+ ignored++;
+ } else if (isSegmentCached(segment)) {
+ cachedSegments.add(segment);
+ } else {
+ final SegmentId segmentId = segment.getId();
+ log.warn("Unable to find cache file for segment[%s]. Deleting lookup entry.", segmentId);
+ removeInfoFile(segment);
+ }
+ }
+ catch (Exception e) {
+ log.makeAlert(e, "Failed to load segment from segmentInfo file")
+ .addData("file", file)
+ .emit();
+ }
+ }
+
+ if (ignored > 0) {
+ log.makeAlert("Ignored misnamed segment cache files on startup.")
+ .addData("numIgnored", ignored)
+ .emit();
+ }
+
+ return cachedSegments;
+ }
+
+ @Override
+ public void storeInfoFile(DataSegment segment) throws IOException
+ {
+ final File infoDir = getInfoDir();
+ FileUtils.mkdirp(infoDir);
+
+ final File segmentInfoCacheFile = new File(infoDir, segment.getId().toString());
+ if (!segmentInfoCacheFile.exists()) {
+ jsonMapper.writeValue(segmentInfoCacheFile, segment);
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7396)
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -454,55 +615,58 @@
}
@Override
- public void loadSegmentIntoPageCache(DataSegment segment, ExecutorService exec)
+ public void loadSegmentIntoPageCache(DataSegment segment)
{
- ExecutorService execToUse = exec != null ? exec : loadSegmentsIntoPageCacheOnDownloadExec;
- if (execToUse == null) {
+ if (loadSegmentsIntoPageCacheOnDownloadExec == null) {
return;
}
- execToUse.submit(
- () -> {
- final ReferenceCountingLock lock = createOrGetLock(segment);
- synchronized (lock) {
- try {
- for (StorageLocation location : locations) {
- File localStorageDir = new File(location.getPath(), DataSegmentPusher.getDefaultStorageDir(segment, false));
- if (localStorageDir.exists()) {
- File baseFile = location.getPath();
- if (localStorageDir.equals(baseFile)) {
- continue;
- }
-
- log.info("Loading directory[%s] into page cache", localStorageDir);
-
- File[] children = localStorageDir.listFiles();
- if (children != null) {
- for (File child : children) {
- InputStream in = null;
- try {
- in = new FileInputStream(child);
- IOUtils.copy(in, new NullOutputStream());
-
- log.info("Loaded [%s] into page cache", child.getAbsolutePath());
- }
- catch (Exception e) {
- log.error("Failed to load [%s] into page cache, [%s]", child.getAbsolutePath(), e.getMessage());
- }
- finally {
- IOUtils.closeQuietly(in);
- }
- }
- }
+ loadSegmentsIntoPageCacheOnDownloadExec.submit(() -> loadSegmentIntoPageCacheInternal(segment));
+ }
+
+ @Override
+ public void loadSegmentIntoPageCacheOnBootstrap(DataSegment segment)
+ {
+ if (loadSegmentsIntoPageCacheOnBootstrapExec == null) {
+ return;
+ }
+ loadSegmentsIntoPageCacheOnBootstrapExec.submit(() -> loadSegmentIntoPageCacheInternal(segment));
+ }
+
+ private void loadSegmentIntoPageCacheInternal(DataSegment segment)
+ {
+ final ReferenceCountingLock lock = createOrGetLock(segment);
+ synchronized (lock) {
+ try {
+ for (StorageLocation location : locations) {
+ File localStorageDir = new File(location.getPath(), DataSegmentPusher.getDefaultStorageDir(segment, false));
+ if (localStorageDir.exists()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/7397)
##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -454,55 +615,58 @@
}
@Override
- public void loadSegmentIntoPageCache(DataSegment segment, ExecutorService exec)
+ public void loadSegmentIntoPageCache(DataSegment segment)
{
- ExecutorService execToUse = exec != null ? exec : loadSegmentsIntoPageCacheOnDownloadExec;
- if (execToUse == null) {
+ if (loadSegmentsIntoPageCacheOnDownloadExec == null) {
return;
}
- execToUse.submit(
- () -> {
- final ReferenceCountingLock lock = createOrGetLock(segment);
- synchronized (lock) {
- try {
- for (StorageLocation location : locations) {
- File localStorageDir = new File(location.getPath(), DataSegmentPusher.getDefaultStorageDir(segment, false));
- if (localStorageDir.exists()) {
- File baseFile = location.getPath();
- if (localStorageDir.equals(baseFile)) {
- continue;
- }
-
- log.info("Loading directory[%s] into page cache", localStorageDir);
-
- File[] children = localStorageDir.listFiles();
- if (children != null) {
- for (File child : children) {
- InputStream in = null;
- try {
- in = new FileInputStream(child);
- IOUtils.copy(in, new NullOutputStream());
-
- log.info("Loaded [%s] into page cache", child.getAbsolutePath());
- }
- catch (Exception e) {
- log.error("Failed to load [%s] into page cache, [%s]", child.getAbsolutePath(), e.getMessage());
- }
- finally {
- IOUtils.closeQuietly(in);
- }
- }
- }
+ loadSegmentsIntoPageCacheOnDownloadExec.submit(() -> loadSegmentIntoPageCacheInternal(segment));
+ }
+
+ @Override
+ public void loadSegmentIntoPageCacheOnBootstrap(DataSegment segment)
+ {
+ if (loadSegmentsIntoPageCacheOnBootstrapExec == null) {
+ return;
+ }
+ loadSegmentsIntoPageCacheOnBootstrapExec.submit(() -> loadSegmentIntoPageCacheInternal(segment));
+ }
+
+ private void loadSegmentIntoPageCacheInternal(DataSegment segment)
+ {
+ final ReferenceCountingLock lock = createOrGetLock(segment);
+ synchronized (lock) {
+ try {
+ for (StorageLocation location : locations) {
+ File localStorageDir = new File(location.getPath(), DataSegmentPusher.getDefaultStorageDir(segment, false));
+ if (localStorageDir.exists()) {
+ File baseFile = location.getPath();
+ if (localStorageDir.equals(baseFile)) {
+ continue;
+ }
+
+ log.info("Loading directory[%s] into page cache", localStorageDir);
+
+ File[] children = localStorageDir.listFiles();
+ if (children != null) {
+ for (File child : children) {
+ try (InputStream in = new FileInputStream(child)) {
+ IOUtils.copy(in, new NullOutputStream());
Review Comment:
## Deprecated method or constructor invocation
Invoking [NullOutputStream.NullOutputStream](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/7395)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org