public final class SchemaRegistry extends Object
SchemaRegistry is responsible for managing the schema registry store.
A schema is uniquely identified by an ID and contains other metadata about the schema, such as a name, description,
type, etc. By itself, a schema does not contain an actual schema object. It is more like a group of schema entries.
A schema entry contains the actual schema bytes and is uniquely identified by the schema it belongs to and a
version number. A schema entry is added to a schema and can also be removed. In addition, each schema keeps track
of the latest schema entry.
Schema information is stored in two tables, one for the schema metadata and one for the schema entries.
The schema metadata table contains nine columns:
namespace, id, name, description, created, updated, type, auto, current
The namespace and id columns form the primary key for the metadata table. The current column points to the latest
schema entry version, and the auto column is used for generating version numbers for any new schema entries.
The schema entry table contains four columns:
namespace, id, version, schema
The namespace, id, and version columns form the primary key, while the schema column contains the actual schema.| Modifier and Type | Field and Description |
|---|---|
static io.cdap.cdap.spi.data.table.StructuredTableSpecification |
ENTRY_TABLE_SPEC |
static io.cdap.cdap.spi.data.table.StructuredTableSpecification |
META_TABLE_SPEC |
| Constructor and Description |
|---|
SchemaRegistry(io.cdap.cdap.spi.data.StructuredTable metaTable,
io.cdap.cdap.spi.data.StructuredTable entryTable) |
| Modifier and Type | Method and Description |
|---|---|
long |
add(NamespacedId id,
byte[] specification)
Adds a new entry to the schema.
|
void |
delete(NamespacedId id)
Deletes the schema and all associated entries.
|
static SchemaRegistry |
get(io.cdap.cdap.spi.data.StructuredTableContext context) |
SchemaEntry |
getEntry(NamespacedId id)
Get the latest entry of the specified schema if it exists
|
SchemaEntry |
getEntry(NamespacedId id,
long version)
Get a specific version of the specified schema.
|
Set<Long> |
getVersions(NamespacedId id)
Return all versions of the specified schema.
|
boolean |
hasSchema(NamespacedId id)
Checks if there is a schema entry, its not necessary that there are any version of schema registered.
|
boolean |
hasSchema(NamespacedId id,
long version)
Checks if schema id and version combination exists in the registry.
|
void |
remove(NamespacedId id,
long version)
Deletes a specified version of the schema.
|
void |
write(SchemaDescriptor schemaDescriptor)
Writes an entry in the schema registry.
|
public static final io.cdap.cdap.spi.data.table.StructuredTableSpecification META_TABLE_SPEC
public static final io.cdap.cdap.spi.data.table.StructuredTableSpecification ENTRY_TABLE_SPEC
public SchemaRegistry(io.cdap.cdap.spi.data.StructuredTable metaTable,
io.cdap.cdap.spi.data.StructuredTable entryTable)
public static SchemaRegistry get(io.cdap.cdap.spi.data.StructuredTableContext context)
public void write(SchemaDescriptor schemaDescriptor) throws IOException
schemaDescriptor - information about the schema to writeIOException - if there was an error reading from or writing to the storage systempublic void delete(NamespacedId id) throws IOException
id - of the schema to deleteIOException - if there was an error reading from or writing to the storage systempublic long add(NamespacedId id, byte[] specification) throws IOException
id - the id of the schema to addspecification - the schema to be addedSchemaNotFoundException - if the schema does not existIOException - if there was an error reading from or writing to the storage systempublic void remove(NamespacedId id, long version) throws IOException
id - of the schema to be deleted.version - of the schema to be deleted.SchemaNotFoundException - if the schema does not existIOException - if there was an error reading from or writing to the storage systempublic boolean hasSchema(NamespacedId id, long version) throws IOException
id - of the schema to be checkedversion - version of the schema to be checked.SchemaNotFoundException - if the schema does not existIOException - if there was an error reading from or writing to the storage systempublic boolean hasSchema(NamespacedId id) throws IOException
id - the id of the schema to checkIOException - if there was an error reading from or writing to the storage systempublic Set<Long> getVersions(NamespacedId id) throws IOException
id - the schema idSchemaNotFoundException - if the schema does not existIOException - if there was an error reading from or writing to the storage systempublic SchemaEntry getEntry(NamespacedId id, long version) throws IOException
id - the schema idversion - the entry version to getSchemaNotFoundException - if the schema does not existIOException - if there was an error reading from or writing to the storage systempublic SchemaEntry getEntry(NamespacedId id) throws IOException
id - the schema idSchemaNotFoundException - if the schema or its latest entry could not be foundIOException - if there was an error reading from or writing to the storage systemCopyright © 2024 CDAP Licensed under the Apache License, Version 2.0.