List of usage examples for org.apache.hadoop.io Text compareTo
@Override public int compareTo(BinaryComparable other)
From source file:org.apache.accumulo.test.randomwalk.concurrent.ConcurrentFixture.java
License:Apache License
/** * * @param rand//from w ww . j a v a 2s. c om * A Random to use * @return A two element list with first being smaller than the second, but either value (or both) can be null */ public static List<Text> generateRange(Random rand) { ArrayList<Text> toRet = new ArrayList<>(2); long firstLong = rand.nextLong(); long secondLong = rand.nextLong(); Text first = null, second = null; // Having all negative values = null might be too frequent if (firstLong >= 0) first = new Text(String.format("%016x", firstLong & 0x7fffffffffffffffl)); if (secondLong >= 0) second = new Text(String.format("%016x", secondLong & 0x7fffffffffffffffl)); if (first != null && second != null && first.compareTo(second) > 0) { Text swap = first; first = second; second = swap; } toRet.add(first); toRet.add(second); return toRet; }
From source file:org.apache.accumulo.test.randomwalk.conditional.Compact.java
License:Apache License
@Override public void visit(State state, Environment env, Properties props) throws Exception { String table = state.getString("tableName"); Random rand = (Random) state.get("rand"); Connector conn = env.getConnector(); Text row1 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); Text row2 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); if (row1.compareTo(row2) >= 0) { row1 = null;/*from w ww . ja v a2 s. co m*/ row2 = null; } log.debug("compacting " + row1 + " " + row2); conn.tableOperations().compact(table, row1, row2, rand.nextBoolean(), rand.nextBoolean()); }
From source file:org.apache.accumulo.test.randomwalk.conditional.Flush.java
License:Apache License
@Override public void visit(State state, Environment env, Properties props) throws Exception { String table = state.getString("tableName"); Random rand = (Random) state.get("rand"); Connector conn = env.getConnector(); Text row1 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); Text row2 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); if (row1.compareTo(row2) >= 0) { row1 = null;/*w w w . j a v a2 s. c o m*/ row2 = null; } log.debug("flushing " + row1 + " " + row2); conn.tableOperations().flush(table, row1, row2, rand.nextBoolean()); }
From source file:org.apache.accumulo.test.randomwalk.conditional.Merge.java
License:Apache License
@Override public void visit(State state, Environment env, Properties props) throws Exception { String table = state.getString("tableName"); Random rand = (Random) state.get("rand"); Connector conn = env.getConnector(); Text row1 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); Text row2 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); if (row1.compareTo(row2) >= 0) { row1 = null;/*from ww w .j av a 2s .c o m*/ row2 = null; } log.debug("merging " + row1 + " " + row2); conn.tableOperations().merge(table, row1, row2); }
From source file:org.apache.accumulo.test.randomwalk.image.Verify.java
License:Apache License
@Override public void visit(State state, Environment env, Properties props) throws Exception { Random rand = new Random(); int maxVerify = Integer.parseInt(props.getProperty("maxVerify")); int numVerifications = rand.nextInt(maxVerify - 1) + 1; indexTableName = state.getString("indexTableName"); imageTableName = state.getString("imageTableName"); Connector conn = env.getConnector(); Scanner indexScanner = conn.createScanner(indexTableName, new Authorizations()); Scanner imageScanner = conn.createScanner(imageTableName, new Authorizations()); String uuid = UUID.randomUUID().toString(); MessageDigest alg = MessageDigest.getInstance("SHA-1"); alg.update(uuid.getBytes(UTF_8));//from w ww . j a v a 2 s . c om indexScanner.setRange(new Range(new Text(alg.digest()), null)); indexScanner.setBatchSize(numVerifications); Text curRow = null; int count = 0; for (Entry<Key, Value> entry : indexScanner) { curRow = entry.getKey().getRow(); String rowToVerify = entry.getValue().toString(); verifyRow(imageScanner, rowToVerify); count++; if (count == numVerifications) { break; } } if (count != numVerifications && curRow != null) { Text lastRow = (Text) state.get("lastIndexRow"); if (lastRow.compareTo(curRow) != 0) { log.error("Verified only " + count + " of " + numVerifications + " - curRow " + curRow + " lastKey " + lastRow); } } int verified = ((Integer) state.get("verified")).intValue() + numVerifications; log.debug("Verified " + numVerifications + " - Total " + verified); state.set("verified", Integer.valueOf(verified)); }
From source file:org.apache.accumulo.test.randomwalk.image.Write.java
License:Apache License
@Override public void visit(State state, Environment env, Properties props) throws Exception { MultiTableBatchWriter mtbw = env.getMultiTableBatchWriter(); BatchWriter imagesBW = mtbw.getBatchWriter(state.getString("imageTableName")); BatchWriter indexBW = mtbw.getBatchWriter(state.getString("indexTableName")); String uuid = UUID.randomUUID().toString(); Mutation m = new Mutation(new Text(uuid)); // create a fake image between 4KB and 1MB int maxSize = Integer.parseInt(props.getProperty("maxSize")); int minSize = Integer.parseInt(props.getProperty("minSize")); Random rand = new Random(); int numBytes = rand.nextInt(maxSize - minSize) + minSize; byte[] imageBytes = new byte[numBytes]; rand.nextBytes(imageBytes);// w w w . j av a2 s. c o m m.put(CONTENT_COLUMN_FAMILY, IMAGE_COLUMN_QUALIFIER, new Value(imageBytes)); // store size m.put(META_COLUMN_FAMILY, new Text("size"), new Value(String.format("%d", numBytes).getBytes(UTF_8))); // store hash MessageDigest alg = MessageDigest.getInstance("SHA-1"); alg.update(imageBytes); byte[] hash = alg.digest(); m.put(META_COLUMN_FAMILY, SHA1_COLUMN_QUALIFIER, new Value(hash)); // update write counts state.set("numWrites", state.getLong("numWrites") + 1); Long totalWrites = state.getLong("totalWrites") + 1; state.set("totalWrites", totalWrites); // set count m.put(META_COLUMN_FAMILY, COUNT_COLUMN_QUALIFIER, new Value(String.format("%d", totalWrites).getBytes(UTF_8))); // add mutation imagesBW.addMutation(m); // now add mutation to index Text row = new Text(hash); m = new Mutation(row); m.put(META_COLUMN_FAMILY, UUID_COLUMN_QUALIFIER, new Value(uuid.getBytes(UTF_8))); indexBW.addMutation(m); Text lastRow = (Text) state.get("lastIndexRow"); if (lastRow.compareTo(row) < 0) { state.set("lastIndexRow", new Text(row)); } }
From source file:org.apache.accumulo.testing.core.randomwalk.conditional.Compact.java
License:Apache License
@Override public void visit(State state, RandWalkEnv env, Properties props) throws Exception { String table = state.getString("tableName"); Random rand = (Random) state.get("rand"); Connector conn = env.getAccumuloConnector(); Text row1 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); Text row2 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); if (row1.compareTo(row2) >= 0) { row1 = null;/*w w w.j a v a2 s . com*/ row2 = null; } log.debug("compacting " + row1 + " " + row2); conn.tableOperations().compact(table, row1, row2, rand.nextBoolean(), rand.nextBoolean()); }
From source file:org.apache.accumulo.testing.core.randomwalk.conditional.Flush.java
License:Apache License
@Override public void visit(State state, RandWalkEnv env, Properties props) throws Exception { String table = state.getString("tableName"); Random rand = (Random) state.get("rand"); Connector conn = env.getAccumuloConnector(); Text row1 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); Text row2 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); if (row1.compareTo(row2) >= 0) { row1 = null;//from w ww . jav a 2s .c o m row2 = null; } log.debug("flushing " + row1 + " " + row2); conn.tableOperations().flush(table, row1, row2, rand.nextBoolean()); }
From source file:org.apache.accumulo.testing.core.randomwalk.conditional.Merge.java
License:Apache License
@Override public void visit(State state, RandWalkEnv env, Properties props) throws Exception { String table = state.getString("tableName"); Random rand = (Random) state.get("rand"); Connector conn = env.getAccumuloConnector(); Text row1 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); Text row2 = new Text(Utils.getBank(rand.nextInt((Integer) state.get("numBanks")))); if (row1.compareTo(row2) >= 0) { row1 = null;/*w ww .ja v a 2s . co m*/ row2 = null; } log.debug("merging " + row1 + " " + row2); conn.tableOperations().merge(table, row1, row2); }
From source file:org.apache.accumulo.testing.core.randomwalk.image.Verify.java
License:Apache License
@Override public void visit(State state, RandWalkEnv env, Properties props) throws Exception { Random rand = new Random(); int maxVerify = Integer.parseInt(props.getProperty("maxVerify")); int numVerifications = rand.nextInt(maxVerify - 1) + 1; indexTableName = state.getString("indexTableName"); imageTableName = state.getString("imageTableName"); Connector conn = env.getAccumuloConnector(); Scanner indexScanner = conn.createScanner(indexTableName, new Authorizations()); Scanner imageScanner = conn.createScanner(imageTableName, new Authorizations()); String uuid = UUID.randomUUID().toString(); MessageDigest alg = MessageDigest.getInstance("SHA-1"); alg.update(uuid.getBytes(UTF_8));//from w w w. jav a 2s .co m indexScanner.setRange(new Range(new Text(alg.digest()), null)); indexScanner.setBatchSize(numVerifications); Text curRow = null; int count = 0; for (Entry<Key, Value> entry : indexScanner) { curRow = entry.getKey().getRow(); String rowToVerify = entry.getValue().toString(); verifyRow(imageScanner, rowToVerify); count++; if (count == numVerifications) { break; } } if (count != numVerifications && curRow != null) { Text lastRow = (Text) state.get("lastIndexRow"); if (lastRow.compareTo(curRow) != 0) { log.error("Verified only " + count + " of " + numVerifications + " - curRow " + curRow + " lastKey " + lastRow); } } int verified = ((Integer) state.get("verified")).intValue() + numVerifications; log.debug("Verified " + numVerifications + " - Total " + verified); state.set("verified", Integer.valueOf(verified)); }