Search in sources :

Example 1 with SchemaRegistryService

use of org.apache.pulsar.broker.service.schema.SchemaRegistryService in project pulsar by apache.

the class AbstractTopic method deleteSchema.

@Override
public CompletableFuture<SchemaVersion> deleteSchema() {
    String base = TopicName.get(getName()).getPartitionedTopicName();
    String id = TopicName.get(base).getSchemaName();
    SchemaRegistryService schemaRegistryService = brokerService.pulsar().getSchemaRegistryService();
    return BookkeeperSchemaStorage.ignoreUnrecoverableBKException(schemaRegistryService.getSchema(id)).thenCompose(schema -> {
        if (schema != null) {
            // It's different from `SchemasResource.deleteSchema`
            // because when we delete a topic, the schema
            // history is meaningless. But when we delete a schema of a topic, a new schema could be
            // registered in the future.
            log.info("Delete schema storage of id: {}", id);
            return schemaRegistryService.deleteSchemaStorage(id);
        } else {
            return CompletableFuture.completedFuture(null);
        }
    });
}
Also used : SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService)

Example 2 with SchemaRegistryService

use of org.apache.pulsar.broker.service.schema.SchemaRegistryService in project pulsar by apache.

the class AbstractTopic method addSchema.

@Override
public CompletableFuture<SchemaVersion> addSchema(SchemaData schema) {
    if (schema == null) {
        return CompletableFuture.completedFuture(SchemaVersion.Empty);
    }
    String base = TopicName.get(getName()).getPartitionedTopicName();
    String id = TopicName.get(base).getSchemaName();
    SchemaRegistryService schemaRegistryService = brokerService.pulsar().getSchemaRegistryService();
    if (allowAutoUpdateSchema()) {
        return schemaRegistryService.putSchemaIfAbsent(id, schema, getSchemaCompatibilityStrategy());
    } else {
        return schemaRegistryService.trimDeletedSchemaAndGetList(id).thenCompose(schemaAndMetadataList -> schemaRegistryService.getSchemaVersionBySchemaData(schemaAndMetadataList, schema).thenCompose(schemaVersion -> {
            if (schemaVersion == null) {
                return FutureUtil.failedFuture(new IncompatibleSchemaException("Schema not found and schema auto updating is disabled."));
            } else {
                return CompletableFuture.completedFuture(schemaVersion);
            }
        }));
    }
}
Also used : StatsBuckets(org.apache.bookkeeper.mledger.util.StatsBuckets) Arrays(java.util.Arrays) BookkeeperSchemaStorage(org.apache.pulsar.broker.service.schema.BookkeeperSchemaStorage) LoggerFactory(org.slf4j.LoggerFactory) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) ProducerBusyException(org.apache.pulsar.broker.service.BrokerServiceException.ProducerBusyException) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Pair(org.apache.commons.lang3.tuple.Pair) ResourceGroup(org.apache.pulsar.broker.resourcegroup.ResourceGroup) Map(java.util.Map) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) EnumSet(java.util.EnumSet) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) ResourceGroupPublishLimiter(org.apache.pulsar.broker.resourcegroup.ResourceGroupPublishLimiter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) HierarchyTopicPolicies(org.apache.pulsar.common.policies.data.HierarchyTopicPolicies) Objects(java.util.Objects) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) TopicTerminatedException(org.apache.pulsar.broker.service.BrokerServiceException.TopicTerminatedException) Optional(java.util.Optional) ENTRY_LATENCY_BUCKETS_USEC(org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl.ENTRY_LATENCY_BUCKETS_USEC) Queue(java.util.Queue) IncompatibleSchemaException(org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) LongAdder(java.util.concurrent.atomic.LongAdder) ProducerFencedException(org.apache.pulsar.broker.service.BrokerServiceException.ProducerFencedException) TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) CompletableFuture(java.util.concurrent.CompletableFuture) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SubType(org.apache.pulsar.common.api.proto.CommandSubscribe.SubType) Lists(com.google.common.collect.Lists) MapUtils(org.apache.commons.collections4.MapUtils) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Summary(org.apache.pulsar.broker.stats.prometheus.metrics.Summary) Logger(org.slf4j.Logger) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) MoreObjects(com.google.common.base.MoreObjects) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) TimeUnit(java.util.concurrent.TimeUnit) Policies(org.apache.pulsar.common.policies.data.Policies) ConsumerBusyException(org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException) SchemaData(org.apache.pulsar.common.protocol.schema.SchemaData) Collections(java.util.Collections) IncompatibleSchemaException(org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException) SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService)

Example 3 with SchemaRegistryService

use of org.apache.pulsar.broker.service.schema.SchemaRegistryService in project pulsar by yahoo.

the class AbstractTopic method addSchema.

