Search in sources :

Example 16 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class LocalityGroupUtilTest method testColumnFamilySet.

@Test
public void testColumnFamilySet() {
    ConfigurationCopy conf = new ConfigurationCopy();
    conf.set("table.group.lg1", "cf1,cf2");
    conf.set("table.groups.enabled", "lg1");
    try {
        Map<String, Set<ByteSequence>> groups = LocalityGroupUtil.getLocalityGroups(conf);
        assertEquals(1, groups.size());
        assertNotNull(groups.get("lg1"));
        assertEquals(2, groups.get("lg1").size());
        assertTrue(groups.get("lg1").contains(new ArrayByteSequence("cf1")));
    } catch (LocalityGroupConfigurationError err) {
        fail();
    }
    try {
        conf.set("table.group.lg2", "cf1");
        conf.set("table.groups.enabled", "lg1,lg2");
        LocalityGroupUtil.getLocalityGroups(conf);
        fail();
    } catch (LocalityGroupConfigurationError err) {
    // expected, ignore
    }
}
Also used : LocalityGroupConfigurationError(org.apache.accumulo.core.util.LocalityGroupUtil.LocalityGroupConfigurationError) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) Set(java.util.Set) HashSet(java.util.HashSet) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Test(org.junit.Test)

Example 17 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class LocalityGroupUtilTest method testEncoding.

@Test
public void testEncoding() throws Exception {
    byte[] test1 = new byte[256];
    byte[] test2 = new byte[256];
    for (int i = 0; i < 256; i++) {
        test1[i] = (byte) (0xff & i);
        test2[i] = (byte) (0xff & (255 - i));
    }
    ArrayByteSequence bs1 = new ArrayByteSequence(test1);
    String ecf = LocalityGroupUtil.encodeColumnFamily(bs1);
    // System.out.println(ecf);
    ByteSequence bs2 = LocalityGroupUtil.decodeColumnFamily(ecf);
    assertEquals(bs1, bs2);
    assertEquals(ecf, LocalityGroupUtil.encodeColumnFamily(bs2));
    // test encoding multiple column fams containing binary data
    HashSet<Text> in = new HashSet<>();
    HashSet<ByteSequence> in2 = new HashSet<>();
    in.add(new Text(test1));
    in2.add(new ArrayByteSequence(test1));
    in.add(new Text(test2));
    in2.add(new ArrayByteSequence(test2));
    Set<ByteSequence> out = LocalityGroupUtil.decodeColumnFamilies(LocalityGroupUtil.encodeColumnFamilies(in));
    assertEquals(in2, out);
}
Also used : Text(org.apache.hadoop.io.Text) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence 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 19 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class RFileWriter method startNewLocalityGroup.

/**
 * See javadoc for {@link #startNewLocalityGroup(String, List)}.
 *
 * @param families
 *          will be encoded using UTF-8
 *
 * @throws IllegalStateException
 *           When default locality group already started.
 */
public void startNewLocalityGroup(String name, Set<String> families) throws IOException {
    HashSet<ByteSequence> fams = new HashSet<>();
    for (String family : families) {
        fams.add(new ArrayByteSequence(family));
    }
    _startNewLocalityGroup(name, fams);
}
Also used : ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Example 20 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class RowLocks method acquireRowlocks.

List<RowLock> acquireRowlocks(Map<KeyExtent, List<ServerConditionalMutation>> updates, Map<KeyExtent, List<ServerConditionalMutation>> deferred) {
    ArrayList<RowLock> locks = new ArrayList<>();
    // assume that mutations are in sorted order to avoid deadlock
    synchronized (rowLocks) {
        for (List<ServerConditionalMutation> scml : updates.values()) {
            for (ServerConditionalMutation scm : scml) {
                locks.add(getRowLock(new ArrayByteSequence(scm.getRow())));
            }
        }
    }
    HashSet<ByteSequence> rowsNotLocked = null;
    // acquire as many locks as possible, not blocking on rows that are already locked
    if (locks.size() > 1) {
        for (RowLock rowLock : locks) {
            if (!rowLock.tryLock()) {
                if (rowsNotLocked == null)
                    rowsNotLocked = new HashSet<>();
                rowsNotLocked.add(rowLock.rowSeq);
            }
        }
    } else {
        // if there is only one lock, then wait for it
        locks.get(0).lock();
    }
    if (rowsNotLocked != null) {
        final HashSet<ByteSequence> rnlf = rowsNotLocked;
        // assume will get locks needed, do something expensive otherwise
        ConditionalMutationSet.defer(updates, deferred, new DeferFilter() {

            @Override
            public void defer(List<ServerConditionalMutation> scml, List<ServerConditionalMutation> okMutations, List<ServerConditionalMutation> deferred) {
                for (ServerConditionalMutation scm : scml) {
                    if (rnlf.contains(new ArrayByteSequence(scm.getRow())))
                        deferred.add(scm);
                    else
                        okMutations.add(scm);
                }
            }
        });
        ArrayList<RowLock> filteredLocks = new ArrayList<>();
        ArrayList<RowLock> locksToReturn = new ArrayList<>();
        for (RowLock rowLock : locks) {
            if (rowsNotLocked.contains(rowLock.rowSeq)) {
                locksToReturn.add(rowLock);
            } else {
                filteredLocks.add(rowLock);
            }
        }
        synchronized (rowLocks) {
            for (RowLock rowLock : locksToReturn) {
                returnRowLock(rowLock);
            }
        }
        locks = filteredLocks;
    }
    return locks;
}
Also used : DeferFilter(org.apache.accumulo.tserver.ConditionalMutationSet.DeferFilter) ServerConditionalMutation(org.apache.accumulo.tserver.data.ServerConditionalMutation) ArrayList(java.util.ArrayList) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Aggregations

ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)39 ByteSequence (org.apache.accumulo.core.data.ByteSequence)26 HashSet (java.util.HashSet)20 Test (org.junit.Test)18 Key (org.apache.accumulo.core.data.Key)10 Value (org.apache.accumulo.core.data.Value)9 Range (org.apache.accumulo.core.data.Range)8 ArrayList (java.util.ArrayList)7 TreeMap (java.util.TreeMap)6 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)5 Text (org.apache.hadoop.io.Text)5 HashMap (java.util.HashMap)4 ColumnFamilySkippingIterator (org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Scanner (org.apache.accumulo.core.client.Scanner)2 Mutation (org.apache.accumulo.core.data.Mutation)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 IterInfo (org.apache.accumulo.core.data.thrift.IterInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1