diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java index 569ef71..e9a1807 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java @@ -20,8 +20,14 @@ package org.apache.hadoop.hbase; import static org.codehaus.jackson.map.SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.PrintStream; +import java.io.PrintWriter; import java.lang.reflect.Constructor; import java.math.BigDecimal; import java.math.MathContext; @@ -36,6 +42,7 @@ import java.util.Queue; import java.util.Random; import java.util.TreeMap; import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -121,6 +128,9 @@ public class PerformanceEvaluation extends Configured implements Tool { static { MAPPER.configure(SORT_PROPERTIES_ALPHABETICALLY, true); } + private static final Object writeGetsLock = new Object(); + private static ConcurrentLinkedDeque getsQueue = new ConcurrentLinkedDeque(); + private static final String getsStorageFilePath = "/tmp/getsForTest"; public static final String TABLE_NAME = "TestTable"; public static final byte[] FAMILY_NAME = Bytes.toBytes("info"); @@ -578,6 +588,7 @@ public class PerformanceEvaluation extends Configured implements Tool { * below copying your new option from the 'that' to the 'this'. Look for 'clone' below. */ static class TestOptions { + boolean loadGets = false; String cmdName = null; boolean nomapred = false; boolean filterAll = false; @@ -658,6 +669,7 @@ public class PerformanceEvaluation extends Configured implements Tool { this.addColumns = that.addColumns; this.columns = that.columns; this.caching = that.caching; + this.loadGets = that.loadGets; } public int getCaching() { @@ -1350,7 +1362,17 @@ public class PerformanceEvaluation extends Configured implements Tool { if (opts.randomSleep > 0) { Thread.sleep(rd.nextInt(opts.randomSleep)); } - Get get = new Get(getRandomRow(this.rand, opts.totalRows)); + byte[] row; + if (opts.loadGets) { + String rowStr = getsQueue.poll(); + if (rowStr == null) { + return; + } + row = Bytes.toBytes(rowStr); + } else { + row = getRandomRow(this.rand, opts.totalRows); + } + Get get = new Get(row); if (opts.addColumns) { get.addColumn(FAMILY_NAME, QUALIFIER_NAME); } else { @@ -1366,6 +1388,7 @@ public class PerformanceEvaluation extends Configured implements Tool { if (this.gets.size() == opts.multiGet) { Result [] rs = this.table.get(this.gets); updateValueSize(rs); + if (!opts.loadGets) recordGets(this.gets); this.gets.clear(); } } else { @@ -1373,6 +1396,24 @@ public class PerformanceEvaluation extends Configured implements Tool { } } + private void recordGets(ArrayList gets) throws IOException { + LOG.info("Store gets into file" + getsStorageFilePath); + FileWriter writer; + try { + writer = new FileWriter(new File(getsStorageFilePath), true); + } catch (IOException e) { + LOG.error("Failed to open file " + getsStorageFilePath); + throw e; + } + PrintWriter pw = new PrintWriter(writer); + synchronized (writeGetsLock) { + for (Get get : gets) { + pw.println(Bytes.toString(get.getRow())); + } + pw.close(); + } + } + @Override protected int getReportingPeriod() { int period = opts.perClientRunRows / 10; @@ -1675,6 +1716,14 @@ public class PerformanceEvaluation extends Configured implements Tool { if (admin != null) admin.close(); if (connection != null) connection.close(); } + if (opts.loadGets) { + try { + loadGets(); + } catch (IOException e) { + LOG.error("Failed to load gets from file", e); + throw new RuntimeException(e); + } + } if (opts.nomapred) { doLocalClients(opts, getConf()); } else { @@ -1682,6 +1731,25 @@ public class PerformanceEvaluation extends Configured implements Tool { } } + private void loadGets() throws IOException { + FileReader reader; + try { + reader = new FileReader(new File(getsStorageFilePath)); + } catch (FileNotFoundException e) { + LOG.error("Failed to open file " + getsStorageFilePath); + throw e; + } + BufferedReader br = new BufferedReader(reader); + String line = null; + try { + while ((line = br.readLine()) != null) { + getsQueue.add(line); + } + } finally { + if (br != null) br.close(); + } + } + protected void printUsage() { printUsage(this.getClass().getName(), null); } @@ -1784,6 +1852,11 @@ public class PerformanceEvaluation extends Configured implements Tool { String cmd = null; while ((cmd = args.poll()) != null) { + if (cmd.startsWith("--loadGets")) { + opts.loadGets = true; + continue; + } + if (cmd.equals("-h") || cmd.startsWith("--h")) { // place item back onto queue so that caller knows parsing was incomplete args.add(cmd);