@Override public ConditionalWriter createConditionalWriter(String tableName, ConditionalWriterConfig config) throws TableNotFoundException { ensureOpen(); return new ConditionalWriterImpl(this, getTableId(tableName), config); }
@Override public void close() { threadPool.shutdownNow(); cleanupThreadPool.execute(new CleanupTask(getActiveSessions())); }
private TabletServerMutations<QCMutation> dequeue(String location) { BlockingQueue<TabletServerMutations<QCMutation>> queue = getServerQueue(location).queue; ArrayList<TabletServerMutations<QCMutation>> mutations = new ArrayList<>(); queue.drainTo(mutations); if (mutations.size() == 0) return null; if (mutations.size() == 1) { return mutations.get(0); } else { // merge multiple request to a single tablet server TabletServerMutations<QCMutation> tsm = mutations.get(0); for (int i = 1; i < mutations.size(); i++) { for (Entry<KeyExtent,List<QCMutation>> entry : mutations.get(i).getMutations().entrySet()) { List<QCMutation> list = tsm.getMutations().get(entry.getKey()); if (list == null) { list = new ArrayList<>(); tsm.getMutations().put(entry.getKey(), list); } list.addAll(entry.getValue()); } } return tsm; } }
private void invalidateSession(HostAndPort location, Map<Long,CMK> cmidToCm, SessionID sessionId) { if (sessionId == null) { queueRetry(cmidToCm, location); } else { try { invalidateSession(sessionId, location); for (CMK cmk : cmidToCm.values()) cmk.cm.queueResult(new Result(Status.UNKNOWN, cmk.cm, location.toString())); } catch (Exception e2) { queueException(location, cmidToCm, e2); } } }
convertMutations(mutations, cmidToCm, cmid, tmutations, compressedIters); client = getClient(location); sessionId = reserveSessionID(location, client, tinfo); tresults = client.conditionalUpdate(tinfo, sessionId.sessionID, tmutations, compressedIters.getSymbolTable()); } catch (NoSuchScanIDException nssie) { sessionId = null; invalidateSessionID(location); } else { QCMutation qcm = cmidToCm.get(tcmResult.cmid).cm; qcm.queueResult(new Result(fromThrift(tcmResult.status), qcm, location.toString())); queueRetry(ignored, location); context.getCredentials().getPrincipal(), tse.getCode(), Tables.getPrintableTableInfoFromId(context, tableId), tse); queueException(location, cmidToCm, ase); } catch (TTransportException e) { locator.invalidateCache(context, location.toString()); invalidateSession(location, cmidToCm, sessionId); } catch (TApplicationException tae) { queueException(location, cmidToCm, new AccumuloServerException(location.toString(), tae)); } catch (TException e) { locator.invalidateCache(context, location.toString()); invalidateSession(location, cmidToCm, sessionId); } catch (Exception e) {
@Override public Iterator<Result> write(Iterator<ConditionalMutation> mutations) { BlockingQueue<Result> resultQueue = new LinkedBlockingQueue<>(); List<QCMutation> mutationList = new ArrayList<>(); int count = 0; long entryTime = System.currentTimeMillis(); mloop: while (mutations.hasNext()) { ConditionalMutation mut = mutations.next(); count++; if (mut.getConditions().size() == 0) throw new IllegalArgumentException( "ConditionalMutation had no conditions " + new String(mut.getRow(), UTF_8)); for (Condition cond : mut.getConditions()) { if (!isVisible(cond.getVisibility())) { resultQueue.add(new Result(Status.INVISIBLE_VISIBILITY, mut, null)); continue mloop; } } // copy the mutations so that even if caller changes it, it will not matter mutationList.add(new QCMutation(mut, resultQueue, entryTime)); } queue(mutationList); return new RQIterator(resultQueue, count); }
private void invalidateSession(long sessionId, HostAndPort location) throws TException { TabletClientService.Iface client = null; TInfo tinfo = Tracer.traceInfo(); try { client = getClient(location); client.invalidateConditionalUpdate(tinfo, sessionId); } finally { ThriftUtil.returnClient((TServiceClient) client); } }
private void convertMutations(TabletServerMutations<QCMutation> mutations, Map<Long,CMK> cmidToCm, MutableLong cmid, Map<TKeyExtent,List<TConditionalMutation>> tmutations, CompressedIterators compressedIters) { for (Entry<KeyExtent,List<QCMutation>> entry : mutations.getMutations().entrySet()) { TKeyExtent tke = entry.getKey().toThrift(); ArrayList<TConditionalMutation> tcondMutaions = new ArrayList<>(); List<QCMutation> condMutations = entry.getValue(); for (QCMutation cm : condMutations) { TMutation tm = cm.toThrift(); List<TCondition> conditions = convertConditions(cm, compressedIters); cmidToCm.put(cmid.longValue(), new CMK(entry.getKey(), cm)); TConditionalMutation tcm = new TConditionalMutation(conditions, tm, cmid.longValue()); cmid.increment(); tcondMutaions.add(tcm); } tmutations.put(tke, tcondMutaions); } }
invalidateSession(sessionId.sessionID, location);
private void reschedule(SendTask task) { ServerQueue serverQueue = getServerQueue(task.location); // just finished processing work for this server, could reschedule if it has more work or // immediately process the work // this code reschedules the the server for processing later... there may be other queues with // more data that need to be processed... also it will give the current server time to build // up more data... the thinking is that rescheduling instead or processing immediately will // result // in bigger batches and less RPC overhead synchronized (serverQueue) { if (serverQueue.queue.size() > 0) threadPool.execute(new LoggingRunnable(log, Trace.wrap(task))); else serverQueue.taskQueued = false; } }
private void queue(String location, TabletServerMutations<QCMutation> mutations) { ServerQueue serverQueue = getServerQueue(location); synchronized (serverQueue) { serverQueue.queue.add(mutations); // never execute more than one task per server if (!serverQueue.taskQueued) { threadPool.execute(new LoggingRunnable(log, Trace.wrap(new SendTask(location)))); serverQueue.taskQueued = true; } } }