HBASE-10024 Add an interface to create put with immutable arrays
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1545592 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
edbf698cc1
commit
38d454dc2b
|
@ -138,10 +138,28 @@ public class Put extends Mutation implements HeapSize, Comparable<Row> {
|
|||
return add(family, qualifier, this.ts, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #add(byte[], byte[], byte[])}. This version expects
|
||||
* that the underlying arrays won't change. It's intended
|
||||
* for usage internal HBase to and for advanced client applications.
|
||||
*/
|
||||
public Put addImmutable(byte [] family, byte [] qualifier, byte [] value) {
|
||||
return addImmutable(family, qualifier, this.ts, value);
|
||||
}
|
||||
|
||||
public Put add(byte[] family, byte [] qualifier, byte [] value, Tag[] tag) {
|
||||
return add(family, qualifier, this.ts, value, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #add(byte[], byte[], byte[], Tag[] tag)}. This version expects
|
||||
* that the underlying arrays won't change. It's intended
|
||||
* for usage internal HBase to and for advanced client applications.
|
||||
*/
|
||||
public Put addImmutable(byte[] family, byte [] qualifier, byte [] value, Tag[] tag) {
|
||||
return addImmutable(family, qualifier, this.ts, value, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the specified column and value, with the specified timestamp as
|
||||
* its version to this Put operation.
|
||||
|
@ -152,6 +170,22 @@ public class Put extends Mutation implements HeapSize, Comparable<Row> {
|
|||
* @return this
|
||||
*/
|
||||
public Put add(byte [] family, byte [] qualifier, long ts, byte [] value) {
|
||||
if (ts < 0) {
|
||||
throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
|
||||
}
|
||||
List<Cell> list = getCellList(family);
|
||||
KeyValue kv = createPutKeyValue(family, qualifier, ts, value);
|
||||
list.add(kv);
|
||||
familyMap.put(CellUtil.cloneFamily(kv), list);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #add(byte[], byte[], long, byte[])}. This version expects
|
||||
* that the underlying arrays won't change. It's intended
|
||||
* for usage internal HBase to and for advanced client applications.
|
||||
*/
|
||||
public Put addImmutable(byte [] family, byte [] qualifier, long ts, byte [] value) {
|
||||
if (ts < 0) {
|
||||
throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
|
||||
}
|
||||
|
@ -170,7 +204,21 @@ public class Put extends Mutation implements HeapSize, Comparable<Row> {
|
|||
List<Cell> list = getCellList(family);
|
||||
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, tag);
|
||||
list.add(kv);
|
||||
familyMap.put(kv.getFamily(), list);
|
||||
familyMap.put(CellUtil.cloneFamily(kv), list);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #add(byte[], byte[], long, byte[], Tag[] tag)}. This version expects
|
||||
* that the underlying arrays won't change. It's intended
|
||||
* for usage internal HBase to and for advanced client applications.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Put addImmutable(byte[] family, byte[] qualifier, long ts, byte[] value, Tag[] tag) {
|
||||
List<Cell> list = getCellList(family);
|
||||
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, tag);
|
||||
list.add(kv);
|
||||
familyMap.put(family, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -191,10 +239,29 @@ public class Put extends Mutation implements HeapSize, Comparable<Row> {
|
|||
List<Cell> list = getCellList(family);
|
||||
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, tag);
|
||||
list.add(kv);
|
||||
familyMap.put(kv.getFamily(), list);
|
||||
familyMap.put(CellUtil.cloneFamily(kv), list);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See {@link #add(byte[], ByteBuffer, long, ByteBuffer, Tag[] tag)}. This version expects
|
||||
* that the underlying arrays won't change. It's intended
|
||||
* for usage internal HBase to and for advanced client applications.
|
||||
*/
|
||||
public Put addImmutable(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value,
|
||||
Tag[] tag) {
|
||||
if (ts < 0) {
|
||||
throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
|
||||
}
|
||||
List<Cell> list = getCellList(family);
|
||||
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, tag);
|
||||
list.add(kv);
|
||||
familyMap.put(family, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add the specified column and value, with the specified timestamp as
|
||||
* its version to this Put operation.
|
||||
|
@ -211,7 +278,23 @@ public class Put extends Mutation implements HeapSize, Comparable<Row> {
|
|||
List<Cell> list = getCellList(family);
|
||||
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, null);
|
||||
list.add(kv);
|
||||
familyMap.put(kv.getFamily(), list);
|
||||
familyMap.put(CellUtil.cloneFamily(kv), list);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #add(byte[], ByteBuffer, long, ByteBuffer)}. This version expects
|
||||
* that the underlying arrays won't change. It's intended
|
||||
* for usage internal HBase to and for advanced client applications.
|
||||
*/
|
||||
public Put addImmutable(byte[] family, ByteBuffer qualifier, long ts, ByteBuffer value) {
|
||||
if (ts < 0) {
|
||||
throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
|
||||
}
|
||||
List<Cell> list = getCellList(family);
|
||||
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, null);
|
||||
list.add(kv);
|
||||
familyMap.put(family, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -503,7 +503,7 @@ public final class ProtobufUtil {
|
|||
if (put == null) {
|
||||
put = new Put(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(), timestamp);
|
||||
}
|
||||
put.add(KeyValueUtil.ensureKeyValue(cell));
|
||||
put.add(cell);
|
||||
}
|
||||
} else {
|
||||
if (proto.hasRow()) {
|
||||
|
@ -535,9 +535,9 @@ public final class ProtobufUtil {
|
|||
for(int i = 0; i< array.length; i++) {
|
||||
tagArray[i] = (Tag)array[i];
|
||||
}
|
||||
put.add(family, qualifier, ts, value, tagArray);
|
||||
put.addImmutable(family, qualifier, ts, value, tagArray);
|
||||
} else {
|
||||
put.add(family, qualifier, ts, value);
|
||||
put.addImmutable(family, qualifier, ts, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,10 +84,12 @@ public class MetaEditor {
|
|||
*/
|
||||
public static Put addDaughtersToPut(Put put, HRegionInfo splitA, HRegionInfo splitB) {
|
||||
if (splitA != null) {
|
||||
put.add(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER, splitA.toByteArray());
|
||||
put.addImmutable(
|
||||
HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER, splitA.toByteArray());
|
||||
}
|
||||
if (splitB != null) {
|
||||
put.add(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER, splitB.toByteArray());
|
||||
put.addImmutable(
|
||||
HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER, splitB.toByteArray());
|
||||
}
|
||||
return put;
|
||||
}
|
||||
|
@ -315,9 +317,9 @@ public class MetaEditor {
|
|||
|
||||
// Put for parent
|
||||
Put putOfMerged = makePutFromRegionInfo(copyOfMerged);
|
||||
putOfMerged.add(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER,
|
||||
putOfMerged.addImmutable(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER,
|
||||
regionA.toByteArray());
|
||||
putOfMerged.add(HConstants.CATALOG_FAMILY, HConstants.MERGEB_QUALIFIER,
|
||||
putOfMerged.addImmutable(HConstants.CATALOG_FAMILY, HConstants.MERGEB_QUALIFIER,
|
||||
regionB.toByteArray());
|
||||
|
||||
// Deletes for merging regions
|
||||
|
@ -561,17 +563,17 @@ public class MetaEditor {
|
|||
|
||||
private static Put addRegionInfo(final Put p, final HRegionInfo hri)
|
||||
throws IOException {
|
||||
p.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER,
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER,
|
||||
hri.toByteArray());
|
||||
return p;
|
||||
}
|
||||
|
||||
private static Put addLocation(final Put p, final ServerName sn, long openSeqNum) {
|
||||
p.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
|
||||
Bytes.toBytes(sn.getHostAndPort()));
|
||||
p.add(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
|
||||
Bytes.toBytes(sn.getStartcode()));
|
||||
p.add(HConstants.CATALOG_FAMILY, HConstants.SEQNUM_QUALIFIER,
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.SEQNUM_QUALIFIER,
|
||||
Bytes.toBytes(openSeqNum));
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public class MetaMigrationConvertingToPB {
|
|||
//This will 'migrate' the HRI from 092.x and 0.94.x to 0.96+ by reading the
|
||||
//writable serialization
|
||||
HRegionInfo hri = parseFrom(hriSplitBytes);
|
||||
p.add(HConstants.CATALOG_FAMILY, which, hri.toByteArray());
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, which, hri.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ public class TableNamespaceManager {
|
|||
|
||||
private void upsert(HTable table, NamespaceDescriptor ns) throws IOException {
|
||||
Put p = new Put(Bytes.toBytes(ns.getName()));
|
||||
p.add(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES,
|
||||
p.addImmutable(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES,
|
||||
HTableDescriptor.NAMESPACE_COL_DESC_BYTES,
|
||||
ProtobufUtil.toProtoNamespaceDescriptor(ns).toByteArray());
|
||||
table.put(p);
|
||||
|
|
|
@ -143,7 +143,7 @@ public class FavoredNodeAssignmentHelper {
|
|||
if (favoredNodeList != null) {
|
||||
put = MetaEditor.makePutFromRegionInfo(regionInfo);
|
||||
byte[] favoredNodes = getFavoredNodes(favoredNodeList);
|
||||
put.add(HConstants.CATALOG_FAMILY, FAVOREDNODES_QUALIFIER,
|
||||
put.addImmutable(HConstants.CATALOG_FAMILY, FAVOREDNODES_QUALIFIER,
|
||||
EnvironmentEdgeManager.currentTimeMillis(), favoredNodes);
|
||||
LOG.info("Create the region " + regionInfo.getRegionNameAsString() +
|
||||
" with favored nodes " + Bytes.toString(favoredNodes));
|
||||
|
|
|
@ -462,7 +462,7 @@ public class NamespaceUpgrade implements Tool {
|
|||
// create a put for new _acl_ entry with rowkey as hbase:acl
|
||||
Put p = new Put(AccessControlLists.ACL_GLOBAL_NAME);
|
||||
for (Cell c : r.rawCells()) {
|
||||
p.add(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c));
|
||||
p.addImmutable(CellUtil.cloneFamily(c), CellUtil.cloneQualifier(c), CellUtil.cloneValue(c));
|
||||
}
|
||||
region.put(p);
|
||||
// delete the old entry
|
||||
|
|
|
@ -605,11 +605,11 @@ public class SplitTransaction {
|
|||
}
|
||||
|
||||
public Put addLocation(final Put p, final ServerName sn, long openSeqNum) {
|
||||
p.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
|
||||
Bytes.toBytes(sn.getHostAndPort()));
|
||||
p.add(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
|
||||
Bytes.toBytes(sn.getStartcode()));
|
||||
p.add(HConstants.CATALOG_FAMILY, HConstants.SEQNUM_QUALIFIER,
|
||||
p.addImmutable(HConstants.CATALOG_FAMILY, HConstants.SEQNUM_QUALIFIER,
|
||||
Bytes.toBytes(openSeqNum));
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ public class RowResource extends ResourceBase {
|
|||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
put.add(parts[0], parts[1], cell.getTimestamp(), cell.getValue());
|
||||
put.addImmutable(parts[0], parts[1], cell.getTimestamp(), cell.getValue());
|
||||
}
|
||||
puts.add(put);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
|
@ -293,7 +293,7 @@ public class RowResource extends ResourceBase {
|
|||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
put.add(parts[0], parts[1], timestamp, message);
|
||||
put.addImmutable(parts[0], parts[1], timestamp, message);
|
||||
table = servlet.getTable(tableResource.getName());
|
||||
table.put(put);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
|
@ -471,7 +471,7 @@ public class RowResource extends ResourceBase {
|
|||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
put.add(valueToPutParts[0], valueToPutParts[1], valueToPutCell
|
||||
put.addImmutable(valueToPutParts[0], valueToPutParts[1], valueToPutCell
|
||||
.getTimestamp(), valueToPutCell.getValue());
|
||||
|
||||
table = servlet.getTable(this.tableResource.getName());
|
||||
|
|
|
@ -157,7 +157,7 @@ public class AccessControlLists {
|
|||
for (int i = 0; i < actions.length; i++) {
|
||||
value[i] = actions[i].code();
|
||||
}
|
||||
p.add(ACL_LIST_FAMILY, key, value);
|
||||
p.addImmutable(ACL_LIST_FAMILY, key, value);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Writing permission with rowKey "+
|
||||
Bytes.toString(rowKey)+" "+
|
||||
|
|
|
@ -568,11 +568,12 @@ public class VisibilityController extends BaseRegionObserver implements MasterOb
|
|||
Map<String, List<Integer>> userAuths) throws IOException {
|
||||
if (!labels.containsKey(SYSTEM_LABEL)) {
|
||||
Put p = new Put(Bytes.toBytes(SYSTEM_LABEL_ORDINAL));
|
||||
p.add(LABELS_TABLE_FAMILY, LABEL_QUALIFIER, Bytes.toBytes(SYSTEM_LABEL));
|
||||
p.addImmutable(LABELS_TABLE_FAMILY, LABEL_QUALIFIER, Bytes.toBytes(SYSTEM_LABEL));
|
||||
// Set auth for "system" label for all super users.
|
||||
List<String> superUsers = getSystemAndSuperUsers();
|
||||
for (String superUser : superUsers) {
|
||||
p.add(LABELS_TABLE_FAMILY, Bytes.toBytes(superUser), DUMMY_VALUE, LABELS_TABLE_TAGS);
|
||||
p.addImmutable(
|
||||
LABELS_TABLE_FAMILY, Bytes.toBytes(superUser), DUMMY_VALUE, LABELS_TABLE_TAGS);
|
||||
}
|
||||
region.put(p);
|
||||
labels.put(SYSTEM_LABEL, SYSTEM_LABEL_ORDINAL);
|
||||
|
@ -1037,7 +1038,8 @@ public class VisibilityController extends BaseRegionObserver implements MasterOb
|
|||
response.addResult(failureResultBuilder.build());
|
||||
} else {
|
||||
Put p = new Put(Bytes.toBytes(ordinalCounter));
|
||||
p.add(LABELS_TABLE_FAMILY, LABEL_QUALIFIER, label, LABELS_TABLE_TAGS);
|
||||
p.addImmutable(
|
||||
LABELS_TABLE_FAMILY, LABEL_QUALIFIER, label, LABELS_TABLE_TAGS);
|
||||
puts.add(p);
|
||||
ordinalCounter++;
|
||||
response.addResult(successResult);
|
||||
|
@ -1127,7 +1129,8 @@ public class VisibilityController extends BaseRegionObserver implements MasterOb
|
|||
response.addResult(failureResultBuilder.build());
|
||||
} else {
|
||||
Put p = new Put(Bytes.toBytes(labelOrdinal));
|
||||
p.add(LABELS_TABLE_FAMILY, user, DUMMY_VALUE, LABELS_TABLE_TAGS);
|
||||
p.addImmutable(
|
||||
LABELS_TABLE_FAMILY, user, DUMMY_VALUE, LABELS_TABLE_TAGS);
|
||||
puts.add(p);
|
||||
response.addResult(successResult);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.hadoop.conf.Configuration;
|
|||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.MediumTests;
|
||||
import org.apache.hadoop.hbase.Server;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.SplitLogCounters;
|
||||
import org.apache.hadoop.hbase.SplitLogTask;
|
||||
|
@ -357,7 +356,7 @@ public class TestSplitLogWorker {
|
|||
SplitLogWorker slw = new SplitLogWorker(zkw, testConf, mockedRS, neverEndingTask);
|
||||
slw.start();
|
||||
try {
|
||||
waitForCounter(SplitLogCounters.tot_wkr_task_acquired, 0, maxTasks, 3000);
|
||||
waitForCounter(SplitLogCounters.tot_wkr_task_acquired, 0, maxTasks, 6000);
|
||||
for (int i = 0; i < maxTasks; i++) {
|
||||
byte[] bytes = ZKUtil.getData(zkw, ZKSplitLog.getEncodedNodeName(zkw, TATAS + i));
|
||||
SplitLogTask slt = SplitLogTask.parseFrom(bytes);
|
||||
|
@ -402,7 +401,7 @@ public class TestSplitLogWorker {
|
|||
slw.start();
|
||||
try {
|
||||
int acquiredTasks = 0;
|
||||
waitForCounter(SplitLogCounters.tot_wkr_task_acquired, 0, 2, 3000);
|
||||
waitForCounter(SplitLogCounters.tot_wkr_task_acquired, 0, 2, 6000);
|
||||
for (int i = 0; i < maxTasks; i++) {
|
||||
byte[] bytes = ZKUtil.getData(zkw, ZKSplitLog.getEncodedNodeName(zkw, TATAS + i));
|
||||
SplitLogTask slt = SplitLogTask.parseFrom(bytes);
|
||||
|
|
|
@ -1033,7 +1033,7 @@ public class ThriftServerRunner implements Runnable {
|
|||
LOG.warn("No column qualifier specified. Delete is the only mutation supported "
|
||||
+ "over the whole column family.");
|
||||
} else {
|
||||
put.add(famAndQf[0], famAndQf[1],
|
||||
put.addImmutable(famAndQf[0], famAndQf[1],
|
||||
m.value != null ? getBytes(m.value)
|
||||
: HConstants.EMPTY_BYTE_ARRAY);
|
||||
}
|
||||
|
@ -1092,7 +1092,7 @@ public class ThriftServerRunner implements Runnable {
|
|||
+ "over the whole column family.");
|
||||
}
|
||||
if (famAndQf.length == 2) {
|
||||
put.add(famAndQf[0], famAndQf[1],
|
||||
put.addImmutable(famAndQf[0], famAndQf[1],
|
||||
m.value != null ? getBytes(m.value)
|
||||
: HConstants.EMPTY_BYTE_ARRAY);
|
||||
} else {
|
||||
|
|
|
@ -198,10 +198,12 @@ public class ThriftUtilities {
|
|||
|
||||
for (TColumnValue columnValue : in.getColumnValues()) {
|
||||
if (columnValue.isSetTimestamp()) {
|
||||
out.add(columnValue.getFamily(), columnValue.getQualifier(), columnValue.getTimestamp(),
|
||||
out.addImmutable(
|
||||
columnValue.getFamily(), columnValue.getQualifier(), columnValue.getTimestamp(),
|
||||
columnValue.getValue());
|
||||
} else {
|
||||
out.add(columnValue.getFamily(), columnValue.getQualifier(), columnValue.getValue());
|
||||
out.addImmutable(
|
||||
columnValue.getFamily(), columnValue.getQualifier(), columnValue.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue