[
https://issues.apache.org/jira/browse/HBASE-10254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13859064#comment-13859064
]
James Taylor commented on HBASE-10254:
--------------------------------------
Here's the simplified version of Increment. How will this perform relative to
HRegion.increment() ? If all increments are done through my new coprocessor,
are there edge cases that aren't covered
package com.salesforce.phoenix.coprocessor;
import java.io.IOException;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.coprocessor.BaseEndpointCoprocessor;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.regionserver.HRegion;
import com.salesforce.phoenix.schema.PDataType;
import com.salesforce.phoenix.util.KeyValueUtil;
public class SequenceEndpointImpl extends BaseEndpointCoprocessor {
@Override
public RegionCoprocessorEnvironment getEnvironment() {
return (RegionCoprocessorEnvironment)super.getEnvironment();
}
public Long incrementColumnValue(byte[] row, byte[] family, byte[]
qualifier,
long amount, TimeRange tr, long incrementTimestamp, boolean
writeToWAL) throws IOException {
RegionCoprocessorEnvironment env = this.getEnvironment();
HRegion region = env.getRegion();
region.startRegionOperation();
try {
Integer lid = region.getLock(null, row, true);
try {
Get get = new Get(row);
get.setTimeRange(tr.getMin(), tr.getMax());
get.addColumn(family, qualifier);
Result result = region.get(get);
if (result.isEmpty()) {
return null;
}
KeyValue existingKV = result.raw()[0];
long value =
PDataType.LONG.getCodec().decodeLong(existingKV.getBuffer(),
existingKV.getValueOffset(), null);
value += amount;
byte[] valueBuffer = new byte[PDataType.LONG.getByteSize()];
PDataType.LONG.getCodec().encodeLong(value, valueBuffer, 0);
Put put = new Put(row);
KeyValue newKV = KeyValueUtil.newKeyValue(row, family,
qualifier, incrementTimestamp, valueBuffer);
put.add(newKV);
region.put(put, writeToWAL);
return value;
} finally {
region.releaseRowLock(lid);
}
} finally {
region.closeRegionOperation();
}
}
}
> Optionally return null when attempting to Increment KeyValue that doesn't
> exist
> -------------------------------------------------------------------------------
>
> Key: HBASE-10254
> URL: https://issues.apache.org/jira/browse/HBASE-10254
> Project: HBase
> Issue Type: Bug
> Reporter: James Taylor
>
> Instead of creating a new KeyValue starting from 0 when an Increment is done
> on a row that doesn't exist, we should optionally return null. A Get is
> already being done, so it's easy to detect this case. This can be done in a
> backward compatible manner if the behavior is done optionally. In addition,
> Increment does not allow me to specify the timestamp to use for the KeyValue.
> This should be added as well.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)