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 CFBD0200C14 for ; Mon, 23 Jan 2017 16:54:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CE61D160B60; Mon, 23 Jan 2017 15:54:34 +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 00E01160B49 for ; Mon, 23 Jan 2017 16:54:33 +0100 (CET) Received: (qmail 62127 invoked by uid 500); 23 Jan 2017 15:54:33 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 62047 invoked by uid 99); 23 Jan 2017 15:54:32 -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, 23 Jan 2017 15:54:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9461BDFCA0; Mon, 23 Jan 2017 15:54:32 +0000 (UTC) From: keith-turner To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request #204: ACCUMULO-4574 Modified TableOperations online to... Content-Type: text/plain Message-Id: <20170123155432.9461BDFCA0@git1-us-west.apache.org> Date: Mon, 23 Jan 2017 15:54:32 +0000 (UTC) archived-at: Mon, 23 Jan 2017 15:54:35 -0000 Github user keith-turner commented on a diff in the pull request: https://github.com/apache/accumulo/pull/204#discussion_r97346413 --- Diff: test/src/test/java/org/apache/accumulo/test/functional/TableChangeStateIT.java --- @@ -0,0 +1,549 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.test.functional; + +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.BatchWriter; +import org.apache.accumulo.core.client.BatchWriterConfig; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.Scanner; +import org.apache.accumulo.core.client.TableExistsException; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.impl.Tables; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.master.state.tables.TableState; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.core.zookeeper.ZooUtil; +import org.apache.accumulo.fate.zookeeper.ZooCache; +import org.apache.accumulo.fate.zookeeper.ZooReader; +import org.apache.hadoop.io.Text; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * ACCUMULO-4574. Test to verify that changing table state to online / offline {@link org.apache.accumulo.core.client.admin.TableOperations#online(String)} when + * the table is already in that state returns without blocking. + */ +public class TableChangeStateIT extends ConfigurableMacIT { + + private static final Logger log = LoggerFactory.getLogger(TableChangeStateIT.class); + + private static final int NUM_ROWS = 1000; + + @Override + protected int defaultTimeoutSeconds() { + return 4 * 60; + } + + /** + * Validate that {@code TableOperations} online operation does not block when table is already online and fate transaction lock is held by other operations. + * The test creates, populates a table and then runs a compaction with a slow iterator so that operation takes long enough to simulate the condition. After + * the online operation while compaction is running completes, the test is complete and the compaction is canceled so that other tests can run. + * + * @throws Exception + * any exception is a test failure. + */ + @Test + public void changeTableStateTest() throws Exception { + + Connector connector = getConnector(); + String tableName = getUniqueNames(1)[0]; + + createData(tableName); + + assertEquals("verify table online after created", TableState.ONLINE, getTableState(connector, tableName)); + + OnlineStatus status = onLine(tableName); + + log.trace("Online 1 in {} ms", TimeUnit.MILLISECONDS.convert(status.runningTime(), TimeUnit.NANOSECONDS)); + + assertFalse("verify no exception thrown changing state", status.hasError()); + assertEquals("verify table is still online", TableState.ONLINE, getTableState(connector, tableName)); + + // verify that offline then online functions as expected. + + connector.tableOperations().offline(tableName, true); + assertEquals("verify table is offline", TableState.OFFLINE, getTableState(connector, tableName)); + + OnlineStatus status2 = onLine(tableName); + + log.trace("Online 2 in {} ms", TimeUnit.MILLISECONDS.convert(status2.runningTime(), TimeUnit.NANOSECONDS)); + + if (status2.hasError()) { + log.debug("Online failed with exception", status2.getException()); + } + + assertFalse("verify no exception thrown changing state", status2.hasError()); + assertEquals("verify table is back online", TableState.ONLINE, getTableState(connector, tableName)); + + // launch a full table compaction with the slow iterator to ensure table lock is acquired and held by the compaction + Thread compactThread = new Thread(new SlowCompactionRunner(tableName)); + compactThread.start(); + + assertTrue("verify that compaction running and fate transaction exists", blockUntilCompactionRunning()); + + // try to set online while fate transaction is in progress - before ACCUMULO-4574 this would block + OnlineStatus status3 = onLine(tableName); + log.trace("Online while compacting in {} ms", TimeUnit.MILLISECONDS.convert(status3.runningTime(), TimeUnit.NANOSECONDS)); + + if (status3.hasError()) { + log.debug("Online failed with exception", status3.getException()); + } + + assertFalse("verify no exception thrown changing state", status3.hasError()); + assertTrue("online should take less time than expected compaction time", status3.runningTime() < TimeUnit.NANOSECONDS.convert(2, TimeUnit.SECONDS)); --- End diff -- Will Java GC or swap cause this to fail when there is no problem? --- 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. ---