Skip to content

Commit a68ec11

Browse files
kevinrr888ctubbsii
andcommitted
Changes:
- Changed ClientSideIteratorScanner.getConfig() to use the safer getPluginEnv() - Added getPluginEnv() impl to all IteratorEnvironments (besides test envs) - Improved RFile.ScannerOptions.withTableProperties() javadoc to better explain how iterators will have access to these properties - Opted for RFileScanner.IterEnv.getTableId() to return null instead of a dummy id - Removed incorrect impl of RFileScanner.IterEnv.get(Service/Plugin)Env().getTableName() to instead just throw UnsupOpExc since the method doesn't make sense anyways. Co-authored-by: Christopher Tubbs <[email protected]>
1 parent 242b520 commit a68ec11

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,7 @@ public SamplerConfiguration getSamplerConfiguration() {
145145
@Override
146146
@Deprecated(since = "2.0.0")
147147
public AccumuloConfiguration getConfig() {
148-
var ctx = context.get();
149-
try {
150-
return new ConfigurationCopy(
151-
ctx.tableOperations().getConfiguration(ctx.getTableName(tableId.get())));
152-
} catch (AccumuloException | TableNotFoundException e) {
153-
throw new RuntimeException("Error getting table configuration", e);
154-
}
148+
return new ConfigurationCopy(getPluginEnv().getConfiguration(getTableId()));
155149
}
156150

157151
@Deprecated(since = "2.1.0")
@@ -160,6 +154,11 @@ public ServiceEnvironment getServiceEnv() {
160154
return serviceEnvironment.get();
161155
}
162156

157+
@Override
158+
public PluginEnvironment getPluginEnv() {
159+
return serviceEnvironment.get();
160+
}
161+
163162
@Override
164163
public TableId getTableId() {
165164
return tableId.get();

core/src/main/java/org/apache/accumulo/core/client/rfile/RFile.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ public interface ScannerOptions {
176176
* properties could be passed here.
177177
*
178178
* <p>
179-
* Starting with {@code 2.1.4}, {@link PluginEnvironment#getConfiguration(TableId)} (obtained by
180-
* {@link IteratorEnvironment#getPluginEnv()}) will return the properties passed in here.
179+
* Configured iterators will have access to these properties via the
180+
* {@link PluginEnvironment#getConfiguration(TableId)} (obtained by
181+
* {@link IteratorEnvironment#getPluginEnv()}). The tableId used to get the configuration should
182+
* be the one returned programmatically from {@link IteratorEnvironment#getTableId()}.
181183
*
182184
* @param props iterable over Accumulo table key value properties.
183185
* @return this
@@ -189,10 +191,6 @@ public interface ScannerOptions {
189191
* {@link Property#TABLE_PREFIX} may be accepted and used. For example, cache and crypto
190192
* properties could be passed here.
191193
*
192-
* <p>
193-
* Starting with {@code 2.1.4}, {@link PluginEnvironment#getConfiguration(TableId)} (obtained by
194-
* {@link IteratorEnvironment#getPluginEnv()}) will return the properties passed in here.
195-
*
196194
* @param props a map instead of an Iterable
197195
* @return this
198196
* @see #withTableProperties(Iterable)

core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.function.Supplier;
3232

3333
import org.apache.accumulo.core.client.IteratorSetting;
34+
import org.apache.accumulo.core.client.PluginEnvironment;
3435
import org.apache.accumulo.core.client.Scanner;
3536
import org.apache.accumulo.core.client.rfile.RFileScannerBuilder.InputArgs;
3637
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
@@ -85,8 +86,6 @@ class RFileScanner extends ScannerOptions implements Scanner {
8586
private static final String errorMsg =
8687
"This scanner is unrelated to any table or accumulo instance;"
8788
+ " it operates directly on files. Therefore, it can not support this operation.";
88-
private static final TableId dummyTableId = TableId.of("RFileScannerFakeTableId");
89-
9089
private Range range;
9190
private BlockCacheManager blockCacheManager = null;
9291
private BlockCache dataCache = null;
@@ -357,9 +356,16 @@ public SamplerConfiguration getSamplerConfiguration() {
357356
return RFileScanner.this.getSamplerConfiguration();
358357
}
359358

359+
/**
360+
* This method only exists to be used as described in {@link IteratorEnvironment#getPluginEnv()}
361+
* so the table config can be obtained. This simply returns null since a table id does not make
362+
* sense in the context of scanning RFiles, but is needed to obtain the table configuration.
363+
*
364+
* @return null
365+
*/
360366
@Override
361367
public TableId getTableId() {
362-
return dummyTableId;
368+
return null;
363369
}
364370

365371
@Override
@@ -374,6 +380,11 @@ public ServiceEnvironment getServiceEnv() {
374380
return serviceEnvironment.get();
375381
}
376382

383+
@Override
384+
public PluginEnvironment getPluginEnv() {
385+
return serviceEnvironment.get();
386+
}
387+
377388
private ServiceEnvironment createServiceEnv() {
378389
return new ServiceEnvironment() {
379390
@Override
@@ -391,15 +402,14 @@ public <T> T instantiate(String className, Class<T> base)
391402

392403
@Override
393404
public String getTableName(TableId tableId) {
394-
Preconditions.checkArgument(tableId.equals(getTableId()), "Expected " + getTableId()
395-
+ " but got " + tableId + " when requesting the table config");
396-
return tableId.canonical();
405+
throw new UnsupportedOperationException(errorMsg);
397406
}
398407

399408
@Override
400409
public Configuration getConfiguration(TableId tableId) {
401-
Preconditions.checkArgument(tableId.equals(getTableId()), "Expected " + getTableId()
402-
+ " but got " + tableId + " when requesting the table config");
410+
Preconditions.checkArgument(tableId == getTableId(),
411+
"Expected tableId obtained from IteratorEnvironment.getTableId() but got " + tableId
412+
+ " when requesting the table config");
403413
return new ConfigurationImpl(tableConf);
404414
}
405415

core/src/main/java/org/apache/accumulo/core/clientImpl/OfflineIterator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import org.apache.accumulo.core.client.AccumuloException;
3737
import org.apache.accumulo.core.client.AccumuloSecurityException;
38+
import org.apache.accumulo.core.client.PluginEnvironment;
3839
import org.apache.accumulo.core.client.SampleNotPresentException;
3940
import org.apache.accumulo.core.client.TableNotFoundException;
4041
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
@@ -169,6 +170,11 @@ public ServiceEnvironment getServiceEnv() {
169170
return serviceEnvironment.get();
170171
}
171172

173+
@Override
174+
public PluginEnvironment getPluginEnv() {
175+
return serviceEnvironment.get();
176+
}
177+
172178
@Override
173179
public TableId getTableId() {
174180
return tableId;

server/base/src/main/java/org/apache/accumulo/server/iterators/TabletIteratorEnvironment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collections;
2424
import java.util.Map;
2525

26+
import org.apache.accumulo.core.client.PluginEnvironment;
2627
import org.apache.accumulo.core.client.SampleNotPresentException;
2728
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
2829
import org.apache.accumulo.core.conf.AccumuloConfiguration;
@@ -232,6 +233,11 @@ public ServiceEnvironment getServiceEnv() {
232233
return serviceEnvironment;
233234
}
234235

236+
@Override
237+
public PluginEnvironment getPluginEnv() {
238+
return serviceEnvironment;
239+
}
240+
235241
@Override
236242
public TableId getTableId() {
237243
return tableId;

test/src/main/java/org/apache/accumulo/test/IteratorEnvIT.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public boolean accept(Key k, Value v) {
185185
*/
186186
private static void testEnv(IteratorScope scope, Map<String,String> opts,
187187
IteratorEnvironment env) {
188-
TableId expectedTableId = TableId.of(opts.get("expected.table.id"));
188+
String expTableIdStr = opts.get("expected.table.id");
189+
TableId expTableId = expTableIdStr == null ? null : TableId.of(expTableIdStr);
189190

190191
// verify getServiceEnv() and getPluginEnv() are the same objects,
191192
// so further checks only need to use getPluginEnv()
@@ -227,7 +228,7 @@ private static void testEnv(IteratorScope scope, Map<String,String> opts,
227228
if (env.isSamplingEnabled()) {
228229
throw new RuntimeException("Test failed - isSamplingEnabled returned true, expected false");
229230
}
230-
if (!expectedTableId.equals(env.getTableId())) {
231+
if (expTableId != null && !expTableId.equals(env.getTableId())) {
231232
throw new RuntimeException("Test failed - Error getting Table ID");
232233
}
233234
}
@@ -248,7 +249,8 @@ public void finish() {
248249
public void test() throws Exception {
249250
String[] tables = getUniqueNames(5);
250251
testScan(tables[0], ScanIter.class);
251-
testRFileScan("RFileScannerFakeTableId", ScanIter.class);
252+
// No table id when scanning at file level
253+
testRFileScan(ScanIter.class);
252254
testOfflineScan(tables[1], ScanIter.class);
253255
testClientSideScan(tables[2], ScanIter.class);
254256
testCompact(tables[3], MajcIter.class);
@@ -269,14 +271,13 @@ private void testScan(String tableName,
269271
}
270272
}
271273

272-
private void testRFileScan(String tableName,
273-
Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) throws Exception {
274+
private void testRFileScan(Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass)
275+
throws Exception {
274276
TreeMap<Key,Value> data = createTestData();
275277
LocalFileSystem fs = FileSystem.getLocal(new Configuration());
276278
String rFilePath = createRFile(fs, data);
277279

278280
IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
279-
cfg.addOption("expected.table.id", tableName);
280281
cfg.addOption("bad.col.fam", "badcf");
281282

282283
try (Scanner scan = RFile.newScanner().from(rFilePath).withFileSystem(fs)

0 commit comments

Comments
 (0)