Search in sources :

Example 1 with Location

use of org.apache.accumulo.core.metadata.schema.TabletMetadata.Location in project accumulo by apache.

the class ZooKeeperInstance method getRootTabletLocation.

@Override
public String getRootTabletLocation() {
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Looking up root tablet location in zookeeper.", Thread.currentThread().getId());
        timer = new OpTimer().start();
    }
    Location loc = TabletsMetadata.getRootMetadata(Constants.ZROOT + "/" + getInstanceID(), zooCache).getLocation();
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), loc, String.format("%.3f secs", timer.scale(SECONDS)));
    }
    if (loc == null || loc.getType() != LocationType.CURRENT) {
        return null;
    }
    return loc.getHostPort();
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer) Location(org.apache.accumulo.core.metadata.schema.TabletMetadata.Location)

Example 2 with Location

use of org.apache.accumulo.core.metadata.schema.TabletMetadata.Location in project accumulo by apache.

the class ClientContext method getRootTabletLocation.

/**
 * Returns the location of the tablet server that is serving the root tablet.
 *
 * @return location in "hostname:port" form
 */
public String getRootTabletLocation() {
    ensureOpen();
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Looking up root tablet location in zookeeper.", Thread.currentThread().getId());
        timer = new OpTimer().start();
    }
    Location loc = getAmple().readTablet(RootTable.EXTENT, ReadConsistency.EVENTUAL, LOCATION).getLocation();
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), loc, String.format("%.3f secs", timer.scale(SECONDS)));
    }
    if (loc == null || loc.getType() != LocationType.CURRENT) {
        return null;
    }
    return loc.getHostPort();
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer) Location(org.apache.accumulo.core.metadata.schema.TabletMetadata.Location)

Example 3 with Location

use of org.apache.accumulo.core.metadata.schema.TabletMetadata.Location in project accumulo by apache.

the class TableOperationsImpl method waitForTableStateTransition.

private void waitForTableStateTransition(TableId tableId, TableState expectedState) throws AccumuloException, TableNotFoundException {
    Text startRow = null;
    Text lastRow = null;
    while (true) {
        if (context.getTableState(tableId) != expectedState) {
            context.clearTableListCache();
            TableState currentState = context.getTableState(tableId);
            if (currentState != expectedState) {
                context.requireNotDeleted(tableId);
                if (currentState == TableState.DELETING)
                    throw new TableNotFoundException(tableId.canonical(), "", TABLE_DELETED_MSG);
                throw new AccumuloException("Unexpected table state " + tableId + " " + currentState + " != " + expectedState);
            }
        }
        Range range;
        if (startRow == null || lastRow == null)
            range = new KeyExtent(tableId, null, null).toMetaRange();
        else
            range = new Range(startRow, lastRow);
        TabletsMetadata tablets = TabletsMetadata.builder(context).scanMetadataTable().overRange(range).fetch(LOCATION, PREV_ROW).build();
        KeyExtent lastExtent = null;
        int total = 0;
        int waitFor = 0;
        int holes = 0;
        Text continueRow = null;
        MapCounter<String> serverCounts = new MapCounter<>();
        for (TabletMetadata tablet : tablets) {
            total++;
            Location loc = tablet.getLocation();
            if ((expectedState == TableState.ONLINE && (loc == null || loc.getType() == LocationType.FUTURE)) || (expectedState == TableState.OFFLINE && loc != null)) {
                if (continueRow == null)
                    continueRow = tablet.getExtent().toMetaRow();
                waitFor++;
                lastRow = tablet.getExtent().toMetaRow();
                if (loc != null) {
                    serverCounts.increment(loc.getHostPortSession(), 1);
                }
            }
            if (!tablet.getExtent().tableId().equals(tableId)) {
                throw new AccumuloException("Saw unexpected table Id " + tableId + " " + tablet.getExtent());
            }
            if (lastExtent != null && !tablet.getExtent().isPreviousExtent(lastExtent)) {
                holes++;
            }
            lastExtent = tablet.getExtent();
        }
        if (continueRow != null) {
            startRow = continueRow;
        }
        if (holes > 0 || total == 0) {
            startRow = null;
            lastRow = null;
        }
        if (waitFor > 0 || holes > 0 || total == 0) {
            long waitTime;
            long maxPerServer = 0;
            if (serverCounts.size() > 0) {
                maxPerServer = serverCounts.max();
                waitTime = maxPerServer * 10;
            } else
                waitTime = waitFor * 10L;
            waitTime = Math.max(100, waitTime);
            waitTime = Math.min(5000, waitTime);
            log.trace("Waiting for {}({}) tablets, startRow = {} lastRow = {}, holes={} sleeping:{}ms", waitFor, maxPerServer, startRow, lastRow, holes, waitTime);
            sleepUninterruptibly(waitTime, MILLISECONDS);
        } else {
            break;
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Constraint(org.apache.accumulo.core.data.constraints.Constraint) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) MapCounter(org.apache.accumulo.core.util.MapCounter) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) TableState(org.apache.accumulo.core.manager.state.tables.TableState) Location(org.apache.accumulo.core.metadata.schema.TabletMetadata.Location) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation)

