Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 18CAD200C1A for ; Mon, 13 Feb 2017 19:55:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 177A0160B60; Mon, 13 Feb 2017 18:55:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 376F6160B4A for ; Mon, 13 Feb 2017 19:55:47 +0100 (CET) Received: (qmail 82119 invoked by uid 500); 13 Feb 2017 18:55:46 -0000 Mailing-List: contact dev-help@tephra.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tephra.incubator.apache.org Delivered-To: mailing list dev@tephra.incubator.apache.org Received: (qmail 82101 invoked by uid 99); 13 Feb 2017 18:55:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Feb 2017 18:55:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id A37EFC150F for ; Mon, 13 Feb 2017 18:55:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -7.019 X-Spam-Level: X-Spam-Status: No, score=-7.019 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id zDKujbecz4Hb for ; Mon, 13 Feb 2017 18:55:44 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 5131C5F252 for ; Mon, 13 Feb 2017 18:55:43 +0000 (UTC) Received: (qmail 81615 invoked by uid 99); 13 Feb 2017 18:55:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Feb 2017 18:55:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C8A9EDFC31; Mon, 13 Feb 2017 18:55:12 +0000 (UTC) From: gokulavasan To: dev@tephra.incubator.apache.org Reply-To: dev@tephra.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-tephra pull request #34: TEPHRA-216 Handle empty transactional reg... Content-Type: text/plain Message-Id: <20170213185512.C8A9EDFC31@git1-us-west.apache.org> Date: Mon, 13 Feb 2017 18:55:12 +0000 (UTC) archived-at: Mon, 13 Feb 2017 18:55:48 -0000 Github user gokulavasan commented on a diff in the pull request: https://github.com/apache/incubator-tephra/pull/34#discussion_r100868455 --- Diff: tephra-hbase-compat-0.96/src/test/java/org/apache/tephra/hbase/txprune/InvalidListPruneTest.java --- @@ -341,6 +310,87 @@ public HTableInterface get() throws IOException { } } + @Test + public void testPruneEmptyTable() throws Exception { + // Make sure that empty tables do not block the progress of pruning + + // Create an empty table + TableName txEmptyTable = TableName.valueOf("emptyPruneTestTable"); + HTable emptyHTable = createTable(txEmptyTable.getName(), new byte[][]{family}, false, + Collections.singletonList(TestTransactionProcessor.class.getName())); + + TransactionPruningPlugin transactionPruningPlugin = new TestTransactionPruningPlugin(); + transactionPruningPlugin.initialize(conf); + + try { + long now1 = System.currentTimeMillis(); + long inactiveTxTimeNow1 = (now1 - 150) * TxConstants.MAX_TX_PER_MS; + long noPruneUpperBound = -1; + long expectedPruneUpperBound1 = (now1 - 200) * TxConstants.MAX_TX_PER_MS; + InMemoryTransactionStateCache.setTransactionSnapshot( + new TransactionSnapshot(expectedPruneUpperBound1, expectedPruneUpperBound1, expectedPruneUpperBound1, + ImmutableSet.of(expectedPruneUpperBound1), + ImmutableSortedMap.of())); + testUtil.compact(txEmptyTable, true); + testUtil.compact(txDataTable1, true); + // Since the write to prune table happens async, we need to sleep a bit before checking the state of the table + TimeUnit.SECONDS.sleep(2); + + // fetch prune upper bound, there should be no prune upper bound since txEmptyTable cannot be compacted + long pruneUpperBound1 = transactionPruningPlugin.fetchPruneUpperBound(now1, inactiveTxTimeNow1); + Assert.assertEquals(noPruneUpperBound, pruneUpperBound1); + transactionPruningPlugin.pruneComplete(now1, noPruneUpperBound); + + // Now flush the empty table, this will record the table region as empty, and then pruning will continue + testUtil.flush(txEmptyTable); + // Since the write to prune table happens async, we need to sleep a bit before checking the state of the table + TimeUnit.SECONDS.sleep(2); + + // fetch prune upper bound, again, this time it should work + pruneUpperBound1 = transactionPruningPlugin.fetchPruneUpperBound(now1, inactiveTxTimeNow1); + Assert.assertEquals(expectedPruneUpperBound1, pruneUpperBound1); + transactionPruningPlugin.pruneComplete(now1, expectedPruneUpperBound1); + + // Now add some data to the empty table + // (adding data non-transactionally is okay too, we just need some data for the compaction to run) + emptyHTable.put(new Put(Bytes.toBytes(1)).add(family, qualifier, Bytes.toBytes(1))); + emptyHTable.close(); + + // Now run another compaction on txDataTable1 with an updated tx snapshot + long now2 = System.currentTimeMillis(); + long inactiveTxTimeNow2 = (now2 - 150) * TxConstants.MAX_TX_PER_MS; + long expectedPruneUpperBound2 = (now2 - 200) * TxConstants.MAX_TX_PER_MS; + InMemoryTransactionStateCache.setTransactionSnapshot( + new TransactionSnapshot(expectedPruneUpperBound2, expectedPruneUpperBound2, expectedPruneUpperBound2, + ImmutableSet.of(expectedPruneUpperBound2), + ImmutableSortedMap.of())); + testUtil.flush(txEmptyTable); + testUtil.compact(txDataTable1, true); + // Since the write to prune table happens async, we need to sleep a bit before checking the state of the table + TimeUnit.SECONDS.sleep(2); + + // Running a prune now should still return min(inactiveTxTimeNow1, expectedPruneUpperBound1) since + // txEmptyTable is no longer empty. This information is returned since the txEmptyTable was recorded as being + // empty in the previous run with inactiveTxTimeNow1 + long pruneUpperBound2 = transactionPruningPlugin.fetchPruneUpperBound(now2, inactiveTxTimeNow2); + Assert.assertEquals(inactiveTxTimeNow1, pruneUpperBound2); + transactionPruningPlugin.pruneComplete(now2, expectedPruneUpperBound1); + + // However, after compacting txEmptyTable we should get the latest upper bound + testUtil.flush(txEmptyTable); + testUtil.compact(txEmptyTable, true); + // Since the write to prune table happens async, we need to sleep a bit before checking the state of the table + TimeUnit.SECONDS.sleep(2); + pruneUpperBound2 = transactionPruningPlugin.fetchPruneUpperBound(now2, inactiveTxTimeNow2); + Assert.assertEquals(expectedPruneUpperBound2, pruneUpperBound2); + transactionPruningPlugin.pruneComplete(now2, expectedPruneUpperBound2); + } finally { + transactionPruningPlugin.destroy(); + hBaseAdmin.disableTable(txEmptyTable); + hBaseAdmin.deleteTable(txEmptyTable); + } + } --- End diff -- Fix alignment --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---