Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 266F1110EB for ; Mon, 22 Sep 2014 15:58:40 +0000 (UTC) Received: (qmail 38013 invoked by uid 500); 22 Sep 2014 15:58:40 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 37974 invoked by uid 500); 22 Sep 2014 15:58:40 -0000 Mailing-List: contact commits-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 commits@accumulo.apache.org Received: (qmail 37948 invoked by uid 99); 22 Sep 2014 15:58:40 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Sep 2014 15:58:40 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C17129D130D; Mon, 22 Sep 2014 15:58:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ecn@apache.org To: commits@accumulo.apache.org Date: Mon, 22 Sep 2014 15:58:43 -0000 Message-Id: In-Reply-To: <4d00b37d3a4e4d8a80875814f868568f@git.apache.org> References: <4d00b37d3a4e4d8a80875814f868568f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/7] git commit: ACCUMULO-3157 close scanners ACCUMULO-3157 close scanners Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/2f68e078 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/2f68e078 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/2f68e078 Branch: refs/heads/master Commit: 2f68e078d378ec5a836e04e0aeed60dc837e81f9 Parents: 65be6dc 9167993 Author: Eric Newton Authored: Mon Sep 22 11:55:19 2014 -0400 Committer: Eric Newton Committed: Mon Sep 22 11:55:19 2014 -0400 ---------------------------------------------------------------------- .../server/util/FindOfflineTablets.java | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/2f68e078/server/base/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java ---------------------------------------------------------------------- diff --cc server/base/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java index 64c23d0,0000000..8f78488 mode 100644,000000..100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java @@@ -1,129 -1,0 +1,132 @@@ +/* + * 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.server.util; + +import java.util.Iterator; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.impl.Tables; +import org.apache.accumulo.core.conf.DefaultConfiguration; +import org.apache.accumulo.core.data.KeyExtent; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.master.state.tables.TableState; +import org.apache.accumulo.core.metadata.MetadataTable; +import org.apache.accumulo.core.metadata.RootTable; +import org.apache.accumulo.core.metadata.schema.MetadataSchema; +import org.apache.accumulo.core.security.Credentials; +import org.apache.accumulo.server.cli.ClientOpts; +import org.apache.accumulo.server.master.LiveTServerSet; +import org.apache.accumulo.server.master.LiveTServerSet.Listener; +import org.apache.accumulo.server.master.state.DistributedStoreException; +import org.apache.accumulo.server.master.state.MetaDataTableScanner; +import org.apache.accumulo.server.master.state.TServerInstance; +import org.apache.accumulo.server.master.state.TabletLocationState; +import org.apache.accumulo.server.master.state.TabletState; +import org.apache.accumulo.server.master.state.ZooTabletStateStore; +import org.apache.accumulo.server.security.SystemCredentials; +import org.apache.accumulo.server.tables.TableManager; +import org.apache.hadoop.io.Text; +import org.apache.log4j.Logger; + +public class FindOfflineTablets { + private static final Logger log = Logger.getLogger(FindOfflineTablets.class); + + public static void main(String[] args) throws Exception { + ClientOpts opts = new ClientOpts(); + opts.parseArgs(FindOfflineTablets.class.getName(), args); + Instance instance = opts.getInstance(); + SystemCredentials creds = SystemCredentials.get(); + + findOffline(instance, creds, null); + } + + static int findOffline(Instance instance, Credentials creds, String tableName) throws AccumuloException, TableNotFoundException { + + final AtomicBoolean scanning = new AtomicBoolean(false); + + LiveTServerSet tservers = new LiveTServerSet(instance, DefaultConfiguration.getDefaultConfiguration(), new Listener() { + @Override + public void update(LiveTServerSet current, Set deleted, Set added) { + if (!deleted.isEmpty() && scanning.get()) + log.warn("Tablet servers deleted while scanning: " + deleted); + if (!added.isEmpty() && scanning.get()) + log.warn("Tablet servers added while scanning: " + added); + } + }); + tservers.startListeningForTabletServerChanges(); + scanning.set(true); + + Iterator zooScanner; + try { + zooScanner = new ZooTabletStateStore().iterator(); + } catch (DistributedStoreException e) { + throw new AccumuloException(e); + } + + int offline = 0; + + System.out.println("Scanning zookeeper"); + if ((offline = checkTablets(zooScanner, tservers)) > 0) + return offline; + + if (RootTable.NAME.equals(tableName)) + return 0; + + System.out.println("Scanning " + RootTable.NAME); + Iterator rootScanner = new MetaDataTableScanner(instance, creds, MetadataSchema.TabletsSection.getRange(), RootTable.NAME); + if ((offline = checkTablets(rootScanner, tservers)) > 0) + return offline; + + if (MetadataTable.NAME.equals(tableName)) + return 0; + + System.out.println("Scanning " + MetadataTable.NAME); + + Range range = MetadataSchema.TabletsSection.getRange(); + if (tableName != null) { + String tableId = Tables.getTableId(instance, tableName); + range = new KeyExtent(new Text(tableId), null, null).toMetadataRange(); + } + + Iterator metaScanner = new MetaDataTableScanner(instance, creds, range, MetadataTable.NAME); + return checkTablets(metaScanner, tservers); + } + + private static int checkTablets(Iterator scanner, LiveTServerSet tservers) { + int offline = 0; + - while (scanner.hasNext() && !System.out.checkError()) { - TabletLocationState locationState = scanner.next(); - TabletState state = locationState.getState(tservers.getCurrentServers()); - if (state != null && state != TabletState.HOSTED - && TableManager.getInstance().getTableState(locationState.extent.getTableId().toString()) != TableState.OFFLINE) { - System.out.println(locationState + " is " + state + " #walogs:" + locationState.walogs.size()); - offline++; ++ try { ++ while (scanner.hasNext() && !System.out.checkError()) { ++ TabletLocationState locationState = scanner.next(); ++ TabletState state = locationState.getState(tservers.getCurrentServers()); ++ if (state != null && state != TabletState.HOSTED ++ && TableManager.getInstance().getTableState(locationState.extent.getTableId().toString()) != TableState.OFFLINE) { ++ System.out.println(locationState + " is " + state + " #walogs:" + locationState.walogs.size()); ++ offline++; ++ } + } - } - - return offline; ++ ++ return offline; ++ } finally { ++ scanner.close(); ++ } + } - +}