Search in sources :

Example 1 with TimeSettingIterator

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;
}
Also used : FileSKVIterator(org.apache.accumulo.core.file.FileSKVIterator) ArrayList(java.util.ArrayList) FileOperations(org.apache.accumulo.core.file.FileOperations) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) TimeSettingIterator(org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator) IOException(java.io.IOException) IOException(java.io.IOException) ProblemReport(org.apache.accumulo.server.problems.ProblemReport) FileSystem(org.apache.hadoop.fs.FileSystem) ProblemReportingIterator(org.apache.accumulo.server.problems.ProblemReportingIterator) Value(org.apache.accumulo.core.data.Value) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TabletFile(org.apache.accumulo.core.metadata.TabletFile) Key(org.apache.accumulo.core.data.Key)

Example 2 with TimeSettingIterator

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());
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) TimeSettingIterator(org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 3 with TimeSettingIterator

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());
}
Also used : Value(org.apache.accumulo.core.data.Value) TimeSettingIterator(org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 4 with TimeSettingIterator

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());
}
Also used : Value(org.apache.accumulo.core.data.Value) TimeSettingIterator(org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Aggregations

Key (org.apache.accumulo.core.data.Key)4 Value (org.apache.accumulo.core.data.Value)4 TimeSettingIterator (org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator)4 TreeMap (java.util.TreeMap)3 Range (org.apache.accumulo.core.data.Range)3 SortedMapIterator (org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator)3 Test (org.junit.jupiter.api.Test)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 FileOperations (org.apache.accumulo.core.file.FileOperations)1 FileSKVIterator (org.apache.accumulo.core.file.FileSKVIterator)1 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)1 StoredTabletFile (org.apache.accumulo.core.metadata.StoredTabletFile)1 TabletFile (org.apache.accumulo.core.metadata.TabletFile)1 DataFileValue (org.apache.accumulo.core.metadata.schema.DataFileValue)1 ProblemReport (org.apache.accumulo.server.problems.ProblemReport)1 ProblemReportingIterator (org.apache.accumulo.server.problems.ProblemReportingIterator)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Text (org.apache.hadoop.io.Text)1