Search in sources :

Example 1 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class ConnectorManager method createCatalog.

private synchronized void createCatalog(CatalogName catalogName, String connectorName, InternalConnectorFactory factory, Map<String, String> properties) {
    // create all connectors before adding, so a broken connector does not leave the system half updated
    CatalogClassLoaderSupplier duplicatePluginClassLoaderFactory = new CatalogClassLoaderSupplier(catalogName, factory.getDuplicatePluginClassLoaderFactory(), handleResolver);
    MaterializedConnector connector = new MaterializedConnector(catalogName, createConnector(catalogName, factory.getConnectorFactory(), duplicatePluginClassLoaderFactory, properties), duplicatePluginClassLoaderFactory::destroy);
    MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaCatalogName(catalogName), new InformationSchemaConnector(catalogName.getCatalogName(), nodeManager, metadataManager, accessControlManager), () -> {
    });
    CatalogName systemId = createSystemTablesCatalogName(catalogName);
    SystemTablesProvider systemTablesProvider;
    if (nodeManager.getCurrentNode().isCoordinator()) {
        systemTablesProvider = new CoordinatorSystemTablesProvider(transactionManager, metadataManager, catalogName.getCatalogName(), new StaticSystemTablesProvider(connector.getSystemTables()));
    } else {
        systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
    }
    MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, catalogName)), () -> {
    });
    SecurityManagement securityManagement = connector.getAccessControl().isPresent() ? CONNECTOR : SYSTEM;
    Catalog catalog = new Catalog(catalogName.getCatalogName(), connector.getCatalogName(), connectorName, connector.getConnector(), securityManagement, informationSchemaConnector.getCatalogName(), informationSchemaConnector.getConnector(), systemConnector.getCatalogName(), systemConnector.getConnector());
    try {
        addConnectorInternal(connector);
        addConnectorInternal(informationSchemaConnector);
        addConnectorInternal(systemConnector);
        catalogManager.registerCatalog(catalog);
    } catch (Throwable e) {
        catalogManager.removeCatalog(catalog.getCatalogName());
        removeConnectorInternal(systemConnector.getCatalogName());
        removeConnectorInternal(informationSchemaConnector.getCatalogName());
        removeConnectorInternal(connector.getCatalogName());
        throw e;
    }
    connector.getEventListeners().forEach(eventListenerManager::addEventListener);
}
Also used : CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemConnector(io.trino.connector.system.SystemConnector) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) AccessControlManager(io.trino.security.AccessControlManager) ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) TableProceduresPropertyManager(io.trino.metadata.TableProceduresPropertyManager) TransactionManager(io.trino.transaction.TransactionManager) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) NodeInfo(io.airlift.node.NodeInfo) SplitManager(io.trino.split.SplitManager) ConnectorContext(io.trino.spi.connector.ConnectorContext) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HandleResolver(io.trino.metadata.HandleResolver) PageSorter(io.trino.spi.PageSorter) Map(java.util.Map) MetadataManager(io.trino.metadata.MetadataManager) ConnectorNodePartitioningProvider(io.trino.spi.connector.ConnectorNodePartitioningProvider) ImmutableSet(com.google.common.collect.ImmutableSet) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PageSinkManager(io.trino.split.PageSinkManager) ConnectorAccessControl(io.trino.spi.connector.ConnectorAccessControl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PropertyMetadata(io.trino.spi.session.PropertyMetadata) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) TableProcedureMetadata(io.trino.spi.connector.TableProcedureMetadata) ConnectorIndexProvider(io.trino.spi.connector.ConnectorIndexProvider) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) List(java.util.List) VersionEmbedder(io.trino.spi.VersionEmbedder) CONNECTOR(io.trino.metadata.Catalog.SecurityManagement.CONNECTOR) Optional(java.util.Optional) SystemConnector(io.trino.connector.system.SystemConnector) ColumnPropertyManager(io.trino.metadata.ColumnPropertyManager) SystemTable(io.trino.spi.connector.SystemTable) RecordPageSourceProvider(io.trino.split.RecordPageSourceProvider) InternalNodeManager(io.trino.metadata.InternalNodeManager) Logger(io.airlift.log.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Procedure(io.trino.spi.procedure.Procedure) Verify.verify(com.google.common.base.Verify.verify) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) PageIndexerFactory(io.trino.spi.PageIndexerFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) TableProceduresRegistry(io.trino.metadata.TableProceduresRegistry) IndexManager(io.trino.index.IndexManager) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Catalog(io.trino.metadata.Catalog) SchemaPropertyManager(io.trino.metadata.SchemaPropertyManager) SYSTEM(io.trino.metadata.Catalog.SecurityManagement.SYSTEM) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) PluginClassLoader(io.trino.server.PluginClassLoader) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider) ConnectorPageSourceProvider(io.trino.spi.connector.ConnectorPageSourceProvider) PageSourceManager(io.trino.split.PageSourceManager) EventListenerManager(io.trino.eventlistener.EventListenerManager) CatalogManager(io.trino.metadata.CatalogManager) TablePropertyManager(io.trino.metadata.TablePropertyManager) ProcedureRegistry(io.trino.metadata.ProcedureRegistry) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) EventListener(io.trino.spi.eventlistener.EventListener) TypeManager(io.trino.spi.type.TypeManager) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) ConnectorPageSinkProvider(io.trino.spi.connector.ConnectorPageSinkProvider) Connector(io.trino.spi.connector.Connector) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) Catalog(io.trino.metadata.Catalog) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider)

Example 2 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestRollbackTask method testNoTransactionRollback.

