use of org.apache.thrift.TApplicationException in project accumulo by apache.
the class ThriftScanner method scan.
public static List<KeyValue> scan(ClientContext context, ScanState scanState, int timeOut) throws ScanTimedOutException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
TabletLocation loc = null;
Instance instance = context.getInstance();
long startTime = System.currentTimeMillis();
String lastError = null;
String error = null;
int tooManyFilesCount = 0;
long sleepMillis = 100;
final long maxSleepTime = context.getConfiguration().getTimeInMillis(Property.GENERAL_MAX_SCANNER_RETRY_PERIOD);
List<KeyValue> results = null;
Span span = Trace.start("scan");
try {
while (results == null && !scanState.finished) {
if (Thread.currentThread().isInterrupted()) {
throw new AccumuloException("Thread interrupted");
}
if ((System.currentTimeMillis() - startTime) / 1000.0 > timeOut)
throw new ScanTimedOutException();
while (loc == null) {
long currentTime = System.currentTimeMillis();
if ((currentTime - startTime) / 1000.0 > timeOut)
throw new ScanTimedOutException();
Span locateSpan = Trace.start("scan:locateTablet");
try {
loc = TabletLocator.getLocator(context, scanState.tableId).locateTablet(context, scanState.startRow, scanState.skipStartRow, false);
if (loc == null) {
if (!Tables.exists(instance, scanState.tableId))
throw new TableDeletedException(scanState.tableId.canonicalID());
else if (Tables.getTableState(instance, scanState.tableId) == TableState.OFFLINE)
throw new TableOfflineException(instance, scanState.tableId.canonicalID());
error = "Failed to locate tablet for table : " + scanState.tableId + " row : " + scanState.startRow;
if (!error.equals(lastError))
log.debug("{}", error);
else if (log.isTraceEnabled())
log.trace("{}", error);
lastError = error;
sleepMillis = pause(sleepMillis, maxSleepTime);
} else {
// when a tablet splits we do want to continue scanning the low child
// of the split if we are already passed it
Range dataRange = loc.tablet_extent.toDataRange();
if (scanState.range.getStartKey() != null && dataRange.afterEndKey(scanState.range.getStartKey())) {
// go to the next tablet
scanState.startRow = loc.tablet_extent.getEndRow();
scanState.skipStartRow = true;
loc = null;
} else if (scanState.range.getEndKey() != null && dataRange.beforeStartKey(scanState.range.getEndKey())) {
// should not happen
throw new RuntimeException("Unexpected tablet, extent : " + loc.tablet_extent + " range : " + scanState.range + " startRow : " + scanState.startRow);
}
}
} catch (AccumuloServerException e) {
log.debug("Scan failed, server side exception : {}", e.getMessage());
throw e;
} catch (AccumuloException e) {
error = "exception from tablet loc " + e.getMessage();
if (!error.equals(lastError))
log.debug("{}", error);
else if (log.isTraceEnabled())
log.trace("{}", error);
lastError = error;
sleepMillis = pause(sleepMillis, maxSleepTime);
} finally {
locateSpan.stop();
}
}
Span scanLocation = Trace.start("scan:location");
scanLocation.data("tserver", loc.tablet_location);
try {
results = scan(loc, scanState, context);
} catch (AccumuloSecurityException e) {
Tables.clearCache(instance);
if (!Tables.exists(instance, scanState.tableId))
throw new TableDeletedException(scanState.tableId.canonicalID());
e.setTableInfo(Tables.getPrintableTableInfoFromId(instance, scanState.tableId));
throw e;
} catch (TApplicationException tae) {
throw new AccumuloServerException(loc.tablet_location, tae);
} catch (TSampleNotPresentException tsnpe) {
String message = "Table " + Tables.getPrintableTableInfoFromId(instance, scanState.tableId) + " does not have sampling configured or built";
throw new SampleNotPresentException(message, tsnpe);
} catch (NotServingTabletException e) {
error = "Scan failed, not serving tablet " + loc;
if (!error.equals(lastError))
log.debug("{}", error);
else if (log.isTraceEnabled())
log.trace("{}", error);
lastError = error;
TabletLocator.getLocator(context, scanState.tableId).invalidateCache(loc.tablet_extent);
loc = null;
// no need to try the current scan id somewhere else
scanState.scanID = null;
if (scanState.isolated)
throw new IsolationException();
sleepMillis = pause(sleepMillis, maxSleepTime);
} catch (NoSuchScanIDException e) {
error = "Scan failed, no such scan id " + scanState.scanID + " " + loc;
if (!error.equals(lastError))
log.debug("{}", error);
else if (log.isTraceEnabled())
log.trace("{}", error);
lastError = error;
if (scanState.isolated)
throw new IsolationException();
scanState.scanID = null;
} catch (TooManyFilesException e) {
error = "Tablet has too many files " + loc + " retrying...";
if (!error.equals(lastError)) {
log.debug("{}", error);
tooManyFilesCount = 0;
} else {
tooManyFilesCount++;
if (tooManyFilesCount == 300)
log.warn("{}", error);
else if (log.isTraceEnabled())
log.trace("{}", error);
}
lastError = error;
// not sure what state the scan session on the server side is
// in after this occurs, so lets be cautious and start a new
// scan session
scanState.scanID = null;
if (scanState.isolated)
throw new IsolationException();
sleepMillis = pause(sleepMillis, maxSleepTime);
} catch (TException e) {
TabletLocator.getLocator(context, scanState.tableId).invalidateCache(context.getInstance(), loc.tablet_location);
error = "Scan failed, thrift error " + e.getClass().getName() + " " + e.getMessage() + " " + loc;
if (!error.equals(lastError))
log.debug("{}", error);
else if (log.isTraceEnabled())
log.trace("{}", error);
lastError = error;
loc = null;
// do not want to continue using the same scan id, if a timeout occurred could cause a batch to be skipped
// because a thread on the server side may still be processing the timed out continue scan
scanState.scanID = null;
if (scanState.isolated)
throw new IsolationException();
sleepMillis = pause(sleepMillis, maxSleepTime);
} finally {
scanLocation.stop();
}
}
if (results != null && results.size() == 0 && scanState.finished) {
results = null;
}
return results;
} catch (InterruptedException ex) {
throw new AccumuloException(ex);
} finally {
span.stop();
}
}
use of org.apache.thrift.TApplicationException in project accumulo by apache.
the class ServerClient method executeRawVoid.
public static void executeRawVoid(ClientContext context, ClientExec<ClientService.Client> exec) throws Exception {
while (true) {
ClientService.Client client = null;
String server = null;
try {
Pair<String, Client> pair = ServerClient.getConnection(context);
server = pair.getFirst();
client = pair.getSecond();
exec.execute(client);
break;
} catch (TApplicationException tae) {
throw new AccumuloServerException(server, tae);
} catch (TTransportException tte) {
log.debug("ClientService request failed " + server + ", retrying ... ", tte);
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} finally {
if (client != null)
ServerClient.close(client);
}
}
}
use of org.apache.thrift.TApplicationException in project accumulo by apache.
the class ConditionalWriterImpl method invalidateSession.
/**
* The purpose of this code is to ensure that a conditional mutation will not execute when its status is unknown. This allows a user to read the row when the
* status is unknown and not have to worry about the tserver applying the mutation after the scan.
*
* <p>
* If a conditional mutation is taking a long time to process, then this method will wait for it to finish... unless this exceeds timeout.
*/
private void invalidateSession(SessionID sessionId, HostAndPort location) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
long sleepTime = 50;
long startTime = System.currentTimeMillis();
Instance instance = context.getInstance();
LockID lid = new LockID(ZooUtil.getRoot(instance) + Constants.ZTSERVERS, sessionId.lockId);
ZooCacheFactory zcf = new ZooCacheFactory();
while (true) {
if (!ZooLock.isLockHeld(zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()), lid)) {
// ACCUMULO-1152 added a tserver lock check to the tablet location cache, so this invalidation prevents future attempts to contact the
// tserver even its gone zombie and is still running w/o a lock
locator.invalidateCache(context.getInstance(), location.toString());
return;
}
try {
// if the mutation is currently processing, this method will block until its done or times out
invalidateSession(sessionId.sessionID, location);
return;
} catch (TApplicationException tae) {
throw new AccumuloServerException(location.toString(), tae);
} catch (TException e) {
locator.invalidateCache(context.getInstance(), location.toString());
}
if ((System.currentTimeMillis() - startTime) + sleepTime > timeout)
throw new TimedOutException(Collections.singleton(location.toString()));
sleepUninterruptibly(sleepTime, TimeUnit.MILLISECONDS);
sleepTime = Math.min(2 * sleepTime, MAX_SLEEP);
}
}
use of org.apache.thrift.TApplicationException in project hive by apache.
the class TestTablesCreateDropAlterTruncate method tablesInOtherCatalogs.
@Test
public void tablesInOtherCatalogs() throws TException, URISyntaxException {
String catName = "create_etc_tables_in_other_catalogs";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "db_in_other_catalog";
// For this one don't specify a location to make sure it gets put in the catalog directory
Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, metaStore.getConf());
Table table = new TableBuilder().inDb(db).setTableName("mvSource").addCol("col1_1", ColumnType.STRING_TYPE_NAME).addCol("col2_2", ColumnType.INT_TYPE_NAME).build(metaStore.getConf());
client.createTable(table);
SourceTable sourceTable = createSourceTable(table);
String[] tableNames = new String[4];
for (int i = 0; i < tableNames.length; i++) {
tableNames[i] = "table_in_other_catalog_" + i;
TableBuilder builder = new TableBuilder().inDb(db).setTableName(tableNames[i]).addCol("col1_" + i, ColumnType.STRING_TYPE_NAME).addCol("col2_" + i, ColumnType.INT_TYPE_NAME);
// Make one have a non-standard location
if (i == 0) {
builder.setLocation(MetaStoreTestUtils.getTestWarehouseDir(tableNames[i]));
}
// Make one partitioned
if (i == 2) {
builder.addPartCol("pcol1", ColumnType.STRING_TYPE_NAME);
}
// Make one a materialized view
if (i == 3) {
builder.setType(TableType.MATERIALIZED_VIEW.name()).setRewriteEnabled(true).addMaterializedViewReferencedTable(sourceTable);
}
client.createTable(builder.build(metaStore.getConf()));
}
// Add partitions for the partitioned table
String[] partVals = new String[3];
Table partitionedTable = client.getTable(catName, dbName, tableNames[2]);
for (int i = 0; i < partVals.length; i++) {
partVals[i] = "part" + i;
new PartitionBuilder().inTable(partitionedTable).addValue(partVals[i]).addToTable(client, metaStore.getConf());
}
// Get tables, make sure the locations are correct
for (int i = 0; i < tableNames.length; i++) {
Table t = client.getTable(catName, dbName, tableNames[i]);
Assert.assertEquals(catName, t.getCatName());
String expectedLocation = (i < 1) ? new File(MetaStoreTestUtils.getTestWarehouseDir(tableNames[i])).toURI().toString() : new File(cat.getLocationUri() + File.separatorChar + dbName + ".db", tableNames[i]).toURI().toString();
Assert.assertEquals(expectedLocation, t.getSd().getLocation() + "/");
File dir = new File(new URI(t.getSd().getLocation()).getPath());
Assert.assertTrue(dir.exists() && dir.isDirectory());
}
// Make sure getting table in the wrong catalog does not work
try {
Table t = client.getTable(DEFAULT_DATABASE_NAME, tableNames[0]);
Assert.fail();
} catch (NoSuchObjectException e) {
// NOP
}
// test getAllTables
Set<String> fetchedNames = new HashSet<>(client.getAllTables(catName, dbName));
Assert.assertEquals(tableNames.length + 1, fetchedNames.size());
for (String tableName : tableNames) {
Assert.assertTrue(fetchedNames.contains(tableName));
}
fetchedNames = new HashSet<>(client.getAllTables(DEFAULT_DATABASE_NAME));
for (String tableName : tableNames) {
Assert.assertFalse(fetchedNames.contains(tableName));
}
// test getMaterializedViewsForRewriting
List<String> materializedViews = client.getMaterializedViewsForRewriting(catName, dbName);
Assert.assertEquals(1, materializedViews.size());
Assert.assertEquals(tableNames[3], materializedViews.get(0));
fetchedNames = new HashSet<>(client.getMaterializedViewsForRewriting(DEFAULT_DATABASE_NAME));
Assert.assertFalse(fetchedNames.contains(tableNames[3]));
// test getTableObjectsByName
List<Table> fetchedTables = client.getTableObjectsByName(catName, dbName, Arrays.asList(tableNames[0], tableNames[1]));
Assert.assertEquals(2, fetchedTables.size());
Collections.sort(fetchedTables);
Assert.assertEquals(tableNames[0], fetchedTables.get(0).getTableName());
Assert.assertEquals(tableNames[1], fetchedTables.get(1).getTableName());
fetchedTables = client.getTableObjectsByName(DEFAULT_DATABASE_NAME, Arrays.asList(tableNames[0], tableNames[1]));
Assert.assertEquals(0, fetchedTables.size());
// Test altering the table
Table t = client.getTable(catName, dbName, tableNames[0]).deepCopy();
t.getParameters().put("test", "test");
client.alter_table(catName, dbName, tableNames[0], t);
t = client.getTable(catName, dbName, tableNames[0]).deepCopy();
Assert.assertEquals("test", t.getParameters().get("test"));
// Alter a table in the wrong catalog
try {
client.alter_table(DEFAULT_DATABASE_NAME, tableNames[0], t);
Assert.fail();
} catch (InvalidOperationException e) {
// NOP
}
// Update the metadata for the materialized view
CreationMetadata cm = client.getTable(catName, dbName, tableNames[3]).getCreationMetadata();
Table table1 = new TableBuilder().inDb(db).setTableName("mvSource2").addCol("col1_1", ColumnType.STRING_TYPE_NAME).addCol("col2_2", ColumnType.INT_TYPE_NAME).build(metaStore.getConf());
client.createTable(table1);
sourceTable = createSourceTable(table1);
cm.addToTablesUsed(TableName.getDbTable(sourceTable.getTable().getDbName(), sourceTable.getTable().getTableName()));
cm.addToSourceTables(sourceTable);
cm.unsetMaterializationTime();
client.updateCreationMetadata(catName, dbName, tableNames[3], cm);
List<String> partNames = new ArrayList<>();
for (String partVal : partVals) {
partNames.add("pcol1=" + partVal);
}
// Truncate a table
client.truncateTable(catName, dbName, tableNames[0], partNames);
// Truncate a table in the wrong catalog
try {
client.truncateTable(DEFAULT_DATABASE_NAME, tableNames[0], partNames);
Assert.fail();
} catch (NoSuchObjectException | TApplicationException e) {
// NOP
}
// Drop a table from the wrong catalog
try {
client.dropTable(DEFAULT_DATABASE_NAME, tableNames[0], true, false);
Assert.fail();
} catch (NoSuchObjectException | TApplicationException e) {
// NOP
}
// Should ignore the failure
client.dropTable(DEFAULT_DATABASE_NAME, tableNames[0], false, true);
// Have to do this in reverse order so that we drop the materialized view first.
for (int i = tableNames.length - 1; i >= 0; i--) {
t = client.getTable(catName, dbName, tableNames[i]);
File tableDir = new File(new URI(t.getSd().getLocation()).getPath());
Assert.assertTrue(tableDir.exists() && tableDir.isDirectory());
if (tableNames[i].equalsIgnoreCase(tableNames[0])) {
client.dropTable(catName, dbName, tableNames[i], false, false);
Assert.assertTrue(tableDir.exists() && tableDir.isDirectory());
} else {
client.dropTable(catName, dbName, tableNames[i]);
Assert.assertFalse(tableDir.exists());
}
}
client.dropTable(table.getCatName(), table.getDbName(), table.getTableName());
client.dropTable(table1.getCatName(), table1.getDbName(), table1.getTableName());
Assert.assertEquals(0, client.getAllTables(catName, dbName).size());
}
use of org.apache.thrift.TApplicationException in project hive by apache.
the class TestForeignKey method addNoSuchDb.
@Test
public void addNoSuchDb() throws TException {
Table parentTable = testTables[0];
List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder().onTable(parentTable).addColumn("col1").build(metaStore.getConf());
client.addPrimaryKey(pk);
try {
List<SQLForeignKey> fk = new SQLForeignKeyBuilder().setTableName(testTables[0].getTableName()).setDbName("nosuch").fromPrimaryKey(pk).addColumn("col2").build(metaStore.getConf());
client.addForeignKey(fk);
Assert.fail();
} catch (InvalidObjectException | TApplicationException e) {
// NOP
}
}
Aggregations