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 971BC10750 for ; Tue, 17 Dec 2013 19:04:02 +0000 (UTC) Received: (qmail 25810 invoked by uid 500); 17 Dec 2013 19:04:01 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 25618 invoked by uid 500); 17 Dec 2013 19:04:01 -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 25357 invoked by uid 99); 17 Dec 2013 19:04:01 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Dec 2013 19:04:01 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 672168BA838; Tue, 17 Dec 2013 19:04:01 +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: Tue, 17 Dec 2013 19:04:09 -0000 Message-Id: <1bec417e4f6c47958bb924c993d1ea7c@git.apache.org> In-Reply-To: <938251b8a6c04b2abb5d206ab2eb09b3@git.apache.org> References: <938251b8a6c04b2abb5d206ab2eb09b3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [09/14] git commit: Merge branch '1.4.5-SNAPSHOT' into 1.5.1-SNAPSHOT Merge branch '1.4.5-SNAPSHOT' into 1.5.1-SNAPSHOT Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3458bfae Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3458bfae Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3458bfae Branch: refs/heads/master Commit: 3458bfaec1ada8a164e596ac132939e370e52f86 Parents: a78246d 59932f6 Author: Eric Newton Authored: Tue Dec 17 14:02:33 2013 -0500 Committer: Eric Newton Committed: Tue Dec 17 14:02:33 2013 -0500 ---------------------------------------------------------------------- .../apache/accumulo/server/master/state/MetaDataTableScanner.java | 1 + 1 file changed, 1 insertion(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/3458bfae/server/src/main/java/org/apache/accumulo/server/master/state/MetaDataTableScanner.java ---------------------------------------------------------------------- diff --cc server/src/main/java/org/apache/accumulo/server/master/state/MetaDataTableScanner.java index 7570908,0000000..bf1da22 mode 100644,000000..100644 --- a/server/src/main/java/org/apache/accumulo/server/master/state/MetaDataTableScanner.java +++ b/server/src/main/java/org/apache/accumulo/server/master/state/MetaDataTableScanner.java @@@ -1,184 -1,0 +1,185 @@@ +/* + * 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.master.state; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.SortedMap; + +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.client.BatchScanner; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.ScannerBase; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.KeyExtent; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.user.WholeRowIterator; +import org.apache.accumulo.core.security.CredentialHelper; +import org.apache.accumulo.core.security.thrift.TCredentials; +import org.apache.accumulo.server.master.state.TabletLocationState.BadLocationStateException; +import org.apache.hadoop.io.Text; +import org.apache.log4j.Logger; + +public class MetaDataTableScanner implements Iterator { + private static final Logger log = Logger.getLogger(MetaDataTableScanner.class); + + BatchScanner mdScanner; + Iterator> iter; + + public MetaDataTableScanner(Instance instance, TCredentials auths, Range range, CurrentState state) { + // scan over metadata table, looking for tablets in the wrong state based on the live servers and online tables + try { + Connector connector = instance.getConnector(auths.getPrincipal(), CredentialHelper.extractToken(auths)); + mdScanner = connector.createBatchScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS, 8); + configureScanner(mdScanner, state); + mdScanner.setRanges(Collections.singletonList(range)); + iter = mdScanner.iterator(); + } catch (Exception ex) { + mdScanner.close(); + throw new RuntimeException(ex); + } + } + + static public void configureScanner(ScannerBase scanner, CurrentState state) { + Constants.METADATA_PREV_ROW_COLUMN.fetch(scanner); + scanner.fetchColumnFamily(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY); + scanner.fetchColumnFamily(Constants.METADATA_FUTURE_LOCATION_COLUMN_FAMILY); ++ scanner.fetchColumnFamily(Constants.METADATA_LAST_LOCATION_COLUMN_FAMILY); + scanner.fetchColumnFamily(Constants.METADATA_LOG_COLUMN_FAMILY); + scanner.fetchColumnFamily(Constants.METADATA_CHOPPED_COLUMN_FAMILY); + scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class)); + IteratorSetting tabletChange = new IteratorSetting(1001, "tabletChange", TabletStateChangeIterator.class); + if (state != null) { + TabletStateChangeIterator.setCurrentServers(tabletChange, state.onlineTabletServers()); + TabletStateChangeIterator.setOnlineTables(tabletChange, state.onlineTables()); + TabletStateChangeIterator.setMerges(tabletChange, state.merges()); + } + scanner.addScanIterator(tabletChange); + } + + public MetaDataTableScanner(Instance instance, TCredentials auths, Range range) { + this(instance, auths, range, null); + } + + public void close() { + if (iter != null) { + mdScanner.close(); + iter = null; + } + } + + public void finalize() { + close(); + } + + @Override + public boolean hasNext() { + if (iter == null) + return false; + boolean result = iter.hasNext(); + if (!result) { + close(); + } + return result; + } + + @Override + public TabletLocationState next() { + try { + return fetch(); + } catch (RuntimeException ex) { + // something is wrong with the records in the !METADATA table, just skip over it + log.error(ex, ex); + mdScanner.close(); + return null; + } + } + + public static TabletLocationState createTabletLocationState(Key k, Value v) throws IOException, BadLocationStateException { + final SortedMap decodedRow = WholeRowIterator.decodeRow(k, v); + KeyExtent extent = null; + TServerInstance future = null; + TServerInstance current = null; + TServerInstance last = null; + List> walogs = new ArrayList>(); + boolean chopped = false; + + for (Entry entry : decodedRow.entrySet()) { + Key key = entry.getKey(); + Text row = key.getRow(); + Text cf = key.getColumnFamily(); + Text cq = key.getColumnQualifier(); + + if (cf.compareTo(Constants.METADATA_FUTURE_LOCATION_COLUMN_FAMILY) == 0) { + TServerInstance location = new TServerInstance(entry.getValue(), cq); + if (future != null) { + throw new BadLocationStateException("found two assignments for the same extent " + key.getRow() + ": " + future + " and " + location); + } + future = location; + } else if (cf.compareTo(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY) == 0) { + TServerInstance location = new TServerInstance(entry.getValue(), cq); + if (current != null) { + throw new BadLocationStateException("found two locations for the same extent " + key.getRow() + ": " + current + " and " + location); + } + current = location; + } else if (cf.compareTo(Constants.METADATA_LOG_COLUMN_FAMILY) == 0) { + String[] split = entry.getValue().toString().split("\\|")[0].split(";"); + walogs.add(Arrays.asList(split)); + } else if (cf.compareTo(Constants.METADATA_LAST_LOCATION_COLUMN_FAMILY) == 0) { + TServerInstance location = new TServerInstance(entry.getValue(), cq); + if (last != null) { + throw new BadLocationStateException("found two last locations for the same extent " + key.getRow() + ": " + last + " and " + location); + } + last = new TServerInstance(entry.getValue(), cq); + } else if (cf.compareTo(Constants.METADATA_CHOPPED_COLUMN_FAMILY) == 0) { + chopped = true; + } else if (Constants.METADATA_PREV_ROW_COLUMN.equals(cf, cq)) { + extent = new KeyExtent(row, entry.getValue()); + } + } + if (extent == null) { + log.warn("No prev-row for key extent: " + decodedRow); + return null; + } + return new TabletLocationState(extent, future, current, last, walogs, chopped); + } + + private TabletLocationState fetch() { + try { + Entry e = iter.next(); + return createTabletLocationState(e.getKey(), e.getValue()); + } catch (IOException ex) { + throw new RuntimeException(ex); + } catch (BadLocationStateException ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void remove() { + throw new RuntimeException("Unimplemented"); + } +}