keith-turner commented on a change in pull request #2342: URL: https://github.com/apache/accumulo/pull/2342#discussion_r745089271
########## File path: test/src/main/java/org/apache/accumulo/test/functional/FlushNoFileIT.java ########## @@ -0,0 +1,129 @@ +/* + * 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 static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Collection; +import java.util.EnumSet; +import java.util.Map; + +import org.apache.accumulo.core.client.Accumulo; +import org.apache.accumulo.core.client.AccumuloClient; +import org.apache.accumulo.core.client.BatchWriter; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.admin.NewTableConfiguration; +import org.apache.accumulo.core.data.ByteSequence; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.IteratorEnvironment; +import org.apache.accumulo.core.iterators.IteratorUtil; +import org.apache.accumulo.core.iterators.SortedKeyValueIterator; +import org.apache.accumulo.harness.AccumuloClusterHarness; +import org.apache.hadoop.io.Text; +import org.junit.Test; + +/** + * Tests that Accumulo will flush but not create a file that has 0 entries. + */ +public class FlushNoFileIT extends AccumuloClusterHarness { + + public static class NullIterator implements SortedKeyValueIterator<Key,Value> { + + @Override + public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, + IteratorEnvironment env) {} + + @Override + public boolean hasTop() { + return false; + } + + @Override + public void next() throws IOException {} + + @Override + public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) {} + + @Override + public Key getTopKey() { + return null; + } + + @Override + public Value getTopValue() { + return null; + } + + @Override + public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) { + return null; + } + } + + @Override + protected int defaultTimeoutSeconds() { + return 60; + } + + @Test + public void test() throws Exception { + try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) { + + String tableName = getUniqueNames(1)[0]; + + NewTableConfiguration ntc = new NewTableConfiguration(); + IteratorSetting iteratorSetting = new IteratorSetting(20, NullIterator.class); + ntc.attachIterator(iteratorSetting, EnumSet.of(IteratorUtil.IteratorScope.minc)); + + c.tableOperations().create(tableName, ntc); + + try (BatchWriter bw = c.createBatchWriter(tableName)) { + Mutation m = new Mutation(new Text("r1")); + m.put("acf", tableName, "1"); + bw.addMutation(m); + } + + FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 0, 0); + + c.tableOperations().flush(tableName, null, null, true); + + FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 0, 0); + + long flushId = FunctionalTestUtils.checkFlushId(c, tableName, 0); + + try (BatchWriter bw = c.createBatchWriter(tableName)) { + Mutation m = new Mutation(new Text("r2")); + m.put("acf", tableName, "1"); + bw.addMutation(m); + } + + c.tableOperations().flush(tableName, null, null, true); + + FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 0, 0); + + long secondFlushId = FunctionalTestUtils.checkFlushId(c, tableName, flushId); + assertTrue("Flush ID did not change", secondFlushId > flushId); + } Review comment: Would also be nice to do a scan of the table. Just to ensure the scan does not throw any errors for this case. ########## File path: test/src/main/java/org/apache/accumulo/test/functional/FunctionalTestUtils.java ########## @@ -218,4 +219,30 @@ private static FateStatus getFateStatus(ClientContext context, AccumuloCluster c throw new RuntimeException(e); } } + + static long checkFlushId(AccumuloClient c, String tableName, long prevFlushID) throws Exception { + try (Scanner scanner = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) { Review comment: Could use ample for this instead of a scanner. Not sure if the following compiles or works, just typed it up as a quick example. ```java try(TabletsMetadata tablets = ((ClientContext)c).getAmple().readTablets(tableId).fetch(FLUSH_ID).build())){ for(TabletMetadata tablet : tablets) { tablets.getFlushId(); } } ``` ########## File path: test/src/main/java/org/apache/accumulo/test/functional/FunctionalTestUtils.java ########## @@ -218,4 +219,30 @@ private static FateStatus getFateStatus(ClientContext context, AccumuloCluster c throw new RuntimeException(e); } } + + static long checkFlushId(AccumuloClient c, String tableName, long prevFlushID) throws Exception { + try (Scanner scanner = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) { + String tableId = c.tableOperations().tableIdMap().get(tableName); + scanner.setRange(new Range(new Text(tableId + ";"), true, new Text(tableId + "<"), true)); + scanner.fetchColumnFamily(TabletsSection.ServerColumnFamily.NAME); + TabletsSection.ServerColumnFamily.FLUSH_COLUMN.fetch(scanner); + + long flushId = -1L; + for (Entry<Key,Value> entry : scanner) { + Key key = entry.getKey(); + String val = entry.getValue().toString(); + + if (key.getColumnQualifierData().toString().equals(FLUSH_QUAL)) { + flushId = Long.parseLong(val); Review comment: Does it matter if diff tablets have diff flush ids? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
