use of io.trino.spi.TrinoException in project trino by trinodb.
the class FileSingleStreamSpiller method readPages.
private Iterator<Page> readPages() {
checkState(writable, "Repeated reads are disallowed to prevent potential resource leaks");
writable = false;
try {
InputStream input = closer.register(targetFile.newInputStream());
Iterator<Page> pages = PagesSerdeUtil.readPages(serde, input);
return closeWhenExhausted(pages, input);
} catch (IOException e) {
fileSystemErrorHandler.run();
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Failed to read spilled pages", e);
}
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class FileSingleStreamSpiller method close.
@Override
public void close() {
closer.register(localSpillContext);
closer.register(() -> memoryContext.setBytes(0));
try {
closer.close();
} catch (IOException e) {
fileSystemErrorHandler.run();
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Failed to close spiller", e);
}
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class FileSingleStreamSpiller method writePages.
private void writePages(Iterator<Page> pageIterator) {
checkState(writable, "Spilling no longer allowed. The spiller has been made non-writable on first read for subsequent reads to be consistent");
try (SliceOutput output = new OutputStreamSliceOutput(targetFile.newOutputStream(APPEND), BUFFER_SIZE);
PagesSerde.PagesSerdeContext context = serde.newContext()) {
while (pageIterator.hasNext()) {
Page page = pageIterator.next();
spilledPagesInMemorySize += page.getSizeInBytes();
Slice serializedPage = serde.serialize(context, page);
long pageSize = serializedPage.length();
localSpillContext.updateBytes(pageSize);
spillerStats.addToTotalSpilledBytes(pageSize);
output.writeBytes(serializedPage);
}
} catch (UncheckedIOException | IOException e) {
fileSystemErrorHandler.run();
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Failed to spill pages", e);
}
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class FileSingleStreamSpillerFactory method getNextSpillPath.
private synchronized Path getNextSpillPath() {
int spillPathsCount = spillPaths.size();
for (int i = 0; i < spillPathsCount; ++i) {
int pathIndex = (roundRobinIndex + i) % spillPathsCount;
Path path = spillPaths.get(pathIndex);
if (hasEnoughDiskSpace(path) && spillPathHealthCache.getUnchecked(path)) {
roundRobinIndex = (roundRobinIndex + i + 1) % spillPathsCount;
return path;
}
}
if (spillPaths.isEmpty()) {
throw new TrinoException(OUT_OF_SPILL_SPACE, "No spill paths configured");
}
throw new TrinoException(OUT_OF_SPILL_SPACE, "No free or healthy space available for spill");
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class Session method beginTransactionId.
public Session beginTransactionId(TransactionId transactionId, TransactionManager transactionManager, AccessControl accessControl) {
requireNonNull(transactionId, "transactionId is null");
checkArgument(this.transactionId.isEmpty(), "Session already has an active transaction");
requireNonNull(transactionManager, "transactionManager is null");
requireNonNull(accessControl, "accessControl is null");
validateSystemProperties(accessControl, this.systemProperties);
// Now that there is a transaction, the catalog name can be resolved to a connector, and the catalog properties can be validated
ImmutableMap.Builder<String, Map<String, String>> connectorProperties = ImmutableMap.builder();
for (Entry<String, Map<String, String>> catalogEntry : this.catalogProperties.entrySet()) {
String catalogName = catalogEntry.getKey();
Map<String, String> catalogProperties = catalogEntry.getValue();
if (catalogProperties.isEmpty()) {
continue;
}
CatalogName catalog = transactionManager.getCatalogName(transactionId, catalogName).orElseThrow(() -> new TrinoException(NOT_FOUND, "Session property catalog does not exist: " + catalogName));
validateCatalogProperties(Optional.of(transactionId), accessControl, catalog, catalogProperties);
connectorProperties.put(catalogName, catalogProperties);
}
ImmutableMap.Builder<String, SelectedRole> connectorRoles = ImmutableMap.builder();
for (Entry<String, SelectedRole> entry : identity.getCatalogRoles().entrySet()) {
String catalogName = entry.getKey();
SelectedRole role = entry.getValue();
if (transactionManager.getCatalogName(transactionId, catalogName).isEmpty()) {
throw new TrinoException(NOT_FOUND, "Catalog for role does not exist: " + catalogName);
}
if (role.getType() == SelectedRole.Type.ROLE) {
accessControl.checkCanSetCatalogRole(new SecurityContext(transactionId, identity, queryId), role.getRole().orElseThrow(), catalogName);
}
connectorRoles.put(catalogName, role);
}
return new Session(queryId, Optional.of(transactionId), clientTransactionSupport, Identity.from(identity).withConnectorRoles(connectorRoles.buildOrThrow()).build(), source, catalog, schema, path, traceToken, timeZoneKey, locale, remoteUserAddress, userAgent, clientInfo, clientTags, clientCapabilities, resourceEstimates, start, systemProperties, connectorProperties.buildOrThrow(), sessionPropertyManager, preparedStatements, protocolHeaders);
}
Aggregations