Search in sources :

Example 1 with MemoryIterator

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

the class InMemoryMapTest method test3.

@Test
public void test3() 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");
    mutate(imm, "r3", "foo:cq1", 3, "bar9");
    mutate(imm, "r3", "foo:cq1", 3, "bara");
    MemoryIterator ski2 = imm.skvIterator(null);
    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());
    ski2.seek(new Range(new Text("r3")), LocalityGroupUtil.EMPTY_CF_SET, false);
    testAndCallNext(ski2, "r3", "foo:cq1", 3, "bara");
    testAndCallNext(ski2, "r3", "foo:cq1", 3, "bar9");
    assertFalse(ski1.hasTop());
}
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 2 with MemoryIterator

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

the class InMemoryMapTest method test2.

@Test
public void test2() throws Exception {
    InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath());
    MemoryIterator ski1 = imm.skvIterator(null);
    mutate(imm, "r1", "foo:cq1", 3, "bar1");
    MemoryIterator ski2 = imm.skvIterator(null);
    ski1.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
    assertFalse(ski1.hasTop());
    ski2.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
    assertTrue(ski2.hasTop());
    testAndCallNext(ski2, "r1", "foo:cq1", 3, "bar1");
    assertFalse(ski2.hasTop());
}
Also used : MemoryIterator(org.apache.accumulo.tserver.InMemoryMap.MemoryIterator) Range(org.apache.accumulo.core.data.Range) Test(org.junit.Test)

Example 3 with MemoryIterator

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

the class InMemoryMapTest method testNoSampleConfig.

@Test(expected = SampleNotPresentException.class)
public void testNoSampleConfig() throws Exception {
    InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath());
    mutate(imm, "r", "cf:cq", 5, "b");
    SamplerConfigurationImpl sampleConfig2 = new SamplerConfigurationImpl(RowSampler.class.getName(), ImmutableMap.of("hasher", "murmur3_32", "modulus", "9"));
    MemoryIterator iter = imm.skvIterator(sampleConfig2);
    iter.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
}
Also used : RowSampler(org.apache.accumulo.core.client.sample.RowSampler) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) MemoryIterator(org.apache.accumulo.tserver.InMemoryMap.MemoryIterator) Range(org.apache.accumulo.core.data.Range) Test(org.junit.Test)

Example 4 with MemoryIterator

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

the class InMemoryMapTest method runInterruptSampleTest.

private void runInterruptSampleTest(boolean deepCopy, boolean delete, boolean dcAfterDelete) throws Exception {
    SamplerConfigurationImpl sampleConfig1 = new SamplerConfigurationImpl(RowSampler.class.getName(), ImmutableMap.of("hasher", "murmur3_32", "modulus", "2"));
    Sampler sampler = SamplerFactory.newSampler(sampleConfig1, DefaultConfiguration.getInstance());
    ConfigurationCopy config1 = newConfig(tempFolder.newFolder().getAbsolutePath());
    for (Entry<String, String> entry : sampleConfig1.toTablePropertiesMap().entrySet()) {
        config1.set(entry.getKey(), entry.getValue());
    }
    InMemoryMap imm = new InMemoryMap(config1);
    TreeMap<Key, Value> expectedSample = new TreeMap<>();
    TreeMap<Key, Value> expectedAll = new TreeMap<>();
    for (int r = 0; r < 1000; 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 miter = imm.skvIterator(sampleConfig1);
    AtomicBoolean iFlag = new AtomicBoolean(false);
    miter.setInterruptFlag(iFlag);
    SortedKeyValueIterator<Key, Value> iter = miter;
    if (delete && !dcAfterDelete) {
        imm.delete(0);
    }
    if (deepCopy) {
        iter = iter.deepCopy(new SampleIE(sampleConfig1));
    }
    if (delete && dcAfterDelete) {
        imm.delete(0);
    }
    assertEquals(expectedSample, readAll(iter));
    iFlag.set(true);
    try {
        readAll(iter);
        Assert.fail();
    } catch (IterationInterruptedException iie) {
    }
    miter.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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) IterationInterruptedException(org.apache.accumulo.core.iterators.IterationInterruptedException) Key(org.apache.accumulo.core.data.Key)

Example 5 with MemoryIterator

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

the class InMemoryMapTest method testDeferredSamplerCreation.

@Test
public void testDeferredSamplerCreation() throws Exception {
    SamplerConfigurationImpl sampleConfig1 = new SamplerConfigurationImpl(RowSampler.class.getName(), ImmutableMap.of("hasher", "murmur3_32", "modulus", "9"));
    ConfigurationCopy config1 = newConfig(tempFolder.newFolder().getAbsolutePath());
    for (Entry<String, String> entry : sampleConfig1.toTablePropertiesMap().entrySet()) {
        config1.set(entry.getKey(), entry.getValue());
    }
    InMemoryMap imm = new InMemoryMap(config1);
    // change sampler config after creating in mem map.
    SamplerConfigurationImpl sampleConfig2 = new SamplerConfigurationImpl(RowSampler.class.getName(), ImmutableMap.of("hasher", "murmur3_32", "modulus", "7"));
    for (Entry<String, String> entry : sampleConfig2.toTablePropertiesMap().entrySet()) {
        config1.set(entry.getKey(), entry.getValue());
    }
    TreeMap<Key, Value> expectedSample = new TreeMap<>();
    TreeMap<Key, Value> expectedAll = new TreeMap<>();
    Sampler sampler = SamplerFactory.newSampler(sampleConfig2, config1);
    for (int i = 0; i < 100; i++) {
        mutate(imm, "r" + i, "cf:cq", 5, "v" + i, sampler, expectedSample, expectedAll);
    }
    MemoryIterator iter = imm.skvIterator(sampleConfig2);
    iter.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
    Assert.assertEquals(expectedSample, readAll(iter));
    SortedKeyValueIterator<Key, Value> dc = iter.deepCopy(new SampleIE(sampleConfig2));
    dc.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
    Assert.assertEquals(expectedSample, readAll(dc));
    iter = imm.skvIterator(null);
    iter.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
    Assert.assertEquals(expectedAll, readAll(iter));
    iter = imm.skvIterator(sampleConfig1);
    thrown.expect(SampleNotPresentException.class);
    iter.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) TreeMap(java.util.TreeMap) Range(org.apache.accumulo.core.data.Range) 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)

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