Search in sources :

Example 1 with SubjectNotSoftDeletedException

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

the class KafkaSchemaRegistry method deleteSubject.

@Override
public List<Integer> deleteSubject(String subject, boolean permanentDelete) throws SchemaRegistryException {
    // Ensure cache is up-to-date before any potential writes
    try {
        if (isReadOnlyMode(subject)) {
            throw new OperationNotPermittedException("Subject " + subject + " is in read-only mode");
        }
        kafkaStore.waitUntilKafkaReaderReachesLastOffset(subject, kafkaStoreTimeoutMs);
        List<Integer> deletedVersions = new ArrayList<>();
        int deleteWatermarkVersion = 0;
        Iterator<Schema> schemasToBeDeleted = getAllVersions(subject, permanentDelete);
        while (schemasToBeDeleted.hasNext()) {
            deleteWatermarkVersion = schemasToBeDeleted.next().getVersion();
            SchemaKey key = new SchemaKey(subject, deleteWatermarkVersion);
            if (!lookupCache.referencesSchema(key).isEmpty()) {
                throw new ReferenceExistsException(key.toString());
            }
            if (permanentDelete) {
                SchemaValue schemaValue = (SchemaValue) lookupCache.get(key);
                if (schemaValue != null && !schemaValue.isDeleted()) {
                    throw new SubjectNotSoftDeletedException(subject);
                }
            }
            deletedVersions.add(deleteWatermarkVersion);
        }
        if (!permanentDelete) {
            DeleteSubjectKey key = new DeleteSubjectKey(subject);
            DeleteSubjectValue value = new DeleteSubjectValue(subject, deleteWatermarkVersion);
            kafkaStore.put(key, value);
            if (getMode(subject) != null) {
                deleteMode(subject);
            }
            if (getCompatibilityLevel(subject) != null) {
                deleteCompatibility(subject);
            }
        } else {
            for (Integer version : deletedVersions) {
                kafkaStore.put(new SchemaKey(subject, version), null);
            }
        }
        return deletedVersions;
    } 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 subject in the" + " backend Kafka store", e);
    }
}
Also used : ReferenceExistsException(io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Schema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) ArrayList(java.util.ArrayList) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) SubjectNotSoftDeletedException(io.confluent.kafka.schemaregistry.exceptions.SubjectNotSoftDeletedException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException) StoreTimeoutException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) SchemaRegistryTimeoutException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)

Aggregations

ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)1 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)1 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)1 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)1 ReferenceExistsException (io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException)1 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)1 SchemaRegistryTimeoutException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)1 SubjectNotSoftDeletedException (io.confluent.kafka.schemaregistry.exceptions.SubjectNotSoftDeletedException)1 StoreException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)1 StoreTimeoutException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException)1 ArrayList (java.util.ArrayList)1