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
}
}
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);
}
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();
}
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);
}
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;
}
Aggregations