forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#562] Improve logic inserting SqlMetaData data.
Create class to support to compatibility.
- Loading branch information
1 parent
8269a8f
commit fc6a68c
Showing
7 changed files
with
190 additions
and
7 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...c/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseSqlMetaDataCompatibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
.../main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseSqlMetaDataPastVersionDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters