HBASE-8782 Thrift2 can not parse values when using framed transport (Hamed Madani)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1496556 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Lars George 2013-06-25 17:40:19 +00:00
parent a34d443c95
commit 6f54a1d4b3

View File

@ -28,6 +28,7 @@ import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.putsFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultFromHBase; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultsFromHBase; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultsFromHBase;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.scanFromThrift; import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.scanFromThrift;
import static org.apache.thrift.TBaseHelper.byteBufferToByteArray;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
@ -45,7 +46,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.HTablePool; import org.apache.hadoop.hbase.client.HTablePool;
import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.ResultScanner;
@ -114,7 +114,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
return result; return result;
} }
} }
private static long now() { private static long now() {
return System.nanoTime(); return System.nanoTime();
} }
@ -123,8 +123,8 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
htablePool = new HTablePool(conf, Integer.MAX_VALUE); htablePool = new HTablePool(conf, Integer.MAX_VALUE);
} }
private HTableInterface getTable(byte[] tableName) { private HTableInterface getTable(ByteBuffer tableName) {
return htablePool.getTable(tableName); return htablePool.getTable(byteBufferToByteArray(tableName));
} }
private void closeTable(HTableInterface table) throws TIOError { private void closeTable(HTableInterface table) throws TIOError {
@ -143,7 +143,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
/** /**
* Assigns a unique ID to the scanner and adds the mapping to an internal HashMap. * Assigns a unique ID to the scanner and adds the mapping to an internal HashMap.
* *
* @param scanner to add * @param scanner to add
* @return Id for this Scanner * @return Id for this Scanner
*/ */
@ -155,7 +155,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
/** /**
* Returns the Scanner associated with the specified Id. * Returns the Scanner associated with the specified Id.
* *
* @param id of the Scanner to get * @param id of the Scanner to get
* @return a Scanner, or null if the Id is invalid * @return a Scanner, or null if the Id is invalid
*/ */
@ -165,7 +165,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
/** /**
* Removes the scanner associated with the specified ID from the internal HashMap. * Removes the scanner associated with the specified ID from the internal HashMap.
* *
* @param id of the Scanner to remove * @param id of the Scanner to remove
* @return the removed Scanner, or <code>null</code> if the Id is invalid * @return the removed Scanner, or <code>null</code> if the Id is invalid
*/ */
@ -175,7 +175,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public boolean exists(ByteBuffer table, TGet get) throws TIOError, TException { public boolean exists(ByteBuffer table, TGet get) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
return htable.exists(getFromThrift(get)); return htable.exists(getFromThrift(get));
} catch (IOException e) { } catch (IOException e) {
@ -187,7 +187,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public TResult get(ByteBuffer table, TGet get) throws TIOError, TException { public TResult get(ByteBuffer table, TGet get) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
return resultFromHBase(htable.get(getFromThrift(get))); return resultFromHBase(htable.get(getFromThrift(get)));
} catch (IOException e) { } catch (IOException e) {
@ -199,7 +199,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public List<TResult> getMultiple(ByteBuffer table, List<TGet> gets) throws TIOError, TException { public List<TResult> getMultiple(ByteBuffer table, List<TGet> gets) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
return resultsFromHBase(htable.get(getsFromThrift(gets))); return resultsFromHBase(htable.get(getsFromThrift(gets)));
} catch (IOException e) { } catch (IOException e) {
@ -211,7 +211,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public void put(ByteBuffer table, TPut put) throws TIOError, TException { public void put(ByteBuffer table, TPut put) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
htable.put(putFromThrift(put)); htable.put(putFromThrift(put));
} catch (IOException e) { } catch (IOException e) {
@ -224,9 +224,10 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public boolean checkAndPut(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TPut put) public boolean checkAndPut(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TPut put)
throws TIOError, TException { throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
return htable.checkAndPut(row.array(), family.array(), qualifier.array(), (value == null) ? null : value.array(), putFromThrift(put)); return htable.checkAndPut(byteBufferToByteArray(row), byteBufferToByteArray(family),
byteBufferToByteArray(qualifier), (value == null) ? null : byteBufferToByteArray(value), putFromThrift(put));
} catch (IOException e) { } catch (IOException e) {
throw getTIOError(e); throw getTIOError(e);
} finally { } finally {
@ -236,7 +237,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public void putMultiple(ByteBuffer table, List<TPut> puts) throws TIOError, TException { public void putMultiple(ByteBuffer table, List<TPut> puts) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
htable.put(putsFromThrift(puts)); htable.put(putsFromThrift(puts));
} catch (IOException e) { } catch (IOException e) {
@ -248,7 +249,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public void deleteSingle(ByteBuffer table, TDelete deleteSingle) throws TIOError, TException { public void deleteSingle(ByteBuffer table, TDelete deleteSingle) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
htable.delete(deleteFromThrift(deleteSingle)); htable.delete(deleteFromThrift(deleteSingle));
} catch (IOException e) { } catch (IOException e) {
@ -260,7 +261,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public List<TDelete> deleteMultiple(ByteBuffer table, List<TDelete> deletes) throws TIOError, TException { public List<TDelete> deleteMultiple(ByteBuffer table, List<TDelete> deletes) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
htable.delete(deletesFromThrift(deletes)); htable.delete(deletesFromThrift(deletes));
} catch (IOException e) { } catch (IOException e) {
@ -274,13 +275,15 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value,
TDelete deleteSingle) throws TIOError, TException { TDelete deleteSingle) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
if (value == null) { if (value == null) {
return htable.checkAndDelete(row.array(), family.array(), qualifier.array(), null, deleteFromThrift(deleteSingle)); return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family),
byteBufferToByteArray(qualifier), null, deleteFromThrift(deleteSingle));
} else { } else {
return htable.checkAndDelete(row.array(), family.array(), qualifier.array(), value.array(), deleteFromThrift(deleteSingle)); return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family),
byteBufferToByteArray(qualifier), byteBufferToByteArray(value), deleteFromThrift(deleteSingle));
} }
} catch (IOException e) { } catch (IOException e) {
throw getTIOError(e); throw getTIOError(e);
@ -291,7 +294,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public TResult increment(ByteBuffer table, TIncrement increment) throws TIOError, TException { public TResult increment(ByteBuffer table, TIncrement increment) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
try { try {
return resultFromHBase(htable.increment(incrementFromThrift(increment))); return resultFromHBase(htable.increment(incrementFromThrift(increment)));
} catch (IOException e) { } catch (IOException e) {
@ -303,7 +306,7 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@Override @Override
public int openScanner(ByteBuffer table, TScan scan) throws TIOError, TException { public int openScanner(ByteBuffer table, TScan scan) throws TIOError, TException {
HTableInterface htable = getTable(table.array()); HTableInterface htable = getTable(table);
ResultScanner resultScanner = null; ResultScanner resultScanner = null;
try { try {
resultScanner = htable.getScanner(scanFromThrift(scan)); resultScanner = htable.getScanner(scanFromThrift(scan));