org.apache.hadoop.hbase.client.Delete Java Examples
The following examples show how to use
org.apache.hadoop.hbase.client.Delete.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDefaultHBaseSerde.java From envelope with Apache License 2.0 | 6 votes |
@Test public void testConvertToDelete() { byte[] rowKey = Bytes.add(Bytes.toBytes("GOOG:"), Bytes.toBytes(1000L)); byte[] cf = Bytes.toBytes("cf1"); byte[] clordid = Bytes.toBytes("clordid"); byte[] orderqty = Bytes.toBytes("orderqty"); byte[] leavesqty = Bytes.toBytes("leavesqty"); byte[] cumqty = Bytes.toBytes("cumqty"); Row row = new RowWithSchema(fullSchema, "GOOG", 1000L, "abcd", 100, 10, 5); Delete delete = serde.convertToDelete(row); Map<byte[], List<Cell>> contents = delete.getFamilyCellMap(); assertArrayEquals("Row key should be GOOG:1000L", rowKey, delete.getRow()); assertTrue("Delete contains cf1", contents.containsKey(cf)); List<Cell> cells = contents.get(cf); assertEquals("Delete should have four cells", 4, cells.size()); assertArrayEquals("Cell 0 should be cf1:clordid", clordid, CellUtil.cloneQualifier(cells.get(0))); assertArrayEquals("Cell 1 should be cf1:cumqty", cumqty, CellUtil.cloneQualifier(cells.get(1))); assertArrayEquals("Cell 2 should be cf1:leavesqty", leavesqty, CellUtil.cloneQualifier(cells.get(2))); assertArrayEquals("Cell 3 should be cf1:orderqty", orderqty, CellUtil.cloneQualifier(cells.get(3))); }
Example #2
Source File: LoadTestDataGeneratorWithACL.java From hbase with Apache License 2.0 | 6 votes |
@Override public Mutation beforeMutate(long rowkeyBase, Mutation m) throws IOException { if (!(m instanceof Delete)) { if (userNames != null && userNames.length > 0) { int mod = ((int) rowkeyBase % this.userNames.length); if (((int) rowkeyBase % specialPermCellInsertionFactor) == 0) { // These cells cannot be read back when running as user userName[mod] if (LOG.isTraceEnabled()) { LOG.trace("Adding special perm " + rowkeyBase); } m.setACL(userNames[mod], new Permission(Permission.Action.WRITE)); } else { m.setACL(userNames[mod], new Permission(Permission.Action.READ)); } } } return m; }
Example #3
Source File: RegionCoprocessorHost.java From hbase with Apache License 2.0 | 6 votes |
/** * Supports Coprocessor 'bypass'. * @param row row to check * @param filter filter * @param delete delete to commit if check succeeds * @return true or false to return to client if default processing should be bypassed, or null * otherwise */ public Boolean preCheckAndDelete(final byte [] row, final Filter filter, final Delete delete) throws IOException { boolean bypassable = true; boolean defaultResult = false; if (coprocEnvironments.isEmpty()) { return null; } return execOperationWithResult( new ObserverOperationWithResult<RegionObserver, Boolean>(regionObserverGetter, defaultResult, bypassable) { @Override public Boolean call(RegionObserver observer) throws IOException { return observer.preCheckAndDelete(this, row, filter, delete, getResult()); } }); }
Example #4
Source File: HBaseResourceStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@Override protected void deleteResourceImpl(String resPath, long timestamp) throws IOException { Table table = getConnection().getTable(TableName.valueOf(tableName)); try { boolean hdfsResourceExist = isHdfsResourceExist(table, resPath); long origLastModified = getResourceLastModified(table, resPath); if (checkTimeStampBeforeDelete(origLastModified, timestamp)) { Delete del = new Delete(Bytes.toBytes(resPath)); table.delete(del); if (hdfsResourceExist) { // remove hdfs cell value deletePushdown(resPath); } } else { throw new IOException("Resource " + resPath + " timestamp not match, [originLastModified: " + origLastModified + ", timestampToDelete: " + timestamp + "]"); } } finally { IOUtils.closeQuietly(table); } }
Example #5
Source File: Indexer.java From phoenix with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void preDelete(ObserverContext<RegionCoprocessorEnvironment> e, Delete delete, WALEdit edit, boolean writeToWAL) throws IOException { if (this.disabled) { super.preDelete(e, delete, edit, writeToWAL); return; } try { preDeleteWithExceptions(e, delete, edit, writeToWAL); return; } catch (Throwable t) { rethrowIndexingException(t); } throw new RuntimeException( "Somehow didn't return an index update but also didn't propagate the failure to the client!"); }
Example #6
Source File: TTable.java From phoenix-omid with Apache License 2.0 | 6 votes |
/** * Transactional version of {@link Table#batch(List<? extends Row> rows)} * * @param transaction an instance of transaction to be used * @param rows List of rows that must be instances of Put or Delete * @param addShadowCell denotes whether to add the shadow cell * @throws IOException if a remote or network exception occurs */ public void batch(Transaction transaction, List<? extends Row> rows, boolean addShadowCells) throws IOException { List<Mutation> mutations = new ArrayList<>(rows.size()); for (Row row : rows) { if (row instanceof Put) { mutations.add(putInternal(transaction, (Put)row, addShadowCells)); } else if (row instanceof Delete) { Put deleteP = deleteInternal(transaction, (Delete)row); if (!deleteP.isEmpty()) { mutations.add(deleteP); } } else { throw new UnsupportedOperationException("Unsupported mutation: " + row); } } addMutations(mutations); }
Example #7
Source File: OfflineMetaRebuildTestCore.java From hbase with Apache License 2.0 | 6 votes |
protected void wipeOutMeta() throws IOException { // Mess it up by blowing up meta. Admin admin = TEST_UTIL.getAdmin(); Scan s = new Scan(); Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME); ResultScanner scanner = meta.getScanner(s); List<Delete> dels = new ArrayList<>(); for (Result r : scanner) { RegionInfo info = CatalogFamilyFormat.getRegionInfo(r); if(info != null && !info.getTable().getNamespaceAsString() .equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) { Delete d = new Delete(r.getRow()); dels.add(d); admin.unassign(r.getRow(), true); } } meta.delete(dels); scanner.close(); meta.close(); }
Example #8
Source File: IndexRebuildRegionScanner.java From phoenix with Apache License 2.0 | 6 votes |
@Override public int compare(Mutation o1, Mutation o2) { long ts1 = getTimestamp(o1); long ts2 = getTimestamp(o2); if (ts1 < ts2) { return -1; } if (ts1 > ts2) { return 1; } if (o1 instanceof Put && o2 instanceof Delete) { return -1; } if (o1 instanceof Delete && o2 instanceof Put) { return 1; } return 0; }
Example #9
Source File: CoveredColumnsIndexBuilder.java From phoenix with Apache License 2.0 | 6 votes |
/** * Get the index deletes from the codec {@link IndexCodec#getIndexDeletes(TableState)} and then * add them to the update map. * <p> * Expects the {@link LocalTableState} to already be correctly setup (correct timestamp, updates * applied, etc). * @throws IOException */ protected void addDeleteUpdatesToMap(IndexUpdateManager updateMap, LocalTableState state, long ts) throws IOException { Iterable<IndexUpdate> cleanup = codec.getIndexDeletes(state); if (cleanup != null) { for (IndexUpdate d : cleanup) { if (!d.isValid()) { continue; } // override the timestamps in the delete to match the current batch. Delete remove = (Delete)d.getUpdate(); remove.setTimestamp(ts); updateMap.addIndexUpdate(d.getTableName(), remove); } } }
Example #10
Source File: MultiTableOutputFormat.java From hbase with Apache License 2.0 | 6 votes |
/** * Writes an action (Put or Delete) to the specified table. * * @param tableName * the table being updated. * @param action * the update, either a put or a delete. * @throws IllegalArgumentException * if the action is not a put or a delete. */ @Override public void write(ImmutableBytesWritable tableName, Mutation action) throws IOException { BufferedMutator mutator = getBufferedMutator(tableName); // The actions are not immutable, so we defensively copy them if (action instanceof Put) { Put put = new Put((Put) action); put.setDurability(useWriteAheadLogging ? Durability.SYNC_WAL : Durability.SKIP_WAL); mutator.mutate(put); } else if (action instanceof Delete) { Delete delete = new Delete((Delete) action); mutator.mutate(delete); } else throw new IllegalArgumentException( "action must be either Delete or Put"); }
Example #11
Source File: TestCellACLWithMultipleVersions.java From hbase with Apache License 2.0 | 6 votes |
private void verifyUserDeniedForDeleteMultipleVersions(final User user, final byte[] row, final byte[] q1, final byte[] q2) throws IOException, InterruptedException { user.runAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf)) { try (Table t = connection.getTable(testTable.getTableName())) { Delete d = new Delete(row); d.addColumns(TEST_FAMILY1, q1); d.addColumns(TEST_FAMILY1, q2); t.delete(d); fail(user.getShortName() + " should not be allowed to delete the row"); } catch (Exception e) { } } return null; } }); }
Example #12
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Test public void testMultiColumnFamilyRowDeleteRollback() throws Exception { HTable hTable = createTable(Bytes.toBytes("TestMultColFam"), new byte[][] {TestBytes.family, TestBytes.family2}); try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, TxConstants.ConflictDetection.ROW)) { TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable); txContext.start(); txTable.put(new Put(TestBytes.row).add(TestBytes.family, TestBytes.qualifier, TestBytes.value)); txContext.finish(); txContext.start(); //noinspection ConstantConditions txContext.getCurrentTransaction().setVisibility(Transaction.VisibilityLevel.SNAPSHOT_ALL); Result result = txTable.get(new Get(TestBytes.row)); Assert.assertEquals(1, result.getFamilyMap(TestBytes.family).size()); Assert.assertEquals(0, result.getFamilyMap(TestBytes.family2).size()); txContext.finish(); //Start a tx, delete the row and then abort the tx txContext.start(); txTable.delete(new Delete(TestBytes.row)); txContext.abort(); //Start a tx and scan all the col families to make sure none of them have delete markers txContext.start(); txContext.getCurrentTransaction().setVisibility(Transaction.VisibilityLevel.SNAPSHOT_ALL); result = txTable.get(new Get(TestBytes.row)); Assert.assertEquals(1, result.getFamilyMap(TestBytes.family).size()); Assert.assertEquals(0, result.getFamilyMap(TestBytes.family2).size()); txContext.finish(); } }
Example #13
Source File: MockHTable.java From kylin with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value, Delete delete) throws IOException { if (check(row, family, qualifier, value)) { delete(delete); return true; } return false; }
Example #14
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 5 votes |
private void testDeleteRollback(TxConstants.ConflictDetection conflictDetection) throws Exception { String tableName = String.format("%s%s", "TestColFamilyDelete", conflictDetection); HTable hTable = createTable(Bytes.toBytes(tableName), new byte[][]{TestBytes.family}); try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, conflictDetection)) { TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable); txContext.start(); txTable.put(new Put(TestBytes.row).add(TestBytes.family, TestBytes.qualifier, TestBytes.value)); txContext.finish(); // Start a tx, delete the row and then abort the tx txContext.start(); txTable.delete(new Delete(TestBytes.row)); txContext.abort(); // Start a tx, delete a column family and then abort the tx txContext.start(); txTable.delete(new Delete(TestBytes.row).deleteFamily(TestBytes.family)); txContext.abort(); // Above operations should have no effect on the row, since they were aborted txContext.start(); Get get = new Get(TestBytes.row); Result result = txTable.get(get); assertFalse(result.isEmpty()); assertArrayEquals(TestBytes.value, result.getValue(TestBytes.family, TestBytes.qualifier)); txContext.finish(); } }
Example #15
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> c, final Delete delete, final WALEdit edit, final Durability durability) throws IOException { if (delete.getAttribute(TEST_ATTRIBUTE) == null) { throw new DoNotRetryIOException("Delete should preserve attributes"); } if (delete.getDurability() != Durability.USE_DEFAULT) { throw new DoNotRetryIOException("Durability is not propagated correctly"); } }
Example #16
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> c, final Delete delete, final WALEdit edit, final Durability durability) throws IOException { if (delete.getAttribute(TEST_ATTRIBUTE) == null) { throw new DoNotRetryIOException("Delete should preserve attributes"); } if (delete.getDurability() != Durability.USE_DEFAULT) { throw new DoNotRetryIOException("Durability is not propagated correctly"); } }
Example #17
Source File: HBase_2_ClientService.java From nifi with Apache License 2.0 | 5 votes |
@Override public void deleteCells(String tableName, List<DeleteRequest> deletes) throws IOException { List<Delete> deleteRequests = new ArrayList<>(); for (int index = 0; index < deletes.size(); index++) { DeleteRequest req = deletes.get(index); Delete delete = new Delete(req.getRowId()) .addColumn(req.getColumnFamily(), req.getColumnQualifier()); if (!StringUtils.isEmpty(req.getVisibilityLabel())) { delete.setCellVisibility(new CellVisibility(req.getVisibilityLabel())); } deleteRequests.add(delete); } batchDelete(tableName, deleteRequests); }
Example #18
Source File: TestClientKeyValueLocal.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testReadWrite() throws IOException { byte[] row = Bytes.toBytes("row"); byte[] family = Bytes.toBytes("family"); byte[] qualifier = Bytes.toBytes("qualifier"); byte[] value = Bytes.toBytes("value"); long ts = 10; Type type = KeyValue.Type.Put; ClientKeyValue kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value)); validate(kv, row, family, qualifier, ts, type, value); type = Type.Delete; kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value)); validate(kv, row, family, qualifier, ts, type, value); type = Type.DeleteColumn; kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value)); validate(kv, row, family, qualifier, ts, type, value); type = Type.DeleteFamily; kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value)); validate(kv, row, family, qualifier, ts, type, value); type = Type.Maximum; kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value)); validate(kv, row, family, qualifier, ts, type, value); // test a couple different variables, to make sure we aren't faking it row = Bytes.toBytes("row-never-seen-before1234"); family = Bytes.toBytes("family-to-test-more"); qualifier = Bytes.toBytes("untested-qualifier"); value = Bytes.toBytes("value-that-we-haven't_tested"); ts = System.currentTimeMillis(); kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value)); validate(kv, row, family, qualifier, ts, type, value); }
Example #19
Source File: PrepareIndexMutationsForRebuildTest.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testPutDeleteOnSameTimeStamp() throws Exception { SetupInfo info = setup(TABLE_NAME, INDEX_NAME, "ROW_KEY VARCHAR, C1 VARCHAR", "C1", "ROW_KEY", ""); // insert a row Put dataPut = new Put(Bytes.toBytes(ROW_KEY)); addCellToPutMutation(dataPut, info.indexMaintainer.getEmptyKeyValueFamily().copyBytesIfNecessary(), Bytes.toBytes("C1"), 1, Bytes.toBytes("v1")); addEmptyColumnToDataPutMutation(dataPut, info.pDataTable,1); // delete column of C1 from the inserted row Delete dataDel = new Delete(Bytes.toBytes(ROW_KEY)); addCellToDelMutation(dataDel, info.indexMaintainer.getEmptyKeyValueFamily().copyBytesIfNecessary(), Bytes.toBytes("C1"), 1, KeyValue.Type.DeleteColumn); List<Mutation> actualIndexMutations = IndexRebuildRegionScanner.prepareIndexMutationsForRebuild(info.indexMaintainer, dataPut, dataDel); List<Mutation> expectedIndexMutations = new ArrayList<>(); // The dataDel will be applied on top of dataPut when we replay them for index rebuild, when they have the same time stamp. // idxPut1 is expected as in data table we still see the row of k1 with empty C1, so we need a row in index table with row key "_k1" Put idxPut1 = new Put(generateIndexRowKey(null)); addEmptyColumnToIndexPutMutation(idxPut1, info.indexMaintainer, 1); expectedIndexMutations.add(idxPut1); assertEqualMutationList(Arrays.asList((Mutation)idxPut1), actualIndexMutations); }
Example #20
Source File: TestVisibilityLabelsWithDeletes.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testDeleteFamilyWithoutCellVisibilityWithMulipleVersions() throws Exception { setAuths(); final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPutsWithoutVisibility(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addFamily(fam); table.delete(d); } catch (Throwable t) { throw new IOException(t); } return null; } }; SUPERUSER.runAs(actiona); TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 1); // All cells wrt row1 should be deleted as we are not passing the Cell Visibility CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length)); } }
Example #21
Source File: PhoenixIndexCodec.java From phoenix with Apache License 2.0 | 5 votes |
@Override public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) throws IOException { PhoenixIndexMetaData metaData = (PhoenixIndexMetaData)context; List<IndexMaintainer> indexMaintainers = metaData.getIndexMaintainers(); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); ptr.set(state.getCurrentRowKey()); List<IndexUpdate> indexUpdates = Lists.newArrayList(); for (IndexMaintainer maintainer : indexMaintainers) { // For transactional tables, we use an index maintainer // to aid in rollback if there's a KeyValue column in the index. The alternative would be // to hold on to all uncommitted index row keys (even ones already sent to HBase) on the // client side. Set<ColumnReference> cols = Sets.newHashSet(maintainer.getAllColumns()); cols.add(new ColumnReference(indexMaintainers.get(0).getDataEmptyKeyValueCF(), indexMaintainers.get(0).getEmptyKeyValueQualifier())); Pair<ValueGetter, IndexUpdate> statePair = state.getIndexUpdateState(cols, metaData.getReplayWrite() != null, true, context); ValueGetter valueGetter = statePair.getFirst(); if (valueGetter!=null) { IndexUpdate indexUpdate = statePair.getSecond(); indexUpdate.setTable(maintainer.isLocalIndex() ? tableName : maintainer.getIndexTableName()); Delete delete = maintainer.buildDeleteMutation(KV_BUILDER, valueGetter, ptr, state.getPendingUpdate(), state.getCurrentTimestamp(), regionStartKey, regionEndKey); indexUpdate.setUpdate(delete); indexUpdates.add(indexUpdate); } } return indexUpdates; }
Example #22
Source File: ReadWriteKeyValuesWithCodecIT.java From phoenix with Apache License 2.0 | 5 votes |
/** * @return a bunch of {@link WALEdit}s that test a range of serialization possibilities. */ private List<WALEdit> getEdits() { // Build up a couple of edits List<WALEdit> edits = new ArrayList<WALEdit>(); Put p = new Put(ROW); p.add(FAMILY, null, Bytes.toBytes("v1")); WALEdit withPut = new WALEdit(); addMutation(withPut, p, FAMILY); edits.add(withPut); Delete d = new Delete(ROW); d.deleteColumn(FAMILY, null); WALEdit withDelete = new WALEdit(); addMutation(withDelete, d, FAMILY); edits.add(withDelete); WALEdit withPutsAndDeletes = new WALEdit(); addMutation(withPutsAndDeletes, d, FAMILY); addMutation(withPutsAndDeletes, p, FAMILY); edits.add(withPutsAndDeletes); WALEdit justIndexUpdates = new WALEdit(); byte[] table = Bytes.toBytes("targetTable"); IndexedKeyValue ikv = new IndexedKeyValue(table, p); justIndexUpdates.add(ikv); edits.add(justIndexUpdates); WALEdit mixed = new WALEdit(); addMutation(mixed, d, FAMILY); mixed.add(ikv); addMutation(mixed, p, FAMILY); edits.add(mixed); return edits; }
Example #23
Source File: TestAccessController.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testReadWrite() throws Exception { // action for checkAndDelete AccessTestAction checkAndDeleteAction = new AccessTestAction() { @Override public Object run() throws Exception { Delete d = new Delete(TEST_ROW); d.addFamily(TEST_FAMILY); try(Connection conn = ConnectionFactory.createConnection(conf); Table t = conn.getTable(TEST_TABLE)) { t.checkAndMutate(TEST_ROW, TEST_FAMILY).qualifier(TEST_QUALIFIER) .ifEquals(Bytes.toBytes("test_value")).thenDelete(d); } return null; } }; verifyReadWrite(checkAndDeleteAction); // action for checkAndPut() AccessTestAction checkAndPut = new AccessTestAction() { @Override public Object run() throws Exception { Put p = new Put(TEST_ROW); p.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(1)); try(Connection conn = ConnectionFactory.createConnection(conf); Table t = conn.getTable(TEST_TABLE)) { t.checkAndMutate(TEST_ROW, TEST_FAMILY).qualifier(TEST_QUALIFIER) .ifEquals(Bytes.toBytes("test_value")).thenPut(p); } return null; } }; verifyReadWrite(checkAndPut); }
Example #24
Source File: TransactionState.java From hbase-secondary-index with GNU General Public License v3.0 | 5 votes |
public WriteAction(final Delete delete) { if (null == delete) { throw new IllegalArgumentException( "WriteAction requires a Put or a Delete."); } this.delete = delete; }
Example #25
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 5 votes |
private void testDeleteRollback(TxConstants.ConflictDetection conflictDetection) throws Exception { String tableName = String.format("%s%s", "TestColFamilyDelete", conflictDetection); HTable hTable = createTable(Bytes.toBytes(tableName), new byte[][]{TestBytes.family}); try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, conflictDetection)) { TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable); txContext.start(); txTable.put(new Put(TestBytes.row).add(TestBytes.family, TestBytes.qualifier, TestBytes.value)); txContext.finish(); // Start a tx, delete the row and then abort the tx txContext.start(); txTable.delete(new Delete(TestBytes.row)); txContext.abort(); // Start a tx, delete a column family and then abort the tx txContext.start(); txTable.delete(new Delete(TestBytes.row).deleteFamily(TestBytes.family)); txContext.abort(); // Above operations should have no effect on the row, since they were aborted txContext.start(); Get get = new Get(TestBytes.row); Result result = txTable.get(get); assertFalse(result.isEmpty()); assertArrayEquals(TestBytes.value, result.getValue(TestBytes.family, TestBytes.qualifier)); txContext.finish(); } }
Example #26
Source File: TestQuotaTableUtil.java From hbase with Apache License 2.0 | 5 votes |
private void cleanUpSnapshotSizes() throws IOException { try (Table t = connection.getTable(QuotaTableUtil.QUOTA_TABLE_NAME)) { QuotaTableUtil.createDeletesForExistingTableSnapshotSizes(connection); List<Delete> deletes = QuotaTableUtil.createDeletesForExistingNamespaceSnapshotSizes(connection); deletes.addAll(QuotaTableUtil.createDeletesForExistingTableSnapshotSizes(connection)); t.delete(deletes); } }
Example #27
Source File: Tailer.java From zerowing with MIT License | 5 votes |
protected void handleDelete(HTable table, DBObject selector) { byte[] row = _translator.createRowKey(selector); Delete del = new Delete(row); try { table.delete(del); } catch (IOException e) { log.error("Failed trying to delete object at " + row + " in " + table, e); } }
Example #28
Source File: TestEndToEndCoveredIndexing.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testSimpleDeletes() throws Exception { HTable primary = createSetupTables(fam1); // do a simple Put long ts = 10; Put p = new Put(row1); p.add(FAM, indexed_qualifer, ts, value1); p.add(FAM, regular_qualifer, ts, value2); primary.put(p); primary.flushCommits(); Delete d = new Delete(row1); primary.delete(d); HTable index = new HTable(UTIL.getConfiguration(), fam1.getTable()); List<KeyValue> expected = Collections.<KeyValue> emptyList(); // scan over all time should cause the delete to be covered IndexTestingUtils.verifyIndexTableAtTimestamp(index, expected, 0, Long.MAX_VALUE, value1, HConstants.EMPTY_END_ROW); // scan at the older timestamp should still show the older value List<Pair<byte[], CoveredColumn>> pairs = new ArrayList<Pair<byte[], CoveredColumn>>(); pairs.add(new Pair<byte[], CoveredColumn>(value1, col1)); pairs.add(new Pair<byte[], CoveredColumn>(EMPTY_BYTES, col2)); expected = CoveredColumnIndexCodec.getIndexKeyValueForTesting(row1, ts, pairs); IndexTestingUtils.verifyIndexTableAtTimestamp(index, expected, ts, value1); // cleanup closeAndCleanupTables(index, primary); }
Example #29
Source File: TestCompaction.java From phoenix-omid with Apache License 2.0 | 5 votes |
@Test(timeOut = 60_000) public void testTombstonesAreCleanedUpCase1() throws Exception { String TEST_TABLE = "testTombstonesAreCleanedUpCase1"; createTableIfNotExists(TEST_TABLE, Bytes.toBytes(TEST_FAMILY)); TTable txTable = new TTable(connection, TEST_TABLE); HBaseTransaction tx1 = (HBaseTransaction) tm.begin(); byte[] rowId = Bytes.toBytes("case1"); Put p = new Put(rowId); p.addColumn(fam, qual, Bytes.toBytes("testValue")); txTable.put(tx1, p); tm.commit(tx1); HBaseTransaction lwmTx = (HBaseTransaction) tm.begin(); setCompactorLWM(lwmTx.getStartTimestamp(), TEST_TABLE); HBaseTransaction tx2 = (HBaseTransaction) tm.begin(); Delete d = new Delete(rowId); d.addColumn(fam, qual); txTable.delete(tx2, d); tm.commit(tx2); TTableCellGetterAdapter getter = new TTableCellGetterAdapter(txTable); assertTrue(CellUtils.hasCell(rowId, fam, qual, tx1.getStartTimestamp(), getter), "Put cell should be there"); assertTrue(CellUtils.hasShadowCell(rowId, fam, qual, tx1.getStartTimestamp(), getter), "Put shadow cell should be there"); assertTrue(CellUtils.hasCell(rowId, fam, qual, tx2.getStartTimestamp(), getter), "Delete cell should be there"); assertTrue(CellUtils.hasShadowCell(rowId, fam, qual, tx2.getStartTimestamp(), getter), "Delete shadow cell should be there"); }
Example #30
Source File: HBaseUtils.java From geowave with Apache License 2.0 | 5 votes |
public static RowMutations getDeleteMutations( final byte[] rowId, final byte[] columnFamily, final byte[] columnQualifier, final String[] authorizations) throws IOException { final RowMutations m = new RowMutations(rowId); final Delete d = new Delete(rowId); d.addColumns(columnFamily, columnQualifier); m.add(d); return m; }