Search in sources :

Example 41 with TrinoException

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);
    }
}
Also used : InputStream(java.io.InputStream) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 42 with TrinoException

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);
    }
}
Also used : TrinoException(io.trino.spi.TrinoException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 43 with TrinoException

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);
    }
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) OutputStreamSliceOutput(io.airlift.slice.OutputStreamSliceOutput) PagesSerde(io.trino.execution.buffer.PagesSerde) Slice(io.airlift.slice.Slice) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) OutputStreamSliceOutput(io.airlift.slice.OutputStreamSliceOutput)

Example 44 with TrinoException

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");
}
Also used : Path(java.nio.file.Path) TrinoException(io.trino.spi.TrinoException)

Example 45 with TrinoException

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);
}
Also used : SelectedRole(io.trino.spi.security.SelectedRole) ImmutableMap(com.google.common.collect.ImmutableMap) SecurityContext(io.trino.security.SecurityContext) TrinoException(io.trino.spi.TrinoException) CatalogName(io.trino.connector.CatalogName) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorSession(io.trino.spi.connector.ConnectorSession)

Aggregations

TrinoException (io.trino.spi.TrinoException)623 IOException (java.io.IOException)151 ImmutableList (com.google.common.collect.ImmutableList)105 List (java.util.List)100 Type (io.trino.spi.type.Type)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)90 SchemaTableName (io.trino.spi.connector.SchemaTableName)83 Path (org.apache.hadoop.fs.Path)83 Optional (java.util.Optional)79 ArrayList (java.util.ArrayList)77 Map (java.util.Map)76 ImmutableMap (com.google.common.collect.ImmutableMap)70 Objects.requireNonNull (java.util.Objects.requireNonNull)69 ConnectorSession (io.trino.spi.connector.ConnectorSession)63 TableNotFoundException (io.trino.spi.connector.TableNotFoundException)62 ImmutableSet (com.google.common.collect.ImmutableSet)56 VarcharType (io.trino.spi.type.VarcharType)54 Set (java.util.Set)54 Slice (io.airlift.slice.Slice)53 Table (io.trino.plugin.hive.metastore.Table)52