Search in sources :

Example 6 with TabletLocation

use of org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation in project accumulo by apache.

the class TableOperationsImpl method addSplits.

private void addSplits(String tableName, SortedSet<Text> partitionKeys, Table.ID tableId) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, AccumuloServerException {
    TabletLocator tabLocator = TabletLocator.getLocator(context, tableId);
    for (Text split : partitionKeys) {
        boolean successful = false;
        int attempt = 0;
        long locationFailures = 0;
        while (!successful) {
            if (attempt > 0)
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            attempt++;
            TabletLocation tl = tabLocator.locateTablet(context, split, false, false);
            if (tl == null) {
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableNotFoundException(tableId.canonicalID(), tableName, null);
                else if (Tables.getTableState(context.getInstance(), tableId) == TableState.OFFLINE)
                    throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
                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(Tracer.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(TimeUnit.SECONDS)));
                    }
                } finally {
                    ThriftUtil.returnClient(client);
                }
            } catch (TApplicationException tae) {
                throw new AccumuloServerException(address.toString(), tae);
            } catch (TTransportException e) {
                tabLocator.invalidateCache(context.getInstance(), tl.tablet_location);
                continue;
            } catch (ThriftSecurityException e) {
                Tables.clearCache(context.getInstance());
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableNotFoundException(tableId.canonicalID(), tableName, null);
                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 (5 == locationFailures || 0 == locationFailures % 50) {
                    log.warn("Having difficulty locating hosting tabletserver for split {} on table {}. Seen {} failures.", split, tableName, locationFailures);
                }
                tabLocator.invalidateCache(tl.tablet_extent);
                continue;
            } catch (TException e) {
                tabLocator.invalidateCache(context.getInstance(), tl.tablet_location);
                continue;
            }
            successful = true;
        }
    }
}
Also used : TException(org.apache.thrift.TException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) 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.client.impl.thrift.ThriftSecurityException) Constraint(org.apache.accumulo.core.constraints.Constraint) TApplicationException(org.apache.thrift.TApplicationException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TabletLocation(org.apache.accumulo.core.client.impl.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 7 with TabletLocation

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

Example 8 with TabletLocation

use of org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation in project accumulo by apache.

the class TabletLocatorImplTest method locateTabletTest.

private void locateTabletTest(TabletLocatorImpl cache, String row, boolean skipRow, KeyExtent expected, String server) throws Exception {
    TabletLocation tl = cache.locateTablet(context, new Text(row), skipRow, false);
    if (expected == null) {
        if (tl != null)
            System.out.println("tl = " + tl);
        assertNull(tl);
    } else {
        assertNotNull(tl);
        assertEquals(server, tl.tablet_location);
        assertEquals(expected, tl.tablet_extent);
    }
}
Also used : TabletLocation(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation) Text(org.apache.hadoop.io.Text)

Example 9 with TabletLocation

use of org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation in project accumulo by apache.

the class TabletLocatorImplTest method runTest.

static void runTest(TreeMap<Text, TabletLocation> mc, KeyExtent remove, Set<KeyExtent> expected) {
    // copy so same metaCache can be used for multiple test
    mc = new TreeMap<>(mc);
    TabletLocatorImpl.removeOverlapping(mc, remove);
    HashSet<KeyExtent> eic = new HashSet<>();
    for (TabletLocation tl : mc.values()) {
        eic.add(tl.tablet_extent);
    }
    assertEquals(expected, eic);
}
Also used : TabletLocation(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) HashSet(java.util.HashSet)

Example 10 with TabletLocation

use of org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation in project accumulo by apache.

the class MetadataLocationObtainer method getMetadataLocationEntries.

public static TabletLocations getMetadataLocationEntries(SortedMap<Key, Value> entries) {
    Key key;
    Value val;
    Text location = null;
    Text session = null;
    Value prevRow = null;
    KeyExtent ke;
    List<TabletLocation> results = new ArrayList<>();
    ArrayList<KeyExtent> locationless = new ArrayList<>();
    Text lastRowFromKey = new Text();
    // text obj below is meant to be reused in loop for efficiency
    Text colf = new Text();
    Text colq = new Text();
    for (Entry<Key, Value> entry : entries.entrySet()) {
        key = entry.getKey();
        val = entry.getValue();
        if (key.compareRow(lastRowFromKey) != 0) {
            prevRow = null;
            location = null;
            session = null;
            key.getRow(lastRowFromKey);
        }
        colf = key.getColumnFamily(colf);
        colq = key.getColumnQualifier(colq);
        // interpret the row id as a key extent
        if (colf.equals(TabletsSection.CurrentLocationColumnFamily.NAME) || colf.equals(TabletsSection.FutureLocationColumnFamily.NAME)) {
            if (location != null) {
                throw new IllegalStateException("Tablet has multiple locations : " + lastRowFromKey);
            }
            location = new Text(val.toString());
            session = new Text(colq);
        } else if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.equals(colf, colq)) {
            prevRow = new Value(val);
        }
        if (prevRow != null) {
            ke = new KeyExtent(key.getRow(), prevRow);
            if (location != null)
                results.add(new TabletLocation(ke, location.toString(), session.toString()));
            else
                locationless.add(ke);
            location = null;
            prevRow = null;
        }
    }
    return new TabletLocations(results, locationless);
}
Also used : TabletLocations(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocations) TabletLocation(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation) Value(org.apache.accumulo.core.data.Value) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

TabletLocation (org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation)11 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)6 Text (org.apache.hadoop.io.Text)6 ArrayList (java.util.ArrayList)4 TreeMap (java.util.TreeMap)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 Path (org.apache.hadoop.fs.Path)3 TException (org.apache.thrift.TException)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 TableOfflineException (org.apache.accumulo.core.client.TableOfflineException)2 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)2 Key (org.apache.accumulo.core.data.Key)2 Range (org.apache.accumulo.core.data.Range)2 Value (org.apache.accumulo.core.data.Value)2