mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 16:28:48 +10:00
[#562] Improve logic inserting SqlMetaData data.
Create class to support to compatibility.
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2014 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.collector.dao.hbase;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.navercorp.pinpoint.collector.dao.SqlMetaDataDao;
|
||||
import com.navercorp.pinpoint.common.hbase.HBaseAdminTemplate;
|
||||
import com.navercorp.pinpoint.common.hbase.HBaseTables;
|
||||
import com.navercorp.pinpoint.thrift.dto.TSqlMetaData;
|
||||
|
||||
/**
|
||||
* @author minwoo.jung
|
||||
*/
|
||||
//@Repository
|
||||
public class HbaseSqlMetaDataCompatibility implements SqlMetaDataDao {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final boolean SQL_METADATA_VER2_EXISTED;
|
||||
|
||||
@Autowired
|
||||
private SqlMetaDataDao hbaseSqlMetaDataPastVersionDao;
|
||||
|
||||
@Autowired
|
||||
private SqlMetaDataDao hbaseSqlMetaDataDao;
|
||||
|
||||
@Autowired
|
||||
public HbaseSqlMetaDataCompatibility(HBaseAdminTemplate hBaseAdminTemplate) {
|
||||
SQL_METADATA_VER2_EXISTED = hBaseAdminTemplate.tableExists(HBaseTables.SQL_METADATA_VER2);
|
||||
|
||||
if (SQL_METADATA_VER2_EXISTED == false) {
|
||||
logger.warn("Please create 'SqlMetaData_Ver2' table.");
|
||||
}
|
||||
|
||||
if(hBaseAdminTemplate.tableExists(HBaseTables.SQL_METADATA) == false && SQL_METADATA_VER2_EXISTED == false) {
|
||||
throw new RuntimeException("Please check for sqlMetaData_ver2 table in HBase. Need to create 'SqlMetaData_Ver2' table.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(TSqlMetaData sqlMetaData) {
|
||||
if (SQL_METADATA_VER2_EXISTED) {
|
||||
hbaseSqlMetaDataDao.insert(sqlMetaData);
|
||||
} else {
|
||||
hbaseSqlMetaDataPastVersionDao.insert(sqlMetaData);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHbaseSqlMetaDataPastVersionDao(SqlMetaDataDao hbaseSqlMetaDataPastVersionDao) {
|
||||
this.hbaseSqlMetaDataPastVersionDao = hbaseSqlMetaDataPastVersionDao;
|
||||
}
|
||||
|
||||
public void setHbaseSqlMetaDataDao(SqlMetaDataDao hbaseSqlMetaDataDao) {
|
||||
this.hbaseSqlMetaDataDao = hbaseSqlMetaDataDao;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -32,9 +32,9 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author
|
||||
*/
|
||||
@Repository
|
||||
//@Repository
|
||||
public class HbaseSqlMetaDataDao implements SqlMetaDataDao {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@@ -43,7 +43,7 @@ public class HbaseSqlMetaDataDao implements SqlMetaDataDao {
|
||||
private HbaseOperations2 hbaseTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("metadataRowKeyDistributor")
|
||||
@Qualifier("metadataRowKeyDistributor2")
|
||||
private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix;
|
||||
|
||||
@Override
|
||||
@@ -64,9 +64,9 @@ public class HbaseSqlMetaDataDao implements SqlMetaDataDao {
|
||||
byte[] sqlBytes = Bytes.toBytes(sql);
|
||||
|
||||
// added sqlBytes into qualifier intentionally not to conflict hashcode
|
||||
put.addColumn(HBaseTables.SQL_METADATA_CF_SQL, sqlBytes, null);
|
||||
put.addColumn(HBaseTables.SQL_METADATA_VER2_CF_SQL, sqlBytes, null);
|
||||
|
||||
hbaseTemplate.put(HBaseTables.SQL_METADATA, put);
|
||||
hbaseTemplate.put(HBaseTables.SQL_METADATA_VER2, put);
|
||||
}
|
||||
|
||||
private byte[] getDistributedKey(byte[] rowKey) {
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2014 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.collector.dao.hbase;
|
||||
|
||||
import com.navercorp.pinpoint.collector.dao.SqlMetaDataDao;
|
||||
import com.navercorp.pinpoint.common.bo.SqlMetaDataBo;
|
||||
import com.navercorp.pinpoint.common.hbase.HBaseTables;
|
||||
import com.navercorp.pinpoint.common.hbase.HbaseOperations2;
|
||||
import com.navercorp.pinpoint.thrift.dto.TSqlMetaData;
|
||||
import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix;
|
||||
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
//@Repository
|
||||
public class HbaseSqlMetaDataPastVersionDao implements SqlMetaDataDao {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private HbaseOperations2 hbaseTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("metadataRowKeyDistributor")
|
||||
private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix;
|
||||
|
||||
@Override
|
||||
public void insert(TSqlMetaData sqlMetaData) {
|
||||
if (sqlMetaData == null) {
|
||||
throw new NullPointerException("sqlMetaData must not be null");
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("insert:{}", sqlMetaData);
|
||||
}
|
||||
|
||||
SqlMetaDataBo sqlMetaDataBo = new SqlMetaDataBo(sqlMetaData.getAgentId(), sqlMetaData.getAgentStartTime(), sqlMetaData.getSqlId());
|
||||
final byte[] rowKey = getDistributedKey(sqlMetaDataBo.toRowKey());
|
||||
|
||||
|
||||
Put put = new Put(rowKey);
|
||||
String sql = sqlMetaData.getSql();
|
||||
byte[] sqlBytes = Bytes.toBytes(sql);
|
||||
|
||||
// added sqlBytes into qualifier intentionally not to conflict hashcode
|
||||
put.addColumn(HBaseTables.SQL_METADATA_CF_SQL, sqlBytes, null);
|
||||
|
||||
hbaseTemplate.put(HBaseTables.SQL_METADATA, put);
|
||||
}
|
||||
|
||||
private byte[] getDistributedKey(byte[] rowKey) {
|
||||
return rowKeyDistributorByHashPrefix.getDistributedKey(rowKey);
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -24,16 +24,17 @@ import org.apache.thrift.TBase;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Service
|
||||
//@Service
|
||||
public class SqlMetaDataHandler implements RequestResponseHandler {
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
// @Autowired
|
||||
private SqlMetaDataDao sqlMetaDataDao;
|
||||
|
||||
@Override
|
||||
@@ -60,4 +61,8 @@ public class SqlMetaDataHandler implements RequestResponseHandler {
|
||||
}
|
||||
return new TResult(true);
|
||||
}
|
||||
|
||||
public void setSqlMetaDataDao(SqlMetaDataDao sqlMetaDataDao) {
|
||||
this.sqlMetaDataDao = sqlMetaDataDao;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,4 +134,15 @@
|
||||
<constructor-arg ref="typeLoaderService"/>
|
||||
</bean>
|
||||
|
||||
<bean id="sqlMetaDataHandler" class="com.navercorp.pinpoint.collector.handler.SqlMetaDataHandler">
|
||||
<property name="sqlMetaDataDao" ref="hbaseSqlMetaDataCompatibility"/>
|
||||
</bean>
|
||||
|
||||
<bean id="hbaseSqlMetaDataCompatibility" class="com.navercorp.pinpoint.collector.dao.hbase.HbaseSqlMetaDataCompatibility">
|
||||
<property name="hbaseSqlMetaDataDao" ref="hbaseSqlMetaDataDao"/>
|
||||
<property name="hbaseSqlMetaDataPastVersionDao" ref="hbaseSqlMetaDataPastVersionDao"/>
|
||||
</bean>
|
||||
|
||||
<bean id="hbaseSqlMetaDataPastVersionDao" class="com.navercorp.pinpoint.collector.dao.hbase.HbaseSqlMetaDataPastVersionDao"/>
|
||||
<bean id="hbaseSqlMetaDataDao" class="com.navercorp.pinpoint.collector.dao.hbase.HbaseSqlMetaDataDao"/>
|
||||
</beans>
|
||||
@@ -47,6 +47,10 @@
|
||||
<property name="configuration" ref="hbaseConfiguration"/>
|
||||
<property name="tableFactory" ref="connectionFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="hBaseAdminTemplate" class="com.navercorp.pinpoint.common.hbase.HBaseAdminTemplate" destroy-method="close">
|
||||
<constructor-arg ref="hbaseConfiguration" index="0"></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="applicationTraceIndexDistributor" class="com.sematext.hbase.wd.RowKeyDistributorByHashPrefix">
|
||||
<constructor-arg ref="applicationTraceIndex"/>
|
||||
@@ -87,6 +91,16 @@
|
||||
<constructor-arg type="int" value="32"/>
|
||||
<constructor-arg type="int" value="8"/>
|
||||
</bean>
|
||||
|
||||
<bean id="metadataRowKeyDistributor2" class="com.sematext.hbase.wd.RowKeyDistributorByHashPrefix">
|
||||
<constructor-arg ref="metadataRangeHasher2"/>
|
||||
</bean>
|
||||
|
||||
<bean id="metadataRangeHasher2" class="com.navercorp.pinpoint.common.hbase.distributor.RangeOneByteSimpleHash">
|
||||
<constructor-arg type="int" value="0"/>
|
||||
<constructor-arg type="int" value="36"/>
|
||||
<constructor-arg type="int" value="32"/>
|
||||
</bean>
|
||||
|
||||
<bean id="acceptApplicationRowKeyDistributor" class="com.sematext.hbase.wd.RowKeyDistributorByHashPrefix">
|
||||
<constructor-arg ref="acceptApplicationHasher"/>
|
||||
|
||||
Reference in New Issue
Block a user