Example 4 with Location

use of org.apache.accumulo.core.metadata.schema.TabletMetadata.Location in project accumulo by apache.

the class RootTabletLocator method getRootTabletLocation.

protected TabletLocation getRootTabletLocation(ClientContext context) {
    Logger log = LoggerFactory.getLogger(this.getClass());
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Looking up root tablet location in zookeeper.", Thread.currentThread().getId());
        timer = new OpTimer().start();
    }
    Location loc = context.getAmple().readTablet(RootTable.EXTENT, ReadConsistency.EVENTUAL, LOCATION).getLocation();
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), loc, String.format("%.3f secs", timer.scale(SECONDS)));
    }
    if (loc == null || loc.getType() != LocationType.CURRENT) {
        return null;
    }
    String server = loc.getHostPort();
    if (lockChecker.isLockHeld(server, loc.getSession()))
        return new TabletLocation(RootTable.EXTENT, server, loc.getSession());
    else
        return null;
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer) Logger(org.slf4j.Logger) Location(org.apache.accumulo.core.metadata.schema.TabletMetadata.Location)

Example 5 with Location

use of org.apache.accumulo.core.metadata.schema.TabletMetadata.Location in project accumulo by apache.

the class ZooTabletStateStore method iterator.

@Override
public ClosableIterator<TabletLocationState> iterator() {
    return new ClosableIterator<>() {

        boolean finished = false;

        @Override
        public boolean hasNext() {
            return !finished;
        }

        @Override
        public TabletLocationState next() {
            finished = true;
            try {
                TabletMetadata rootMeta = ample.readTablet(RootTable.EXTENT, ReadConsistency.EVENTUAL);
                TServerInstance currentSession = null;
                TServerInstance futureSession = null;
                TServerInstance lastSession = null;
                Location loc = rootMeta.getLocation();
                if (loc != null && loc.getType() == LocationType.FUTURE)
                    futureSession = loc;
                if (rootMeta.getLast() != null)
                    lastSession = rootMeta.getLast();
                if (loc != null && loc.getType() == LocationType.CURRENT) {
                    currentSession = loc;
                }
                List<Collection<String>> logs = new ArrayList<>();
                rootMeta.getLogs().forEach(logEntry -> {
                    logs.add(Collections.singleton(logEntry.filename));
                    log.debug("root tablet log {}", logEntry.filename);
                });
                return new TabletLocationState(RootTable.EXTENT, futureSession, currentSession, lastSession, null, logs, false);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void close() {
        }
    };
}
Also used : ArrayList(java.util.ArrayList) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) Collection(java.util.Collection) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Location(org.apache.accumulo.core.metadata.schema.TabletMetadata.Location)

Aggregations

Location (org.apache.accumulo.core.metadata.schema.TabletMetadata.Location)5 OpTimer (org.apache.accumulo.core.util.OpTimer)3 TabletMetadata (org.apache.accumulo.core.metadata.schema.TabletMetadata)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 TabletLocation (org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation)1 Range (org.apache.accumulo.core.data.Range)1 Constraint (org.apache.accumulo.core.data.constraints.Constraint)1 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)1 TRowRange (org.apache.accumulo.core.dataImpl.thrift.TRowRange)1 TableState (org.apache.accumulo.core.manager.state.tables.TableState)1 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)1 TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)1 TabletsMetadata (org.apache.accumulo.core.metadata.schema.TabletsMetadata)1 MapCounter (org.apache.accumulo.core.util.MapCounter)1 Text (org.apache.hadoop.io.Text)1 Logger (org.slf4j.Logger)1