You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by mm...@apache.org on 2019/02/21 18:21:27 UTC
[accumulo] branch master updated: Evolve IteratorEnvironment into
proper API. Closes #954 (#955)
This is an automated email from the ASF dual-hosted git repository.
mmiller pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/master by this push:
new 0ba3d36 Evolve IteratorEnvironment into proper API. Closes #954 (#955)
0ba3d36 is described below
commit 0ba3d361b92e46628b6f8caa033e0ca3672ab622
Author: Mike Miller <mm...@apache.org>
AuthorDate: Thu Feb 21 13:21:22 2019 -0500
Evolve IteratorEnvironment into proper API. Closes #954 (#955)
* Deprecated old methods in IteratorEnvironment
* Added methods to get ServiceEnvironment and TableId
* Give all methods in IteratorEnvironment default impls allowing the removal of BaseIteratorEnvironment
* Remove unused references to AccumuloConfiguration in iterators
* Updated missing Javadoc on IteratorEnvironment
* Created IteratorEnvIT
---
.../core/client/ClientSideIteratorScanner.java | 17 --
.../accumulo/core/client/rfile/RFileScanner.java | 4 +-
.../core/clientImpl/BaseIteratorEnvironment.java | 84 --------
.../accumulo/core/clientImpl/OfflineIterator.java | 6 -
.../accumulo/core/file/map/MapFileOperations.java | 8 +-
.../core/iterators/IteratorEnvironment.java | 96 ++++++++-
.../core/iterators/system/MapFileIterator.java | 4 +-
.../apache/accumulo/core/file/rfile/RFileTest.java | 4 +-
.../core/iterators/DefaultIteratorEnvironment.java | 10 +-
.../iterators/FirstEntryInRowIteratorTest.java | 3 +-
.../core/iterators/SortedMapIteratorTest.java | 3 +-
.../iterators/user/RowDeletingIteratorTest.java | 4 +-
.../iterators/user/RowEncodingIteratorTest.java | 4 +-
.../iterators/user/TransformingIteratorTest.java | 3 +-
.../environments/SimpleIteratorEnvironment.java | 50 -----
.../server/replication/StatusCombinerTest.java | 4 +-
.../accumulo/tserver/ConditionCheckerContext.java | 3 +-
.../tserver/TabletIteratorEnvironment.java | 59 ++++--
.../apache/accumulo/tserver/tablet/Compactor.java | 5 +-
.../accumulo/tserver/tablet/ScanDataSource.java | 3 +-
.../apache/accumulo/tserver/InMemoryMapTest.java | 4 +-
.../org/apache/accumulo/test/IteratorEnvIT.java | 221 +++++++++++++++++++++
22 files changed, 374 insertions(+), 225 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java b/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java
index 789277b..c666b1d 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java
@@ -31,7 +31,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.clientImpl.ScannerOptions;
-import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.data.ArrayByteSequence;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Column;
@@ -86,17 +85,6 @@ public class ClientSideIteratorScanner extends ScannerOptions implements Scanner
}
@Override
- public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName)
- throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public AccumuloConfiguration getConfig() {
- throw new UnsupportedOperationException();
- }
-
- @Override
public IteratorScope getIteratorScope() {
return IteratorScope.scan;
}
@@ -112,11 +100,6 @@ public class ClientSideIteratorScanner extends ScannerOptions implements Scanner
}
@Override
- public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
- throw new UnsupportedOperationException();
- }
-
- @Override
public Authorizations getAuthorizations() {
return ClientSideIteratorScanner.this.getAuthorizations();
}
diff --git a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java
index d6db861..571f335 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java
@@ -33,7 +33,6 @@ import org.apache.accumulo.core.client.IteratorSetting;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.rfile.RFileScannerBuilder.InputArgs;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.clientImpl.ScannerOptions;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.ConfigurationCopy;
@@ -52,6 +51,7 @@ import org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBu
import org.apache.accumulo.core.file.rfile.RFile;
import org.apache.accumulo.core.file.rfile.RFile.Reader;
import org.apache.accumulo.core.iterators.IteratorAdapter;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.IteratorUtil;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
@@ -304,7 +304,7 @@ class RFileScanner extends ScannerOptions implements Scanner {
super.updateScanIteratorOption(iteratorName, key, value);
}
- private class IterEnv extends BaseIteratorEnvironment {
+ private class IterEnv implements IteratorEnvironment {
@Override
public IteratorScope getIteratorScope() {
return IteratorScope.scan;
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/BaseIteratorEnvironment.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/BaseIteratorEnvironment.java
deleted file mode 100644
index 143ccd8..0000000
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/BaseIteratorEnvironment.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.clientImpl;
-
-import java.io.IOException;
-
-import org.apache.accumulo.core.client.sample.SamplerConfiguration;
-import org.apache.accumulo.core.conf.AccumuloConfiguration;
-import org.apache.accumulo.core.data.Key;
-import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.iterators.IteratorEnvironment;
-import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
-import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
-import org.apache.accumulo.core.security.Authorizations;
-
-/**
- * An implementation of {@link IteratorEnvironment} that throws
- * {@link UnsupportedOperationException} for each operation. This is useful for situations that need
- * to extend {@link IteratorEnvironment} and implement a subset of the methods.
- */
-public class BaseIteratorEnvironment implements IteratorEnvironment {
-
- @Override
- public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName)
- throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public AccumuloConfiguration getConfig() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IteratorScope getIteratorScope() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isFullMajorCompaction() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Authorizations getAuthorizations() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isSamplingEnabled() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public SamplerConfiguration getSamplerConfiguration() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IteratorEnvironment cloneWithSamplingEnabled() {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/OfflineIterator.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/OfflineIterator.java
index afa987c..0598ccb 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/OfflineIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/OfflineIterator.java
@@ -59,7 +59,6 @@ import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.accumulo.core.util.LocalityGroupUtil;
import org.apache.accumulo.core.volume.VolumeConfiguration;
-import org.apache.commons.lang.NotImplementedException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.Text;
@@ -82,11 +81,6 @@ class OfflineIterator implements Iterator<Entry<Key,Value>> {
}
@Override
- public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName) {
- throw new NotImplementedException();
- }
-
- @Override
public AccumuloConfiguration getConfig() {
return conf;
}
diff --git a/core/src/main/java/org/apache/accumulo/core/file/map/MapFileOperations.java b/core/src/main/java/org/apache/accumulo/core/file/map/MapFileOperations.java
index 2feef6c..c31a35b 100644
--- a/core/src/main/java/org/apache/accumulo/core/file/map/MapFileOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/file/map/MapFileOperations.java
@@ -139,8 +139,8 @@ public class MapFileOperations extends FileOperations {
@Override
protected FileSKVIterator openReader(FileOptions options) throws IOException {
- FileSKVIterator iter = new RangeIterator(new MapFileIterator(options.getTableConfiguration(),
- options.getFileSystem(), options.getFilename(), options.getConfiguration()));
+ FileSKVIterator iter = new RangeIterator(new MapFileIterator(options.getFileSystem(),
+ options.getFilename(), options.getConfiguration()));
if (options.isSeekToBeginning()) {
iter.seek(new Range(new Key(), null), new ArrayList<>(), false);
}
@@ -166,8 +166,8 @@ public class MapFileOperations extends FileOperations {
@Override
protected FileSKVIterator openScanReader(FileOptions options) throws IOException {
- MapFileIterator mfIter = new MapFileIterator(options.getTableConfiguration(),
- options.getFileSystem(), options.getFilename(), options.getConfiguration());
+ MapFileIterator mfIter = new MapFileIterator(options.getFileSystem(), options.getFilename(),
+ options.getConfiguration());
FileSKVIterator iter = new RangeIterator(mfIter);
iter.seek(options.getRange(), options.getColumnFamilies(), options.isRangeInclusive());
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorEnvironment.java b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorEnvironment.java
index db73ef4..95e969f 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorEnvironment.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorEnvironment.java
@@ -22,27 +22,63 @@ import org.apache.accumulo.core.client.SampleNotPresentException;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.spi.common.ServiceEnvironment;
public interface IteratorEnvironment {
- SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName) throws IOException;
-
- AccumuloConfiguration getConfig();
+ /**
+ * @deprecated since 2.0.0. This is a legacy method used for internal backwards compatibility.
+ */
+ @Deprecated
+ default SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
- IteratorScope getIteratorScope();
+ /**
+ * @deprecated since 2.0.0. This method was using an unstable non public type. Use
+ * {@link #getServiceEnv()}
+ */
+ @Deprecated
+ default AccumuloConfiguration getConfig() {
+ throw new UnsupportedOperationException();
+ }
- boolean isFullMajorCompaction();
+ /**
+ * Return the executed scope of the Iterator. Value will be one of the following:
+ * {@link IteratorScope#scan}, {@link IteratorScope#minc}, {@link IteratorScope#majc}
+ */
+ default IteratorScope getIteratorScope() {
+ throw new UnsupportedOperationException();
+ }
- default boolean isUserCompaction() {
+ /**
+ * Return true if the compaction is a full major compaction. Will throw IllegalStateException if
+ * {@link #getIteratorScope()} != {@link IteratorScope#majc}.
+ */
+ default boolean isFullMajorCompaction() {
throw new UnsupportedOperationException();
}
- void registerSideChannel(SortedKeyValueIterator<Key,Value> iter);
+ /**
+ * @deprecated since 2.0.0. This was an experimental feature and was never tested or documented.
+ */
+ @Deprecated
+ default void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
+ throw new UnsupportedOperationException();
+ }
- Authorizations getAuthorizations();
+ /**
+ * Return the Scan Authorizations used in this Iterator. Will throw UnsupportedOperationException
+ * if {@link #getIteratorScope()} != {@link IteratorScope#scan}.
+ */
+ default Authorizations getAuthorizations() {
+ throw new UnsupportedOperationException();
+ }
/**
* Returns a new iterator environment object that can be used to create deep copies over sample
@@ -75,7 +111,9 @@ public interface IteratorEnvironment {
* when sampling is not configured for table.
* @since 1.8.0
*/
- IteratorEnvironment cloneWithSamplingEnabled();
+ default IteratorEnvironment cloneWithSamplingEnabled() {
+ throw new UnsupportedOperationException();
+ }
/**
* There are at least two conditions under which sampling will be enabled for an environment. One
@@ -86,12 +124,48 @@ public interface IteratorEnvironment {
* @return true if sampling is enabled for this environment.
* @since 1.8.0
*/
- boolean isSamplingEnabled();
+ default boolean isSamplingEnabled() {
+ throw new UnsupportedOperationException();
+ }
/**
*
* @return sampling configuration is sampling is enabled for environment, otherwise returns null.
* @since 1.8.0
*/
- SamplerConfiguration getSamplerConfiguration();
+ default SamplerConfiguration getSamplerConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * True if compaction was user initiated.
+ *
+ * @since 2.0.0
+ */
+ default boolean isUserCompaction() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns an object containing information about the server where this iterator was run. To
+ * obtain a table configuration, use the following methods:
+ *
+ * <pre>
+ * iterEnv.getServiceEnv().getConfiguration(env.getTableId())
+ * </pre>
+ *
+ * @since 2.0.0
+ */
+ default ServiceEnvironment getServiceEnv() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Return the table Id associated with this iterator.
+ *
+ * @since 2.0.0
+ */
+ default TableId getTableId() {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/system/MapFileIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/system/MapFileIterator.java
index dd73649..15f63c2 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/system/MapFileIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/system/MapFileIterator.java
@@ -22,7 +22,6 @@ import java.util.Collection;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
@@ -52,8 +51,7 @@ public class MapFileIterator implements FileSKVIterator {
private FileSystem fs;
private String dirName;
- public MapFileIterator(AccumuloConfiguration acuconf, FileSystem fs, String dir,
- Configuration conf) throws IOException {
+ public MapFileIterator(FileSystem fs, String dir, Configuration conf) throws IOException {
this.reader = MapFileUtil.openMapFile(fs, dir, conf);
this.fs = fs;
this.dirName = dir;
diff --git a/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java b/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java
index 4e1fce7..072d428 100644
--- a/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java
@@ -50,7 +50,6 @@ import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.sample.RowSampler;
import org.apache.accumulo.core.client.sample.Sampler;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.ConfigurationCopy;
import org.apache.accumulo.core.conf.DefaultConfiguration;
@@ -73,6 +72,7 @@ import org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager;
import org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBuilder;
import org.apache.accumulo.core.file.rfile.RFile.Reader;
import org.apache.accumulo.core.file.rfile.bcfile.BCFile;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
import org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator;
import org.apache.accumulo.core.metadata.MetadataTable;
@@ -101,7 +101,7 @@ import com.google.common.primitives.Bytes;
public class RFileTest {
- public static class SampleIE extends BaseIteratorEnvironment {
+ public static class SampleIE implements IteratorEnvironment {
private SamplerConfiguration samplerConfig;
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java b/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java
index 84c2704..ceb7199 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java
@@ -18,7 +18,6 @@ package org.apache.accumulo.core.iterators;
import java.io.IOException;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.DefaultConfiguration;
import org.apache.accumulo.core.data.Key;
@@ -27,7 +26,7 @@ import org.apache.accumulo.core.iterators.system.MapFileIterator;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
-public class DefaultIteratorEnvironment extends BaseIteratorEnvironment {
+public class DefaultIteratorEnvironment implements IteratorEnvironment {
AccumuloConfiguration conf;
Configuration hadoopConf = new Configuration();
@@ -44,12 +43,7 @@ public class DefaultIteratorEnvironment extends BaseIteratorEnvironment {
public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName)
throws IOException {
FileSystem fs = FileSystem.get(hadoopConf);
- return new MapFileIterator(this.conf, fs, mapFileName, hadoopConf);
- }
-
- @Override
- public AccumuloConfiguration getConfig() {
- return conf;
+ return new MapFileIterator(fs, mapFileName, hadoopConf);
}
@Override
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java
index 4d9cc46..4c716c1 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import java.util.TreeMap;
import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.PartialKey;
import org.apache.accumulo.core.data.Range;
@@ -39,7 +38,7 @@ public class FirstEntryInRowIteratorTest {
org.apache.accumulo.core.iterators.SortedMapIterator source = new SortedMapIterator(sourceMap);
CountingIterator counter = new CountingIterator(source);
FirstEntryInRowIterator feiri = new FirstEntryInRowIterator();
- IteratorEnvironment env = new BaseIteratorEnvironment();
+ IteratorEnvironment env = new DefaultIteratorEnvironment();
feiri.init(counter, iteratorSetting.getOptions(), env);
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/SortedMapIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/SortedMapIteratorTest.java
index 6476c48..797e582 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/SortedMapIteratorTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/SortedMapIteratorTest.java
@@ -21,7 +21,6 @@ import java.util.TreeMap;
import org.apache.accumulo.core.client.SampleNotPresentException;
import org.apache.accumulo.core.client.sample.RowSampler;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.junit.Test;
public class SortedMapIteratorTest {
@@ -29,7 +28,7 @@ public class SortedMapIteratorTest {
@Test(expected = SampleNotPresentException.class)
public void testSampleNotPresent() {
SortedMapIterator smi = new SortedMapIterator(new TreeMap<>());
- smi.deepCopy(new BaseIteratorEnvironment() {
+ smi.deepCopy(new IteratorEnvironment() {
@Override
public boolean isSamplingEnabled() {
return true;
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/RowDeletingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/RowDeletingIteratorTest.java
index 1c0d397..1f51663 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/RowDeletingIteratorTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/RowDeletingIteratorTest.java
@@ -24,12 +24,12 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeMap;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.data.ArrayByteSequence;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
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.IteratorScope;
import org.apache.accumulo.core.iterators.SortedMapIterator;
import org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator;
@@ -38,7 +38,7 @@ import org.junit.Test;
public class RowDeletingIteratorTest {
- public static class TestIE extends BaseIteratorEnvironment {
+ public static class TestIE implements IteratorEnvironment {
private IteratorScope scope;
private boolean fmc;
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/RowEncodingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/RowEncodingIteratorTest.java
index 524ac50..93526d3 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/RowEncodingIteratorTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/RowEncodingIteratorTest.java
@@ -32,10 +32,10 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.data.Key;
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.SortedMapIterator;
import org.apache.commons.collections.BufferOverflowException;
@@ -44,7 +44,7 @@ import org.junit.Test;
public class RowEncodingIteratorTest {
- private static final class DummyIteratorEnv extends BaseIteratorEnvironment {
+ private static final class DummyIteratorEnv implements IteratorEnvironment {
@Override
public IteratorUtil.IteratorScope getIteratorScope() {
return IteratorUtil.IteratorScope.scan;
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/TransformingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/TransformingIteratorTest.java
index 7b6eda7..158b212 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/TransformingIteratorTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/TransformingIteratorTest.java
@@ -35,7 +35,6 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.data.ArrayByteSequence;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
@@ -745,7 +744,7 @@ public class TransformingIteratorTest {
}
}
- private static class MajCIteratorEnvironmentAdapter extends BaseIteratorEnvironment {
+ private static class MajCIteratorEnvironmentAdapter implements IteratorEnvironment {
@Override
public IteratorScope getIteratorScope() {
return IteratorScope.majc;
diff --git a/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/environments/SimpleIteratorEnvironment.java b/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/environments/SimpleIteratorEnvironment.java
index 1f6ecf4..9d41f7f 100644
--- a/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/environments/SimpleIteratorEnvironment.java
+++ b/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/environments/SimpleIteratorEnvironment.java
@@ -16,16 +16,7 @@
*/
package org.apache.accumulo.iteratortest.environments;
-import java.io.IOException;
-
-import org.apache.accumulo.core.client.sample.SamplerConfiguration;
-import org.apache.accumulo.core.conf.AccumuloConfiguration;
-import org.apache.accumulo.core.data.Key;
-import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
-import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
-import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
-import org.apache.accumulo.core.security.Authorizations;
/**
* A simple implementation of {@link IteratorEnvironment} which is unimplemented.
@@ -33,49 +24,8 @@ import org.apache.accumulo.core.security.Authorizations;
public class SimpleIteratorEnvironment implements IteratorEnvironment {
@Override
- public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName)
- throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public AccumuloConfiguration getConfig() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IteratorScope getIteratorScope() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isFullMajorCompaction() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Authorizations getAuthorizations() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IteratorEnvironment cloneWithSamplingEnabled() {
- throw new UnsupportedOperationException();
- }
-
- @Override
public boolean isSamplingEnabled() {
return false;
}
- @Override
- public SamplerConfiguration getSamplerConfiguration() {
- throw new UnsupportedOperationException();
- }
-
}
diff --git a/server/base/src/test/java/org/apache/accumulo/server/replication/StatusCombinerTest.java b/server/base/src/test/java/org/apache/accumulo/server/replication/StatusCombinerTest.java
index e8e1c9e..8b67a31 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/replication/StatusCombinerTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/replication/StatusCombinerTest.java
@@ -29,10 +29,10 @@ import java.util.List;
import org.apache.accumulo.core.client.IteratorSetting;
import org.apache.accumulo.core.client.IteratorSetting.Column;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.iterators.Combiner;
import org.apache.accumulo.core.iterators.DevNull;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.replication.ReplicationSchema.StatusSection;
import org.apache.accumulo.server.replication.proto.Replication.Status;
@@ -45,7 +45,7 @@ public class StatusCombinerTest {
private Key key;
private Status.Builder builder;
- private static class TestIE extends BaseIteratorEnvironment {
+ private static class TestIE implements IteratorEnvironment {
@Override
public IteratorScope getIteratorScope() {
return IteratorScope.scan;
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/ConditionCheckerContext.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/ConditionCheckerContext.java
index b715179..9e7c1e2 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/ConditionCheckerContext.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/ConditionCheckerContext.java
@@ -80,7 +80,8 @@ public class ConditionCheckerContext {
classCache = new HashMap<>();
- tie = new TabletIteratorEnvironment(serverContext, IteratorScope.scan, tableConf);
+ tie = new TabletIteratorEnvironment(serverContext, IteratorScope.scan, tableConf,
+ tableConf.getTableId());
}
SortedKeyValueIterator<Key,Value> buildIterator(SortedKeyValueIterator<Key,Value> systemIter,
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletIteratorEnvironment.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletIteratorEnvironment.java
index 4a4e093..dbbec0d 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletIteratorEnvironment.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletIteratorEnvironment.java
@@ -25,6 +25,7 @@ import org.apache.accumulo.core.client.SampleNotPresentException;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
@@ -33,7 +34,9 @@ import org.apache.accumulo.core.iterators.system.MultiIterator;
import org.apache.accumulo.core.metadata.schema.DataFileValue;
import org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.spi.common.ServiceEnvironment;
import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.ServiceEnvironmentImpl;
import org.apache.accumulo.server.fs.FileRef;
import org.apache.accumulo.server.iterators.SystemIteratorEnvironment;
import org.apache.accumulo.tserver.FileManager.ScanFileManager;
@@ -43,11 +46,13 @@ import org.apache.hadoop.fs.Path;
public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
private final ServerContext context;
+ private final ServiceEnvironment serviceEnvironment;
private final ScanFileManager trm;
private final IteratorScope scope;
private final boolean fullMajorCompaction;
private boolean userCompaction;
- private final AccumuloConfiguration config;
+ private final AccumuloConfiguration tableConfig;
+ private final TableId tableId;
private final ArrayList<SortedKeyValueIterator<Key,Value>> topLevelIterators;
private Map<FileRef,DataFileValue> files;
@@ -56,31 +61,36 @@ public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
private boolean enableSampleForDeepCopy;
public TabletIteratorEnvironment(ServerContext context, IteratorScope scope,
- AccumuloConfiguration config) {
+ AccumuloConfiguration tableConfig, TableId tableId) {
if (scope == IteratorScope.majc)
throw new IllegalArgumentException("must set if compaction is full");
this.context = context;
+ this.serviceEnvironment = new ServiceEnvironmentImpl(context);
this.scope = scope;
this.trm = null;
- this.config = config;
+ this.tableConfig = tableConfig;
+ this.tableId = tableId;
this.fullMajorCompaction = false;
this.userCompaction = false;
this.authorizations = Authorizations.EMPTY;
this.topLevelIterators = new ArrayList<>();
}
- private TabletIteratorEnvironment(ServerContext context, IteratorScope scope,
- AccumuloConfiguration config, ScanFileManager trm, Map<FileRef,DataFileValue> files,
- Authorizations authorizations, SamplerConfigurationImpl samplerConfig,
+ public TabletIteratorEnvironment(ServerContext context, IteratorScope scope,
+ AccumuloConfiguration tableConfig, TableId tableId, ScanFileManager trm,
+ Map<FileRef,DataFileValue> files, Authorizations authorizations,
+ SamplerConfigurationImpl samplerConfig,
ArrayList<SortedKeyValueIterator<Key,Value>> topLevelIterators) {
if (scope == IteratorScope.majc)
throw new IllegalArgumentException("must set if compaction is full");
this.context = context;
+ this.serviceEnvironment = new ServiceEnvironmentImpl(context);
this.scope = scope;
this.trm = trm;
- this.config = config;
+ this.tableConfig = tableConfig;
+ this.tableId = tableId;
this.fullMajorCompaction = false;
this.files = files;
this.authorizations = authorizations;
@@ -94,22 +104,18 @@ public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
this.topLevelIterators = topLevelIterators;
}
- public TabletIteratorEnvironment(ServerContext context, IteratorScope scope,
- AccumuloConfiguration config, ScanFileManager trm, Map<FileRef,DataFileValue> files,
- Authorizations authorizations, SamplerConfigurationImpl samplerConfig) {
- this(context, scope, config, trm, files, authorizations, samplerConfig, new ArrayList<>());
- }
-
public TabletIteratorEnvironment(ServerContext context, IteratorScope scope, boolean fullMajC,
- AccumuloConfiguration config, MajorCompactionReason reason) {
+ AccumuloConfiguration tableConfig, TableId tableId, MajorCompactionReason reason) {
if (scope != IteratorScope.majc)
throw new IllegalArgumentException(
"Tried to set maj compaction type when scope was " + scope);
this.context = context;
+ this.serviceEnvironment = new ServiceEnvironmentImpl(context);
this.scope = scope;
this.trm = null;
- this.config = config;
+ this.tableConfig = tableConfig;
+ this.tableId = tableId;
this.fullMajorCompaction = fullMajC;
this.userCompaction = reason.equals(MajorCompactionReason.USER);
this.authorizations = Authorizations.EMPTY;
@@ -117,8 +123,9 @@ public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
}
@Override
+ @SuppressWarnings("deprecation")
public AccumuloConfiguration getConfig() {
- return config;
+ return tableConfig;
}
@Override
@@ -142,6 +149,7 @@ public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
}
@Override
+ @SuppressWarnings("deprecation")
public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName)
throws IOException {
FileRef ref = new FileRef(mapFileName, new Path(mapFileName));
@@ -149,6 +157,7 @@ public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
}
@Override
+ @SuppressWarnings("deprecation")
public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
topLevelIterators.add(iter);
}
@@ -179,7 +188,7 @@ public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
public SamplerConfiguration getSamplerConfiguration() {
if (samplerConfig == null) {
// only create this once so that it stays the same, even if config changes
- SamplerConfigurationImpl sci = SamplerConfigurationImpl.newSamplerConfig(config);
+ SamplerConfigurationImpl sci = SamplerConfigurationImpl.newSamplerConfig(tableConfig);
if (sci == null) {
return null;
}
@@ -194,17 +203,27 @@ public class TabletIteratorEnvironment implements SystemIteratorEnvironment {
throw new UnsupportedOperationException();
}
- SamplerConfigurationImpl sci = SamplerConfigurationImpl.newSamplerConfig(config);
+ SamplerConfigurationImpl sci = SamplerConfigurationImpl.newSamplerConfig(tableConfig);
if (sci == null) {
throw new SampleNotPresentException();
}
- return new TabletIteratorEnvironment(context, scope, config, trm, files, authorizations, sci,
- topLevelIterators);
+ return new TabletIteratorEnvironment(context, scope, tableConfig, tableId, trm, files,
+ authorizations, sci, topLevelIterators);
}
@Override
public ServerContext getServerContext() {
return context;
}
+
+ @Override
+ public ServiceEnvironment getServiceEnv() {
+ return serviceEnvironment;
+ }
+
+ @Override
+ public TableId getTableId() {
+ return tableId;
+ }
}
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Compactor.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Compactor.java
index 3f9ded3..8323666 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Compactor.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Compactor.java
@@ -359,9 +359,10 @@ public class Compactor implements Callable<CompactionStats> {
TabletIteratorEnvironment iterEnv;
if (env.getIteratorScope() == IteratorScope.majc)
iterEnv = new TabletIteratorEnvironment(context, IteratorScope.majc, !propogateDeletes,
- acuTableConf, getMajorCompactionReason());
+ acuTableConf, getExtent().getTableId(), getMajorCompactionReason());
else if (env.getIteratorScope() == IteratorScope.minc)
- iterEnv = new TabletIteratorEnvironment(context, IteratorScope.minc, acuTableConf);
+ iterEnv = new TabletIteratorEnvironment(context, IteratorScope.minc, acuTableConf,
+ getExtent().getTableId());
else
throw new IllegalArgumentException();
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/ScanDataSource.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/ScanDataSource.java
index 34b1130..ca58cb2 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/ScanDataSource.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/ScanDataSource.java
@@ -193,7 +193,8 @@ class ScanDataSource implements DataSource {
TabletIteratorEnvironment iterEnv = new TabletIteratorEnvironment(
tablet.getTabletServer().getContext(), IteratorScope.scan, tablet.getTableConfiguration(),
- fileManager, files, options.getAuthorizations(), samplerConfig);
+ tablet.getExtent().getTableId(), fileManager, files, options.getAuthorizations(),
+ samplerConfig, new ArrayList<>());
statsIterator = new StatsIterator(multiIter, TabletServer.seekCount,
tablet.getScannedCounter());
diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java
index 8211fc6..951d5da 100644
--- a/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java
+++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java
@@ -40,7 +40,6 @@ import org.apache.accumulo.core.client.SampleNotPresentException;
import org.apache.accumulo.core.client.sample.RowSampler;
import org.apache.accumulo.core.client.sample.Sampler;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
-import org.apache.accumulo.core.clientImpl.BaseIteratorEnvironment;
import org.apache.accumulo.core.conf.ConfigurationCopy;
import org.apache.accumulo.core.conf.DefaultConfiguration;
import org.apache.accumulo.core.conf.Property;
@@ -53,6 +52,7 @@ import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IterationInterruptedException;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
import org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator;
import org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl;
@@ -78,7 +78,7 @@ import com.google.common.collect.ImmutableMap;
public class InMemoryMapTest {
- private static class SampleIE extends BaseIteratorEnvironment {
+ private static class SampleIE implements IteratorEnvironment {
private final SamplerConfiguration sampleConfig;
diff --git a/test/src/main/java/org/apache/accumulo/test/IteratorEnvIT.java b/test/src/main/java/org/apache/accumulo/test/IteratorEnvIT.java
new file mode 100644
index 0000000..de7044b
--- /dev/null
+++ b/test/src/main/java/org/apache/accumulo/test/IteratorEnvIT.java
@@ -0,0 +1,221 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.Map;
+
+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.Scanner;
+import org.apache.accumulo.core.client.admin.CompactionConfig;
+import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.WrappingIterator;
+import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
+import org.apache.hadoop.conf.Configuration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test that objects in IteratorEnvironment returned from the server are as expected.
+ */
+public class IteratorEnvIT extends AccumuloClusterHarness {
+
+ @Override
+ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {
+ cfg.setNumTservers(1);
+ }
+
+ @Override
+ protected int defaultTimeoutSeconds() {
+ return 60;
+ }
+
+ private AccumuloClient client;
+
+ /**
+ * Basic scan iterator to test IteratorEnvironment returns what is expected.
+ */
+ public static class ScanIter extends WrappingIterator {
+ IteratorScope scope = IteratorScope.scan;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ testEnv(scope, options, env);
+
+ // Checking for compaction on a scan should throw an error.
+ try {
+ assertFalse(env.isUserCompaction());
+ fail("Expected to throw IllegalStateException when checking compaction on a scan.");
+ } catch (IllegalStateException e) {}
+ try {
+ assertFalse(env.isFullMajorCompaction());
+ fail("Expected to throw IllegalStateException when checking compaction on a scan.");
+ } catch (IllegalStateException e) {}
+ }
+ }
+
+ /**
+ * Basic compaction iterator to test IteratorEnvironment returns what is expected.
+ */
+ public static class MajcIter extends WrappingIterator {
+ IteratorScope scope = IteratorScope.majc;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ testEnv(scope, options, env);
+ assertTrue(env.isUserCompaction());
+ assertTrue(env.isFullMajorCompaction());
+ }
+ }
+
+ /**
+ *
+ */
+ public static class MincIter extends WrappingIterator {
+ IteratorScope scope = IteratorScope.minc;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ testEnv(scope, options, env);
+ try {
+ assertTrue(env.isUserCompaction());
+ fail("Expected to throw IllegalStateException when checking compaction on a scan.");
+ } catch (IllegalStateException e) {}
+ try {
+ assertFalse(env.isFullMajorCompaction());
+ fail("Expected to throw IllegalStateException when checking compaction on a scan.");
+ } catch (IllegalStateException e) {}
+ }
+ }
+
+ /**
+ * Test the environment methods return what is expected.
+ */
+ @SuppressWarnings("deprecation")
+ private static void testEnv(IteratorScope scope, Map<String,String> opts,
+ IteratorEnvironment env) {
+ TableId expectedTableId = TableId.of(opts.get("expected.table.id"));
+ assertEquals("Expected table property not found", "value1",
+ env.getConfig().get("table.custom.iterator.env.test"));
+ assertEquals("Expected table property not found", "value1",
+ env.getServiceEnv().getConfiguration(env.getTableId()).getTableCustom("iterator.env.test"));
+ assertEquals("Error getting iterator scope", scope, env.getIteratorScope());
+ assertFalse("isSamplingEnabled returned true, expected false", env.isSamplingEnabled());
+ assertEquals("Error getting Table ID", expectedTableId, env.getTableId());
+ }
+
+ @Before
+ public void setup() {
+ client = createAccumuloClient();
+ }
+
+ @After
+ public void finish() {
+ client.close();
+ }
+
+ @Test
+ public void test() throws Exception {
+ String[] tables = getUniqueNames(3);
+ testScan(tables[0], ScanIter.class);
+ testCompact(tables[1], MajcIter.class);
+ testMinCompact(tables[2], MincIter.class);
+ }
+
+ private void testScan(String tableName,
+ Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) throws Exception {
+ writeData(tableName);
+
+ IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
+ cfg.addOption("expected.table.id", client.tableOperations().tableIdMap().get(tableName));
+ try (Scanner scan = client.createScanner(tableName)) {
+ scan.addScanIterator(cfg);
+ Iterator<Map.Entry<Key,Value>> iter = scan.iterator();
+ iter.forEachRemaining(e -> assertEquals("cf1", e.getKey().getColumnFamily().toString()));
+ }
+ }
+
+ public void testCompact(String tableName,
+ Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) throws Exception {
+ writeData(tableName);
+
+ IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
+ cfg.addOption("expected.table.id", client.tableOperations().tableIdMap().get(tableName));
+ CompactionConfig config = new CompactionConfig();
+ config.setIterators(Collections.singletonList(cfg));
+ client.tableOperations().compact(tableName, config);
+ }
+
+ public void testMinCompact(String tableName,
+ Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) throws Exception {
+ writeData(tableName);
+
+ IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
+ cfg.addOption("expected.table.id", client.tableOperations().tableIdMap().get(tableName));
+
+ client.tableOperations().attachIterator(tableName, cfg, EnumSet.of(IteratorScope.minc));
+
+ client.tableOperations().flush(tableName);
+ }
+
+ private NewTableConfiguration getTableConfig() {
+ NewTableConfiguration ntc = new NewTableConfiguration();
+ ntc.setProperties(Collections.singletonMap("table.custom.iterator.env.test", "value1"));
+ return ntc;
+ }
+
+ private void writeData(String tableName) throws Exception {
+ client.tableOperations().create(tableName, getTableConfig());
+
+ try (BatchWriter bw = client.createBatchWriter(tableName)) {
+ Mutation m = new Mutation("row1");
+ m.at().family("cf1").qualifier("cq1").put("val1");
+ bw.addMutation(m);
+ m = new Mutation("row2");
+ m.at().family("cf1").qualifier("cq1").put("val2");
+ bw.addMutation(m);
+ m = new Mutation("row3");
+ m.at().family("cf1").qualifier("cq1").put("val3");
+ bw.addMutation(m);
+ }
+ }
+}