Search in sources :

Example 1 with Catalog

use of io.prestosql.metadata.Catalog in project hetu-core by openlookeng.

the class TestTransactionManager method registerConnector.

private static void registerConnector(CatalogManager catalogManager, TransactionManager transactionManager, String catalogName, CatalogName catalog, Connector connector) {
    CatalogName systemId = createSystemTablesCatalogName(catalog);
    InternalNodeManager nodeManager = new InMemoryNodeManager();
    Metadata metadata = createTestMetadataManager(catalogManager);
    catalogManager.registerCatalog(new Catalog(catalogName, catalog, connector, createInformationSchemaCatalogName(catalog), new InformationSchemaConnector(catalogName, nodeManager, metadata, new AllowAllAccessControl()), systemId, new SystemConnector(nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, catalog))));
}
Also used : SystemConnector(io.prestosql.connector.system.SystemConnector) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) InternalNodeManager(io.prestosql.metadata.InternalNodeManager) AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) Metadata(io.prestosql.metadata.Metadata) CatalogName.createSystemTablesCatalogName(io.prestosql.spi.connector.CatalogName.createSystemTablesCatalogName) CatalogName.createInformationSchemaCatalogName(io.prestosql.spi.connector.CatalogName.createInformationSchemaCatalogName) CatalogName(io.prestosql.spi.connector.CatalogName) Catalog(io.prestosql.metadata.Catalog) InMemoryNodeManager(io.prestosql.metadata.InMemoryNodeManager)

Example 2 with Catalog

use of io.prestosql.metadata.Catalog in project hetu-core by openlookeng.

the class TestCarbonAutoVacuum method testAutoVacuum.

