Skip to content

Commit

Permalink
[#9176] Improved code so that connection object of pinot is reused
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Sep 13, 2022
1 parent d745085 commit 0f4ecb7
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2022 NAVER Corp.
*
* Licensed 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 com.navercorp.pinpoint.metric.common.pinot;

import com.navercorp.pinpoint.metric.web.mybatis.PinotConnectionDelegator;
import org.apache.pinot.client.PinotDriver;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;

/**
* @author minwoo.jung
*/
public class PinpointPinotDriver implements Driver {

private final PinotDriver pinotDriver = new PinotDriver();
private final Object connectionMonitor = new Object();
private Connection connection;

@Override
public Connection connect(String url, Properties info) throws SQLException {
synchronized(this.connectionMonitor) {
if (this.connection == null || this.connection.isClosed()) {
initConnection(url, info);
}

return this.connection;
}
}

private Connection initConnection(String url, Properties info) throws SQLException {
Connection connection = pinotDriver.connect(url, info);
this.connection = new PinotConnectionDelegator(connection);
return connection;
}

@Override
public boolean acceptsURL(String url) throws SQLException {
return pinotDriver.acceptsURL(url);
}

@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
return pinotDriver.getPropertyInfo(url, info);
}

@Override
public int getMajorVersion() {
return pinotDriver.getMajorVersion();
}

@Override
public int getMinorVersion() {
return pinotDriver.getMinorVersion();
}

@Override
public boolean jdbcCompliant() {
return pinotDriver.jdbcCompliant();
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return pinotDriver.getParentLogger();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/**
* @author Hyunjoon Cho
*/
@Deprecated
public class DataSourceDelegator implements DataSource {

private final DataSource delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void rollback() throws SQLException {

@Override
public void close() throws SQLException {
delegate.close();
// delegate.close();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="pinotDataSource"
class="com.navercorp.pinpoint.metric.web.mybatis.DataSourceDelegator">
<constructor-arg index="0" ref="originalPinotDataSource"/>
</bean>

<bean id="originalPinotDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${pinpoint.pinot.jdbc.driverClassName}" />
class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="${pinpoint.pinot.jdbc.driverClassName}" />
<property name="url" value="${pinpoint.pinot.jdbc.url}" />
<property name="username" value="${pinpoint.pinot.jdbc.username}" />
<property name="password" value="${pinpoint.pinot.jdbc.password}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pinpoint.pinot.jdbc.driverClassName=org.apache.pinot.client.PinotDriver
pinpoint.pinot.jdbc.driverClassName=com.navercorp.pinpoint.metric.common.pinot.PinpointPinotDriver
pinpoint.pinot.jdbc.url=jdbc:pinot://localhost:9000
pinpoint.pinot.jdbc.username=userId
pinpoint.pinot.jdbc.password=password
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pinpoint.pinot.jdbc.driverClassName=org.apache.pinot.client.PinotDriver
pinpoint.pinot.jdbc.driverClassName=com.navercorp.pinpoint.metric.common.pinot.PinpointPinotDriver
pinpoint.pinot.jdbc.url=jdbc:pinot://localhost:9000
pinpoint.pinot.jdbc.username=userId
pinpoint.pinot.jdbc.password=password

0 comments on commit 0f4ecb7

Please sign in to comment.