Search in sources :

Example 11 with TabletLocation

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;
        }
    }
}
Also used : TException(org.apache.thrift.TException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) TTransportException(org.apache.thrift.transport.TTransportException) Text(org.apache.hadoop.io.Text) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) Constraint(org.apache.accumulo.core.data.constraints.Constraint) TApplicationException(org.apache.thrift.TApplicationException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation) OpTimer(org.apache.accumulo.core.util.OpTimer) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService)

Example 12 with TabletLocation

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);
    }
}
Also used : TException(org.apache.thrift.TException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) Text(org.apache.hadoop.io.Text)

Aggregations

TabletLocation (org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation)12 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)7 Text (org.apache.hadoop.io.Text)7 ArrayList (java.util.ArrayList)5 TreeMap (java.util.TreeMap)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 IOException (java.io.IOException)3 List (java.util.List)3 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 Key (org.apache.accumulo.core.data.Key)3 Range (org.apache.accumulo.core.data.Range)3 Value (org.apache.accumulo.core.data.Value)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 ExecutorService (java.util.concurrent.ExecutorService)2 TabletLocator (org.apache.accumulo.core.clientImpl.TabletLocator)2 TabletLocations (org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocations)2 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2