protected void addSystemLabel(Region region, Map<String, Integer> labels, Map<String, List<Integer>> userAuths) throws IOException { if (!labels.containsKey(SYSTEM_LABEL)) { byte[] row = Bytes.toBytes(SYSTEM_LABEL_ORDINAL); Put p = new Put(row); p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(LABELS_TABLE_FAMILY) .setQualifier(LABEL_QUALIFIER) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(Bytes.toBytes(SYSTEM_LABEL)) .build()); region.put(p); labels.put(SYSTEM_LABEL, SYSTEM_LABEL_ORDINAL); } }
@Override public Boolean call() throws Exception { try (Table t = connection.getTable(tableName)) { byte[] value = Bytes.toBytes(Double.toString(ThreadLocalRandom.current().nextDouble())); byte[] rk = Bytes.toBytes(ThreadLocalRandom.current().nextLong()); Put p = new Put(rk); p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(rk) .setFamily(FAMILY) .setQualifier(QUAL) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(value) .build()); t.put(p); } return true; } }
public static void addReplicationBarrier(Put put, long openSeqNum) throws IOException { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.REPLICATION_BARRIER_FAMILY) .setQualifier(HConstants.SEQNUM_QUALIFIER) .setTimestamp(put.getTimestamp()) .setType(Type.Put) .setValue(Bytes.toBytes(openSeqNum)) .build()); }
private Cell createCell(byte[] row, byte[] family, byte[] qualifier, long ts, long value) { return CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row) .setType(Cell.Type.Put).setFamily(family).setQualifier(qualifier) .setTimestamp(ts).setValue(Bytes.toBytes(value)).build(); }
private static Put addSequenceNum(Put p, long openSeqNum, int replicaId) throws IOException { return p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(p.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(getSeqNumColumn(replicaId)) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(Bytes.toBytes(openSeqNum)) .build()); } }
private static void addRegionStateToPut(Put put, RegionState.State state) throws IOException { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(getRegionStateColumn()) .setTimestamp(put.getTimestamp()) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(state.name())) .build()); }
private static void addReplicationParent(Put put, List<RegionInfo> parents) throws IOException { byte[] value = getParentsBytes(parents); put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(put.getRow()) .setFamily(HConstants.REPLICATION_BARRIER_FAMILY).setQualifier(REPLICATION_PARENT_QUALIFIER) .setTimestamp(put.getTimestamp()).setType(Type.Put).setValue(value).build()); }
public static Put addRegionInfo(final Put p, final RegionInfo hri) throws IOException { p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(p.getRow()) .setFamily(getCatalogFamily()) .setQualifier(HConstants.REGIONINFO_QUALIFIER) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(RegionInfo.toByteArray(hri)) .build()); return p; }
/** * Generates and returns a Put containing the region info for the catalog table and the servers * @return Put object */ private static Put makePutFromRegionInfo(RegionInfo regionInfo, List<ServerName> favoredNodeList) throws IOException { Put put = null; if (favoredNodeList != null) { long time = EnvironmentEdgeManager.currentTime(); put = MetaTableAccessor.makePutFromRegionInfo(regionInfo, time); byte[] favoredNodes = getFavoredNodes(favoredNodeList); put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(FAVOREDNODES_QUALIFIER) .setTimestamp(time) .setType(Type.Put) .setValue(favoredNodes) .build()); LOG.debug("Create the region {} with favored nodes {}", regionInfo.getRegionNameAsString(), favoredNodeList); } return put; }
@Test public void testPutCopyConstructor() throws IOException { Put origin = new Put(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Cell.Type.Put) .setValue(Bytes.toBytes("value")) .build()); origin.addColumn(family, Bytes.toBytes("q0"), Bytes.toBytes("V-01")); origin.addColumn(family, Bytes.toBytes("q1"), 100, Bytes.toBytes("V-01")); Put clone = new Put(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q2"), Bytes.toBytes("V-02")); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
private static Put addEmptyLocation(Put p, int replicaId) throws IOException { CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); return p.add(builder.clear() .setRow(p.getRow()) .setFamily(getCatalogFamily()) .setQualifier(getServerColumn(replicaId)) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .build()) .add(builder.clear() .setRow(p.getRow()) .setFamily(getCatalogFamily()) .setQualifier(getStartCodeColumn(replicaId)) .setTimestamp(p.getTimestamp()) .setType(Cell.Type.Put) .build()) .add(builder.clear() .setRow(p.getRow()) .setFamily(getCatalogFamily()) .setQualifier(getSeqNumColumn(replicaId)) .setTimestamp(p.getTimestamp()) .setType(Cell.Type.Put) .build()); }
@Override public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException { byte[] row = increment.getRow(); Put put = new Put(row); long ts = getUniqueTimestamp(row); for (Map.Entry<byte[], List<Cell>> entry : increment.getFamilyCellMap().entrySet()) { for (Cell cell : entry.getValue()) { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row) .setFamily(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()) .setQualifier(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()) .setValue(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()) .setType(Cell.Type.Put).setTimestamp(ts).build()); } } c.getEnvironment().getRegion().put(put); c.bypass(); return Result.EMPTY_RESULT; }
@Test public void testDeleteCopyConstructor() throws IOException { Delete origin = new Delete(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Type.Delete) .build()); origin.addColumn(family, Bytes.toBytes("q0")); origin.addColumns(family, Bytes.toBytes("q1")); origin.addFamily(family); origin.addColumns(family, Bytes.toBytes("q2"), 100); origin.addFamilyVersion(family, 1000); Delete clone = new Delete(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q3")); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
@Test public void testAppendCopyConstructor() throws IOException { Append origin = new Append(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Type.Put) .setValue(Bytes.toBytes(100)) .build()); origin.addColumn(family, Bytes.toBytes("q0"), Bytes.toBytes("value")); origin.setTimeRange(100, 1000); Append clone = new Append(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("value")); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
@Test public void testNumberOfMemStoreScannersAfterFlush() throws IOException { long seqId = 100; long timestamp = System.currentTimeMillis(); Cell cell0 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family) .setQualifier(qf1).setTimestamp(timestamp).setType(Cell.Type.Put) .setValue(qf1).build(); PrivateCellUtil.setSequenceId(cell0, seqId); testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Collections.emptyList()); Cell cell1 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family) .setQualifier(qf2).setTimestamp(timestamp).setType(Cell.Type.Put) .setValue(qf1).build(); PrivateCellUtil.setSequenceId(cell1, seqId); testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Arrays.asList(cell1)); seqId = 101; timestamp = System.currentTimeMillis(); Cell cell2 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row2).setFamily(family) .setQualifier(qf2).setTimestamp(timestamp).setType(Cell.Type.Put) .setValue(qf1).build(); PrivateCellUtil.setSequenceId(cell2, seqId); testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Arrays.asList(cell1, cell2)); }
@Override public OperationStatus[] setAuths(byte[] user, List<byte[]> authLabels) throws IOException { assert labelsRegion != null; OperationStatus[] finalOpStatus = new OperationStatus[authLabels.size()]; Put p = new Put(user); CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); for (byte[] auth : authLabels) { p.add(builder.clear() .setRow(p.getRow()) .setFamily(LABELS_TABLE_FAMILY) .setQualifier(auth) .setTimestamp(p.getTimestamp()) .setType(Cell.Type.Put) .setValue(DUMMY_VALUE) .build()); } this.labelsRegion.put(p); // This is a testing impl and so not doing any caching for (int i = 0; i < authLabels.size(); i++) { finalOpStatus[i] = new OperationStatus(OperationStatusCode.SUCCESS); } return finalOpStatus; }
@Test public void testIncrementCopyConstructor() throws IOException { Increment origin = new Increment(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(100)) .build()); origin.addColumn(family, Bytes.toBytes("q0"), 4); origin.setTimeRange(100, 1000); Increment clone = new Increment(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q1"), 3); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
private Cell createCell(byte[] row, byte[] qualifier, long ts, long sequenceId, byte[] value) throws IOException { Cell c = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family) .setQualifier(qualifier).setTimestamp(ts).setType(Cell.Type.Put) .setValue(value).build(); PrivateCellUtil.setSequenceId(c, sequenceId); return c; }
@Test public void testCellBuilderWithShallowCopy() { byte[] row = new byte[]{OLD_DATA}; byte[] family = new byte[]{OLD_DATA}; byte[] qualifier = new byte[]{OLD_DATA}; byte[] value = new byte[]{OLD_DATA}; Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(family) .setQualifier(qualifier) .setType(Cell.Type.Put) .setValue(value) .build(); row[0] = NEW_DATA; family[0] = NEW_DATA; qualifier[0] = NEW_DATA; value[0] = NEW_DATA; assertEquals(NEW_DATA, cell.getRowArray()[cell.getRowOffset()]); assertEquals(NEW_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); assertEquals(NEW_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); assertEquals(NEW_DATA, cell.getValueArray()[cell.getValueOffset()]); }
@Test public void testCellBuilderWithDeepCopy() { byte[] row = new byte[]{OLD_DATA}; byte[] family = new byte[]{OLD_DATA}; byte[] qualifier = new byte[]{OLD_DATA}; byte[] value = new byte[]{OLD_DATA}; Cell cell = CellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(row) .setFamily(family) .setQualifier(qualifier) .setType(Cell.Type.Put) .setValue(value) .build(); row[0] = NEW_DATA; family[0] = NEW_DATA; qualifier[0] = NEW_DATA; value[0] = NEW_DATA; assertEquals(OLD_DATA, cell.getRowArray()[cell.getRowOffset()]); assertEquals(OLD_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); assertEquals(OLD_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); assertEquals(OLD_DATA, cell.getValueArray()[cell.getValueOffset()]); }