Skip to content

Commit e017698

Browse files
neeradsomanchitdcmeehan
authored andcommitted
Node TTL Fetchers and Cluster TTL Providers
1 parent 911ec40 commit e017698

File tree

52 files changed

+2127
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2127
-13
lines changed

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@
172172
<module>presto-thrift-testing-udf-server</module>
173173
<module>presto-thrift-spec</module>
174174
<module>presto-testng-services</module>
175+
<module>presto-node-ttl-fetchers</module>
176+
<module>presto-cluster-ttl-providers</module>
175177
</modules>
176178

177179
<dependencyManagement>
@@ -233,6 +235,18 @@
233235
<version>${project.version}</version>
234236
</dependency>
235237

238+
<dependency>
239+
<groupId>com.facebook.presto</groupId>
240+
<artifactId>presto-node-ttl-fetchers</artifactId>
241+
<version>${project.version}</version>
242+
</dependency>
243+
244+
<dependency>
245+
<groupId>com.facebook.presto</groupId>
246+
<artifactId>presto-cluster-ttl-providers</artifactId>
247+
<version>${project.version}</version>
248+
</dependency>
249+
236250
<dependency>
237251
<groupId>com.facebook.presto</groupId>
238252
<artifactId>presto-array</artifactId>

presto-cluster-ttl-providers/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>presto-root</artifactId>
7+
<groupId>com.facebook.presto</groupId>
8+
<version>0.262-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>presto-cluster-ttl-providers</artifactId>
13+
<description>Presto - Cluster Ttl Providers</description>
14+
<packaging>presto-plugin</packaging>
15+
16+
<properties>
17+
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.google.guava</groupId>
23+
<artifactId>guava</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>com.google.inject</groupId>
28+
<artifactId>guice</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>com.facebook.airlift</groupId>
33+
<artifactId>configuration</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>com.facebook.airlift</groupId>
38+
<artifactId>bootstrap</artifactId>
39+
</dependency>
40+
41+
<!-- Presto SPI -->
42+
<dependency>
43+
<groupId>com.facebook.presto</groupId>
44+
<artifactId>presto-spi</artifactId>
45+
<scope>provided</scope>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>io.airlift</groupId>
50+
<artifactId>units</artifactId>
51+
<scope>provided</scope>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.facebook.presto</groupId>
56+
<artifactId>presto-common</artifactId>
57+
<scope>provided</scope>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.testng</groupId>
62+
<artifactId>testng</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
</dependencies>
66+
67+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.clusterttlproviders;
15+
16+
import com.facebook.presto.clusterttlproviders.infinite.InfiniteClusterTtlProviderFactory;
17+
import com.facebook.presto.clusterttlproviders.percentile.PercentileClusterTtlProviderFactory;
18+
import com.facebook.presto.spi.Plugin;
19+
import com.facebook.presto.spi.ttl.ClusterTtlProviderFactory;
20+
import com.google.common.collect.ImmutableList;
21+
22+
public class ClusterTtlProviderPlugin
23+
implements Plugin
24+
{
25+
@Override
26+
public Iterable<ClusterTtlProviderFactory> getClusterTtlProviderFactories()
27+
{
28+
return ImmutableList.of(new InfiniteClusterTtlProviderFactory(), new PercentileClusterTtlProviderFactory());
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.facebook.presto.clusterttlproviders.infinite;
16+
17+
import com.facebook.presto.spi.ttl.ClusterTtlProvider;
18+
import com.facebook.presto.spi.ttl.ConfidenceBasedTtlInfo;
19+
import com.facebook.presto.spi.ttl.NodeTtl;
20+
21+
import java.util.List;
22+
23+
import static com.facebook.presto.spi.ttl.ConfidenceBasedTtlInfo.getInfiniteTtl;
24+
25+
public class InfiniteClusterTtlProvider
26+
implements ClusterTtlProvider
27+
{
28+
@Override
29+
public ConfidenceBasedTtlInfo getClusterTtl(List<NodeTtl> nodeTtls)
30+
{
31+
return getInfiniteTtl();
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.clusterttlproviders.infinite;
15+
16+
import com.facebook.presto.spi.ttl.ClusterTtlProvider;
17+
import com.facebook.presto.spi.ttl.ClusterTtlProviderFactory;
18+
19+
import java.util.Map;
20+
21+
public class InfiniteClusterTtlProviderFactory
22+
implements ClusterTtlProviderFactory
23+
{
24+
@Override
25+
public String getName()
26+
{
27+
return "infinite";
28+
}
29+
30+
@Override
31+
public ClusterTtlProvider create(Map<String, String> config)
32+
{
33+
return new InfiniteClusterTtlProvider();
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.facebook.presto.clusterttlproviders.percentile;
16+
17+
import com.facebook.presto.spi.ttl.ClusterTtlProvider;
18+
import com.facebook.presto.spi.ttl.ConfidenceBasedTtlInfo;
19+
import com.facebook.presto.spi.ttl.NodeTtl;
20+
import com.google.inject.Inject;
21+
22+
import java.util.Comparator;
23+
import java.util.List;
24+
import java.util.Optional;
25+
26+
import static com.google.common.base.Preconditions.checkArgument;
27+
import static java.util.Objects.requireNonNull;
28+
import static java.util.stream.Collectors.toList;
29+
30+
public class PercentileBasedClusterTtlProvider
31+
implements ClusterTtlProvider
32+
{
33+
private final Comparator<ConfidenceBasedTtlInfo> ttlComparator = Comparator.comparing(ConfidenceBasedTtlInfo::getExpiryInstant);
34+
private final int percentile;
35+
36+
@Inject
37+
public PercentileBasedClusterTtlProvider(PercentileBasedClusterTtlProviderConfig config)
38+
{
39+
requireNonNull(config, "config is null");
40+
checkArgument(config.getPercentile() > 0, "percentile should be greater than 0");
41+
this.percentile = config.getPercentile();
42+
}
43+
44+
@Override
45+
public ConfidenceBasedTtlInfo getClusterTtl(List<NodeTtl> nodeTtls)
46+
{
47+
List<ConfidenceBasedTtlInfo> ttls = nodeTtls.stream()
48+
.map(this::getMinTtl)
49+
.filter(Optional::isPresent)
50+
.map(Optional::get)
51+
.sorted(ttlComparator)
52+
.collect(toList());
53+
54+
if (ttls.size() == 0) {
55+
return new ConfidenceBasedTtlInfo(0, 100);
56+
}
57+
58+
return ttls.get((int) Math.ceil(ttls.size() * percentile / 100.0) - 1);
59+
}
60+
61+
private Optional<ConfidenceBasedTtlInfo> getMinTtl(NodeTtl nodeTtl)
62+
{
63+
return nodeTtl.getTtlInfo().stream().min(ttlComparator);
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.clusterttlproviders.percentile;
15+
16+
import com.facebook.airlift.configuration.Config;
17+
18+
public class PercentileBasedClusterTtlProviderConfig
19+
{
20+
private int percentile = 1;
21+
22+
public int getPercentile()
23+
{
24+
return percentile;
25+
}
26+
27+
@Config("percentile")
28+
public PercentileBasedClusterTtlProviderConfig setPercentile(int percentile)
29+
{
30+
this.percentile = percentile;
31+
return this;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.clusterttlproviders.percentile;
15+
16+
import com.facebook.presto.spi.ttl.ClusterTtlProvider;
17+
import com.google.inject.Binder;
18+
import com.google.inject.Module;
19+
import com.google.inject.Scopes;
20+
21+
import static com.facebook.airlift.configuration.ConfigBinder.configBinder;
22+
23+
public class PercentileBasedClusterTtlProviderModule
24+
implements Module
25+
{
26+
@Override
27+
public void configure(Binder binder)
28+
{
29+
configBinder(binder).bindConfig(PercentileBasedClusterTtlProviderConfig.class, "cluster-ttl-provider");
30+
binder.bind(ClusterTtlProvider.class).to(PercentileBasedClusterTtlProvider.class).in(Scopes.SINGLETON);
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.clusterttlproviders.percentile;
15+
16+
import com.facebook.airlift.bootstrap.Bootstrap;
17+
import com.facebook.presto.spi.ttl.ClusterTtlProvider;
18+
import com.facebook.presto.spi.ttl.ClusterTtlProviderFactory;
19+
import com.google.inject.Injector;
20+
21+
import java.util.Map;
22+
23+
public class PercentileClusterTtlProviderFactory
24+
implements ClusterTtlProviderFactory
25+
{
26+
@Override
27+
public String getName()
28+
{
29+
return "percentile";
30+
}
31+
32+
@Override
33+
public ClusterTtlProvider create(Map<String, String> config)
34+
{
35+
try {
36+
Bootstrap app = new Bootstrap(new PercentileBasedClusterTtlProviderModule());
37+
Injector injector = app
38+
.doNotInitializeLogging()
39+
.setRequiredConfigurationProperties(config)
40+
.initialize();
41+
return injector.getInstance(ClusterTtlProvider.class);
42+
}
43+
catch (Exception e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)