Search in sources :

Example 11 with MemoryIterator

use of org.apache.accumulo.tserver.InMemoryMap.MemoryIterator in project accumulo by apache.

the class InMemoryMapTest method test4.

@Test
public void test4() throws Exception {
    InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath());
    mutate(imm, "r1", "foo:cq1", 3, "bar1");
    mutate(imm, "r1", "foo:cq1", 3, "bar2");
    MemoryIterator ski1 = imm.skvIterator(null);
    mutate(imm, "r1", "foo:cq1", 3, "bar3");
    imm.delete(0);
    ski1.seek(new Range(new Text("r1")), LocalityGroupUtil.EMPTY_CF_SET, false);
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar2");
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar1");
    assertFalse(ski1.hasTop());
    ski1.seek(new Range(new Text("r1")), LocalityGroupUtil.EMPTY_CF_SET, false);
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar2");
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar1");
    assertFalse(ski1.hasTop());
    ski1.seek(new Range(new Text("r2")), LocalityGroupUtil.EMPTY_CF_SET, false);
    assertFalse(ski1.hasTop());
    ski1.seek(new Range(newKey("r1", "foo:cq1", 3), null), LocalityGroupUtil.EMPTY_CF_SET, false);
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar2");
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar1");
    assertFalse(ski1.hasTop());
    ski1.close();
}
Also used : MemoryIterator(org.apache.accumulo.tserver.InMemoryMap.MemoryIterator) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Test(org.junit.Test)

Example 12 with MemoryIterator

use of org.apache.accumulo.tserver.InMemoryMap.MemoryIterator in project accumulo by apache.

the class InMemoryMapTest method test5.

@Test
public void test5() throws Exception {
    InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath());
    mutate(imm, "r1", "foo:cq1", 3, "bar1");
    mutate(imm, "r1", "foo:cq1", 3, "bar2");
    mutate(imm, "r1", "foo:cq1", 3, "bar3");
    MemoryIterator ski1 = imm.skvIterator(null);
    ski1.seek(new Range(new Text("r1")), LocalityGroupUtil.EMPTY_CF_SET, false);
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar3");
    imm.delete(0);
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar2");
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar1");
    assertFalse(ski1.hasTop());
    ski1.close();
    imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath());
    mutate(imm, "r1", "foo:cq1", 3, "bar1");
    mutate(imm, "r1", "foo:cq2", 3, "bar2");
    mutate(imm, "r1", "foo:cq3", 3, "bar3");
    ski1 = imm.skvIterator(null);
    ski1.seek(new Range(new Text("r1")), LocalityGroupUtil.EMPTY_CF_SET, false);
    testAndCallNext(ski1, "r1", "foo:cq1", 3, "bar1");
    imm.delete(0);
    testAndCallNext(ski1, "r1", "foo:cq2", 3, "bar2");
    testAndCallNext(ski1, "r1", "foo:cq3", 3, "bar3");
    assertFalse(ski1.hasTop());
    ski1.close();
}
Also used : MemoryIterator(org.apache.accumulo.tserver.InMemoryMap.MemoryIterator) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Test(org.junit.Test)

Example 13 with MemoryIterator

use of org.apache.accumulo.tserver.InMemoryMap.MemoryIterator in project accumulo by apache.

the class InMemoryMapTest method testSample.