@Override
public CompletableFuture<SchemaVersion> addSchema(SchemaData schema) {
    if (schema == null) {
        return CompletableFuture.completedFuture(SchemaVersion.Empty);
    }
    String base = TopicName.get(getName()).getPartitionedTopicName();
    String id = TopicName.get(base).getSchemaName();
    SchemaRegistryService schemaRegistryService = brokerService.pulsar().getSchemaRegistryService();
    if (allowAutoUpdateSchema()) {
        return schemaRegistryService.putSchemaIfAbsent(id, schema, getSchemaCompatibilityStrategy());
    } else {
        return schemaRegistryService.trimDeletedSchemaAndGetList(id).thenCompose(schemaAndMetadataList -> schemaRegistryService.getSchemaVersionBySchemaData(schemaAndMetadataList, schema).thenCompose(schemaVersion -> {
            if (schemaVersion == null) {
                return FutureUtil.failedFuture(new IncompatibleSchemaException("Schema not found and schema auto updating is disabled."));
            } else {
                return CompletableFuture.completedFuture(schemaVersion);
            }
        }));
    }
}
Also used : StatsBuckets(org.apache.bookkeeper.mledger.util.StatsBuckets) Arrays(java.util.Arrays) BookkeeperSchemaStorage(org.apache.pulsar.broker.service.schema.BookkeeperSchemaStorage) LoggerFactory(org.slf4j.LoggerFactory) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) ProducerBusyException(org.apache.pulsar.broker.service.BrokerServiceException.ProducerBusyException) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) SubscriptionPolicies(org.apache.pulsar.common.policies.data.SubscriptionPolicies) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Pair(org.apache.commons.lang3.tuple.Pair) ResourceGroup(org.apache.pulsar.broker.resourcegroup.ResourceGroup) Map(java.util.Map) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) EnumSet(java.util.EnumSet) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) ResourceGroupPublishLimiter(org.apache.pulsar.broker.resourcegroup.ResourceGroupPublishLimiter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) HierarchyTopicPolicies(org.apache.pulsar.common.policies.data.HierarchyTopicPolicies) Objects(java.util.Objects) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) TopicTerminatedException(org.apache.pulsar.broker.service.BrokerServiceException.TopicTerminatedException) Optional(java.util.Optional) ENTRY_LATENCY_BUCKETS_USEC(org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl.ENTRY_LATENCY_BUCKETS_USEC) Queue(java.util.Queue) IncompatibleSchemaException(org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) LongAdder(java.util.concurrent.atomic.LongAdder) ProducerFencedException(org.apache.pulsar.broker.service.BrokerServiceException.ProducerFencedException) TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) CompletableFuture(java.util.concurrent.CompletableFuture) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) SubType(org.apache.pulsar.common.api.proto.CommandSubscribe.SubType) Lists(com.google.common.collect.Lists) MapUtils(org.apache.commons.collections4.MapUtils) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Summary(org.apache.pulsar.broker.stats.prometheus.metrics.Summary) Logger(org.slf4j.Logger) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) MoreObjects(com.google.common.base.MoreObjects) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) TimeUnit(java.util.concurrent.TimeUnit) Policies(org.apache.pulsar.common.policies.data.Policies) ConsumerBusyException(org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException) SchemaData(org.apache.pulsar.common.protocol.schema.SchemaData) Collections(java.util.Collections) IncompatibleSchemaException(org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException) SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService)

Example 4 with SchemaRegistryService

use of org.apache.pulsar.broker.service.schema.SchemaRegistryService in project pulsar by yahoo.

the class AbstractTopic method deleteSchema.

@Override
public CompletableFuture<SchemaVersion> deleteSchema() {
    String base = TopicName.get(getName()).getPartitionedTopicName();
    String id = TopicName.get(base).getSchemaName();
    SchemaRegistryService schemaRegistryService = brokerService.pulsar().getSchemaRegistryService();
    return BookkeeperSchemaStorage.ignoreUnrecoverableBKException(schemaRegistryService.getSchema(id)).thenCompose(schema -> {
        if (schema != null) {
            // It's different from `SchemasResource.deleteSchema`
            // because when we delete a topic, the schema
            // history is meaningless. But when we delete a schema of a topic, a new schema could be
            // registered in the future.
            log.info("Delete schema storage of id: {}", id);
            return schemaRegistryService.deleteSchemaStorage(id);
        } else {
            return CompletableFuture.completedFuture(null);
        }
    });
}
Also used : SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService)

Example 5 with SchemaRegistryService

use of org.apache.pulsar.broker.service.schema.SchemaRegistryService in project incubator-pulsar by apache.

the class AbstractTopic method deleteSchema.

@Override
public CompletableFuture<SchemaVersion> deleteSchema() {
    String base = TopicName.get(getName()).getPartitionedTopicName();
    String id = TopicName.get(base).getSchemaName();
    SchemaRegistryService schemaRegistryService = brokerService.pulsar().getSchemaRegistryService();
    return BookkeeperSchemaStorage.ignoreUnrecoverableBKException(schemaRegistryService.getSchema(id)).thenCompose(schema -> {
        if (schema != null) {
            // It's different from `SchemasResource.deleteSchema`
            // because when we delete a topic, the schema
            // history is meaningless. But when we delete a schema of a topic, a new schema could be
            // registered in the future.
            log.info("Delete schema storage of id: {}", id);
            return schemaRegistryService.deleteSchemaStorage(id);
        } else {
            return CompletableFuture.completedFuture(null);
        }
    });
}
Also used : SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService)

Aggregations

SchemaRegistryService (org.apache.pulsar.broker.service.schema.SchemaRegistryService)10 List (java.util.List)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 TopicName (org.apache.pulsar.common.naming.TopicName)7 FutureUtil (org.apache.pulsar.common.util.FutureUtil)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Lists (com.google.common.collect.Lists)6 Collections (java.util.Collections)6 Map (java.util.Map)6 Objects (java.util.Objects)6 Optional (java.util.Optional)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 TimeUnit (java.util.concurrent.TimeUnit)6 Getter (lombok.Getter)6 ArrayList (java.util.ArrayList)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 IOException (java.io.IOException)4 Pair (org.apache.commons.lang3.tuple.Pair)3 IncompatibleSchemaException (org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException)3