[
https://issues.apache.org/jira/browse/HBASE-17872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15954963#comment-15954963
]
Chia-Ping Tsai commented on HBASE-17872:
----------------------------------------
The MemStoreLABImpl may clone the different cells (impl by ByteBufferKeyValue)
into same buffer concurrently, so these ByteBufferKeyValues will call the
ByteBufferUtils.copyFromBufferToBuffer concurrently.
{noformat}
public static Cell copyCellTo(Cell cell, ByteBuffer buf, int offset, int len)
{
int tagsLen = cell.getTagsLength();
if (cell instanceof ExtendedCell) {
((ExtendedCell) cell).write(buf, offset);
} else {
// Normally all Cell impls within Server will be of type ExtendedCell.
Just considering the
// other case also. The data fragments within Cell is copied into buf as
in KeyValue
// serialization format only.
KeyValueUtil.appendTo(cell, buf, offset, true);
}
//...
}
{noformat}
{noformat}
@Override
public void write(ByteBuffer buf, int offset) {
ByteBufferUtils.copyFromBufferToBuffer(this.buf, buf, this.offset, offset,
this.length);
}
{noformat}
> Make ByteBufferUtils thread-safe
> --------------------------------
>
> Key: HBASE-17872
> URL: https://issues.apache.org/jira/browse/HBASE-17872
> Project: HBase
> Issue Type: Bug
> Reporter: Chia-Ping Tsai
> Assignee: Chia-Ping Tsai
> Priority: Critical
>
> A case is shown below.
> We will get the wrong position of buffer in multithreaded environment, so the
> method makes the invalid cell in MSLAB.
> {noformat}
> public static int copyFromBufferToBuffer(ByteBuffer in, ByteBuffer out, int
> sourceOffset,
> int destinationOffset, int length) {
> if (in.hasArray() && out.hasArray()) {
> // ...
> } else if (UNSAFE_AVAIL) {
> // ...
> } else {
> int outOldPos = out.position();
> out.position(destinationOffset);
> ByteBuffer inDup = in.duplicate();
> inDup.position(sourceOffset).limit(sourceOffset + length);
> out.put(inDup);
> out.position(outOldPos);
> }
> return destinationOffset + length;
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)