@Test
public void testSample() throws Exception {
    SamplerConfigurationImpl sampleConfig = new SamplerConfigurationImpl(RowSampler.class.getName(), ImmutableMap.of("hasher", "murmur3_32", "modulus", "7"));
    Sampler sampler = SamplerFactory.newSampler(sampleConfig, DefaultConfiguration.getInstance());
    ConfigurationCopy config1 = newConfig(tempFolder.newFolder().getAbsolutePath());
    for (Entry<String, String> entry : sampleConfig.toTablePropertiesMap().entrySet()) {
        config1.set(entry.getKey(), entry.getValue());
    }
    ConfigurationCopy config2 = newConfig(tempFolder.newFolder().getAbsolutePath());
    config2.set(Property.TABLE_LOCALITY_GROUP_PREFIX + "lg1", LocalityGroupUtil.encodeColumnFamilies(toTextSet("cf2")));
    config2.set(Property.TABLE_LOCALITY_GROUPS.getKey(), "lg1");
    for (Entry<String, String> entry : sampleConfig.toTablePropertiesMap().entrySet()) {
        config2.set(entry.getKey(), entry.getValue());
    }
    for (ConfigurationCopy config : Arrays.asList(config1, config2)) {
        InMemoryMap imm = new InMemoryMap(config);
        TreeMap<Key, Value> expectedSample = new TreeMap<>();
        TreeMap<Key, Value> expectedAll = new TreeMap<>();
        TreeMap<Key, Value> expectedNone = new TreeMap<>();
        MemoryIterator iter0 = imm.skvIterator(sampleConfig);
        for (int r = 0; r < 100; r++) {
            String row = String.format("r%06d", r);
            mutate(imm, row, "cf1:cq1", 5, "v" + (2 * r), sampler, expectedSample, expectedAll);
            mutate(imm, row, "cf2:cq2", 5, "v" + ((2 * r) + 1), sampler, expectedSample, expectedAll);
        }
        assertTrue(expectedSample.size() > 0);
        MemoryIterator iter1 = imm.skvIterator(sampleConfig);
        MemoryIterator iter2 = imm.skvIterator(null);
        SortedKeyValueIterator<Key, Value> iter0dc1 = iter0.deepCopy(new SampleIE());
        SortedKeyValueIterator<Key, Value> iter0dc2 = iter0.deepCopy(new SampleIE(sampleConfig));
        SortedKeyValueIterator<Key, Value> iter1dc1 = iter1.deepCopy(new SampleIE());
        SortedKeyValueIterator<Key, Value> iter1dc2 = iter1.deepCopy(new SampleIE(sampleConfig));
        SortedKeyValueIterator<Key, Value> iter2dc1 = iter2.deepCopy(new SampleIE());
        SortedKeyValueIterator<Key, Value> iter2dc2 = iter2.deepCopy(new SampleIE(sampleConfig));
        assertEquals(expectedNone, readAll(iter0));
        assertEquals(expectedNone, readAll(iter0dc1));
        assertEquals(expectedNone, readAll(iter0dc2));
        assertEquals(expectedSample, readAll(iter1));
        assertEquals(expectedAll, readAll(iter2));
        assertEquals(expectedAll, readAll(iter1dc1));
        assertEquals(expectedAll, readAll(iter2dc1));
        assertEquals(expectedSample, readAll(iter1dc2));
        assertEquals(expectedSample, readAll(iter2dc2));
        imm.delete(0);
        assertEquals(expectedNone, readAll(iter0));
        assertEquals(expectedNone, readAll(iter0dc1));
        assertEquals(expectedNone, readAll(iter0dc2));
        assertEquals(expectedSample, readAll(iter1));
        assertEquals(expectedAll, readAll(iter2));
        assertEquals(expectedAll, readAll(iter1dc1));
        assertEquals(expectedAll, readAll(iter2dc1));
        assertEquals(expectedSample, readAll(iter1dc2));
        assertEquals(expectedSample, readAll(iter2dc2));
        SortedKeyValueIterator<Key, Value> iter0dc3 = iter0.deepCopy(new SampleIE());
        SortedKeyValueIterator<Key, Value> iter0dc4 = iter0.deepCopy(new SampleIE(sampleConfig));
        SortedKeyValueIterator<Key, Value> iter1dc3 = iter1.deepCopy(new SampleIE());
        SortedKeyValueIterator<Key, Value> iter1dc4 = iter1.deepCopy(new SampleIE(sampleConfig));
        SortedKeyValueIterator<Key, Value> iter2dc3 = iter2.deepCopy(new SampleIE());
        SortedKeyValueIterator<Key, Value> iter2dc4 = iter2.deepCopy(new SampleIE(sampleConfig));
        assertEquals(expectedNone, readAll(iter0dc3));
        assertEquals(expectedNone, readAll(iter0dc4));
        assertEquals(expectedAll, readAll(iter1dc3));
        assertEquals(expectedAll, readAll(iter2dc3));
        assertEquals(expectedSample, readAll(iter1dc4));
        assertEquals(expectedSample, readAll(iter2dc4));
        iter1.close();
        iter2.close();
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) TreeMap(java.util.TreeMap) RowSampler(org.apache.accumulo.core.client.sample.RowSampler) Sampler(org.apache.accumulo.core.client.sample.Sampler) RowSampler(org.apache.accumulo.core.client.sample.RowSampler) Value(org.apache.accumulo.core.data.Value) MemoryIterator(org.apache.accumulo.tserver.InMemoryMap.MemoryIterator) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 14 with MemoryIterator

use of org.apache.accumulo.tserver.InMemoryMap.MemoryIterator in project accumulo by apache.

the class InMemoryMapTest method testBug1.

@Test
public void testBug1() throws Exception {
    InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath());
    for (int i = 0; i < 20; i++) {
        mutate(imm, "r1", "foo:cq" + i, 3, "bar" + i);
    }
    for (int i = 0; i < 20; i++) {
        mutate(imm, "r2", "foo:cq" + i, 3, "bar" + i);
    }
    MemoryIterator ski1 = imm.skvIterator(null);
    ColumnFamilySkippingIterator cfsi = new ColumnFamilySkippingIterator(ski1);
    imm.delete(0);
    ArrayList<ByteSequence> columns = new ArrayList<>();
    columns.add(new ArrayByteSequence("bar"));
    // this seek resulted in an infinite loop before a bug was fixed
    cfsi.seek(new Range("r1"), columns, true);
    assertFalse(cfsi.hasTop());
    ski1.close();
}
Also used : ColumnFamilySkippingIterator(org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator) MemoryIterator(org.apache.accumulo.tserver.InMemoryMap.MemoryIterator) ArrayList(java.util.ArrayList) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Range(org.apache.accumulo.core.data.Range) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Test(org.junit.Test)

