Search in sources :

Example 1 with BlockEncodingSerde

use of io.prestosql.spi.block.BlockEncodingSerde in project hetu-core by openlookeng.

the class SplitCacheStateManager method startStateServices.

@PostConstruct
public void startStateServices() {
    if (!PropertyService.getBooleanProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED)) {
        log.info("Split cache map feature is disabled.");
        return;
    }
    if (!PropertyService.getBooleanProperty(HetuConstant.MULTI_COORDINATOR_ENABLED)) {
        return;
    }
    BlockEncodingSerde blockEncodingSerde = metadata.getFunctionAndTypeManager().getBlockEncodingSerde();
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TypeDeserializer(metadata)).addSerializer(Block.class, new BlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new BlockJsonSerde.Deserializer(blockEncodingSerde)).addKeyDeserializer(SplitKey.class, new SplitKey.KeyDeserializer()));
    AtomicReference<InitializationStatus> status = new AtomicReference<>(InitializationStatus.INITIALIZING);
    // Async: One-shot action. Fetch split cache map info from state store if available
    if (initializer == null) {
        final Duration delay = new Duration(2, TimeUnit.SECONDS);
        final Duration timeout = new Duration(60, TimeUnit.SECONDS);
        initializer = new SplitCacheStateInitializer(provider, splitCacheMap, delay, timeout, mapper, status);
        initializer.start();
    }
    if (updater == null) {
        Duration updateInterval = PropertyService.getDurationProperty(HetuConstant.SPLIT_CACHE_STATE_UPDATE_INTERVAL);
        // Async Task - Periodically update state store with local split cache map changes
        updater = new SplitCacheStateUpdater(provider, splitCacheMap, updateInterval, mapper, status);
        updater.start();
    }
    log.info("-- Initialized split cache map state store and started state services --");
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(io.airlift.units.Duration) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) InitializationStatus(io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) BlockJsonSerde(io.prestosql.block.BlockJsonSerde) Block(io.prestosql.spi.block.Block) TypeDeserializer(io.prestosql.type.TypeDeserializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) PostConstruct(javax.annotation.PostConstruct)

Example 2 with BlockEncodingSerde

use of io.prestosql.spi.block.BlockEncodingSerde in project hetu-core by openlookeng.

the class ExecutingStatementResource method getQuery.

protected Query getQuery(QueryId queryId, String slug) {
    Query query = queries.get(queryId);
    if (query != null) {
        if (!query.isSlugValid(slug)) {
            throw badRequest(NOT_FOUND, "Query not found");
        }
        return query;
    }
    // this is the first time the query has been accessed on this coordinator
    Session session;
    try {
        if (!queryManager.isQuerySlugValid(queryId, slug)) {
            throw badRequest(NOT_FOUND, "Query not found");
        }
        session = queryManager.getQuerySession(queryId);
    } catch (NoSuchElementException e) {
        throw badRequest(NOT_FOUND, "Query not found");
    }
    query = queries.computeIfAbsent(queryId, id -> {
        ExchangeClient exchangeClient = exchangeClientSupplier.get(new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), ExecutingStatementResource.class.getSimpleName()));
        if (SystemSessionProperties.isSnapshotEnabled(session)) {
            exchangeClient.setSnapshotEnabled(snapshotUtils.getOrCreateQuerySnapshotManager(queryId, session));
        }
        return Query.create(session, slug, queryManager, exchangeClient, responseExecutor, timeoutExecutor, blockEncodingSerde);
    });
    return query;
}
Also used : Produces(javax.ws.rs.Produces) SystemSessionProperties(io.prestosql.SystemSessionProperties) Path(javax.ws.rs.Path) Duration(io.airlift.units.Duration) QueryManager(io.prestosql.execution.QueryManager) PreDestroy(javax.annotation.PreDestroy) MediaType(javax.ws.rs.core.MediaType) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) QueryParam(javax.ws.rs.QueryParam) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) SnapshotUtils(io.prestosql.snapshot.SnapshotUtils) HeaderParam(javax.ws.rs.HeaderParam) X_FORWARDED_PROTO(com.google.common.net.HttpHeaders.X_FORWARDED_PROTO) PRESTO_SET_ROLE(io.prestosql.client.PrestoHeaders.PRESTO_SET_ROLE) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) QueryStatusInfo(io.prestosql.client.QueryStatusInfo) Suspended(javax.ws.rs.container.Suspended) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AsyncResponseHandler.bindAsyncResponse(io.airlift.jaxrs.AsyncResponseHandler.bindAsyncResponse) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) PRESTO_CLEAR_TRANSACTION_ID(io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_TRANSACTION_ID) PathParam(javax.ws.rs.PathParam) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) GET(javax.ws.rs.GET) PRESTO_SET_CATALOG(io.prestosql.client.PrestoHeaders.PRESTO_SET_CATALOG) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) PRESTO_CLEAR_SESSION(io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_SESSION) ExchangeClient(io.prestosql.operator.ExchangeClient) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) QueryResults(io.prestosql.client.QueryResults) ForStatementResource(io.prestosql.server.ForStatementResource) PRESTO_SET_PATH(io.prestosql.client.PrestoHeaders.PRESTO_SET_PATH) PRESTO_STARTED_TRANSACTION_ID(io.prestosql.client.PrestoHeaders.PRESTO_STARTED_TRANSACTION_ID) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) Futures(com.google.common.util.concurrent.Futures) URLEncoder(java.net.URLEncoder) PRESTO_SET_SCHEMA(io.prestosql.client.PrestoHeaders.PRESTO_SET_SCHEMA) PRESTO_ADDED_PREPARE(io.prestosql.client.PrestoHeaders.PRESTO_ADDED_PREPARE) Ordering(com.google.common.collect.Ordering) ExchangeClientSupplier(io.prestosql.operator.ExchangeClientSupplier) PRESTO_DEALLOCATED_PREPARE(io.prestosql.client.PrestoHeaders.PRESTO_DEALLOCATED_PREPARE) PRESTO_SET_SESSION(io.prestosql.client.PrestoHeaders.PRESTO_SET_SESSION) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ExchangeClient(io.prestosql.operator.ExchangeClient) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) NoSuchElementException(java.util.NoSuchElementException) Session(io.prestosql.Session)

