From commits-return-70124-archive-asf-public=cust-asf.ponee.io@hbase.apache.org Sat Mar 24 16:13:15 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E04B51807AA for ; Sat, 24 Mar 2018 16:13:11 +0100 (CET) Received: (qmail 84761 invoked by uid 500); 24 Mar 2018 15:13:06 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 83274 invoked by uid 99); 24 Mar 2018 15:13:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 Mar 2018 15:13:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DCF6CF6723; Sat, 24 Mar 2018 15:13:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Sat, 24 Mar 2018 15:13:32 -0000 Message-Id: In-Reply-To: <4f47cf46d5244b3f8b4197cc0d9d2901@git.apache.org> References: <4f47cf46d5244b3f8b4197cc0d9d2901@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [30/51] [partial] hbase-site git commit: Published site at e468b4022f76688851b3e0c34722f01a56bd624f. http://git-wip-us.apache.org/repos/asf/hbase-site/blob/16541468/apidocs/src-html/org/apache/hadoop/hbase/client/Mutation.html ---------------------------------------------------------------------- diff --git a/apidocs/src-html/org/apache/hadoop/hbase/client/Mutation.html b/apidocs/src-html/org/apache/hadoop/hbase/client/Mutation.html index 2f412f5..96c070a 100644 --- a/apidocs/src-html/org/apache/hadoop/hbase/client/Mutation.html +++ b/apidocs/src-html/org/apache/hadoop/hbase/client/Mutation.html @@ -121,7 +121,7 @@ 113 protected Mutation(Mutation clone) { 114 super(clone); 115 this.row = clone.getRow(); -116 this.ts = clone.getTimeStamp(); +116 this.ts = clone.getTimestamp(); 117 this.familyMap = clone.getFamilyCellMap().entrySet().stream() 118 .collect(Collectors.toMap(e -> e.getKey(), e -> new ArrayList<>(e.getValue()), 119 (k, v) -> { @@ -352,617 +352,629 @@ 344 /** 345 * Method for retrieving the timestamp 346 * @return timestamp -347 */ -348 public long getTimeStamp() { -349 return this.ts; -350 } -351 -352 /** -353 * Marks that the clusters with the given clusterIds have consumed the mutation -354 * @param clusterIds of the clusters that have consumed the mutation -355 */ -356 public Mutation setClusterIds(List<UUID> clusterIds) { -357 ByteArrayDataOutput out = ByteStreams.newDataOutput(); -358 out.writeInt(clusterIds.size()); -359 for (UUID clusterId : clusterIds) { -360 out.writeLong(clusterId.getMostSignificantBits()); -361 out.writeLong(clusterId.getLeastSignificantBits()); -362 } -363 setAttribute(CONSUMED_CLUSTER_IDS, out.toByteArray()); -364 return this; -365 } -366 -367 /** -368 * @return the set of clusterIds that have consumed the mutation -369 */ -370 public List<UUID> getClusterIds() { -371 List<UUID> clusterIds = new ArrayList<>(); -372 byte[] bytes = getAttribute(CONSUMED_CLUSTER_IDS); -373 if(bytes != null) { -374 ByteArrayDataInput in = ByteStreams.newDataInput(bytes); -375 int numClusters = in.readInt(); -376 for(int i=0; i<numClusters; i++){ -377 clusterIds.add(new UUID(in.readLong(), in.readLong())); -378 } -379 } -380 return clusterIds; -381 } -382 -383 /** -384 * Sets the visibility expression associated with cells in this Mutation. -385 * @param expression -386 */ -387 public Mutation setCellVisibility(CellVisibility expression) { -388 this.setAttribute(VisibilityConstants.VISIBILITY_LABELS_ATTR_KEY, -389 toCellVisibility(expression).toByteArray()); -390 return this; -391 } -392 -393 /** -394 * @return CellVisibility associated with cells in this Mutation. -395 * @throws DeserializationException -396 */ -397 public CellVisibility getCellVisibility() throws DeserializationException { -398 byte[] cellVisibilityBytes = this.getAttribute(VisibilityConstants.VISIBILITY_LABELS_ATTR_KEY); -399 if (cellVisibilityBytes == null) return null; -400 return toCellVisibility(cellVisibilityBytes); -401 } -402 -403 /** -404 * Create a protocol buffer CellVisibility based on a client CellVisibility. -405 * -406 * @param cellVisibility -407 * @return a protocol buffer CellVisibility +347 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +348 * Use {@link #getTimestamp()} instead +349 */ +350 @Deprecated +351 public long getTimeStamp() { +352 return this.getTimestamp(); +353 } +354 +355 /** +356 * Method for retrieving the timestamp. +357 * +358 * @return timestamp +359 */ +360 public long getTimestamp() { +361 return this.ts; +362 } +363 +364 /** +365 * Marks that the clusters with the given clusterIds have consumed the mutation +366 * @param clusterIds of the clusters that have consumed the mutation +367 */ +368 public Mutation setClusterIds(List<UUID> clusterIds) { +369 ByteArrayDataOutput out = ByteStreams.newDataOutput(); +370 out.writeInt(clusterIds.size()); +371 for (UUID clusterId : clusterIds) { +372 out.writeLong(clusterId.getMostSignificantBits()); +373 out.writeLong(clusterId.getLeastSignificantBits()); +374 } +375 setAttribute(CONSUMED_CLUSTER_IDS, out.toByteArray()); +376 return this; +377 } +378 +379 /** +380 * @return the set of clusterIds that have consumed the mutation +381 */ +382 public List<UUID> getClusterIds() { +383 List<UUID> clusterIds = new ArrayList<>(); +384 byte[] bytes = getAttribute(CONSUMED_CLUSTER_IDS); +385 if(bytes != null) { +386 ByteArrayDataInput in = ByteStreams.newDataInput(bytes); +387 int numClusters = in.readInt(); +388 for(int i=0; i<numClusters; i++){ +389 clusterIds.add(new UUID(in.readLong(), in.readLong())); +390 } +391 } +392 return clusterIds; +393 } +394 +395 /** +396 * Sets the visibility expression associated with cells in this Mutation. +397 * @param expression +398 */ +399 public Mutation setCellVisibility(CellVisibility expression) { +400 this.setAttribute(VisibilityConstants.VISIBILITY_LABELS_ATTR_KEY, +401 toCellVisibility(expression).toByteArray()); +402 return this; +403 } +404 +405 /** +406 * @return CellVisibility associated with cells in this Mutation. +407 * @throws DeserializationException 408 */ -409 static ClientProtos.CellVisibility toCellVisibility(CellVisibility cellVisibility) { -410 ClientProtos.CellVisibility.Builder builder = ClientProtos.CellVisibility.newBuilder(); -411 builder.setExpression(cellVisibility.getExpression()); -412 return builder.build(); +409 public CellVisibility getCellVisibility() throws DeserializationException { +410 byte[] cellVisibilityBytes = this.getAttribute(VisibilityConstants.VISIBILITY_LABELS_ATTR_KEY); +411 if (cellVisibilityBytes == null) return null; +412 return toCellVisibility(cellVisibilityBytes); 413 } 414 415 /** -416 * Convert a protocol buffer CellVisibility to a client CellVisibility +416 * Create a protocol buffer CellVisibility based on a client CellVisibility. 417 * -418 * @param proto -419 * @return the converted client CellVisibility +418 * @param cellVisibility +419 * @return a protocol buffer CellVisibility 420 */ -421 private static CellVisibility toCellVisibility(ClientProtos.CellVisibility proto) { -422 if (proto == null) return null; -423 return new CellVisibility(proto.getExpression()); -424 } -425 -426 /** -427 * Convert a protocol buffer CellVisibility bytes to a client CellVisibility -428 * -429 * @param protoBytes -430 * @return the converted client CellVisibility -431 * @throws DeserializationException +421 static ClientProtos.CellVisibility toCellVisibility(CellVisibility cellVisibility) { +422 ClientProtos.CellVisibility.Builder builder = ClientProtos.CellVisibility.newBuilder(); +423 builder.setExpression(cellVisibility.getExpression()); +424 return builder.build(); +425 } +426 +427 /** +428 * Convert a protocol buffer CellVisibility to a client CellVisibility +429 * +430 * @param proto +431 * @return the converted client CellVisibility 432 */ -433 private static CellVisibility toCellVisibility(byte[] protoBytes) throws DeserializationException { -434 if (protoBytes == null) return null; -435 ClientProtos.CellVisibility.Builder builder = ClientProtos.CellVisibility.newBuilder(); -436 ClientProtos.CellVisibility proto = null; -437 try { -438 ProtobufUtil.mergeFrom(builder, protoBytes); -439 proto = builder.build(); -440 } catch (IOException e) { -441 throw new DeserializationException(e); -442 } -443 return toCellVisibility(proto); -444 } -445 -446 /** -447 * Number of KeyValues carried by this Mutation. -448 * @return the total number of KeyValues -449 */ -450 public int size() { -451 int size = 0; -452 for (List<Cell> cells : this.familyMap.values()) { -453 size += cells.size(); +433 private static CellVisibility toCellVisibility(ClientProtos.CellVisibility proto) { +434 if (proto == null) return null; +435 return new CellVisibility(proto.getExpression()); +436 } +437 +438 /** +439 * Convert a protocol buffer CellVisibility bytes to a client CellVisibility +440 * +441 * @param protoBytes +442 * @return the converted client CellVisibility +443 * @throws DeserializationException +444 */ +445 private static CellVisibility toCellVisibility(byte[] protoBytes) throws DeserializationException { +446 if (protoBytes == null) return null; +447 ClientProtos.CellVisibility.Builder builder = ClientProtos.CellVisibility.newBuilder(); +448 ClientProtos.CellVisibility proto = null; +449 try { +450 ProtobufUtil.mergeFrom(builder, protoBytes); +451 proto = builder.build(); +452 } catch (IOException e) { +453 throw new DeserializationException(e); 454 } -455 return size; +455 return toCellVisibility(proto); 456 } 457 458 /** -459 * @return the number of different families -460 */ -461 public int numFamilies() { -462 return familyMap.size(); -463 } -464 -465 /** -466 * @return Calculate what Mutation adds to class heap size. -467 */ -468 @Override -469 public long heapSize() { -470 long heapsize = MUTATION_OVERHEAD; -471 // Adding row -472 heapsize += ClassSize.align(ClassSize.ARRAY + this.row.length); -473 -474 // Adding map overhead -475 heapsize += -476 ClassSize.align(this.familyMap.size() * ClassSize.MAP_ENTRY); -477 for(Map.Entry<byte [], List<Cell>> entry : this.familyMap.entrySet()) { -478 //Adding key overhead -479 heapsize += -480 ClassSize.align(ClassSize.ARRAY + entry.getKey().length); -481 -482 //This part is kinds tricky since the JVM can reuse references if you -483 //store the same value, but have a good match with SizeOf at the moment -484 //Adding value overhead -485 heapsize += ClassSize.align(ClassSize.ARRAYLIST); -486 int size = entry.getValue().size(); -487 heapsize += ClassSize.align(ClassSize.ARRAY + -488 size * ClassSize.REFERENCE); -489 -490 for(Cell cell : entry.getValue()) { -491 heapsize += PrivateCellUtil.estimatedSizeOfCell(cell); -492 } -493 } -494 heapsize += getAttributeSize(); -495 heapsize += extraHeapSize(); -496 return ClassSize.align(heapsize); -497 } -498 -499 /** -500 * @return The serialized ACL for this operation, or null if none -501 */ -502 public byte[] getACL() { -503 return getAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL); -504 } -505 -506 /** -507 * @param user User short name -508 * @param perms Permissions for the user -509 */ -510 public Mutation setACL(String user, Permission perms) { -511 setAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL, -512 AccessControlUtil.toUsersAndPermissions(user, perms).toByteArray()); -513 return this; -514 } -515 -516 /** -517 * @param perms A map of permissions for a user or users -518 */ -519 public Mutation setACL(Map<String, Permission> perms) { -520 ListMultimap<String, Permission> permMap = ArrayListMultimap.create(); -521 for (Map.Entry<String, Permission> entry : perms.entrySet()) { -522 permMap.put(entry.getKey(), entry.getValue()); -523 } -524 setAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL, -525 AccessControlUtil.toUsersAndPermissions(permMap).toByteArray()); -526 return this; -527 } -528 -529 /** -530 * Return the TTL requested for the result of the mutation, in milliseconds. -531 * @return the TTL requested for the result of the mutation, in milliseconds, -532 * or Long.MAX_VALUE if unset -533 */ -534 public long getTTL() { -535 byte[] ttlBytes = getAttribute(OP_ATTRIBUTE_TTL); -536 if (ttlBytes != null) { -537 return Bytes.toLong(ttlBytes); -538 } -539 return Long.MAX_VALUE; -540 } -541 -542 /** -543 * Set the TTL desired for the result of the mutation, in milliseconds. -544 * @param ttl the TTL desired for the result of the mutation, in milliseconds -545 * @return this -546 */ -547 public Mutation setTTL(long ttl) { -548 setAttribute(OP_ATTRIBUTE_TTL, Bytes.toBytes(ttl)); -549 return this; -550 } -551 -552 /** -553 * @return current value for returnResults -554 */ -555 // Used by Increment and Append only. -556 @InterfaceAudience.Private -557 protected boolean isReturnResults() { -558 byte[] v = getAttribute(RETURN_RESULTS); -559 return v == null ? true : Bytes.toBoolean(v); -560 } -561 -562 @InterfaceAudience.Private -563 // Used by Increment and Append only. -564 protected Mutation setReturnResults(boolean returnResults) { -565 setAttribute(RETURN_RESULTS, Bytes.toBytes(returnResults)); -566 return this; -567 } -568 -569 /** -570 * Subclasses should override this method to add the heap size of their own fields. -571 * @return the heap size to add (will be aligned). -572 */ -573 protected long extraHeapSize(){ -574 return 0L; -575 } -576 -577 /** -578 * Set the timestamp of the delete. -579 */ -580 public Mutation setTimestamp(long timestamp) { -581 if (timestamp < 0) { -582 throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); -583 } -584 this.ts = timestamp; -585 return this; -586 } -587 -588 /** -589 * A convenience method to determine if this object's familyMap contains -590 * a value assigned to the given family &amp; qualifier. -591 * Both given arguments must match the KeyValue object to return true. -592 * -593 * @param family column family -594 * @param qualifier column qualifier -595 * @return returns true if the given family and qualifier already has an -596 * existing KeyValue object in the family map. -597 */ -598 public boolean has(byte [] family, byte [] qualifier) { -599 return has(family, qualifier, this.ts, HConstants.EMPTY_BYTE_ARRAY, true, true); -600 } -601 -602 /** -603 * A convenience method to determine if this object's familyMap contains -604 * a value assigned to the given family, qualifier and timestamp. -605 * All 3 given arguments must match the KeyValue object to return true. -606 * -607 * @param family column family -608 * @param qualifier column qualifier -609 * @param ts timestamp -610 * @return returns true if the given family, qualifier and timestamp already has an -611 * existing KeyValue object in the family map. -612 */ -613 public boolean has(byte [] family, byte [] qualifier, long ts) { -614 return has(family, qualifier, ts, HConstants.EMPTY_BYTE_ARRAY, false, true); -615 } -616 -617 /** -618 * A convenience method to determine if this object's familyMap contains -619 * a value assigned to the given family, qualifier and timestamp. -620 * All 3 given arguments must match the KeyValue object to return true. -621 * -622 * @param family column family -623 * @param qualifier column qualifier -624 * @param value value to check -625 * @return returns true if the given family, qualifier and value already has an -626 * existing KeyValue object in the family map. -627 */ -628 public boolean has(byte [] family, byte [] qualifier, byte [] value) { -629 return has(family, qualifier, this.ts, value, true, false); -630 } -631 -632 /** -633 * A convenience method to determine if this object's familyMap contains -634 * the given value assigned to the given family, qualifier and timestamp. -635 * All 4 given arguments must match the KeyValue object to return true. -636 * -637 * @param family column family -638 * @param qualifier column qualifier -639 * @param ts timestamp -640 * @param value value to check -641 * @return returns true if the given family, qualifier timestamp and value -642 * already has an existing KeyValue object in the family map. -643 */ -644 public boolean has(byte [] family, byte [] qualifier, long ts, byte [] value) { -645 return has(family, qualifier, ts, value, false, false); -646 } -647 -648 /** -649 * Returns a list of all KeyValue objects with matching column family and qualifier. -650 * -651 * @param family column family -652 * @param qualifier column qualifier -653 * @return a list of KeyValue objects with the matching family and qualifier, -654 * returns an empty list if one doesn't exist for the given family. +459 * Number of KeyValues carried by this Mutation. +460 * @return the total number of KeyValues +461 */ +462 public int size() { +463 int size = 0; +464 for (List<Cell> cells : this.familyMap.values()) { +465 size += cells.size(); +466 } +467 return size; +468 } +469 +470 /** +471 * @return the number of different families +472 */ +473 public int numFamilies() { +474 return familyMap.size(); +475 } +476 +477 /** +478 * @return Calculate what Mutation adds to class heap size. +479 */ +480 @Override +481 public long heapSize() { +482 long heapsize = MUTATION_OVERHEAD; +483 // Adding row +484 heapsize += ClassSize.align(ClassSize.ARRAY + this.row.length); +485 +486 // Adding map overhead +487 heapsize += +488 ClassSize.align(this.familyMap.size() * ClassSize.MAP_ENTRY); +489 for(Map.Entry<byte [], List<Cell>> entry : this.familyMap.entrySet()) { +490 //Adding key overhead +491 heapsize += +492 ClassSize.align(ClassSize.ARRAY + entry.getKey().length); +493 +494 //This part is kinds tricky since the JVM can reuse references if you +495 //store the same value, but have a good match with SizeOf at the moment +496 //Adding value overhead +497 heapsize += ClassSize.align(ClassSize.ARRAYLIST); +498 int size = entry.getValue().size(); +499 heapsize += ClassSize.align(ClassSize.ARRAY + +500 size * ClassSize.REFERENCE); +501 +502 for(Cell cell : entry.getValue()) { +503 heapsize += PrivateCellUtil.estimatedSizeOfCell(cell); +504 } +505 } +506 heapsize += getAttributeSize(); +507 heapsize += extraHeapSize(); +508 return ClassSize.align(heapsize); +509 } +510 +511 /** +512 * @return The serialized ACL for this operation, or null if none +513 */ +514 public byte[] getACL() { +515 return getAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL); +516 } +517 +518 /** +519 * @param user User short name +520 * @param perms Permissions for the user +521 */ +522 public Mutation setACL(String user, Permission perms) { +523 setAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL, +524 AccessControlUtil.toUsersAndPermissions(user, perms).toByteArray()); +525 return this; +526 } +527 +528 /** +529 * @param perms A map of permissions for a user or users +530 */ +531 public Mutation setACL(Map<String, Permission> perms) { +532 ListMultimap<String, Permission> permMap = ArrayListMultimap.create(); +533 for (Map.Entry<String, Permission> entry : perms.entrySet()) { +534 permMap.put(entry.getKey(), entry.getValue()); +535 } +536 setAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL, +537 AccessControlUtil.toUsersAndPermissions(permMap).toByteArray()); +538 return this; +539 } +540 +541 /** +542 * Return the TTL requested for the result of the mutation, in milliseconds. +543 * @return the TTL requested for the result of the mutation, in milliseconds, +544 * or Long.MAX_VALUE if unset +545 */ +546 public long getTTL() { +547 byte[] ttlBytes = getAttribute(OP_ATTRIBUTE_TTL); +548 if (ttlBytes != null) { +549 return Bytes.toLong(ttlBytes); +550 } +551 return Long.MAX_VALUE; +552 } +553 +554 /** +555 * Set the TTL desired for the result of the mutation, in milliseconds. +556 * @param ttl the TTL desired for the result of the mutation, in milliseconds +557 * @return this +558 */ +559 public Mutation setTTL(long ttl) { +560 setAttribute(OP_ATTRIBUTE_TTL, Bytes.toBytes(ttl)); +561 return this; +562 } +563 +564 /** +565 * @return current value for returnResults +566 */ +567 // Used by Increment and Append only. +568 @InterfaceAudience.Private +569 protected boolean isReturnResults() { +570 byte[] v = getAttribute(RETURN_RESULTS); +571 return v == null ? true : Bytes.toBoolean(v); +572 } +573 +574 @InterfaceAudience.Private +575 // Used by Increment and Append only. +576 protected Mutation setReturnResults(boolean returnResults) { +577 setAttribute(RETURN_RESULTS, Bytes.toBytes(returnResults)); +578 return this; +579 } +580 +581 /** +582 * Subclasses should override this method to add the heap size of their own fields. +583 * @return the heap size to add (will be aligned). +584 */ +585 protected long extraHeapSize(){ +586 return 0L; +587 } +588 +589 /** +590 * Set the timestamp of the delete. +591 */ +592 public Mutation setTimestamp(long timestamp) { +593 if (timestamp < 0) { +594 throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); +595 } +596 this.ts = timestamp; +597 return this; +598 } +599 +600 /** +601 * A convenience method to determine if this object's familyMap contains +602 * a value assigned to the given family &amp; qualifier. +603 * Both given arguments must match the KeyValue object to return true. +604 * +605 * @param family column family +606 * @param qualifier column qualifier +607 * @return returns true if the given family and qualifier already has an +608 * existing KeyValue object in the family map. +609 */ +610 public boolean has(byte [] family, byte [] qualifier) { +611 return has(family, qualifier, this.ts, HConstants.EMPTY_BYTE_ARRAY, true, true); +612 } +613 +614 /** +615 * A convenience method to determine if this object's familyMap contains +616 * a value assigned to the given family, qualifier and timestamp. +617 * All 3 given arguments must match the KeyValue object to return true. +618 * +619 * @param family column family +620 * @param qualifier column qualifier +621 * @param ts timestamp +622 * @return returns true if the given family, qualifier and timestamp already has an +623 * existing KeyValue object in the family map. +624 */ +625 public boolean has(byte [] family, byte [] qualifier, long ts) { +626 return has(family, qualifier, ts, HConstants.EMPTY_BYTE_ARRAY, false, true); +627 } +628 +629 /** +630 * A convenience method to determine if this object's familyMap contains +631 * a value assigned to the given family, qualifier and timestamp. +632 * All 3 given arguments must match the KeyValue object to return true. +633 * +634 * @param family column family +635 * @param qualifier column qualifier +636 * @param value value to check +637 * @return returns true if the given family, qualifier and value already has an +638 * existing KeyValue object in the family map. +639 */ +640 public boolean has(byte [] family, byte [] qualifier, byte [] value) { +641 return has(family, qualifier, this.ts, value, true, false); +642 } +643 +644 /** +645 * A convenience method to determine if this object's familyMap contains +646 * the given value assigned to the given family, qualifier and timestamp. +647 * All 4 given arguments must match the KeyValue object to return true. +648 * +649 * @param family column family +650 * @param qualifier column qualifier +651 * @param ts timestamp +652 * @param value value to check +653 * @return returns true if the given family, qualifier timestamp and value +654 * already has an existing KeyValue object in the family map. 655 */ -656 public List<Cell> get(byte[] family, byte[] qualifier) { -657 List<Cell> filteredList = new ArrayList<>(); -658 for (Cell cell: getCellList(family)) { -659 if (CellUtil.matchingQualifier(cell, qualifier)) { -660 filteredList.add(cell); -661 } -662 } -663 return filteredList; -664 } -665 -666 /* -667 * Private method to determine if this object's familyMap contains -668 * the given value assigned to the given family, qualifier and timestamp -669 * respecting the 2 boolean arguments -670 * -671 * @param family -672 * @param qualifier -673 * @param ts -674 * @param value -675 * @param ignoreTS -676 * @param ignoreValue -677 * @return returns true if the given family, qualifier timestamp and value -678 * already has an existing KeyValue object in the family map. -679 */ -680 protected boolean has(byte[] family, byte[] qualifier, long ts, byte[] value, -681 boolean ignoreTS, boolean ignoreValue) { -682 List<Cell> list = getCellList(family); -683 if (list.isEmpty()) { -684 return false; -685 } -686 // Boolean analysis of ignoreTS/ignoreValue. -687 // T T => 2 -688 // T F => 3 (first is always true) -689 // F T => 2 -690 // F F => 1 -691 if (!ignoreTS && !ignoreValue) { -692 for (Cell cell : list) { -693 if (CellUtil.matchingFamily(cell, family) && -694 CellUtil.matchingQualifier(cell, qualifier) && -695 CellUtil.matchingValue(cell, value) && -696 cell.getTimestamp() == ts) { -697 return true; -698 } -699 } -700 } else if (ignoreValue && !ignoreTS) { -701 for (Cell cell : list) { -702 if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) -703 && cell.getTimestamp() == ts) { -704 return true; -705 } -706 } -707 } else if (!ignoreValue && ignoreTS) { -708 for (Cell cell : list) { -709 if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) -710 && CellUtil.matchingValue(cell, value)) { -711 return true; -712 } -713 } -714 } else { -715 for (Cell cell : list) { -716 if (CellUtil.matchingFamily(cell, family) && -717 CellUtil.matchingQualifier(cell, qualifier)) { -718 return true; -719 } -720 } -721 } -722 return false; -723 } -724 -725 /** -726 * @param row Row to check -727 * @throws IllegalArgumentException Thrown if <code>row</code> is empty or null or -728 * &gt; {@link HConstants#MAX_ROW_LENGTH} -729 * @return <code>row</code> -730 */ -731 static byte [] checkRow(final byte [] row) { -732 return checkRow(row, 0, row == null? 0: row.length); -733 } -734 -735 /** -736 * @param row Row to check -737 * @param offset -738 * @param length +656 public boolean has(byte [] family, byte [] qualifier, long ts, byte [] value) { +657 return has(family, qualifier, ts, value, false, false); +658 } +659 +660 /** +661 * Returns a list of all KeyValue objects with matching column family and qualifier. +662 * +663 * @param family column family +664 * @param qualifier column qualifier +665 * @return a list of KeyValue objects with the matching family and qualifier, +666 * returns an empty list if one doesn't exist for the given family. +667 */ +668 public List<Cell> get(byte[] family, byte[] qualifier) { +669 List<Cell> filteredList = new ArrayList<>(); +670 for (Cell cell: getCellList(family)) { +671 if (CellUtil.matchingQualifier(cell, qualifier)) { +672 filteredList.add(cell); +673 } +674 } +675 return filteredList; +676 } +677 +678 /* +679 * Private method to determine if this object's familyMap contains +680 * the given value assigned to the given family, qualifier and timestamp +681 * respecting the 2 boolean arguments +682 * +683 * @param family +684 * @param qualifier +685 * @param ts +686 * @param value +687 * @param ignoreTS +688 * @param ignoreValue +689 * @return returns true if the given family, qualifier timestamp and value +690 * already has an existing KeyValue object in the family map. +691 */ +692 protected boolean has(byte[] family, byte[] qualifier, long ts, byte[] value, +693 boolean ignoreTS, boolean ignoreValue) { +694 List<Cell> list = getCellList(family); +695 if (list.isEmpty()) { +696 return false; +697 } +698 // Boolean analysis of ignoreTS/ignoreValue. +699 // T T => 2 +700 // T F => 3 (first is always true) +701 // F T => 2 +702 // F F => 1 +703 if (!ignoreTS && !ignoreValue) { +704 for (Cell cell : list) { +705 if (CellUtil.matchingFamily(cell, family) && +706 CellUtil.matchingQualifier(cell, qualifier) && +707 CellUtil.matchingValue(cell, value) && +708 cell.getTimestamp() == ts) { +709 return true; +710 } +711 } +712 } else if (ignoreValue && !ignoreTS) { +713 for (Cell cell : list) { +714 if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) +715 && cell.getTimestamp() == ts) { +716 return true; +717 } +718 } +719 } else if (!ignoreValue && ignoreTS) { +720 for (Cell cell : list) { +721 if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) +722 && CellUtil.matchingValue(cell, value)) { +723 return true; +724 } +725 } +726 } else { +727 for (Cell cell : list) { +728 if (CellUtil.matchingFamily(cell, family) && +729 CellUtil.matchingQualifier(cell, qualifier)) { +730 return true; +731 } +732 } +733 } +734 return false; +735 } +736 +737 /** +738 * @param row Row to check 739 * @throws IllegalArgumentException Thrown if <code>row</code> is empty or null or 740 * &gt; {@link HConstants#MAX_ROW_LENGTH} 741 * @return <code>row</code> 742 */ -743 static byte [] checkRow(final byte [] row, final int offset, final int length) { -744 if (row == null) { -745 throw new IllegalArgumentException("Row buffer is null"); -746 } -747 if (length == 0) { -748 throw new IllegalArgumentException("Row length is 0"); -749 } -750 if (length > HConstants.MAX_ROW_LENGTH) { -751 throw new IllegalArgumentException("Row length " + length + " is > " + -752 HConstants.MAX_ROW_LENGTH); -753 } -754 return row; -755 } -756 -757 static void checkRow(ByteBuffer row) { -758 if (row == null) { -759 throw new IllegalArgumentException("Row buffer is null"); -760 } -761 if (row.remaining() == 0) { -762 throw new IllegalArgumentException("Row length is 0"); -763 } -764 if (row.remaining() > HConstants.MAX_ROW_LENGTH) { -765 throw new IllegalArgumentException("Row length " + row.remaining() + " is > " + -766 HConstants.MAX_ROW_LENGTH); -767 } -768 } -769 -770 Mutation add(Cell cell) throws IOException { -771 //Checking that the row of the kv is the same as the mutation -772 // TODO: It is fraught with risk if user pass the wrong row. -773 // Throwing the IllegalArgumentException is more suitable I'd say. -774 if (!CellUtil.matchingRows(cell, this.row)) { -775 throw new WrongRowIOException("The row in " + cell.toString() + -776 " doesn't match the original one " + Bytes.toStringBinary(this.row)); -777 } -778 -779 if (cell.getFamilyArray() == null || cell.getFamilyLength() == 0) { -780 throw new IllegalArgumentException("Family cannot be null"); -781 } -782 -783 byte[] family = CellUtil.cloneFamily(cell); -784 if (cell instanceof ExtendedCell) { -785 getCellList(family).add(cell); -786 } else { -787 getCellList(family).add(new CellWrapper(cell)); -788 } -789 return this; -790 } -791 -792 private static final class CellWrapper implements ExtendedCell { -793 private static final long FIXED_OVERHEAD = ClassSize.align( -794 ClassSize.OBJECT // object header -795 + KeyValue.TIMESTAMP_SIZE // timestamp -796 + Bytes.SIZEOF_LONG // sequence id -797 + 1 * ClassSize.REFERENCE); // references to cell -798 private final Cell cell; -799 private long sequenceId; -800 private long timestamp; -801 -802 CellWrapper(Cell cell) { -803 assert !(cell instanceof ExtendedCell); -804 this.cell = cell; -805 this.sequenceId = cell.getSequenceId(); -806 this.timestamp = cell.getTimestamp(); -807 } -808 -809 @Override -810 public void setSequenceId(long seqId) { -811 sequenceId = seqId; -812 } +743 static byte [] checkRow(final byte [] row) { +744 return checkRow(row, 0, row == null? 0: row.length); +745 } +746 +747 /** +748 * @param row Row to check +749 * @param offset +750 * @param length +751 * @throws IllegalArgumentException Thrown if <code>row</code> is empty or null or +752 * &gt; {@link HConstants#MAX_ROW_LENGTH} +753 * @return <code>row</code> +754 */ +755 static byte [] checkRow(final byte [] row, final int offset, final int length) { +756 if (row == null) { +757 throw new IllegalArgumentException("Row buffer is null"); +758 } +759 if (length == 0) { +760 throw new IllegalArgumentException("Row length is 0"); +761 } +762 if (length > HConstants.MAX_ROW_LENGTH) { +763 throw new IllegalArgumentException("Row length " + length + " is > " + +764 HConstants.MAX_ROW_LENGTH); +765 } +766 return row; +767 } +768 +769 static void checkRow(ByteBuffer row) { +770 if (row == null) { +771 throw new IllegalArgumentException("Row buffer is null"); +772 } +773 if (row.remaining() == 0) { +774 throw new IllegalArgumentException("Row length is 0"); +775 } +776 if (row.remaining() > HConstants.MAX_ROW_LENGTH) { +777 throw new IllegalArgumentException("Row length " + row.remaining() + " is > " + +778 HConstants.MAX_ROW_LENGTH); +779 } +780 } +781 +782 Mutation add(Cell cell) throws IOException { +783 //Checking that the row of the kv is the same as the mutation +784 // TODO: It is fraught with risk if user pass the wrong row. +785 // Throwing the IllegalArgumentException is more suitable I'd say. +786 if (!CellUtil.matchingRows(cell, this.row)) { +787 throw new WrongRowIOException("The row in " + cell.toString() + +788 " doesn't match the original one " + Bytes.toStringBinary(this.row)); +789 } +790 +791 if (cell.getFamilyArray() == null || cell.getFamilyLength() == 0) { +792 throw new IllegalArgumentException("Family cannot be null"); +793 } +794 +795 byte[] family = CellUtil.cloneFamily(cell); +796 if (cell instanceof ExtendedCell) { +797 getCellList(family).add(cell); +798 } else { +799 getCellList(family).add(new CellWrapper(cell)); +800 } +801 return this; +802 } +803 +804 private static final class CellWrapper implements ExtendedCell { +805 private static final long FIXED_OVERHEAD = ClassSize.align( +806 ClassSize.OBJECT // object header +807 + KeyValue.TIMESTAMP_SIZE // timestamp +808 + Bytes.SIZEOF_LONG // sequence id +809 + 1 * ClassSize.REFERENCE); // references to cell +810 private final Cell cell; +811 private long sequenceId; +812 private long timestamp; 813 -814 @Override -815 public void setTimestamp(long ts) { -816 timestamp = ts; -817 } -818 -819 @Override -820 public void setTimestamp(byte[] ts) { -821 timestamp = Bytes.toLong(ts); -822 } -823 -824 @Override -825 public long