#472_backport_update_hbase_1.0_api

This commit is contained in:
Woonduk Kang
2015-05-27 16:58:22 +09:00
parent edd3ae6653
commit 0d48b74f0d
5 changed files with 38 additions and 20 deletions
@@ -25,7 +25,6 @@ import com.navercorp.pinpoint.common.hbase.HBaseTables;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.hadoop.hbase.RowMapper;
@@ -50,8 +49,8 @@ public class AnnotationMapper implements RowMapper<Map<Long, List<AnnotationBo>>
Map<Long, List<AnnotationBo>> annotationList = new HashMap<Long, List<AnnotationBo>>();
for (Cell cell : rawCells) {
final byte[] bytes = cell.getRowArray();
Buffer buffer = new OffsetFixedBuffer(bytes, cell.getQualifierOffset());
Buffer buffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset());
long spanId = buffer.readLong();
if (CellUtil.matchingFamily(cell, HBaseTables.TRACES_CF_ANNOTATION)) {
@@ -55,10 +55,10 @@ public class ApiMetaDataMapper implements RowMapper<List<ApiMetaDataBo>> {
final byte[] rowKey = getOriginalKey(result.getRow());
List<ApiMetaDataBo> apiMetaDataList = new ArrayList<ApiMetaDataBo>();
Cell[] rawCells = result.rawCells();
for (Cell cell : result.rawCells()) {
ApiMetaDataBo apiMetaDataBo = new ApiMetaDataBo();
apiMetaDataBo.readRowKey(rowKey);
byte[] qualifier = CellUtil.cloneQualifier(cell);
Buffer buffer = new FixedBuffer(qualifier);
String apiInfo = buffer.readPrefixedString();
@@ -17,11 +17,10 @@
package com.navercorp.pinpoint.web.mapper;
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.buffer.FixedBuffer;
import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer;
import com.navercorp.pinpoint.web.service.map.AcceptApplication;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +50,7 @@ public class HostApplicationMapperVer2 implements RowMapper<List<AcceptApplicati
final List<AcceptApplication> acceptApplicationList = new ArrayList<AcceptApplication>(result.size());
for (Cell cell : result.rawCells()) {
AcceptApplication acceptedApplication = createAcceptedApplication(CellUtil.cloneQualifier(cell));
AcceptApplication acceptedApplication = createAcceptedApplication(cell);
acceptApplicationList.add(acceptedApplication);
}
return acceptApplicationList;
@@ -68,8 +67,8 @@ public class HostApplicationMapperVer2 implements RowMapper<List<AcceptApplicati
// }
// }
private AcceptApplication createAcceptedApplication(byte[] qualifier) {
Buffer reader = new FixedBuffer(qualifier);
private AcceptApplication createAcceptedApplication(Cell cell) {
Buffer reader = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset());
String host = reader.readPrefixedString();
String bindApplicationName = reader.readPrefixedString();
short bindServiceType = reader.readShort();
@@ -27,40 +27,52 @@ import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.hadoop.hbase.RowMapper;
import org.springframework.stereotype.Component;
import java.util.Arrays;
/**
* @author emeroad
*/
@Component
public class ResponseTimeMapper implements RowMapper<ResponseTime> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public ResponseTime mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return null;
}
final byte[] rowKey = result.getRow();
ResponseTime responseTime = createResponseTime(rowKey);
for (Cell cell : result.rawCells()) {
if (!CellUtil.matchingFamily(cell, HBaseTables.MAP_STATISTICS_SELF_CF_COUNTER)) {
continue;
if (CellUtil.matchingFamily(cell, HBaseTables.MAP_STATISTICS_SELF_CF_COUNTER)) {
recordColumn(responseTime, cell);
}
byte[] qualifier = CellUtil.cloneQualifier(cell);
recordColumn(responseTime, qualifier, cell.getValueArray(), cell.getValueOffset());
if (logger.isDebugEnabled()) {
logger.debug("unknown column family:{}", Arrays.toString(CellUtil.cloneFamily(cell)));
}
}
return responseTime;
}
void recordColumn(ResponseTime responseTime, byte[] qualifier, byte[] value, int valueOffset) {
short slotNumber = Bytes.toShort(qualifier);
void recordColumn(ResponseTime responseTime, Cell cell) {
final byte[] qArray = cell.getQualifierArray();
final int qOffset = cell.getQualifierOffset();
short slotNumber = Bytes.toShort(qArray, qOffset);
// agentId should be added as data.
String agentId = Bytes.toString(qualifier, BytesUtils.SHORT_BYTE_LENGTH, qualifier.length - BytesUtils.SHORT_BYTE_LENGTH);
long count = Bytes.toLong(value, valueOffset);
String agentId = Bytes.toString(qArray, qOffset + BytesUtils.SHORT_BYTE_LENGTH, cell.getQualifierLength() - BytesUtils.SHORT_BYTE_LENGTH);
long count = Bytes.toLong(cell.getValueArray(), cell.getValueOffset());
responseTime.addResponseTime(agentId, slotNumber, count);
}
@@ -26,6 +26,10 @@ import com.navercorp.pinpoint.web.vo.ResponseTime;
import junit.framework.Assert;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
@@ -36,16 +40,20 @@ public class ResponseTimeMapperTest {
@Test
public void testResponseTimeMapperTest() throws Exception {
ResponseTimeMapper responseTimeMapper = new ResponseTimeMapper();
ResponseTime responseTime = new ResponseTime("applicaionName", ServiceType.TOMCAT.getCode(), System.currentTimeMillis());
Buffer buffer = new AutomaticBuffer();
HistogramSlot histogramSlot = ServiceType.TOMCAT.getHistogramSchema().findHistogramSlot(1000);
short histogramSlotTime = histogramSlot.getSlotTime();
buffer.put(histogramSlotTime);
buffer.put(Bytes.toBytes("agent"));
byte[] bufferArray = buffer.getBuffer();
byte[] valueArray = Bytes.toBytes(1L);
responseTimeMapper.recordColumn(responseTime, buffer.getBuffer(), Bytes.toBytes(1L), 0);
Cell mockCell = CellUtil.createCell(HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, bufferArray, HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), valueArray);
ResponseTimeMapper responseTimeMapper = new ResponseTimeMapper();
ResponseTime responseTime = new ResponseTime("applicationName", ServiceType.TOMCAT.getCode(), System.currentTimeMillis());
responseTimeMapper.recordColumn(responseTime, mockCell);
Histogram agentHistogram = responseTime.findHistogram("agent");
long fastCount = agentHistogram.getFastCount();