-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HBASE-23705 Add CellComparator to HFileContext #1062
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,16 +17,15 @@ | |
*/ | ||
package org.apache.hadoop.hbase; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Comparator; | ||
|
||
import org.apache.hadoop.hbase.KeyValue.Type; | ||
import org.apache.hadoop.hbase.util.ByteBufferUtils; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.apache.yetus.audience.InterfaceStability; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.hbase.thirdparty.com.google.common.primitives.Longs; | ||
|
||
/** | ||
|
@@ -377,6 +376,26 @@ private static int compareRows(byte[] left, int loffset, int llength, byte[] rig | |
return result; | ||
} | ||
|
||
@Override | ||
public int compareRows(ByteBuffer row, Cell cell) { | ||
byte [] array; | ||
int offset; | ||
int len = row.remaining(); | ||
if (row.hasArray()) { | ||
array = row.array(); | ||
offset = row.position() + row.arrayOffset(); | ||
} else { | ||
// We copy the row array if offheap just so we can do a compare. We do this elsewhere too | ||
// in BBUtils when Cell is backed by an offheap ByteBuffer. Needs fixing so no copy. TODO. | ||
array = new byte[len]; | ||
offset = 0; | ||
ByteBufferUtils.copyFromBufferToArray(array, row, row.position(), | ||
0, len); | ||
} | ||
// Reverse result since we swap the order of the params we pass below. | ||
return -compareRows(cell, array, offset, len); | ||
} | ||
|
||
@Override | ||
public Comparator getSimpleComparator() { | ||
return this; | ||
|
@@ -387,4 +406,24 @@ public Comparator getSimpleComparator() { | |
public Comparator getSimpleComparator() { | ||
return new BBKVComparator(this); | ||
} | ||
|
||
/** | ||
* Utility method that makes a guess at comparator to use based off passed tableName. | ||
* Use in extreme when no comparator specified. | ||
* @return CellComparator to use going off the {@code tableName} passed. | ||
*/ | ||
public static CellComparator getCellComparator(TableName tableName) { | ||
return getCellComparator(tableName.toBytes()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just use TableName.isMetaTableName(TableName) here? Why to have the indirection of toBytes and then compare bytes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need both. In actual filecontext, it hosts tablename as bytes only -- not as a TableName object. The TableName.toBytes doesn't actually make bytes. TN itself hosts the name in bytes. Maybe I should be clearer in a comment that no new arrays are being made in this code? |
||
} | ||
|
||
/** | ||
* Utility method that makes a guess at comparator to use based off passed tableName. | ||
* Use in extreme when no comparator specified. | ||
* @return CellComparator to use going off the {@code tableName} passed. | ||
*/ | ||
public static CellComparator getCellComparator(byte [] tableName) { | ||
// FYI, TableName.toBytes does not create an array; just returns existing array pointer. | ||
return Bytes.equals(tableName, TableName.META_TABLE_NAME.toBytes())? | ||
CellComparatorImpl.META_COMPARATOR: CellComparatorImpl.COMPARATOR; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BB passed here contain only the row bytes? The BB is sliced for row alone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Javadoc tries to make this explicit. Should I add more?
" * @param row ByteBuffer that wraps a row; will read from current position and will reading all
* remaining; will not disturb the ByteBuffer internal state."