@Test
public void testAutoVacuum() throws SQLException {
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable2");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable3");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable4");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable1(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable1 VALUES (10, 11)");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable2(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (10, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (20, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (30, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (30, 11)");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable3 as select a, b from  carbontestdb1.autovacuumtable2 ");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable4(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (10, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (20, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (30, 12)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (40, 13)");
    CatalogManager catalogManager = hetuServer.getCatalog();
    List<Catalog> catalogs = catalogManager.getCatalogs();
    Catalog catalog = null;
    for (Catalog catalog1 : catalogs) {
        if (catalog1.getConnectorCatalogName().getCatalogName().equals("carbondata")) {
            catalog = catalog1;
            break;
        }
    }
    Connector connector;
    ConnectorMetadata connectorMetadata = null;
    List<ConnectorVacuumTableInfo> tables;
    List<String> tablesNames = new ArrayList<>();
    try {
        CarbondataAutoVacuumThread.enableTracingVacuumTask(true);
        assertNotNull(catalog);
        connector = catalog.getConnector(catalog.getConnectorCatalogName());
        connectorMetadata = connector.getConnectorMetadata();
        connectorMetadata.getTablesForVacuum();
    } catch (Exception e) {
        logger.debug(e.getMessage());
    }
    CarbondataAutoVacuumThread.waitForSubmittedVacuumTasksFinish();
    CarbondataAutoVacuumThread.enableTracingVacuumTask(false);
    tables = connectorMetadata.getTablesForVacuum();
    if (tables != null && 0 != tables.size()) {
        for (ConnectorVacuumTableInfo vacuumTable : tables) {
            tablesNames.add(vacuumTable.getSchemaTableName());
        }
    }
    assertTrue(tablesNames.contains("carbontestdb1.autovacuumtable4"));
    assertTrue(tablesNames.contains("carbontestdb1.autovacuumtable2"));
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable2");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable3");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable4");
}
Also used : ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) Connector(io.prestosql.spi.connector.Connector) ArrayList(java.util.ArrayList) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) CatalogManager(io.prestosql.metadata.CatalogManager) Catalog(io.prestosql.metadata.Catalog) SQLException(java.sql.SQLException) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 3 with Catalog

use of io.prestosql.metadata.Catalog in project hetu-core by openlookeng.

the class AutoVacuumScanner method startVacuum.

private void startVacuum(Catalog catalog, String vacuumTable, boolean isFull) {
    String catalogNameVacuumTable = catalog.getCatalogName() + "." + vacuumTable;
    if (vacuumInProgressMap.containsKey(catalogNameVacuumTable)) {
        log.debug("return Present in vacuumInProgressMap %s ", catalogNameVacuumTable);
        return;
    }
    long attempts = 0;
    QueryId queryId = dispatchManager.createQueryId();
    String slug = "x" + randomUUID().toString().toLowerCase(ENGLISH).replace("-", "");
    String vacuumQuery;
    if (isFull) {
        vacuumQuery = "vacuum table " + catalogNameVacuumTable + "  full";
    } else {
        vacuumQuery = "vacuum table " + catalogNameVacuumTable;
    }
    Session.SessionBuilder sessionBuilder = Session.builder(sessionPropertyManager).setQueryId(queryId).setIdentity(new Identity("openLooKeng", Optional.empty())).setSource("auto-vacuum");
    Session session = sessionBuilder.build();
    AutoVacuumSessionContext sessionContext = new AutoVacuumSessionContext(session);
    vacuumInProgressMap.put(catalogNameVacuumTable, System.currentTimeMillis());
    log.debug("Query.create queryId %s  catalogNameVacuumTable: %s ", queryId.toString(), catalogNameVacuumTable);
    ListenableFuture<?> lf = waitForDispatched(queryId, slug, sessionContext, vacuumQuery);
    Futures.addCallback(lf, new FutureCallback<Object>() {

        @Override
        public void onSuccess(@Nullable Object result) {
            try {
                DispatchQuery dispatchQuery = dispatchManager.getQuery(queryId);
                dispatchQuery.addStateChangeListener((state) -> {
                    Query query = getQuery(queryId, slug);
                    if ((null != query) && (!dispatchManager.getQueryInfo(queryId).getState().isDone())) {
                        query.waitForResults(attempts, Duration.valueOf("1s"), DataSize.valueOf("1MB"));
                    }
                    if (state.isDone()) {
                        log.debug("STATUS  %s QueryID %s Query %s", state.name(), queryId.toString(), vacuumQuery);
                        vacuumInProgressMap.remove(catalogNameVacuumTable);
                    }
                });
            } catch (Throwable e) {
                vacuumInProgressMap.remove(catalogNameVacuumTable);
                log.error("Filed to execute vacuum for table %s QueryID %s", catalogNameVacuumTable, queryId.toString(), e.getMessage());
            }
        }

        @Override
        public void onFailure(Throwable t) {
            vacuumInProgressMap.remove(catalogNameVacuumTable);
            log.error("Query %s request to start vacuum scan failed at queryId[%s]: %s ", vacuumQuery, queryId, t.getMessage());
        }
    }, directExecutor());
}
Also used : ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) Inject(com.google.inject.Inject) DataCenterStatementResource(io.prestosql.datacenter.DataCenterStatementResource) Duration(io.airlift.units.Duration) QueryManager(io.prestosql.execution.QueryManager) PreDestroy(javax.annotation.PreDestroy) Future(java.util.concurrent.Future) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) Map(java.util.Map) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) ENGLISH(java.util.Locale.ENGLISH) PrestoException(io.prestosql.spi.PrestoException) Query(io.prestosql.server.protocol.Query) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Identity(io.prestosql.spi.security.Identity) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) List(java.util.List) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) StandardErrorCode(io.prestosql.spi.StandardErrorCode) ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) Connector(io.prestosql.spi.connector.Connector) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExchangeClient(io.prestosql.operator.ExchangeClient) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) DispatchManager(io.prestosql.dispatcher.DispatchManager) Nullable(javax.annotation.Nullable) ForStatementResource(io.prestosql.server.ForStatementResource) FutureCallback(com.google.common.util.concurrent.FutureCallback) Futures(com.google.common.util.concurrent.Futures) UUID.randomUUID(java.util.UUID.randomUUID) Catalog(io.prestosql.metadata.Catalog) ExchangeClientSupplier(io.prestosql.operator.ExchangeClientSupplier) CatalogManager(io.prestosql.metadata.CatalogManager) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) Query(io.prestosql.server.protocol.Query) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) QueryId(io.prestosql.spi.QueryId) Identity(io.prestosql.spi.security.Identity) Session(io.prestosql.Session)

Example 4 with Catalog

use of io.prestosql.metadata.Catalog in project hetu-core by openlookeng.

the class TestAccessControlManager method registerBogusConnector.

