mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-25 12:46:21 +10:00
[강운덕] [LUCYSUS-1744] flowchart의 traceIndex 조회 로직 최적화 120ms에서 17ms정도로 성능향상이 있는것으로 보임. 로직 최적화가 아니라 cache size때문에 그럴수도 있음.
hbasetemplate2에 multi scan관련 api를 추가함. git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-commons/trunk@783 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -3,7 +3,9 @@ package com.profiler.common.hbase;
|
||||
import org.apache.hadoop.hbase.client.Delete;
|
||||
import org.apache.hadoop.hbase.client.Get;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.hadoop.hbase.client.Scan;
|
||||
import org.springframework.data.hadoop.hbase.HbaseOperations;
|
||||
import org.springframework.data.hadoop.hbase.ResultsExtractor;
|
||||
import org.springframework.data.hadoop.hbase.RowMapper;
|
||||
|
||||
import java.util.List;
|
||||
@@ -63,4 +65,8 @@ public interface HbaseOperations2 extends HbaseOperations {
|
||||
void delete(String tableName, final Delete delete);
|
||||
|
||||
void delete(String tableName, final List<Delete> deletes);
|
||||
|
||||
<T> List<T> find(String tableName, final List<Scan> scans, final ResultsExtractor<T> action);
|
||||
|
||||
<T> List<List<T>> find(String tableName, final List<Scan> scans, final RowMapper<T> action);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.profiler.common.hbase;
|
||||
|
||||
import org.apache.hadoop.hbase.client.*;
|
||||
import org.springframework.data.hadoop.hbase.HbaseTemplate;
|
||||
import org.springframework.data.hadoop.hbase.ResultsExtractor;
|
||||
import org.springframework.data.hadoop.hbase.RowMapper;
|
||||
import org.springframework.data.hadoop.hbase.TableCallback;
|
||||
|
||||
@@ -12,7 +13,6 @@ import java.util.List;
|
||||
*
|
||||
*/
|
||||
public class HbaseTemplate2 extends HbaseTemplate implements HbaseOperations2 {
|
||||
// private HTablePool tablePool;
|
||||
|
||||
@Override
|
||||
public <T> T get(String tableName, byte[] rowName, RowMapper<T> mapper) {
|
||||
@@ -145,4 +145,28 @@ public class HbaseTemplate2 extends HbaseTemplate implements HbaseOperations2 {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> find(String tableName, final List<Scan> scans, final ResultsExtractor<T> action) {
|
||||
return execute(tableName, new TableCallback<List<T>>() {
|
||||
@Override
|
||||
public List<T> doInTable(HTable htable) throws Throwable {
|
||||
List<T> result = new ArrayList<T>(scans.size());
|
||||
for (Scan scan : scans) {
|
||||
ResultScanner scanner = htable.getScanner(scan);
|
||||
try {
|
||||
T t = action.extractData(scanner);
|
||||
result.add(t);
|
||||
} finally {
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<List<T>> find(String tableName, List<Scan> scans, RowMapper<T> action) {
|
||||
return find(tableName, scans, new RowMapperResultsExtractor<T>(action));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.profiler.common.hbase;
|
||||
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||
import org.springframework.data.hadoop.hbase.ResultsExtractor;
|
||||
import org.springframework.data.hadoop.hbase.RowMapper;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* spring꺼가 package라서 그냥 복사해옴.
|
||||
* Adapter encapsulating the RowMapper callback.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class RowMapperResultsExtractor<T> implements ResultsExtractor<List<T>> {
|
||||
|
||||
private final RowMapper<T> rowMapper;
|
||||
|
||||
/**
|
||||
* Create a new RowMapperResultSetExtractor.
|
||||
*
|
||||
* @param rowMapper the RowMapper which creates an object for each row
|
||||
*/
|
||||
public RowMapperResultsExtractor(RowMapper<T> rowMapper) {
|
||||
Assert.notNull(rowMapper, "RowMapper is required");
|
||||
this.rowMapper = rowMapper;
|
||||
}
|
||||
|
||||
public List<T> extractData(ResultScanner results) throws Exception {
|
||||
List<T> rs = new ArrayList<T>();
|
||||
int rowNum = 0;
|
||||
for (Result result : results) {
|
||||
rs.add(this.rowMapper.mapRow(result, rowNum++));
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.profiler.common.util;
|
||||
|
||||
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class BytesUtils {
|
||||
|
||||
public static byte[] longLongToBytes(long value1, long value2) {
|
||||
@@ -132,4 +134,16 @@ public class BytesUtils {
|
||||
buf[14] = (byte) (value >> 8);
|
||||
buf[15] = (byte) (value);
|
||||
}
|
||||
|
||||
public static byte[] add(String prefix, long postfix) {
|
||||
byte[] agentByte = Bytes.toBytes(prefix);
|
||||
return add(agentByte, postfix);
|
||||
}
|
||||
|
||||
public static byte[] add(byte[] preFix, long fostfix) {
|
||||
byte[] buf = new byte[preFix.length + 8];
|
||||
System.arraycopy(preFix, 0, buf, 0, preFix.length);
|
||||
writeLong(fostfix, buf, preFix.length);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user