private void binMutations( MutationSet mutationsToProcess, Map<String, TabletServerMutations<Mutation>> binnedMutations) { try { Set<Entry<String, List<Mutation>>> es = mutationsToProcess.getMutations().entrySet(); for (Entry<String, List<Mutation>> entry : es) { TabletLocator locator = getLocator(entry.getKey()); String table = entry.getKey(); List<Mutation> tableMutations = entry.getValue(); if (tableMutations != null) { ArrayList<Mutation> tableFailures = new ArrayList<Mutation>(); locator.binMutations(credentials, tableMutations, binnedMutations, tableFailures); if (tableFailures.size() > 0) { failedMutations.add(table, tableFailures); if (tableFailures.size() == tableMutations.size()) if (!Tables.exists(instance, entry.getKey())) throw new TableDeletedException(entry.getKey()); else if (Tables.getTableState(instance, table) == TableState.OFFLINE) throw new TableOfflineException(instance, entry.getKey()); } } } return; } catch (AccumuloServerException ase) { updateServerErrors(ase.getServer(), ase); } catch (AccumuloException ae) { // assume an IOError communicating with !METADATA tablet failedMutations.add(mutationsToProcess); } catch (AccumuloSecurityException e) { updateAuthorizationFailures( Collections.singletonMap( new KeyExtent(new Text(MetadataTable.ID), null, null), SecurityErrorCode.valueOf(e.getSecurityErrorCode().name()))); } catch (TableDeletedException e) { updateUnknownErrors(e.getMessage(), e); } catch (TableOfflineException e) { updateUnknownErrors(e.getMessage(), e); } catch (TableNotFoundException e) { updateUnknownErrors(e.getMessage(), e); } // an error ocurred binnedMutations.clear(); }
public static List<KeyValue> scan(ClientContext context, ScanState scanState, int timeOut) throws ScanTimedOutException, AccumuloException, AccumuloSecurityException, TableNotFoundException { TabletLocation loc = null; Instance instance = context.getInstance(); long startTime = System.currentTimeMillis(); String lastError = null; String error = null; int tooManyFilesCount = 0; long sleepMillis = 100; List<KeyValue> results = null; Span span = Trace.start("scan"); try { while (results == null && !scanState.finished) { if (Thread.currentThread().isInterrupted()) { throw new AccumuloException("Thread interrupted"); } if ((System.currentTimeMillis() - startTime) / 1000.0 > timeOut) throw new ScanTimedOutException(); while (loc == null) { long currentTime = System.currentTimeMillis(); if ((currentTime - startTime) / 1000.0 > timeOut) throw new ScanTimedOutException(); Span locateSpan = Trace.start("scan:locateTablet"); try { loc = TabletLocator.getLocator(context, scanState.tableId) .locateTablet(context, scanState.startRow, scanState.skipStartRow, false); if (loc == null) { if (!Tables.exists(instance, scanState.tableId)) throw new TableDeletedException(scanState.tableId); else if (Tables.getTableState(instance, scanState.tableId) == TableState.OFFLINE) throw new TableOfflineException(instance, scanState.tableId); error = "Failed to locate tablet for table : " + scanState.tableId + " row : " + scanState.startRow; if (!error.equals(lastError)) log.debug("{}", error); else if (log.isTraceEnabled()) log.trace("{}", error); lastError = error; sleepMillis = pause(sleepMillis); } else { // when a tablet splits we do want to continue scanning the low child // of the split if we are already passed it Range dataRange = loc.tablet_extent.toDataRange(); if (scanState.range.getStartKey() != null && dataRange.afterEndKey(scanState.range.getStartKey())) { // go to the next tablet scanState.startRow = loc.tablet_extent.getEndRow(); scanState.skipStartRow = true; loc = null; } else if (scanState.range.getEndKey() != null && dataRange.beforeStartKey(scanState.range.getEndKey())) { // should not happen throw new RuntimeException( "Unexpected tablet, extent : " + loc.tablet_extent + " range : " + scanState.range + " startRow : " + scanState.startRow); } } } catch (AccumuloServerException e) { log.debug("Scan failed, server side exception : {}", e.getMessage()); throw e; } catch (AccumuloException e) { error = "exception from tablet loc " + e.getMessage(); if (!error.equals(lastError)) log.debug("{}", error); else if (log.isTraceEnabled()) log.trace("{}", error); lastError = error; sleepMillis = pause(sleepMillis); } finally { locateSpan.stop(); } } Span scanLocation = Trace.start("scan:location"); scanLocation.data("tserver", loc.tablet_location); try { results = scan(loc, scanState, context); } catch (AccumuloSecurityException e) { Tables.clearCache(instance); if (!Tables.exists(instance, scanState.tableId)) throw new TableDeletedException(scanState.tableId); e.setTableInfo(Tables.getPrintableTableInfoFromId(instance, scanState.tableId)); throw e; } catch (TApplicationException tae) { throw new AccumuloServerException(loc.tablet_location, tae); } catch (TSampleNotPresentException tsnpe) { String message = "Table " + Tables.getPrintableTableInfoFromId(instance, scanState.tableId) + " does not have sampling configured or built"; throw new SampleNotPresentException(message, tsnpe); } catch (NotServingTabletException e) { error = "Scan failed, not serving tablet " + loc; if (!error.equals(lastError)) log.debug("{}", error); else if (log.isTraceEnabled()) log.trace("{}", error); lastError = error; TabletLocator.getLocator(context, scanState.tableId).invalidateCache(loc.tablet_extent); loc = null; // no need to try the current scan id somewhere else scanState.scanID = null; if (scanState.isolated) throw new IsolationException(); sleepMillis = pause(sleepMillis); } catch (NoSuchScanIDException e) { error = "Scan failed, no such scan id " + scanState.scanID + " " + loc; if (!error.equals(lastError)) log.debug("{}", error); else if (log.isTraceEnabled()) log.trace("{}", error); lastError = error; if (scanState.isolated) throw new IsolationException(); scanState.scanID = null; } catch (TooManyFilesException e) { error = "Tablet has too many files " + loc + " retrying..."; if (!error.equals(lastError)) { log.debug("{}", error); tooManyFilesCount = 0; } else { tooManyFilesCount++; if (tooManyFilesCount == 300) log.warn("{}", error); else if (log.isTraceEnabled()) log.trace("{}", error); } lastError = error; // not sure what state the scan session on the server side is // in after this occurs, so lets be cautious and start a new // scan session scanState.scanID = null; if (scanState.isolated) throw new IsolationException(); sleepMillis = pause(sleepMillis); } catch (TException e) { TabletLocator.getLocator(context, scanState.tableId) .invalidateCache(context.getInstance(), loc.tablet_location); error = "Scan failed, thrift error " + e.getClass().getName() + " " + e.getMessage() + " " + loc; if (!error.equals(lastError)) log.debug("{}", error); else if (log.isTraceEnabled()) log.trace("{}", error); lastError = error; loc = null; // do not want to continue using the same scan id, if a timeout occurred could cause a // batch to be skipped // because a thread on the server side may still be processing the timed out continue scan scanState.scanID = null; if (scanState.isolated) throw new IsolationException(); sleepMillis = pause(sleepMillis); } finally { scanLocation.stop(); } } if (results != null && results.size() == 0 && scanState.finished) { results = null; } return results; } catch (InterruptedException ex) { throw new AccumuloException(ex); } finally { span.stop(); } }