HBASE-4461 Expose getRowOrBefore via Thrift (jgray)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1175220 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Gray 2011-09-24 18:53:04 +00:00
parent d607687eb1
commit 62e8b5d61d
5 changed files with 2152 additions and 15 deletions

View File

@ -3,6 +3,7 @@ Release 0.93.0 - Unreleased
IMPROVEMENT IMPROVEMENT
HBASE-4132 Extend the WALActionsListener API to accomodate log archival HBASE-4132 Extend the WALActionsListener API to accomodate log archival
(dhruba borthakur) (dhruba borthakur)
HBASE-4461 Expose getRowOrBefore via Thrift (jgray)
Release 0.92.0 - Unreleased Release 0.92.0 - Unreleased
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -18,6 +18,8 @@
package org.apache.hadoop.hbase.thrift; package org.apache.hadoop.hbase.thrift;
import static org.apache.hadoop.hbase.util.Bytes.getBytes;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -47,6 +49,7 @@ import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HServerAddress; import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HBaseAdmin;
@ -56,9 +59,9 @@ import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.Filter; import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.ParseFilter;
import org.apache.hadoop.hbase.filter.PrefixFilter; import org.apache.hadoop.hbase.filter.PrefixFilter;
import org.apache.hadoop.hbase.filter.WhileMatchFilter; import org.apache.hadoop.hbase.filter.WhileMatchFilter;
import org.apache.hadoop.hbase.filter.ParseFilter;
import org.apache.hadoop.hbase.thrift.generated.AlreadyExists; import org.apache.hadoop.hbase.thrift.generated.AlreadyExists;
import org.apache.hadoop.hbase.thrift.generated.BatchMutation; import org.apache.hadoop.hbase.thrift.generated.BatchMutation;
import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor; import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor;
@ -72,6 +75,7 @@ import org.apache.hadoop.hbase.thrift.generated.TRowResult;
import org.apache.hadoop.hbase.thrift.generated.TScan; import org.apache.hadoop.hbase.thrift.generated.TScan;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.VersionInfo; import org.apache.hadoop.hbase.util.VersionInfo;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TCompactProtocol; import org.apache.thrift.protocol.TCompactProtocol;
@ -87,8 +91,6 @@ import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport; import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportFactory; import org.apache.thrift.transport.TTransportFactory;
import static org.apache.hadoop.hbase.util.Bytes.getBytes;
/** /**
* ThriftServer - this class starts up a Thrift server which implements the * ThriftServer - this class starts up a Thrift server which implements the
* Hbase API specified in the Hbase.thrift IDL file. * Hbase API specified in the Hbase.thrift IDL file.
@ -897,6 +899,60 @@ public class ThriftServer {
throw new IOError(e.getMessage()); throw new IOError(e.getMessage());
} }
} }
@Override
public List<TCell> getRowOrBefore(ByteBuffer tableName, ByteBuffer row,
ByteBuffer family) throws IOError {
try {
HTable table = getTable(getBytes(tableName));
Result result = table.getRowOrBefore(getBytes(row), getBytes(family));
return ThriftUtilities.cellFromHBase(result.sorted());
} catch (IOException e) {
throw new IOError(e.getMessage());
}
}
@Override
public TRegionInfo getRegionInfo(ByteBuffer searchRow) throws IOError {
try {
HTable table = getTable(HConstants.META_TABLE_NAME);
Result startRowResult = table.getRowOrBefore(
searchRow.array(), HConstants.CATALOG_FAMILY);
if (startRowResult == null) {
throw new IOException("Cannot find row in .META., row="
+ Bytes.toString(searchRow.array()));
}
// find region start and end keys
byte[] value = startRowResult.getValue(HConstants.CATALOG_FAMILY,
HConstants.REGIONINFO_QUALIFIER);
if (value == null || value.length == 0) {
throw new IOException("HRegionInfo REGIONINFO was null or " +
" empty in Meta for row="
+ Bytes.toString(searchRow.array()));
}
HRegionInfo regionInfo = Writables.getHRegionInfo(value);
TRegionInfo region = new TRegionInfo();
region.setStartKey(regionInfo.getStartKey());
region.setEndKey(regionInfo.getEndKey());
region.id = regionInfo.getRegionId();
region.setName(regionInfo.getRegionName());
region.version = regionInfo.getVersion();
// find region assignment to server
value = startRowResult.getValue(HConstants.CATALOG_FAMILY,
HConstants.SERVER_QUALIFIER);
if (value != null && value.length > 0) {
ServerName sn = new ServerName(value);
region.setServerName(Bytes.toBytes(sn.getHostname()));
region.port = sn.getPort();
}
return region;
} catch (IOException e) {
throw new IOError(e.getMessage());
}
}
} }
// //

View File

@ -31,12 +31,16 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.I64, (short)3); private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.I64, (short)3);
private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)4); private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)4);
private static final org.apache.thrift.protocol.TField VERSION_FIELD_DESC = new org.apache.thrift.protocol.TField("version", org.apache.thrift.protocol.TType.BYTE, (short)5); private static final org.apache.thrift.protocol.TField VERSION_FIELD_DESC = new org.apache.thrift.protocol.TField("version", org.apache.thrift.protocol.TType.BYTE, (short)5);
private static final org.apache.thrift.protocol.TField SERVER_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("serverName", org.apache.thrift.protocol.TType.STRING, (short)6);
private static final org.apache.thrift.protocol.TField PORT_FIELD_DESC = new org.apache.thrift.protocol.TField("port", org.apache.thrift.protocol.TType.I32, (short)7);
public ByteBuffer startKey; // required public ByteBuffer startKey; // required
public ByteBuffer endKey; // required public ByteBuffer endKey; // required
public long id; // required public long id; // required
public ByteBuffer name; // required public ByteBuffer name; // required
public byte version; // required public byte version; // required
public ByteBuffer serverName; // required
public int port; // required
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum { public enum _Fields implements org.apache.thrift.TFieldIdEnum {
@ -44,7 +48,9 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
END_KEY((short)2, "endKey"), END_KEY((short)2, "endKey"),
ID((short)3, "id"), ID((short)3, "id"),
NAME((short)4, "name"), NAME((short)4, "name"),
VERSION((short)5, "version"); VERSION((short)5, "version"),
SERVER_NAME((short)6, "serverName"),
PORT((short)7, "port");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
@ -69,6 +75,10 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
return NAME; return NAME;
case 5: // VERSION case 5: // VERSION
return VERSION; return VERSION;
case 6: // SERVER_NAME
return SERVER_NAME;
case 7: // PORT
return PORT;
default: default:
return null; return null;
} }
@ -111,7 +121,8 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
// isset id assignments // isset id assignments
private static final int __ID_ISSET_ID = 0; private static final int __ID_ISSET_ID = 0;
private static final int __VERSION_ISSET_ID = 1; private static final int __VERSION_ISSET_ID = 1;
private BitSet __isset_bit_vector = new BitSet(2); private static final int __PORT_ISSET_ID = 2;
private BitSet __isset_bit_vector = new BitSet(3);
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static { static {
@ -126,6 +137,10 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , "Text"))); new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , "Text")));
tmpMap.put(_Fields.VERSION, new org.apache.thrift.meta_data.FieldMetaData("version", org.apache.thrift.TFieldRequirementType.DEFAULT, tmpMap.put(_Fields.VERSION, new org.apache.thrift.meta_data.FieldMetaData("version", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BYTE))); new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BYTE)));
tmpMap.put(_Fields.SERVER_NAME, new org.apache.thrift.meta_data.FieldMetaData("serverName", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , "Text")));
tmpMap.put(_Fields.PORT, new org.apache.thrift.meta_data.FieldMetaData("port", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
metaDataMap = Collections.unmodifiableMap(tmpMap); metaDataMap = Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TRegionInfo.class, metaDataMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TRegionInfo.class, metaDataMap);
} }
@ -138,7 +153,9 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
ByteBuffer endKey, ByteBuffer endKey,
long id, long id,
ByteBuffer name, ByteBuffer name,
byte version) byte version,
ByteBuffer serverName,
int port)
{ {
this(); this();
this.startKey = startKey; this.startKey = startKey;
@ -148,6 +165,9 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
this.name = name; this.name = name;
this.version = version; this.version = version;
setVersionIsSet(true); setVersionIsSet(true);
this.serverName = serverName;
this.port = port;
setPortIsSet(true);
} }
/** /**
@ -167,6 +187,10 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
this.name = other.name; this.name = other.name;
} }
this.version = other.version; this.version = other.version;
if (other.isSetServerName()) {
this.serverName = other.serverName;
}
this.port = other.port;
} }
public TRegionInfo deepCopy() { public TRegionInfo deepCopy() {
@ -182,6 +206,9 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
this.name = null; this.name = null;
setVersionIsSet(false); setVersionIsSet(false);
this.version = 0; this.version = 0;
this.serverName = null;
setPortIsSet(false);
this.port = 0;
} }
public byte[] getStartKey() { public byte[] getStartKey() {
@ -332,6 +359,63 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
__isset_bit_vector.set(__VERSION_ISSET_ID, value); __isset_bit_vector.set(__VERSION_ISSET_ID, value);
} }
public byte[] getServerName() {
setServerName(org.apache.thrift.TBaseHelper.rightSize(serverName));
return serverName == null ? null : serverName.array();
}
public ByteBuffer bufferForServerName() {
return serverName;
}
public TRegionInfo setServerName(byte[] serverName) {
setServerName(serverName == null ? (ByteBuffer)null : ByteBuffer.wrap(serverName));
return this;
}
public TRegionInfo setServerName(ByteBuffer serverName) {
this.serverName = serverName;
return this;
}
public void unsetServerName() {
this.serverName = null;
}
/** Returns true if field serverName is set (has been assigned a value) and false otherwise */
public boolean isSetServerName() {
return this.serverName != null;
}
public void setServerNameIsSet(boolean value) {
if (!value) {
this.serverName = null;
}
}
public int getPort() {
return this.port;
}
public TRegionInfo setPort(int port) {
this.port = port;
setPortIsSet(true);
return this;
}
public void unsetPort() {
__isset_bit_vector.clear(__PORT_ISSET_ID);
}
/** Returns true if field port is set (has been assigned a value) and false otherwise */
public boolean isSetPort() {
return __isset_bit_vector.get(__PORT_ISSET_ID);
}
public void setPortIsSet(boolean value) {
__isset_bit_vector.set(__PORT_ISSET_ID, value);
}
public void setFieldValue(_Fields field, Object value) { public void setFieldValue(_Fields field, Object value) {
switch (field) { switch (field) {
case START_KEY: case START_KEY:
@ -374,6 +458,22 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
} }
break; break;
case SERVER_NAME:
if (value == null) {
unsetServerName();
} else {
setServerName((ByteBuffer)value);
}
break;
case PORT:
if (value == null) {
unsetPort();
} else {
setPort((Integer)value);
}
break;
} }
} }
@ -394,6 +494,12 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
case VERSION: case VERSION:
return Byte.valueOf(getVersion()); return Byte.valueOf(getVersion());
case SERVER_NAME:
return getServerName();
case PORT:
return Integer.valueOf(getPort());
} }
throw new IllegalStateException(); throw new IllegalStateException();
} }
@ -415,6 +521,10 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
return isSetName(); return isSetName();
case VERSION: case VERSION:
return isSetVersion(); return isSetVersion();
case SERVER_NAME:
return isSetServerName();
case PORT:
return isSetPort();
} }
throw new IllegalStateException(); throw new IllegalStateException();
} }
@ -477,6 +587,24 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
return false; return false;
} }
boolean this_present_serverName = true && this.isSetServerName();
boolean that_present_serverName = true && that.isSetServerName();
if (this_present_serverName || that_present_serverName) {
if (!(this_present_serverName && that_present_serverName))
return false;
if (!this.serverName.equals(that.serverName))
return false;
}
boolean this_present_port = true;
boolean that_present_port = true;
if (this_present_port || that_present_port) {
if (!(this_present_port && that_present_port))
return false;
if (this.port != that.port)
return false;
}
return true; return true;
} }
@ -543,6 +671,26 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
return lastComparison; return lastComparison;
} }
} }
lastComparison = Boolean.valueOf(isSetServerName()).compareTo(typedOther.isSetServerName());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetServerName()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serverName, typedOther.serverName);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetPort()).compareTo(typedOther.isSetPort());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetPort()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.port, typedOther.port);
if (lastComparison != 0) {
return lastComparison;
}
}
return 0; return 0;
} }
@ -597,6 +745,21 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
} }
break; break;
case 6: // SERVER_NAME
if (field.type == org.apache.thrift.protocol.TType.STRING) {
this.serverName = iprot.readBinary();
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
case 7: // PORT
if (field.type == org.apache.thrift.protocol.TType.I32) {
this.port = iprot.readI32();
setPortIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
default: default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
} }
@ -633,6 +796,14 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
oprot.writeFieldBegin(VERSION_FIELD_DESC); oprot.writeFieldBegin(VERSION_FIELD_DESC);
oprot.writeByte(this.version); oprot.writeByte(this.version);
oprot.writeFieldEnd(); oprot.writeFieldEnd();
if (this.serverName != null) {
oprot.writeFieldBegin(SERVER_NAME_FIELD_DESC);
oprot.writeBinary(this.serverName);
oprot.writeFieldEnd();
}
oprot.writeFieldBegin(PORT_FIELD_DESC);
oprot.writeI32(this.port);
oprot.writeFieldEnd();
oprot.writeFieldStop(); oprot.writeFieldStop();
oprot.writeStructEnd(); oprot.writeStructEnd();
} }
@ -673,6 +844,18 @@ public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegion
sb.append("version:"); sb.append("version:");
sb.append(this.version); sb.append(this.version);
first = false; first = false;
if (!first) sb.append(", ");
sb.append("serverName:");
if (this.serverName == null) {
sb.append("null");
} else {
sb.append(this.serverName);
}
first = false;
if (!first) sb.append(", ");
sb.append("port:");
sb.append(this.port);
first = false;
sb.append(")"); sb.append(")");
return sb.toString(); return sb.toString();
} }

View File

@ -86,7 +86,9 @@ struct TRegionInfo {
2:Text endKey, 2:Text endKey,
3:i64 id, 3:i64 id,
4:Text name, 4:Text name,
5:byte version 5:byte version,
6:Text serverName,
7:i32 port
} }
/** /**
@ -778,4 +780,32 @@ service Hbase {
/** id of a scanner returned by scannerOpen */ /** id of a scanner returned by scannerOpen */
1:ScannerID id 1:ScannerID id
) throws (1:IOError io, 2:IllegalArgument ia) ) throws (1:IOError io, 2:IllegalArgument ia)
/**
* Get the row just before the specified one.
*
* @return value for specified row/column
*/
list<TCell> getRowOrBefore(
/** name of table */
1:Text tableName,
/** row key */
2:Text row,
/** column name */
3:Text family
) throws (1:IOError io)
/**
* Get the regininfo for the specified row. It scans
* the metatable to find region's start and end keys.
*
* @return value for specified row/column
*/
TRegionInfo getRegionInfo(
/** row key */
1:Text row,
) throws (1:IOError io)
} }