use of org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator in project accumulo by apache.
the class FileCompactor method openMapDataFiles.
private List<SortedKeyValueIterator<Key, Value>> openMapDataFiles(ArrayList<FileSKVIterator> readers) throws IOException {
List<SortedKeyValueIterator<Key, Value>> iters = new ArrayList<>(filesToCompact.size());
for (TabletFile mapFile : filesToCompact.keySet()) {
try {
FileOperations fileFactory = FileOperations.getInstance();
FileSystem fs = this.fs.getFileSystemByPath(mapFile.getPath());
FileSKVIterator reader;
reader = fileFactory.newReaderBuilder().forFile(mapFile.getPathStr(), fs, fs.getConf(), context.getCryptoService()).withTableConfiguration(acuTableConf).withRateLimiter(env.getReadLimiter()).build();
readers.add(reader);
SortedKeyValueIterator<Key, Value> iter = new ProblemReportingIterator(context, extent.tableId(), mapFile.getPathStr(), false, reader);
if (filesToCompact.get(mapFile).isTimeSet()) {
iter = new TimeSettingIterator(iter, filesToCompact.get(mapFile).getTime());
}
iters.add(iter);
} catch (Exception e) {
ProblemReports.getInstance(context).report(new ProblemReport(extent.tableId(), ProblemType.FILE_READ, mapFile.getPathStr(), e));
log.warn("Some problem opening map file {} {}", mapFile, e.getMessage(), e);
// failed to open some map file... close the ones that were opened
for (FileSKVIterator reader : readers) {
try {
reader.close();
} catch (Exception e2) {
log.warn("Failed to close map file", e2);
}
}
readers.clear();
if (e instanceof IOException)
throw (IOException) e;
throw new IOException("Failed to open map data files", e);
}
}
return iters;
}
use of org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator in project accumulo by apache.
the class TimeSettingIteratorTest method testEndKeyRangeAtMinLongValue.
@Test
public void testEndKeyRangeAtMinLongValue() throws IOException {
Text row = new Text("a");
Text colf = new Text("b");
Text colq = new Text("c");
Text cv = new Text();
for (boolean inclusiveEndRange : new boolean[] { true, false }) {
TreeMap<Key, Value> sources = new TreeMap<>();
sources.put(new Key(row.getBytes(), colf.getBytes(), colq.getBytes(), cv.getBytes(), Long.MIN_VALUE, true), new Value("00"));
sources.put(new Key(row.getBytes(), colf.getBytes(), colq.getBytes(), cv.getBytes(), Long.MIN_VALUE), new Value("11"));
TimeSettingIterator it = new TimeSettingIterator(new SortedMapIterator(sources), 111L);
IteratorSetting is = new IteratorSetting(1, TimeSettingIterator.class);
it.init(null, is.getOptions(), null);
Key startKey = new Key();
Key endKey = new Key(row, colf, colq, cv, Long.MIN_VALUE);
Range testRange = new Range(startKey, false, endKey, inclusiveEndRange);
it.seek(testRange, new HashSet<>(), false);
assertTrue(it.hasTop());
assertEquals(it.getTopValue(), new Value("00"));
assertEquals(111L, it.getTopKey().getTimestamp());
it.next();
assertTrue(it.hasTop());
assertEquals(it.getTopValue(), new Value("11"));
assertEquals(111L, it.getTopKey().getTimestamp());
it.next();
assertFalse(it.hasTop());
}
}
use of org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator in project accumulo by apache.
the class TimeSettingIteratorTest method test1.
@Test
public void test1() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
tm1.put(new Key("r0", "cf1", "cq1", 9L), new Value("v0"));
tm1.put(new Key("r1", "cf1", "cq1", Long.MAX_VALUE), new Value("v1"));
tm1.put(new Key("r1", "cf1", "cq1", 90L), new Value("v2"));
tm1.put(new Key("r1", "cf1", "cq1", 0L), new Value("v3"));
tm1.put(new Key("r2", "cf1", "cq1", 6L), new Value("v4"));
TimeSettingIterator tsi = new TimeSettingIterator(new SortedMapIterator(tm1), 50);
tsi.seek(new Range(new Key("r1", "cf1", "cq1", 50L), true, new Key("r1", "cf1", "cq1", 50L), true), new HashSet<>(), false);
assertTrue(tsi.hasTop());
assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v1", tsi.getTopValue().toString());
tsi.next();
assertTrue(tsi.hasTop());
assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v2", tsi.getTopValue().toString());
tsi.next();
assertTrue(tsi.hasTop());
assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v3", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
tsi.seek(new Range(new Key("r1", "cf1", "cq1", 50L), false, null, true), new HashSet<>(), false);
assertTrue(tsi.hasTop());
assertEquals(new Key("r2", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v4", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
tsi.seek(new Range(null, true, new Key("r1", "cf1", "cq1", 50L), false), new HashSet<>(), false);
assertTrue(tsi.hasTop());
assertEquals(new Key("r0", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v0", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
tsi.seek(new Range(new Key("r1", "cf1", "cq1", 51L), true, new Key("r1", "cf1", "cq1", 50L), false), new HashSet<>(), false);
assertFalse(tsi.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator in project accumulo by apache.
the class TimeSettingIteratorTest method testAvoidKeyCopy.
@Test
public void testAvoidKeyCopy() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
final Key k = new Key("r0", "cf1", "cq1", 9L);
tm1.put(k, new Value("v0"));
TimeSettingIterator tsi = new TimeSettingIterator(new SortedMapIterator(tm1), 50);
tsi.seek(new Range(), new HashSet<>(), false);
assertTrue(tsi.hasTop());
final Key topKey = tsi.getTopKey();
assertSame(k, topKey, "Expected the topKey to be the same object");
assertEquals(new Key("r0", "cf1", "cq1", 50L), topKey);
assertEquals("v0", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
}
Aggregations