Search in sources :

Example 21 with ArrayByteSequence

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;
}
Also used : TCondition(org.apache.accumulo.core.data.thrift.TCondition) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence)

Example 22 with ArrayByteSequence

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);
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) ArrayList(java.util.ArrayList) AlphaNumKeyConstraint(org.apache.accumulo.test.constraints.AlphaNumKeyConstraint) Result(org.apache.accumulo.core.client.ConditionalWriter.Result) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) Entry(java.util.Map.Entry) Random(java.util.Random) RowIterator(org.apache.accumulo.core.client.RowIterator) ExecutorService(java.util.concurrent.ExecutorService) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Test(org.junit.Test)

Example 23 with ArrayByteSequence

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;
}
Also used : ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence)

Example 24 with ArrayByteSequence

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();
}
Also used : ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence)

Example 25 with ArrayByteSequence

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);
}
Also used : IteratorAdapter(org.apache.accumulo.core.iterators.IteratorAdapter) IOException(java.io.IOException) TreeMap(java.util.TreeMap) IterInfo(org.apache.accumulo.core.data.thrift.IterInfo) Column(org.apache.accumulo.core.data.Column) TreeSet(java.util.TreeSet) Value(org.apache.accumulo.core.data.Value) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence)

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