forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add RowKeyEncoder & RowKeyDecoder - add testcase
- Loading branch information
Showing
21 changed files
with
513 additions
and
109 deletions.
There are no files selected for viewing
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
10 changes: 10 additions & 0 deletions
10
...erver/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/RowKeyDecoder.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,10 @@ | ||
package com.navercorp.pinpoint.common.server.bo.serializer; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public interface RowKeyDecoder<V> { | ||
|
||
V decodeRowKey(byte[] rowkey); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...erver/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/RowKeyEncoder.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,10 @@ | ||
package com.navercorp.pinpoint.common.server.bo.serializer; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public interface RowKeyEncoder<V> { | ||
|
||
byte[] encodeRowKey(V value); | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...ava/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/TraceRowKeyDecoderV1.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,47 @@ | ||
package com.navercorp.pinpoint.common.server.bo.serializer.trace.v1; | ||
|
||
import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyDecoder; | ||
import com.navercorp.pinpoint.common.util.BytesUtils; | ||
import com.navercorp.pinpoint.common.util.TransactionId; | ||
import com.sematext.hbase.wd.AbstractRowKeyDistributor; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
@Component | ||
public class TraceRowKeyDecoderV1 implements RowKeyDecoder<TransactionId> { | ||
|
||
public static final int AGENT_NAME_MAX_LEN = TraceRowKeyEncoderV1.AGENT_NAME_MAX_LEN; | ||
public static final int DISTRIBUTE_HASH_SIZE = TraceRowKeyEncoderV1.DISTRIBUTE_HASH_SIZE; | ||
|
||
private final int distributeHashSize; | ||
|
||
|
||
public TraceRowKeyDecoderV1() { | ||
this(DISTRIBUTE_HASH_SIZE); | ||
} | ||
|
||
public TraceRowKeyDecoderV1(int distributeHashSize) { | ||
this.distributeHashSize = distributeHashSize; | ||
} | ||
|
||
@Override | ||
public TransactionId decodeRowKey(byte[] rowkey) { | ||
if (rowkey == null) { | ||
throw new NullPointerException("rowkey must not be null"); | ||
} | ||
|
||
return readTransactionId(rowkey, distributeHashSize); | ||
} | ||
|
||
private TransactionId readTransactionId(byte[] rowKey, int offset) { | ||
|
||
String agentId = BytesUtils.toStringAndRightTrim(rowKey, offset, AGENT_NAME_MAX_LEN); | ||
long agentStartTime = BytesUtils.bytesToLong(rowKey, offset + AGENT_NAME_MAX_LEN); | ||
long transactionSequence = BytesUtils.bytesToLong(rowKey, offset + BytesUtils.LONG_BYTE_LENGTH + AGENT_NAME_MAX_LEN); | ||
|
||
return new TransactionId(agentId, agentStartTime, transactionSequence); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ava/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/TraceRowKeyEncoderV1.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,45 @@ | ||
package com.navercorp.pinpoint.common.server.bo.serializer.trace.v1; | ||
|
||
import com.navercorp.pinpoint.common.PinpointConstants; | ||
import com.navercorp.pinpoint.common.server.bo.BasicSpan; | ||
import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyEncoder; | ||
import com.navercorp.pinpoint.common.util.BytesUtils; | ||
import com.sematext.hbase.wd.AbstractRowKeyDistributor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
@Component | ||
public class TraceRowKeyEncoderV1 implements RowKeyEncoder<BasicSpan> { | ||
|
||
public static final int AGENT_NAME_MAX_LEN = PinpointConstants.AGENT_NAME_MAX_LEN; | ||
public static final int DISTRIBUTE_HASH_SIZE = 1; | ||
|
||
private final AbstractRowKeyDistributor rowKeyDistributor; | ||
|
||
|
||
@Autowired | ||
public TraceRowKeyEncoderV1(@Qualifier("traceDistributor") AbstractRowKeyDistributor rowKeyDistributor) { | ||
if (rowKeyDistributor == null) { | ||
throw new NullPointerException("rowKeyDistributor must not be null"); | ||
} | ||
|
||
this.rowKeyDistributor = rowKeyDistributor; | ||
} | ||
|
||
public byte[] encodeRowKey(BasicSpan basicSpan) { | ||
if (basicSpan == null) { | ||
throw new NullPointerException("basicSpan must not be null"); | ||
} | ||
|
||
byte[] rowKey = BytesUtils.stringLongLongToBytes(basicSpan.getTraceAgentId(), AGENT_NAME_MAX_LEN, basicSpan.getTraceAgentStartTime(), basicSpan.getTraceTransactionSequence()); | ||
return wrapDistributedRowKey(rowKey); | ||
} | ||
|
||
private byte[] wrapDistributedRowKey(byte[] rowKey) { | ||
return rowKeyDistributor.getDistributedKey(rowKey); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...navercorp/pinpoint/common/server/bo/serializer/trace/v1/TransactionIdRowKeyEncoderV1.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,46 @@ | ||
package com.navercorp.pinpoint.common.server.bo.serializer.trace.v1; | ||
|
||
import com.navercorp.pinpoint.common.PinpointConstants; | ||
import com.navercorp.pinpoint.common.server.bo.BasicSpan; | ||
import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyEncoder; | ||
import com.navercorp.pinpoint.common.util.BytesUtils; | ||
import com.navercorp.pinpoint.common.util.TransactionId; | ||
import com.sematext.hbase.wd.AbstractRowKeyDistributor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
@Component | ||
public class TransactionIdRowKeyEncoderV1 implements RowKeyEncoder<TransactionId> { | ||
|
||
public static final int AGENT_NAME_MAX_LEN = TraceRowKeyEncoderV1.AGENT_NAME_MAX_LEN; | ||
public static final int DISTRIBUTE_HASH_SIZE = TraceRowKeyEncoderV1.DISTRIBUTE_HASH_SIZE; | ||
|
||
private final AbstractRowKeyDistributor rowKeyDistributor; | ||
|
||
@Autowired | ||
public TransactionIdRowKeyEncoderV1(@Qualifier("traceDistributor") AbstractRowKeyDistributor rowKeyDistributor) { | ||
if (rowKeyDistributor == null) { | ||
throw new NullPointerException("rowKeyDistributor must not be null"); | ||
} | ||
|
||
this.rowKeyDistributor = rowKeyDistributor; | ||
} | ||
|
||
public byte[] encodeRowKey(TransactionId transactionId) { | ||
if (transactionId == null) { | ||
throw new NullPointerException("transactionId must not be null"); | ||
} | ||
|
||
byte[] rowKey = BytesUtils.stringLongLongToBytes(transactionId.getAgentId(), AGENT_NAME_MAX_LEN, transactionId.getAgentStartTime(), transactionId.getTransactionSequence()); | ||
return wrapDistributedRowKey(rowKey); | ||
} | ||
|
||
private byte[] wrapDistributedRowKey(byte[] rowKey) { | ||
return rowKeyDistributor.getDistributedKey(rowKey); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...ava/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/TraceRowKeyDecoderV2.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,51 @@ | ||
package com.navercorp.pinpoint.common.server.bo.serializer.trace.v2; | ||
|
||
import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyDecoder; | ||
import com.navercorp.pinpoint.common.util.BytesUtils; | ||
import com.navercorp.pinpoint.common.util.TransactionId; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
@Component | ||
public class TraceRowKeyDecoderV2 implements RowKeyDecoder<TransactionId> { | ||
|
||
public static final int AGENT_NAME_MAX_LEN = TraceRowKeyEncoderV2.AGENT_NAME_MAX_LEN; | ||
public static final int DISTRIBUTE_HASH_SIZE = TraceRowKeyEncoderV2.DISTRIBUTE_HASH_SIZE; | ||
|
||
private final int distributeHashSize; | ||
|
||
|
||
public TraceRowKeyDecoderV2() { | ||
this(DISTRIBUTE_HASH_SIZE); | ||
} | ||
|
||
public TraceRowKeyDecoderV2(int distributeHashSize) { | ||
this.distributeHashSize = distributeHashSize; | ||
} | ||
|
||
|
||
@Override | ||
public TransactionId decodeRowKey(byte[] rowkey) { | ||
if (rowkey == null) { | ||
throw new NullPointerException("rowkey must not be null"); | ||
} | ||
|
||
return readTransactionId(rowkey, distributeHashSize); | ||
} | ||
|
||
private TransactionId readTransactionId(byte[] rowKey, int offset) { | ||
|
||
String agentId = BytesUtils.toStringAndRightTrim(rowKey, offset, AGENT_NAME_MAX_LEN); | ||
long agentStartTime = BytesUtils.bytesToLong(rowKey, offset + AGENT_NAME_MAX_LEN); | ||
long transactionSequence = BytesUtils.bytesToLong(rowKey, offset + BytesUtils.LONG_BYTE_LENGTH + AGENT_NAME_MAX_LEN); | ||
|
||
return new TransactionId(agentId, agentStartTime, transactionSequence); | ||
} | ||
|
||
// for test | ||
public TransactionId readTransactionId(byte[] rowKey) { | ||
return readTransactionId(rowKey, 0); | ||
} | ||
} |
Oops, something went wrong.