Search in sources :

Example 6 with SchemaRegistryTimeoutException

use of io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException in project schema-registry by confluentinc.

the class KafkaSchemaRegistry method deleteSchemaVersion.

@Override
public void deleteSchemaVersion(String subject, Schema schema, boolean permanentDelete) throws SchemaRegistryException {
    try {
        if (isReadOnlyMode(subject)) {
            throw new OperationNotPermittedException("Subject " + subject + " is in read-only mode");
        }
        SchemaKey key = new SchemaKey(subject, schema.getVersion());
        if (!lookupCache.referencesSchema(key).isEmpty()) {
            throw new ReferenceExistsException(key.toString());
        }
        SchemaValue schemaValue = (SchemaValue) lookupCache.get(key);
        if (permanentDelete && schemaValue != null && !schemaValue.isDeleted()) {
            throw new SchemaVersionNotSoftDeletedException(subject, schema.getVersion().toString());
        }
        // Ensure cache is up-to-date before any potential writes
        kafkaStore.waitUntilKafkaReaderReachesLastOffset(subject, kafkaStoreTimeoutMs);
        if (!permanentDelete) {
            schemaValue = new SchemaValue(schema);
            schemaValue.setDeleted(true);
            kafkaStore.put(key, schemaValue);
            if (!getAllVersions(subject, false).hasNext()) {
                if (getMode(subject) != null) {
                    deleteMode(subject);
                }
                if (getCompatibilityLevel(subject) != null) {
                    deleteCompatibility(subject);
                }
            }
        } else {
            kafkaStore.put(key, null);
        }
    } catch (StoreTimeoutException te) {
        throw new SchemaRegistryTimeoutException("Write to the Kafka store timed out while", te);
    } catch (StoreException e) {
        throw new SchemaRegistryStoreException("Error while deleting the schema for subject '" + subject + "' in the backend Kafka store", e);
    }
}
Also used : ReferenceExistsException(io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException) StoreTimeoutException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) SchemaRegistryTimeoutException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException) SchemaVersionNotSoftDeletedException(io.confluent.kafka.schemaregistry.exceptions.SchemaVersionNotSoftDeletedException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)

Example 7 with SchemaRegistryTimeoutException

use of io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException in project schema-registry by confluentinc.

the class KafkaSchemaRegistry method init.

@Override
public void init() throws SchemaRegistryException {
    try {
        kafkaStore.init();
    } catch (StoreInitializationException e) {
        throw new SchemaRegistryInitializationException("Error initializing kafka store while initializing schema registry", e);
    }
    try {
        config.checkBootstrapServers();
        log.info("Joining schema registry with Kafka-based coordination");
        leaderElector = new KafkaGroupLeaderElector(config, myIdentity, this);
        leaderElector.init();
    } catch (SchemaRegistryStoreException e) {
        throw new SchemaRegistryInitializationException("Error electing leader while initializing schema registry", e);
    } catch (SchemaRegistryTimeoutException e) {
        throw new SchemaRegistryInitializationException(e);
    }
}
Also used : StoreInitializationException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreInitializationException) KafkaGroupLeaderElector(io.confluent.kafka.schemaregistry.leaderelector.kafka.KafkaGroupLeaderElector) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) SchemaRegistryInitializationException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryInitializationException) SchemaRegistryTimeoutException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)

Aggregations

SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)7 SchemaRegistryTimeoutException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)7 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)3 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)3 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)3 ReferenceExistsException (io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException)3 StoreException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)3 StoreTimeoutException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException)3 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)2 IdDoesNotMatchException (io.confluent.kafka.schemaregistry.exceptions.IdDoesNotMatchException)2 IncompatibleSchemaException (io.confluent.kafka.schemaregistry.exceptions.IncompatibleSchemaException)2 SchemaRegistryException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException)2 SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)2 SchemaVersionNotSoftDeletedException (io.confluent.kafka.schemaregistry.exceptions.SchemaVersionNotSoftDeletedException)2 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)2 PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)2 Operation (io.swagger.v3.oas.annotations.Operation)2 ArrayList (java.util.ArrayList)2 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)1 RegisterSchemaResponse (io.confluent.kafka.schemaregistry.client.rest.entities.requests.RegisterSchemaResponse)1