@Override
public void binMutations(List<Mutation> mutations, Map<String,TabletServerMutations> binnedMutations, List<Mutation> failures, TCredentials credentials) throws AccumuloException,
AccumuloSecurityException, TableNotFoundException {
OpTimer opTimer = null;
if (log.isTraceEnabled())
opTimer = new OpTimer(log, Level.TRACE).start("Binning " + mutations.size() + " mutations for table " + tableId);
ArrayList<Mutation> notInCache = new ArrayList<Mutation>();
Text row = new Text();
rLock.lock();
try {
processInvalidated(credentials);
// for this to be efficient rows need to be in sorted order, but always sorting is slow... therefore only sort the
// stuff not in the cache.... it is most efficient to pass _locateTablet rows in sorted order
// For this to be efficient, need to avoid fine grained synchronization and fine grained logging.
// Therefore methods called by this are not synchronized and should not log.
for (Mutation mutation : mutations) {
row.set(mutation.getRow());
TabletLocation tl = locateTabletInCache(row);
if (tl == null)
notInCache.add(mutation);
else
addMutation(binnedMutations, mutation, tl);
}
} finally {
rLock.unlock();
}
if (notInCache.size() > 0) {
Collections.sort(notInCache, new Comparator<Mutation>() {
public int compare(Mutation o1, Mutation o2) {
return WritableComparator.compareBytes(o1.getRow(), 0, o1.getRow().length, o2.getRow(), 0, o2.getRow().length);
}
});
wLock.lock();
try {
boolean failed = false;
for (Mutation mutation : notInCache) {
if (failed) {
// when one table does not return a location, something is probably
// screwy, go ahead and fail everything.
failures.add(mutation);
continue;
}
row.set(mutation.getRow());
TabletLocation tl = _locateTablet(row, false, false, false, credentials);
if (tl == null) {
failures.add(mutation);
failed = true;
} else {
addMutation(binnedMutations, mutation, tl);
}
}
} finally {
wLock.unlock();
}
}
if (opTimer != null)
opTimer.stop("Binned " + mutations.size() + " mutations for table " + tableId + " to " + binnedMutations.size() + " tservers in %DURATION%");
}