Search in sources :

Example 1 with TimedOutException

use of org.apache.accumulo.core.client.TimedOutException in project accumulo by apache.

the class TimeoutIT method testBatchWriterTimeout.

public void testBatchWriterTimeout(Connector conn, String tableName) throws Exception {
    conn.tableOperations().create(tableName);
    conn.tableOperations().addConstraint(tableName, SlowConstraint.class.getName());
    // give constraint time to propagate through zookeeper
    sleepUninterruptibly(1, TimeUnit.SECONDS);
    BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig().setTimeout(3, TimeUnit.SECONDS));
    Mutation mut = new Mutation("r1");
    mut.put("cf1", "cq1", "v1");
    bw.addMutation(mut);
    try {
        bw.close();
        fail("batch writer did not timeout");
    } catch (MutationsRejectedException mre) {
        if (mre.getCause() instanceof TimedOutException)
            return;
        throw mre;
    }
}
Also used : TimedOutException(org.apache.accumulo.core.client.TimedOutException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 2 with TimedOutException

use of org.apache.accumulo.core.client.TimedOutException in project accumulo by apache.

the class TimeoutIT method testBatchScannerTimeout.

public void testBatchScannerTimeout(Connector conn, String tableName) throws Exception {
    getConnector().tableOperations().create(tableName);
    BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
    Mutation m = new Mutation("r1");
    m.put("cf1", "cq1", "v1");
    m.put("cf1", "cq2", "v2");
    m.put("cf1", "cq3", "v3");
    m.put("cf1", "cq4", "v4");
    bw.addMutation(m);
    bw.close();
    try (BatchScanner bs = getConnector().createBatchScanner(tableName, Authorizations.EMPTY, 2)) {
        bs.setRanges(Collections.singletonList(new Range()));
        // should not timeout
        for (Entry<Key, Value> entry : bs) {
            entry.getKey();
        }
        bs.setTimeout(5, TimeUnit.SECONDS);
        IteratorSetting iterSetting = new IteratorSetting(100, SlowIterator.class);
        iterSetting.addOption("sleepTime", 2000 + "");
        bs.addScanIterator(iterSetting);
        try {
            for (Entry<Key, Value> entry : bs) {
                entry.getKey();
            }
            fail("batch scanner did not time out");
        } catch (TimedOutException toe) {
        // toe.printStackTrace();
        }
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TimedOutException(org.apache.accumulo.core.client.TimedOutException) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 3 with TimedOutException

use of org.apache.accumulo.core.client.TimedOutException in project accumulo by apache.

the class TabletServerBatchReaderIterator method doLookups.

private void doLookups(Map<String, Map<KeyExtent, List<Range>>> binnedRanges, final ResultReceiver receiver, List<Column> columns) {
    if (timedoutServers.containsAll(binnedRanges.keySet())) {
        // all servers have timed out
        throw new TimedOutException(timedoutServers);
    }
    // when there are lots of threads and a few tablet servers
    // it is good to break request to tablet servers up, the
    // following code determines if this is the case
    int maxTabletsPerRequest = Integer.MAX_VALUE;
    if (numThreads / binnedRanges.size() > 1) {
        int totalNumberOfTablets = 0;
        for (Entry<String, Map<KeyExtent, List<Range>>> entry : binnedRanges.entrySet()) {
            totalNumberOfTablets += entry.getValue().size();
        }
        maxTabletsPerRequest = totalNumberOfTablets / numThreads;
        if (maxTabletsPerRequest == 0) {
            maxTabletsPerRequest = 1;
        }
    }
    Map<KeyExtent, List<Range>> failures = new HashMap<>();
    if (timedoutServers.size() > 0) {
        // go ahead and fail any timed out servers
        for (Iterator<Entry<String, Map<KeyExtent, List<Range>>>> iterator = binnedRanges.entrySet().iterator(); iterator.hasNext(); ) {
            Entry<String, Map<KeyExtent, List<Range>>> entry = iterator.next();
            if (timedoutServers.contains(entry.getKey())) {
                failures.putAll(entry.getValue());
                iterator.remove();
            }
        }
    }
    // randomize tabletserver order... this will help when there are multiple
    // batch readers and writers running against accumulo
    List<String> locations = new ArrayList<>(binnedRanges.keySet());
    Collections.shuffle(locations);
    List<QueryTask> queryTasks = new ArrayList<>();
    for (final String tsLocation : locations) {
        final Map<KeyExtent, List<Range>> tabletsRanges = binnedRanges.get(tsLocation);
        if (maxTabletsPerRequest == Integer.MAX_VALUE || tabletsRanges.size() == 1) {
            QueryTask queryTask = new QueryTask(tsLocation, tabletsRanges, failures, receiver, columns);
            queryTasks.add(queryTask);
        } else {
            HashMap<KeyExtent, List<Range>> tabletSubset = new HashMap<>();
            for (Entry<KeyExtent, List<Range>> entry : tabletsRanges.entrySet()) {
                tabletSubset.put(entry.getKey(), entry.getValue());
                if (tabletSubset.size() >= maxTabletsPerRequest) {
                    QueryTask queryTask = new QueryTask(tsLocation, tabletSubset, failures, receiver, columns);
                    queryTasks.add(queryTask);
                    tabletSubset = new HashMap<>();
                }
            }
            if (tabletSubset.size() > 0) {
                QueryTask queryTask = new QueryTask(tsLocation, tabletSubset, failures, receiver, columns);
                queryTasks.add(queryTask);
            }
        }
    }
    final Semaphore semaphore = new Semaphore(queryTasks.size());
    semaphore.acquireUninterruptibly(queryTasks.size());
    for (QueryTask queryTask : queryTasks) {
        queryTask.setSemaphore(semaphore, queryTasks.size());
        queryThreadPool.execute(new TraceRunnable(queryTask));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) TRange(org.apache.accumulo.core.data.thrift.TRange) Range(org.apache.accumulo.core.data.Range) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TraceRunnable(org.apache.htrace.wrappers.TraceRunnable) Entry(java.util.Map.Entry) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) TimedOutException(org.apache.accumulo.core.client.TimedOutException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with TimedOutException

use of org.apache.accumulo.core.client.TimedOutException in project accumulo by apache.

the class ConditionalWriterImpl method queueRetry.

private void queueRetry(List<QCMutation> mutations, HostAndPort server) {
    if (timeout < Long.MAX_VALUE) {
        long time = System.currentTimeMillis();
        ArrayList<QCMutation> mutations2 = new ArrayList<>(mutations.size());
        for (QCMutation qcm : mutations) {
            qcm.resetDelay();
            if (time + qcm.getDelay(TimeUnit.MILLISECONDS) > qcm.entryTime + timeout) {
                TimedOutException toe;
                if (server != null)
                    toe = new TimedOutException(Collections.singleton(server.toString()));
                else
                    toe = new TimedOutException("Conditional mutation timed out");
                qcm.queueResult(new Result(toe, qcm, (null == server ? null : server.toString())));
            } else {
                mutations2.add(qcm);
            }
        }
        if (mutations2.size() > 0)
            failedMutations.addAll(mutations2);
    } else {
        for (QCMutation qcm : mutations) qcm.resetDelay();
        failedMutations.addAll(mutations);
    }
}
Also used : TimedOutException(org.apache.accumulo.core.client.TimedOutException) ArrayList(java.util.ArrayList) TCMResult(org.apache.accumulo.core.data.thrift.TCMResult)

Example 5 with TimedOutException

use of org.apache.accumulo.core.client.TimedOutException in project accumulo by apache.

the class ConditionalWriterImpl method invalidateSession.

/**
 * The purpose of this code is to ensure that a conditional mutation will not execute when its status is unknown. This allows a user to read the row when the
 * status is unknown and not have to worry about the tserver applying the mutation after the scan.
 *
 * <p>
 * If a conditional mutation is taking a long time to process, then this method will wait for it to finish... unless this exceeds timeout.
 */
private void invalidateSession(SessionID sessionId, HostAndPort location) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    long sleepTime = 50;
    long startTime = System.currentTimeMillis();
    Instance instance = context.getInstance();
    LockID lid = new LockID(ZooUtil.getRoot(instance) + Constants.ZTSERVERS, sessionId.lockId);
    ZooCacheFactory zcf = new ZooCacheFactory();
    while (true) {
        if (!ZooLock.isLockHeld(zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()), lid)) {
            // ACCUMULO-1152 added a tserver lock check to the tablet location cache, so this invalidation prevents future attempts to contact the
            // tserver even its gone zombie and is still running w/o a lock
            locator.invalidateCache(context.getInstance(), location.toString());
            return;
        }
        try {
            // if the mutation is currently processing, this method will block until its done or times out
            invalidateSession(sessionId.sessionID, location);
            return;
        } catch (TApplicationException tae) {
            throw new AccumuloServerException(location.toString(), tae);
        } catch (TException e) {
            locator.invalidateCache(context.getInstance(), location.toString());
        }
        if ((System.currentTimeMillis() - startTime) + sleepTime > timeout)
            throw new TimedOutException(Collections.singleton(location.toString()));
        sleepUninterruptibly(sleepTime, TimeUnit.MILLISECONDS);
        sleepTime = Math.min(2 * sleepTime, MAX_SLEEP);
    }
}
Also used : TException(org.apache.thrift.TException) ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) Instance(org.apache.accumulo.core.client.Instance) TimedOutException(org.apache.accumulo.core.client.TimedOutException) LockID(org.apache.accumulo.fate.zookeeper.ZooUtil.LockID) TApplicationException(org.apache.thrift.TApplicationException)

Aggregations

TimedOutException (org.apache.accumulo.core.client.TimedOutException)5 ArrayList (java.util.ArrayList)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)2 Mutation (org.apache.accumulo.core.data.Mutation)2 Range (org.apache.accumulo.core.data.Range)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Semaphore (java.util.concurrent.Semaphore)1 BatchScanner (org.apache.accumulo.core.client.BatchScanner)1 Instance (org.apache.accumulo.core.client.Instance)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1 TCMResult (org.apache.accumulo.core.data.thrift.TCMResult)1