use of org.apache.accumulo.core.util.HostAndPort 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;
}
}
}
use of org.apache.accumulo.core.util.HostAndPort in project accumulo by apache.
the class TabletServerBatchReaderIterator method doLookup.
static void doLookup(ClientContext context, String server, Map<KeyExtent, List<Range>> requested, Map<KeyExtent, List<Range>> failures, Map<KeyExtent, List<Range>> unscanned, ResultReceiver receiver, List<Column> columns, ScannerOptions options, Authorizations authorizations, TimeoutTracker timeoutTracker) throws IOException, AccumuloSecurityException, AccumuloServerException {
if (requested.size() == 0) {
return;
}
// copy requested to unscanned map. we will remove ranges as they are scanned in trackScanning()
for (Entry<KeyExtent, List<Range>> entry : requested.entrySet()) {
ArrayList<Range> ranges = new ArrayList<>();
for (Range range : entry.getValue()) {
ranges.add(new Range(range));
}
unscanned.put(new KeyExtent(entry.getKey()), ranges);
}
timeoutTracker.startingScan();
TTransport transport = null;
try {
final HostAndPort parsedServer = HostAndPort.fromString(server);
final TabletClientService.Client client;
if (timeoutTracker.getTimeOut() < context.getClientTimeoutInMillis())
client = ThriftUtil.getTServerClient(parsedServer, context, timeoutTracker.getTimeOut());
else
client = ThriftUtil.getTServerClient(parsedServer, context);
try {
OpTimer timer = null;
if (log.isTraceEnabled()) {
log.trace("tid={} Starting multi scan, tserver={} #tablets={} #ranges={} ssil={} ssio={}", Thread.currentThread().getId(), server, requested.size(), sumSizes(requested.values()), options.serverSideIteratorList, options.serverSideIteratorOptions);
timer = new OpTimer().start();
}
TabletType ttype = TabletType.type(requested.keySet());
boolean waitForWrites = !ThriftScanner.serversWaitedForWrites.get(ttype).contains(server);
Map<TKeyExtent, List<TRange>> thriftTabletRanges = Translator.translate(requested, Translators.KET, new Translator.ListTranslator<>(Translators.RT));
InitialMultiScan imsr = client.startMultiScan(Tracer.traceInfo(), context.rpcCreds(), thriftTabletRanges, Translator.translate(columns, Translators.CT), options.serverSideIteratorList, options.serverSideIteratorOptions, ByteBufferUtil.toByteBuffers(authorizations.getAuthorizations()), waitForWrites, SamplerConfigurationImpl.toThrift(options.getSamplerConfiguration()), options.batchTimeOut, options.classLoaderContext);
if (waitForWrites)
ThriftScanner.serversWaitedForWrites.get(ttype).add(server.toString());
MultiScanResult scanResult = imsr.result;
if (timer != null) {
timer.stop();
log.trace("tid={} Got 1st multi scan results, #results={} {} in {}", Thread.currentThread().getId(), scanResult.results.size(), (scanResult.more ? "scanID=" + imsr.scanID : ""), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
}
ArrayList<Entry<Key, Value>> entries = new ArrayList<>(scanResult.results.size());
for (TKeyValue kv : scanResult.results) {
entries.add(new SimpleImmutableEntry<>(new Key(kv.key), new Value(kv.value)));
}
if (entries.size() > 0)
receiver.receive(entries);
if (entries.size() > 0 || scanResult.fullScans.size() > 0)
timeoutTracker.madeProgress();
trackScanning(failures, unscanned, scanResult);
AtomicLong nextOpid = new AtomicLong();
while (scanResult.more) {
timeoutTracker.check();
if (timer != null) {
log.trace("tid={} oid={} Continuing multi scan, scanid={}", Thread.currentThread().getId(), nextOpid.get(), imsr.scanID);
timer.reset().start();
}
scanResult = client.continueMultiScan(Tracer.traceInfo(), imsr.scanID);
if (timer != null) {
timer.stop();
log.trace("tid={} oid={} Got more multi scan results, #results={} {} in {}", Thread.currentThread().getId(), nextOpid.getAndIncrement(), scanResult.results.size(), (scanResult.more ? " scanID=" + imsr.scanID : ""), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
}
entries = new ArrayList<>(scanResult.results.size());
for (TKeyValue kv : scanResult.results) {
entries.add(new SimpleImmutableEntry<>(new Key(kv.key), new Value(kv.value)));
}
if (entries.size() > 0)
receiver.receive(entries);
if (entries.size() > 0 || scanResult.fullScans.size() > 0)
timeoutTracker.madeProgress();
trackScanning(failures, unscanned, scanResult);
}
client.closeMultiScan(Tracer.traceInfo(), imsr.scanID);
} finally {
ThriftUtil.returnClient(client);
}
} catch (TTransportException e) {
log.debug("Server : {} msg : {}", server, e.getMessage());
timeoutTracker.errorOccured(e);
throw new IOException(e);
} catch (ThriftSecurityException e) {
log.debug("Server : {} msg : {}", server, e.getMessage(), e);
throw new AccumuloSecurityException(e.user, e.code, e);
} catch (TApplicationException e) {
log.debug("Server : {} msg : {}", server, e.getMessage(), e);
throw new AccumuloServerException(server, e);
} catch (NoSuchScanIDException e) {
log.debug("Server : {} msg : {}", server, e.getMessage(), e);
throw new IOException(e);
} catch (TSampleNotPresentException e) {
log.debug("Server : " + server + " msg : " + e.getMessage(), e);
String tableInfo = "?";
if (e.getExtent() != null) {
Table.ID tableId = new KeyExtent(e.getExtent()).getTableId();
tableInfo = Tables.getPrintableTableInfoFromId(context.getInstance(), tableId);
}
String message = "Table " + tableInfo + " does not have sampling configured or built";
throw new SampleNotPresentException(message, e);
} catch (TException e) {
log.debug("Server : {} msg : {}", server, e.getMessage(), e);
timeoutTracker.errorOccured(e);
throw new IOException(e);
} finally {
ThriftTransportPool.getInstance().returnTransport(transport);
}
}
use of org.apache.accumulo.core.util.HostAndPort in project accumulo by apache.
the class ReplicationClient method getCoordinatorConnection.
public static ReplicationCoordinator.Client getCoordinatorConnection(ClientContext context) {
Instance instance = context.getInstance();
List<String> locations = instance.getMasterLocations();
if (locations.size() == 0) {
log.debug("No masters for replication to instance {}", instance.getInstanceName());
return null;
}
// This is the master thrift service, we just want the hostname, not the port
String masterThriftService = locations.get(0);
if (masterThriftService.endsWith(":0")) {
log.warn("Master found for {} did not have real location {}", instance.getInstanceName(), masterThriftService);
return null;
}
String zkPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_REPLICATION_COORDINATOR_ADDR;
String replCoordinatorAddr;
log.debug("Using ZooKeeper quorum at {} with path {} to find peer Master information", instance.getZooKeepers(), zkPath);
// Get the coordinator port for the master we're trying to connect to
try {
ZooReader reader = new ZooReader(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
replCoordinatorAddr = new String(reader.getData(zkPath, null), UTF_8);
} catch (KeeperException | InterruptedException e) {
log.error("Could not fetch remote coordinator port", e);
return null;
}
// Throw the hostname and port through HostAndPort to get some normalization
HostAndPort coordinatorAddr = HostAndPort.fromString(replCoordinatorAddr);
log.debug("Connecting to master at {}", coordinatorAddr);
try {
// Master requests can take a long time: don't ever time out
ReplicationCoordinator.Client client = ThriftUtil.getClientNoTimeout(new ReplicationCoordinator.Client.Factory(), coordinatorAddr, context);
return client;
} catch (TTransportException tte) {
log.debug("Failed to connect to master coordinator service ({})", coordinatorAddr, tte);
return null;
}
}
use of org.apache.accumulo.core.util.HostAndPort 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);
}
}
use of org.apache.accumulo.core.util.HostAndPort in project accumulo by apache.
the class ScansResource method getTables.
/**
* Generates a new JSON object with scan information
*
* @return Scan JSON object
*/
@GET
public Scans getTables() {
Scans scans = new Scans();
Map<HostAndPort, ScanStats> entry = Monitor.getScans();
// Adds new scans to the array
for (TabletServerStatus tserverInfo : Monitor.getMmi().getTServerInfo()) {
ScanStats stats = entry.get(HostAndPort.fromString(tserverInfo.name));
if (stats != null) {
scans.addScan(new ScanInformation(tserverInfo, stats.scanCount, stats.oldestScan));
}
}
return scans;
}
Aggregations