-
Notifications
You must be signed in to change notification settings - Fork 478
IteratorEnvironment fixes
#4816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
77163aa
e1ccea2
85ae622
3660d3a
242b520
a68ec11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| import java.util.function.Supplier; | ||
|
|
||
| import org.apache.accumulo.core.client.IteratorSetting; | ||
| import org.apache.accumulo.core.client.PluginEnvironment; | ||
| import org.apache.accumulo.core.client.Scanner; | ||
| import org.apache.accumulo.core.client.rfile.RFileScannerBuilder.InputArgs; | ||
| import org.apache.accumulo.core.client.sample.SamplerConfiguration; | ||
|
|
@@ -44,6 +45,7 @@ | |
| import org.apache.accumulo.core.data.Column; | ||
| import org.apache.accumulo.core.data.Key; | ||
| 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.file.blockfile.cache.impl.BlockCacheConfiguration; | ||
| import org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheManagerFactory; | ||
|
|
@@ -66,19 +68,24 @@ | |
| import org.apache.accumulo.core.spi.cache.BlockCacheManager; | ||
| import org.apache.accumulo.core.spi.cache.CacheEntry; | ||
| import org.apache.accumulo.core.spi.cache.CacheType; | ||
| import org.apache.accumulo.core.spi.common.ServiceEnvironment; | ||
| import org.apache.accumulo.core.spi.crypto.CryptoEnvironment; | ||
| import org.apache.accumulo.core.spi.crypto.CryptoService; | ||
| import org.apache.accumulo.core.util.ConfigurationImpl; | ||
| import org.apache.accumulo.core.util.LocalityGroupUtil; | ||
| import org.apache.hadoop.fs.FSDataInputStream; | ||
| import org.apache.hadoop.io.Text; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Suppliers; | ||
|
|
||
| class RFileScanner extends ScannerOptions implements Scanner { | ||
|
|
||
| private static final byte[] EMPTY_BYTES = new byte[0]; | ||
| private static final Range EMPTY_RANGE = new Range(); | ||
|
|
||
| private static final String errorMsg = | ||
| "This scanner is unrelated to any table or accumulo instance;" | ||
| + " it operates directly on files. Therefore, it can not support this operation."; | ||
| private Range range; | ||
| private BlockCacheManager blockCacheManager = null; | ||
| private BlockCache dataCache = null; | ||
|
|
@@ -311,14 +318,27 @@ public void updateScanIteratorOption(String iteratorName, String key, String val | |
| } | ||
|
|
||
| private class IterEnv implements IteratorEnvironment { | ||
| private final Supplier<ServiceEnvironment> serviceEnvironment; | ||
|
|
||
| private IterEnv() { | ||
| this.serviceEnvironment = Suppliers.memoize(this::createServiceEnv); | ||
| } | ||
|
|
||
| @Override | ||
| public IteratorScope getIteratorScope() { | ||
| return IteratorScope.scan; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isFullMajorCompaction() { | ||
| return false; | ||
| throw new IllegalStateException( | ||
| "Asked about major compaction type when scope is " + getIteratorScope()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isUserCompaction() { | ||
| throw new IllegalStateException( | ||
| "Asked about user initiated compaction type when scope is " + getIteratorScope()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -335,6 +355,70 @@ public boolean isSamplingEnabled() { | |
| public SamplerConfiguration getSamplerConfiguration() { | ||
| return RFileScanner.this.getSamplerConfiguration(); | ||
| } | ||
|
|
||
| /** | ||
| * This method only exists to be used as described in {@link IteratorEnvironment#getPluginEnv()} | ||
| * so the table config can be obtained. This simply returns null since a table id does not make | ||
| * sense in the context of scanning RFiles, but is needed to obtain the table configuration. | ||
| * | ||
| * @return null | ||
| */ | ||
| @Override | ||
| public TableId getTableId() { | ||
| return null; | ||
keith-turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| @Deprecated(since = "2.0.0") | ||
| public AccumuloConfiguration getConfig() { | ||
| return tableConf; | ||
| } | ||
|
|
||
| @Override | ||
| @Deprecated(since = "2.1.0") | ||
| public ServiceEnvironment getServiceEnv() { | ||
| return serviceEnvironment.get(); | ||
| } | ||
|
|
||
| @Override | ||
| public PluginEnvironment getPluginEnv() { | ||
| return serviceEnvironment.get(); | ||
| } | ||
|
|
||
| private ServiceEnvironment createServiceEnv() { | ||
| return new ServiceEnvironment() { | ||
| @Override | ||
| public <T> T instantiate(TableId tableId, String className, Class<T> base) | ||
| throws ReflectiveOperationException { | ||
| return instantiate(className, base); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T instantiate(String className, Class<T> base) | ||
| throws ReflectiveOperationException { | ||
| return this.getClass().getClassLoader().loadClass(className).asSubclass(base) | ||
| .getDeclaredConstructor().newInstance(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTableName(TableId tableId) { | ||
| throw new UnsupportedOperationException(errorMsg); | ||
keith-turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public Configuration getConfiguration(TableId tableId) { | ||
keith-turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Preconditions.checkArgument(tableId == getTableId(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the intention was that the only valid use of this method is: Just wanted to avoid accepting something like |
||
| "Expected tableId obtained from IteratorEnvironment.getTableId() but got " + tableId | ||
| + " when requesting the table config"); | ||
| return new ConfigurationImpl(tableConf); | ||
| } | ||
|
|
||
| @Override | ||
| public Configuration getConfiguration() { | ||
| throw new UnsupportedOperationException(errorMsg); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What prevents us from just using the implementation from
super.getPluginEnv()andsuper.getServiceEnv()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IteratorEnvironmentdoesn't have any implementation forgetServiceEnv()orgetPluginEnv(). Or are you suggesting changingIteratorEnvironment?