[GitHub] milleruntime commented on a change in pull request #488: fixes #469 made bulk import scan split tolerant

2018-05-17 Thread GitBox
milleruntime commented on a change in pull request #488: fixes #469 made bulk 
import scan split tolerant
URL: https://github.com/apache/accumulo/pull/488#discussion_r189047950
 
 

 ##
 File path: 
core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataConsistencyCheckIterator.java
 ##
 @@ -0,0 +1,153 @@
+/*
+ * 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.core.metadata.schema;
+
+import static 
org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
+
+import java.util.Iterator;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.PartialKey;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.impl.KeyExtent;
+import org.apache.hadoop.io.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * Tablets for a table in the metadata table should form a linked list. This 
iterator detects when
+ * tablets do not form a linked list and backs up when this happens.
+ *
+ * 
+ * The purpose of this is to hide inconsistencies caused by splits and detect 
anomalies in the
+ * metadata table.
+ *
+ * 
+ * If a tablet that was returned by this iterator is subsequently deleted from 
the metadata table,
+ * then this iterator will throw a TabletDeletedException. This could occur 
when a table is merged.
+ */
+public class MetadataConsistencyCheckIterator implements 
Iterator {
 
 Review comment:
   Could probably shorten the class name.  Something like 
"MetadataConsistencyIterator" or "MetadataCheckIterator"


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] milleruntime commented on a change in pull request #488: fixes #469 made bulk import scan split tolerant

2018-05-17 Thread GitBox
milleruntime commented on a change in pull request #488: fixes #469 made bulk 
import scan split tolerant
URL: https://github.com/apache/accumulo/pull/488#discussion_r189049542
 
 

 ##
 File path: 
core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataConsistencyCheckIterator.java
 ##
 @@ -0,0 +1,153 @@
+/*
+ * 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.core.metadata.schema;
+
+import static 
org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
+
+import java.util.Iterator;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.PartialKey;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.impl.KeyExtent;
+import org.apache.hadoop.io.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * Tablets for a table in the metadata table should form a linked list. This 
iterator detects when
+ * tablets do not form a linked list and backs up when this happens.
+ *
+ * 
+ * The purpose of this is to hide inconsistencies caused by splits and detect 
anomalies in the
+ * metadata table.
+ *
+ * 
+ * If a tablet that was returned by this iterator is subsequently deleted from 
the metadata table,
+ * then this iterator will throw a TabletDeletedException. This could occur 
when a table is merged.
+ */
+public class MetadataConsistencyCheckIterator implements 
Iterator {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MetadataConsistencyCheckIterator.class);
+
+  private Range range;
+  private Function iteratorFactory;
+  private Iterator source;
+  private TabletMetadata prevTablet = null;
+
+  MetadataConsistencyCheckIterator(Function 
iteratorFactory,
+  Range range) {
+this.range = range;
+this.iteratorFactory = iteratorFactory;
+source = iteratorFactory.apply(range);
+  }
+
+  @Override
+  public boolean hasNext() {
+return source.hasNext();
+  }
+
+  static boolean goodTransition(TabletMetadata prev, TabletMetadata curr) {
+if (!curr.sawPrevEndRow()) {
+  log.warn("Tablet {} had no prev end row.", curr.getExtent());
+  return false;
+}
+
+if (!curr.getTableId().equals(prev.getTableId())) {
+  if (prev.getEndRow() != null) {
+log.debug("Non-null end row for last tablet in table: " + 
prev.getExtent() + " "
++ curr.getExtent());
+return false;
+  }
+
+  if (curr.getPrevEndRow() != null) {
+log.debug("First tablet for table had prev end row {} {} ", 
prev.getExtent(),
+curr.getExtent());
 
 Review comment:
   How do you know you are testing the first tablet here?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] milleruntime commented on a change in pull request #488: fixes #469 made bulk import scan split tolerant

2018-05-17 Thread GitBox
milleruntime commented on a change in pull request #488: fixes #469 made bulk 
import scan split tolerant
URL: https://github.com/apache/accumulo/pull/488#discussion_r189053293
 
 

 ##
 File path: 
core/src/test/java/org/apache/accumulo/core/metadata/schema/MetadataConsistencyCheckIteratorTest.java
 ##
 @@ -0,0 +1,113 @@
+/*
+ * 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.core.metadata.schema;
+
+import static org.apache.accumulo.core.metadata.schema.TabletMetadata.create;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.impl.KeyExtent;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+public class MetadataConsistencyCheckIteratorTest {
+
+  private static class IterFactory implements 
Function {
+private int count;
+private List initial;
+private List subsequent;
+
+IterFactory(List initial, List subsequent) 
{
+  this.initial = initial;
+  this.subsequent = subsequent;
+  count = 0;
+}
+
+@Override
+public Iterator apply(Range range) {
+  Stream stream = count++ == 0 ? initial.stream() : 
subsequent.stream();
+  return stream.filter(tm -> range.contains(new 
Key(tm.getExtent().getMetadataEntry(
+  .iterator();
+}
+  }
+
+  private static void check(List expected, IterFactory 
iterFactory) {
+List actual = new ArrayList<>();
+new MetadataConsistencyCheckIterator(iterFactory, new Range())
+.forEachRemaining(tm -> actual.add(tm.getExtent()));
+Assert.assertEquals(Lists.transform(expected, TabletMetadata::getExtent), 
actual);
+  }
+
+  @Test
+  public void testHole() {
+
+List tablets1 = Arrays.asList(create("4", null, "f"), 
create("4", "f", "m"),
+create("4", "r", "x"), create("4", "x", null));
+List tablets2 = Arrays.asList(create("4", null, "f"), 
create("4", "f", "m"),
+create("4", "m", "r"), create("4", "r", "x"), create("4", "x", null));
+
+check(tablets2, new IterFactory(tablets1, tablets2));
 
 Review comment:
   Exception doesn't get thrown here, only debug message?  I guess I'm 
wondering how/when you determine to throw exception or just fail quietly?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services