private static CatalogName registerBogusConnector(CatalogManager catalogManager, TransactionManager transactionManager, AccessControl accessControl, String catalogName) {
    CatalogName catalog = new CatalogName(catalogName);
    Connector connector = new TpchConnectorFactory().create(catalogName, ImmutableMap.of(), new TestingConnectorContext());
    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    Metadata metadata = createTestMetadataManager(catalogManager);
    CatalogName systemId = createSystemTablesCatalogName(catalog);
    catalogManager.registerCatalog(new Catalog(catalogName, catalog, connector, createInformationSchemaCatalogName(catalog), new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl), systemId, new SystemConnector(nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, catalog))));
    return catalog;
}
Also used : SystemConnector(io.prestosql.connector.system.SystemConnector) Connector(io.prestosql.spi.connector.Connector) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) SystemConnector(io.prestosql.connector.system.SystemConnector) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) Metadata(io.prestosql.metadata.Metadata) CatalogName.createSystemTablesCatalogName(io.prestosql.spi.connector.CatalogName.createSystemTablesCatalogName) CatalogName.createInformationSchemaCatalogName(io.prestosql.spi.connector.CatalogName.createInformationSchemaCatalogName) CatalogName(io.prestosql.spi.connector.CatalogName) TestingConnectorContext(io.prestosql.testing.TestingConnectorContext) Catalog(io.prestosql.metadata.Catalog) InMemoryNodeManager(io.prestosql.metadata.InMemoryNodeManager)

Example 5 with Catalog

use of io.prestosql.metadata.Catalog in project hetu-core by openlookeng.

the class ConnectorManager method updateConnectorIds.

/**
 * update the catalogs this node own in the service announcer.
 */
public synchronized void updateConnectorIds() {
    // get existing announcement
    ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());
    Set<String> connectorIds = new LinkedHashSet<>();
    Set<String> allConnectorIds = new LinkedHashSet<>();
    // automatically build connectorIds if not configured
    List<Catalog> catalogs = catalogManager.getCatalogs();
    // add data center names to connectorIds, then NodeScheduler can schedule task to this node.
    List<String> dataCenterNames = catalogConnectorStore.getDataCenterNames();
    // if this is a dedicated coordinator, only add jmx
    if (serverConfig.isCoordinator() && !schedulerConfig.isIncludeCoordinator()) {
        catalogs.stream().map(Catalog::getConnectorCatalogName).filter(connectorId -> connectorId.getCatalogName().equals("jmx")).map(Object::toString).forEach(connectorIds::add);
    } else {
        catalogs.stream().map(Catalog::getConnectorCatalogName).map(Object::toString).forEach(connectorIds::add);
        dataCenterNames.stream().forEach(connectorIds::add);
    }
    catalogs.stream().map(Catalog::getConnectorCatalogName).map(Object::toString).forEach(allConnectorIds::add);
    dataCenterNames.stream().forEach(allConnectorIds::add);
    // build announcement with updated sources
    Map<String, String> properties = new HashMap<>();
    properties.putAll(announcement.getProperties());
    properties.put("connectorIds", Joiner.on(",").join(connectorIds));
    properties.put("allConnectorIds", Joiner.on(",").join(allConnectorIds));
    // update announcement
    try {
        Field propertiesField = announcement.getClass().getDeclaredField("properties");
        propertiesField.setAccessible(true);
        propertiesField.set(announcement, properties);
    } catch (NoSuchFieldException | IllegalAccessException ex) {
        log.error(ex, "Set announcement properties failed");
        throw new RuntimeException("Set announcement properties failed", ex);
    }
    announcer.addServiceAnnouncement(announcement);
    announcer.forceAnnounce();
    nodeManager.refreshNodes();
    log.info("Announce connector ids, ACTIVE %s, All %s", connectorIds, allConnectorIds);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Catalog(io.prestosql.metadata.Catalog) Field(java.lang.reflect.Field) ServiceAnnouncement(io.airlift.discovery.client.ServiceAnnouncement)

Aggregations

Catalog (io.prestosql.metadata.Catalog)13 CatalogManager (io.prestosql.metadata.CatalogManager)8 Connector (io.prestosql.spi.connector.Connector)7 CatalogName (io.prestosql.spi.connector.CatalogName)6 InformationSchemaConnector (io.prestosql.connector.informationschema.InformationSchemaConnector)4 SystemConnector (io.prestosql.connector.system.SystemConnector)4 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)4 InMemoryNodeManager (io.prestosql.metadata.InMemoryNodeManager)3 InternalNodeManager (io.prestosql.metadata.InternalNodeManager)3 Metadata (io.prestosql.metadata.Metadata)3 CatalogName.createInformationSchemaCatalogName (io.prestosql.spi.connector.CatalogName.createInformationSchemaCatalogName)3 CatalogName.createSystemTablesCatalogName (io.prestosql.spi.connector.CatalogName.createSystemTablesCatalogName)3 Joiner (com.google.common.base.Joiner)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableList (com.google.common.collect.ImmutableList)2 ServiceAnnouncement (io.airlift.discovery.client.ServiceAnnouncement)2 Logger (io.airlift.log.Logger)2 Session (io.prestosql.Session)2 SessionPropertyManager (io.prestosql.metadata.SessionPropertyManager)2 AccessControlManager (io.prestosql.security.AccessControlManager)2