use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.
the class ConditionCheckerContext method checkConditions.
boolean checkConditions(SortedKeyValueIterator<Key, Value> systemIter, ServerConditionalMutation scm) throws IOException {
boolean add = true;
for (TCondition tc : scm.getConditions()) {
Range range;
if (tc.hasTimestamp)
range = Range.exact(new Text(scm.getRow()), new Text(tc.getCf()), new Text(tc.getCq()), new Text(tc.getCv()), tc.getTs());
else
range = Range.exact(new Text(scm.getRow()), new Text(tc.getCf()), new Text(tc.getCq()), new Text(tc.getCv()));
SortedKeyValueIterator<Key, Value> iter = buildIterator(systemIter, tc);
ByteSequence cf = new ArrayByteSequence(tc.getCf());
iter.seek(range, Collections.singleton(cf), true);
Value val = null;
if (iter.hasTop()) {
val = iter.getTopValue();
}
if ((val == null ^ tc.getVal() == null) || (val != null && !Arrays.equals(tc.getVal(), val.get()))) {
add = false;
break;
}
}
return add;
}
use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.
the class ConditionalWriterIT method testThreads.
@Test
public void testThreads() throws Exception {
// test multiple threads using a single conditional writer
String tableName = getUniqueNames(1)[0];
Connector conn = getConnector();
conn.tableOperations().create(tableName);
Random rand = new Random();
switch(rand.nextInt(3)) {
case 1:
conn.tableOperations().addSplits(tableName, nss("4"));
break;
case 2:
conn.tableOperations().addSplits(tableName, nss("3", "5"));
break;
}
try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig())) {
ArrayList<ByteSequence> rows = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
rows.add(new ArrayByteSequence(FastFormat.toZeroPaddedString(abs(rand.nextLong()), 16, 16, new byte[0])));
}
ArrayList<ConditionalMutation> mutations = new ArrayList<>();
for (ByteSequence row : rows) mutations.add(new Stats(row).toMutation());
ArrayList<ByteSequence> rows2 = new ArrayList<>();
Iterator<Result> results = cw.write(mutations.iterator());
while (results.hasNext()) {
Result result = results.next();
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
rows2.add(new ArrayByteSequence(result.getMutation().getRow()));
}
Collections.sort(rows);
Collections.sort(rows2);
Assert.assertEquals(rows, rows2);
AtomicBoolean failed = new AtomicBoolean(false);
ExecutorService tp = Executors.newFixedThreadPool(5);
for (int i = 0; i < 5; i++) {
tp.submit(new MutatorTask(tableName, conn, rows, cw, failed));
}
tp.shutdown();
while (!tp.isTerminated()) {
tp.awaitTermination(1, TimeUnit.MINUTES);
}
Assert.assertFalse("A MutatorTask failed with an exception", failed.get());
}
try (Scanner scanner = conn.createScanner(tableName, Authorizations.EMPTY)) {
RowIterator rowIter = new RowIterator(scanner);
while (rowIter.hasNext()) {
Iterator<Entry<Key, Value>> row = rowIter.next();
new Stats(row);
}
}
}
use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.
the class KeyShortener method shorten.
/*
* return S such that prev < S < current or null if no such sequence
*/
public static ByteSequence shorten(ByteSequence prev, ByteSequence current) {
int minLen = Math.min(prev.length(), current.length());
for (int i = 0; i < minLen; i++) {
int pb = 0xff & prev.byteAt(i);
int cb = 0xff & current.byteAt(i);
int diff = cb - pb;
if (diff == 1) {
int newLen = findNonFF(prev, i + 1);
byte[] successor;
if (newLen < prev.length()) {
successor = Bytes.concat(prev.subSequence(0, newLen).toArray(), BFF);
} else {
successor = Bytes.concat(prev.subSequence(0, newLen).toArray(), B00);
}
return new ArrayByteSequence(successor);
} else if (diff > 1) {
byte[] copy = new byte[i + 1];
System.arraycopy(prev.subSequence(0, i + 1).toArray(), 0, copy, 0, i + 1);
copy[i] = (byte) ((0xff & copy[i]) + 1);
return new ArrayByteSequence(copy);
}
}
ArrayByteSequence successor = new ArrayByteSequence(Bytes.concat(prev.toArray(), B00));
if (successor.equals(current)) {
return null;
}
return successor;
}
use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.
the class Authorizations method setAuthorizations.
private void setAuthorizations(String... authorizations) {
checkArgument(authorizations != null, "authorizations is null");
auths.clear();
for (String str : authorizations) {
str = str.trim();
auths.add(new ArrayByteSequence(str.getBytes(UTF_8)));
}
checkAuths();
}
use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.
the class ClientSideIteratorScanner method iterator.
@Override
public Iterator<Entry<Key, Value>> iterator() {
smi.scanner.setBatchSize(size);
smi.scanner.setTimeout(timeOut, TimeUnit.MILLISECONDS);
smi.scanner.setBatchTimeout(batchTimeOut, TimeUnit.MILLISECONDS);
smi.scanner.setReadaheadThreshold(readaheadThreshold);
if (isolated)
smi.scanner.enableIsolation();
else
smi.scanner.disableIsolation();
smi.samplerConfig = getSamplerConfiguration();
final TreeMap<Integer, IterInfo> tm = new TreeMap<>();
for (IterInfo iterInfo : serverSideIteratorList) {
tm.put(iterInfo.getPriority(), iterInfo);
}
SortedKeyValueIterator<Key, Value> skvi;
try {
skvi = IteratorUtil.loadIterators(smi, tm.values(), serverSideIteratorOptions, new ClientSideIteratorEnvironment(getSamplerConfiguration() != null, getIteratorSamplerConfigurationInternal()), false, null);
} catch (IOException e) {
throw new RuntimeException(e);
}
final Set<ByteSequence> colfs = new TreeSet<>();
for (Column c : this.getFetchedColumns()) {
colfs.add(new ArrayByteSequence(c.getColumnFamily()));
}
try {
skvi.seek(range, colfs, true);
} catch (IOException e) {
throw new RuntimeException(e);
}
return new IteratorAdapter(skvi);
}
Aggregations