Example 3 with BlockEncodingSerde

use of io.prestosql.spi.block.BlockEncodingSerde in project hetu-core by openlookeng.

the class TestSplitCacheChangesListener method setup.

@BeforeSuite
public void setup() {
    Metadata metadata = MetadataManager.createTestMetadataManager();
    PropertyService.setProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED, true);
    BlockEncodingSerde encodingSerde = metadata.getFunctionAndTypeManager().getBlockEncodingSerde();
    objectMapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TypeDeserializer(metadata)).addSerializer(Block.class, new BlockJsonSerde.Serializer(encodingSerde)).addDeserializer(Block.class, new BlockJsonSerde.Deserializer(encodingSerde)).addKeyDeserializer(SplitKey.class, new SplitKey.KeyDeserializer()));
}
Also used : EntryEventType(io.prestosql.spi.statestore.listener.EntryEventType) Type(io.prestosql.spi.type.Type) BlockJsonSerde(io.prestosql.block.BlockJsonSerde) TypeDeserializer(io.prestosql.type.TypeDeserializer) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) Metadata(io.prestosql.metadata.Metadata) Block(io.prestosql.spi.block.Block) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) TestingBlockEncodingSerde(io.prestosql.spi.block.TestingBlockEncodingSerde) TypeDeserializer(io.prestosql.type.TypeDeserializer) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 4 with BlockEncodingSerde

use of io.prestosql.spi.block.BlockEncodingSerde in project hetu-core by openlookeng.

the class GroupIdOperator method capture.

@Override
public Object capture(BlockEncodingSerdeProvider serdeProvider) {
    GroupIdOperatorState myState = new GroupIdOperatorState();
    myState.operatorContext = operatorContext.capture(serdeProvider);
    BlockEncodingSerde blockSerde = serdeProvider.getBlockEncodingSerde();
    myState.nullBlocks = new byte[nullBlocks.length][];
    for (int i = 0; i < nullBlocks.length; i++) {
        myState.nullBlocks[i] = serializeBlock(nullBlocks[i], blockSerde);
    }
    myState.groupIdBlocks = new byte[groupIdBlocks.length][];
    for (int i = 0; i < groupIdBlocks.length; i++) {
        myState.groupIdBlocks[i] = serializeBlock(groupIdBlocks[i], blockSerde);
    }
    myState.currentGroupingSet = currentGroupingSet;
    myState.finishing = finishing;
    return myState;
}
Also used : BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde)

Example 5 with BlockEncodingSerde

use of io.prestosql.spi.block.BlockEncodingSerde in project hetu-core by openlookeng.

the class GroupIdOperator method restore.

@Override
public void restore(Object state, BlockEncodingSerdeProvider serdeProvider) {
    GroupIdOperatorState myState = (GroupIdOperatorState) state;
    this.operatorContext.restore(myState.operatorContext, serdeProvider);
    BlockEncodingSerde blockSerde = serdeProvider.getBlockEncodingSerde();
    for (int i = 0; i < nullBlocks.length; i++) {
        this.nullBlocks[i] = deserializeBlock(myState.nullBlocks[i], blockSerde);
    }
    for (int i = 0; i < groupIdBlocks.length; i++) {
        this.groupIdBlocks[i] = deserializeBlock(myState.groupIdBlocks[i], blockSerde);
    }
    this.currentGroupingSet = myState.currentGroupingSet;
    this.finishing = myState.finishing;
}
Also used : BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde)

Aggregations

BlockEncodingSerde (io.prestosql.spi.block.BlockEncodingSerde)9 Block (io.prestosql.spi.block.Block)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)4 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)4 BlockJsonSerde (io.prestosql.block.BlockJsonSerde)4 TypeDeserializer (io.prestosql.type.TypeDeserializer)4 Metadata (io.prestosql.metadata.Metadata)3 Duration (io.airlift.units.Duration)2 TestingBlockEncodingSerde (io.prestosql.spi.block.TestingBlockEncodingSerde)2 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)2 Type (io.prestosql.spi.type.Type)2 BeforeSuite (org.testng.annotations.BeforeSuite)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Ordering (com.google.common.collect.Ordering)1 X_FORWARDED_PROTO (com.google.common.net.HttpHeaders.X_FORWARDED_PROTO)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 BoundedExecutor (io.airlift.concurrent.BoundedExecutor)1