use of org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation in project accumulo by apache.
the class TableOperationsImpl method addSplits.
private void addSplits(SplitEnv env, SortedSet<Text> partitionKeys) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, AccumuloServerException {
TabletLocator tabLocator = TabletLocator.getLocator(context, env.tableId);
for (Text split : partitionKeys) {
boolean successful = false;
int attempt = 0;
long locationFailures = 0;
while (!successful) {
if (attempt > 0)
sleepUninterruptibly(100, MILLISECONDS);
attempt++;
TabletLocation tl = tabLocator.locateTablet(context, split, false, false);
if (tl == null) {
context.requireTableExists(env.tableId, env.tableName);
context.requireNotOffline(env.tableId, env.tableName);
continue;
}
HostAndPort address = HostAndPort.fromString(tl.tablet_location);
try {
TabletClientService.Client client = ThriftUtil.getTServerClient(address, context);
try {
OpTimer timer = null;
if (log.isTraceEnabled()) {
log.trace("tid={} Splitting tablet {} on {} at {}", Thread.currentThread().getId(), tl.tablet_extent, address, split);
timer = new OpTimer().start();
}
client.splitTablet(TraceUtil.traceInfo(), context.rpcCreds(), tl.tablet_extent.toThrift(), TextUtil.getByteBuffer(split));
// just split it, might as well invalidate it in the cache
tabLocator.invalidateCache(tl.tablet_extent);
if (timer != null) {
timer.stop();
log.trace("Split tablet in {}", String.format("%.3f secs", timer.scale(SECONDS)));
}
} finally {
ThriftUtil.returnClient(client, context);
}
} catch (TApplicationException tae) {
throw new AccumuloServerException(address.toString(), tae);
} catch (TTransportException e) {
tabLocator.invalidateCache(context, tl.tablet_location);
continue;
} catch (ThriftSecurityException e) {
context.clearTableListCache();
context.requireTableExists(env.tableId, env.tableName);
throw new AccumuloSecurityException(e.user, e.code, e);
} catch (NotServingTabletException e) {
// Do not silently spin when we repeatedly fail to get the location for a tablet
locationFailures++;
if (locationFailures == 5 || locationFailures % 50 == 0) {
log.warn("Having difficulty locating hosting tabletserver for split {} on table {}." + " Seen {} failures.", split, env.tableName, locationFailures);
}
tabLocator.invalidateCache(tl.tablet_extent);
continue;
} catch (TException e) {
tabLocator.invalidateCache(context, tl.tablet_location);
continue;
}
successful = true;
}
}
}
use of org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation in project accumulo by apache.
the class Writer method update.
public void update(Mutation m) throws AccumuloException, AccumuloSecurityException, ConstraintViolationException, TableNotFoundException {
checkArgument(m != null, "m is null");
if (m.size() == 0)
throw new IllegalArgumentException("Can not add empty mutations");
while (true) {
TabletLocation tabLoc = TabletLocator.getLocator(context, tableId).locateTablet(context, new Text(m.getRow()), false, true);
if (tabLoc == null) {
log.trace("No tablet location found for row {}", new String(m.getRow(), UTF_8));
sleepUninterruptibly(500, MILLISECONDS);
continue;
}
final HostAndPort parsedLocation = HostAndPort.fromString(tabLoc.tablet_location);
try {
updateServer(context, m, tabLoc.tablet_extent, parsedLocation);
return;
} catch (NotServingTabletException e) {
log.trace("Not serving tablet, server = {}", parsedLocation);
TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent);
} catch (ConstraintViolationException cve) {
log.error("error sending update to {}", parsedLocation, cve);
// probably do not need to invalidate cache, but it does not hurt
TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent);
throw cve;
} catch (TException e) {
log.error("error sending update to {}", parsedLocation, e);
TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent);
}
sleepUninterruptibly(500, MILLISECONDS);
}
}
Aggregations