public static int toZeroPaddedString(byte output[], int outputOffset, long num, int width, int radix, byte[] prefix) { Preconditions.checkArgument(num >= 0); String strNum = Long.toString(num, radix); return toZeroPaddedString(output, outputOffset, strNum, width, prefix); }
public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { Preconditions.checkArgument(num >= 0); String strNum = Long.toString(num, radix); byte ret[] = new byte[Math.max(strNum.length(), width) + prefix.length]; if (toZeroPaddedString(ret, 0, strNum, width, prefix) != ret.length) throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, UTF_8)); return ret; }
public synchronized String getNextName() { while (next >= maxAllocated) { final int allocate = 100 + rand.nextInt(100); try { byte[] max = context.getZooReaderWriter().mutate(nextNamePath, null, ZooUtil.PRIVATE, new ZooReaderWriter.Mutator() { @Override public byte[] mutate(byte[] currentValue) { long l = Long.parseLong(new String(currentValue, UTF_8), Character.MAX_RADIX); l += allocate; return Long.toString(l, Character.MAX_RADIX).getBytes(UTF_8); } }); maxAllocated = Long.parseLong(new String(max, UTF_8), Character.MAX_RADIX); next = maxAllocated - allocate; } catch (Exception e) { throw new RuntimeException(e); } } return new String(FastFormat.toZeroPaddedString(next++, 7, Character.MAX_RADIX, new byte[0]), UTF_8); } }
FastFormat.toZeroPaddedString(dirCount++, 8, 16, Constants.CLONE_PREFIX_BYTES), UTF_8); FastFormat.toZeroPaddedString(dirCount++, 8, 16, Constants.CLONE_PREFIX_BYTES), UTF_8);
static final byte[] genRow(long rowLong) { return FastFormat.toZeroPaddedString(rowLong, 16, 16, EMPTY_BYTES); }
public static Text generateRow(int rowid, int startRow) { return new Text(FastFormat.toZeroPaddedString(rowid + startRow, 10, 10, ROW_PREFIX)); }
String dir = volumeManager.choose(chooserEnv, ServerConstants.getBaseUris(context)) + Constants.HDFS_TABLES_DIR + Path.SEPARATOR + tableId + Path.SEPARATOR + new String( FastFormat.toZeroPaddedString(dirCount++, 8, 16, Constants.CLONE_PREFIX_BYTES)); TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(m, new Value(dir.getBytes(UTF_8)));
public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { byte ret[] = new byte[width + prefix.length]; if (toZeroPaddedString(ret, 0, num, width, radix, prefix) != ret.length) throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, UTF_8)); return ret; }
static Key newKey(int r, int c) { return new Key(new Text(FastFormat.toZeroPaddedString(r, 9, 10, ROW_PREFIX)), new Text(FastFormat.toZeroPaddedString(c, 6, 10, COL_PREFIX))); }
private static void pc(Mutation m, int c, Value v) { m.put(new Text(FastFormat.toZeroPaddedString(c, 6, 10, COL_PREFIX)), ET, Long.MAX_VALUE, v); }
private static void pc(Mutation m, int c, Value v) { m.put(new Text(FastFormat.toZeroPaddedString(c, 3, 10, COL_PREFIX)), ET, v); }
static Mutation newMutation(int r) { return new Mutation(new Text(FastFormat.toZeroPaddedString(r, 9, 10, ROW_PREFIX))); }
static Mutation nm(int r) { return new Mutation(new Text(FastFormat.toZeroPaddedString(r, 6, 10, ROW_PREFIX))); }
int index = ingestInstanceId.length; val[index++] = ':'; int added = FastFormat.toZeroPaddedString(val, index, count, 16, 16, EMPTY_BYTES); if (added != 16) throw new RuntimeException(" " + added); cksum.update(val, 0, index); cksum.getValue(); FastFormat.toZeroPaddedString(val, index, cksum.getValue(), 8, 16, EMPTY_BYTES);
public synchronized String getNextName() { while (next >= maxAllocated) { final int allocate = 100 + rand.nextInt(100); try { byte[] max = ZooReaderWriter.getRetryingInstance().mutate(nextNamePath, null, ZooUtil.PRIVATE, new ZooReaderWriter.Mutator() { public byte[] mutate(byte[] currentValue) throws Exception { long l = Long.parseLong(new String(currentValue, UTF_8), Character.MAX_RADIX); l += allocate; return Long.toString(l, Character.MAX_RADIX).getBytes(UTF_8); } }); maxAllocated = Long.parseLong(new String(max, UTF_8), Character.MAX_RADIX); next = maxAllocated - allocate; } catch (Exception e) { throw new RuntimeException(e); } } return new String(FastFormat.toZeroPaddedString(next++, 7, Character.MAX_RADIX, new byte[0]), UTF_8); }
public synchronized String getNextName() { while (next >= maxAllocated) { final int allocate = 100 + rand.nextInt(100); try { byte[] max = ZooReaderWriter.getInstance().mutate(nextNamePath, null, ZooUtil.PRIVATE, new ZooReaderWriter.Mutator() { @Override public byte[] mutate(byte[] currentValue) throws Exception { long l = Long.parseLong(new String(currentValue, UTF_8), Character.MAX_RADIX); l += allocate; return Long.toString(l, Character.MAX_RADIX).getBytes(UTF_8); } }); maxAllocated = Long.parseLong(new String(max, UTF_8), Character.MAX_RADIX); next = maxAllocated - allocate; } catch (Exception e) { throw new RuntimeException(e); } } return new String(FastFormat.toZeroPaddedString(next++, 7, Character.MAX_RADIX, new byte[0]), UTF_8); }
public static Mutation genMutation(long rowLong, int cfInt, int cqInt, ColumnVisibility cv, byte[] ingestInstanceId, long count, byte[] prevRow, Random r, boolean checksum) { // Adler32 is supposed to be faster, but according to wikipedia is not good for small data.... // so used CRC32 instead CRC32 cksum = null; byte[] rowString = genRow(rowLong); byte[] cfString = FastFormat.toZeroPaddedString(cfInt, 4, 16, EMPTY_BYTES); byte[] cqString = FastFormat.toZeroPaddedString(cqInt, 4, 16, EMPTY_BYTES); if (checksum) { cksum = new CRC32(); cksum.update(rowString); cksum.update(cfString); cksum.update(cqString); cksum.update(cv.getExpression()); } Mutation m = new Mutation(new Text(rowString)); m.put(new Text(cfString), new Text(cqString), cv, createValue(ingestInstanceId, count, prevRow, cksum)); return m; }
private static long write(Connector conn, ArrayList<byte[]> cfset, String table) throws TableNotFoundException, MutationsRejectedException { Random rand = new Random(); byte val[] = new byte[50]; BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig()); long t1 = System.currentTimeMillis(); for (int i = 0; i < 1 << 15; i++) { byte[] row = FastFormat.toZeroPaddedString(abs(rand.nextLong()), 16, 16, new byte[0]); Mutation m = new Mutation(row); for (byte[] cf : cfset) { byte[] cq = FastFormat.toZeroPaddedString(rand.nextInt(1 << 16), 4, 16, new byte[0]); rand.nextBytes(val); m.put(cf, cq, val); } bw.addMutation(m); } bw.close(); long t2 = System.currentTimeMillis(); return t2 - t1; }
Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(FastFormat.toZeroPaddedString(dirCount++, 8, 16, "/c-".getBytes(UTF_8)))); currentRow = metadataRow; mbw.addMutation(m); m = new Mutation(metadataRow); Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(FastFormat.toZeroPaddedString(dirCount++, 8, 16, "/c-".getBytes(UTF_8))));
FastFormat.toZeroPaddedString(abs(rand.nextLong()), 16, 16, new byte[0])));