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();
}
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();
}
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;
}
}
}
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;
}
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() {
}
};
}
Aggregations