@Test
public void testNoTransactionRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, transactionManager);
    assertTrinoExceptionThrownBy(() -> getFutureValue((Future<?>) new RollbackTask(transactionManager).execute(new Rollback(), stateMachine, emptyList(), WarningCollector.NOOP))).hasErrorCode(NOT_IN_TRANSACTION);
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) Rollback(io.trino.sql.tree.Rollback) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 3 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestSetRoleTask method setUp.

@BeforeClass
public void setUp() {
    queryRunner = LocalQueryRunner.create(TEST_SESSION);
    MockConnectorFactory mockConnectorFactory = MockConnectorFactory.builder().withListRoleGrants((connectorSession, roles, grantees, limit) -> ImmutableSet.of(new RoleGrant(new TrinoPrincipal(USER, USER_NAME), ROLE_NAME, false))).build();
    queryRunner.createCatalog(CATALOG_NAME, mockConnectorFactory, ImmutableMap.of());
    MockConnectorFactory systemConnectorFactory = MockConnectorFactory.builder().withName("system_role_connector").build();
    queryRunner.createCatalog(SYSTEM_ROLE_CATALOG_NAME, systemConnectorFactory, ImmutableMap.of());
    transactionManager = queryRunner.getTransactionManager();
    accessControl = queryRunner.getAccessControl();
    metadata = queryRunner.getMetadata();
    parser = queryRunner.getSqlParser();
    executor = newCachedThreadPool(daemonThreadsNamed("test-set-role-task-executor-%s"));
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) USER(io.trino.spi.security.PrincipalType.USER) ParsingOptions(io.trino.sql.parser.ParsingOptions) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TrinoExceptionAssert.assertTrinoExceptionThrownBy(io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Identity(io.trino.spi.security.Identity) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) SqlParser(io.trino.sql.parser.SqlParser) URI(java.net.URI) ExecutorService(java.util.concurrent.ExecutorService) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) CATALOG_NOT_FOUND(io.trino.spi.StandardErrorCode.CATALOG_NOT_FOUND) RoleGrant(io.trino.spi.security.RoleGrant) SelectedRole(io.trino.spi.security.SelectedRole) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) AccessControl(io.trino.security.AccessControl) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) SetRole(io.trino.sql.tree.SetRole) WarningCollector(io.trino.execution.warnings.WarningCollector) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) ROLE_NOT_FOUND(io.trino.spi.StandardErrorCode.ROLE_NOT_FOUND) RoleGrant(io.trino.spi.security.RoleGrant) MockConnectorFactory(io.trino.connector.MockConnectorFactory) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestQueryStateMachine method createQueryStateMachineWithTicker.

private QueryStateMachine createQueryStateMachineWithTicker(Ticker ticker) {
    Metadata metadata = createTestMetadataManager();
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControl = new AccessControlManager(transactionManager, emptyEventListenerManager(), new AccessControlConfig(), DefaultSystemAccessControl.NAME);
    accessControl.setSystemAccessControls(List.of(AllowAllSystemAccessControl.INSTANCE));
    QueryStateMachine stateMachine = QueryStateMachine.beginWithTicker(Optional.empty(), QUERY, Optional.empty(), TEST_SESSION, LOCATION, new ResourceGroupId("test"), false, transactionManager, accessControl, executor, ticker, metadata, WarningCollector.NOOP, QUERY_TYPE);
    stateMachine.setInputs(INPUTS);
    stateMachine.setOutput(OUTPUT);
    stateMachine.setColumns(OUTPUT_FIELD_NAMES, OUTPUT_FIELD_TYPES);
    stateMachine.setUpdateType(UPDATE_TYPE);
    for (Entry<String, String> entry : SET_SESSION_PROPERTIES.entrySet()) {
        stateMachine.addSetSessionProperties(entry.getKey(), entry.getValue());
    }
    RESET_SESSION_PROPERTIES.forEach(stateMachine::addResetSessionProperties);
    return stateMachine;
}
Also used : AccessControlManager(io.trino.security.AccessControlManager) AccessControlConfig(io.trino.security.AccessControlConfig) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) Metadata(io.trino.metadata.Metadata)

Example 5 with TransactionManager

use of io.trino.transaction.TransactionManager in project trino by trinodb.

the class TestStartTransactionTask method testNonTransactionalClient.

@Test
public void testNonTransactionalClient() {
    Session session = sessionBuilder().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    assertTrinoExceptionThrownBy(() -> getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP))).hasErrorCode(INCOMPATIBLE_CLIENT);
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) StartTransaction(io.trino.sql.tree.StartTransaction) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

TransactionManager (io.trino.transaction.TransactionManager)48 InMemoryTransactionManager.createTestTransactionManager (io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)42 Test (org.testng.annotations.Test)40 AccessDeniedException (io.trino.spi.security.AccessDeniedException)17 Session (io.trino.Session)16 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)16 Optional (java.util.Optional)13 ImmutableSet (com.google.common.collect.ImmutableSet)12 SchemaTableName (io.trino.spi.connector.SchemaTableName)12 Map (java.util.Map)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 DefaultSystemAccessControl (io.trino.plugin.base.security.DefaultSystemAccessControl)11 Identity (io.trino.spi.security.Identity)11 Set (java.util.Set)11 Assert.assertEquals (org.testng.Assert.assertEquals)11 QueryId (io.trino.spi.QueryId)10 CatalogSchemaName (io.trino.spi.connector.CatalogSchemaName)10 TestingEventListenerManager.emptyEventListenerManager (io.trino.testing.TestingEventListenerManager.emptyEventListenerManager)10 TransactionBuilder.transaction (io.trino.transaction.TransactionBuilder.transaction)10 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)10