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