Example 15 with MemoryIterator

use of org.apache.accumulo.tserver.InMemoryMap.MemoryIterator in project accumulo by apache.

the class InMemoryMapTest method testLocalityGroups.

@Test
public void testLocalityGroups() throws Exception {
    ConfigurationCopy config = newConfig(tempFolder.newFolder().getAbsolutePath());
    config.set(Property.TABLE_LOCALITY_GROUP_PREFIX + "lg1", LocalityGroupUtil.encodeColumnFamilies(toTextSet("cf1", "cf2")));
    config.set(Property.TABLE_LOCALITY_GROUP_PREFIX + "lg2", LocalityGroupUtil.encodeColumnFamilies(toTextSet("cf3", "cf4")));
    config.set(Property.TABLE_LOCALITY_GROUPS.getKey(), "lg1,lg2");
    InMemoryMap imm = new InMemoryMap(config);
    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "x", 2, "1");
    m1.put("cf1", "y", 2, "2");
    m1.put("cf3", "z", 2, "3");
    m1.put("foo", "b", 2, "9");
    Mutation m2 = new Mutation("r2");
    m2.put("cf2", "x", 3, "5");
    Mutation m3 = new Mutation("r3");
    m3.put("foo", "b", 4, "6");
    Mutation m4 = new Mutation("r4");
    m4.put("foo", "b", 5, "7");
    m4.put("cf4", "z", 5, "8");
    Mutation m5 = new Mutation("r5");
    m5.put("cf3", "z", 6, "A");
    m5.put("cf4", "z", 6, "B");
    imm.mutate(Arrays.asList(m1, m2, m3, m4, m5));
    MemoryIterator iter1 = imm.skvIterator(null);
    seekLocalityGroups(iter1);
    SortedKeyValueIterator<Key, Value> dc1 = iter1.deepCopy(new SampleIE());
    seekLocalityGroups(dc1);
    assertTrue(imm.getNumEntries() == 10);
    assertTrue(imm.estimatedSizeInBytes() > 0);
    imm.delete(0);
    seekLocalityGroups(iter1);
    seekLocalityGroups(dc1);
// TODO uncomment following when ACCUMULO-1628 is fixed
// seekLocalityGroups(iter1.deepCopy(null));
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) MemoryIterator(org.apache.accumulo.tserver.InMemoryMap.MemoryIterator) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

MemoryIterator (org.apache.accumulo.tserver.InMemoryMap.MemoryIterator)17 Test (org.junit.Test)15 Range (org.apache.accumulo.core.data.Range)14 Value (org.apache.accumulo.core.data.Value)7 RowSampler (org.apache.accumulo.core.client.sample.RowSampler)6 Key (org.apache.accumulo.core.data.Key)6 SamplerConfigurationImpl (org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl)6 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)5 Text (org.apache.hadoop.io.Text)5 TreeMap (java.util.TreeMap)3 Sampler (org.apache.accumulo.core.client.sample.Sampler)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Mutation (org.apache.accumulo.core.data.Mutation)2 ArrayList (java.util.ArrayList)1 ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)1 ByteSequence (org.apache.accumulo.core.data.ByteSequence)1 IterationInterruptedException (org.apache.accumulo.core.iterators.IterationInterruptedException)1 ColumnFamilySkippingIterator (org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator)1