Skip to content

Instantly share code, notes, and snippets.

@timoha
Created May 16, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timoha/c7a236b768be9220e85e53e1ca53bf96 to your computer and use it in GitHub Desktop.
Save timoha/c7a236b768be9220e85e53e1ca53bf96 to your computer and use it in GitHub Desktop.
Get with closest_row_before on "hbase:meta" can return empty Cell during region merge/split. This gist reproduces the problem.
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.HColumnDescriptor;
public class GetMetaRow {
private static class Worker extends Thread {
private Admin a;
private TableName tn;
public Worker(Admin admin, TableName tableName) {
a = admin;
tn = tableName;
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(400);
a.split(tn);
} catch (InterruptedException e) {
break;
} catch (IOException e) {
System.out.println("WTF");
}
}
}
}
public static void main(String[] args) throws IOException, Exception {
String table = "TestGetMetaRow";
TableName tn = TableName.valueOf(table);
Configuration hconfig = HBaseConfiguration.create();
hconfig.set(HConstants.ZOOKEEPER_QUORUM, "localhost");
Connection conn = ConnectionFactory.createConnection(hconfig);
// create table
Admin admin = conn.getAdmin();
HTableDescriptor tableDescriptor = new HTableDescriptor(tn);
tableDescriptor.addFamily(new HColumnDescriptor("cf"));
admin.createTable(tableDescriptor);
// populate it with keys
Table t = conn.getTable(tn);
for (int i = 0; i < 1000; i++) {
byte[] data = Bytes.toBytes(String.format("%026d", i));
Put put = new Put(data).addColumn("cf".getBytes(), null, data);
t.put(put);
}
Worker w = new Worker(admin, tn);
w.start();
System.out.println("Starting gets on hbase:meta");
// start getting the first row region of the table until the error
Table tb = conn.getTable(TableName.valueOf("hbase:meta"));
Get g = new Get(Bytes.toBytes(table + ",,:")).addFamily("info".getBytes()).setClosestRowBefore(true);
while (true) {
Result result = tb.get(g);
if (Result.getTotalSizeOfCells(result) == 0) {
System.out.println("GOT ZERO CELLS!!!!");
break;
}
}
w.interrupt();
// clean up
admin.disableTable(tn);
admin.deleteTable(tn);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment