/** {@inheritDoc} */ @Override public SchemaEntry getSchemaEntry(Schema schema) throws IOException { return getSchemaEntry(getSchemaHash(schema)); }
/** {@inheritDoc} */ @Override public Schema getSchema(BytesKey schemaHash) throws IOException { final SchemaEntry entry = getSchemaEntry(schemaHash); return (entry == null) ? null : entry.getSchema(); }
/** {@inheritDoc} */ @Override public synchronized Schema getSchema(long schemaId) throws IOException { final SchemaEntry entry = getSchemaEntry(schemaId); return (entry == null) ? null : entry.getSchema(); }
/** * Looks up a schema entry given an Avro schema object. * * Looks first in-memory. If the schema is not known in-memory, looks in the HTables. * * @param schema Avro schema to look up. * @return Either the pre-existing entry for the specified schema, or a newly created entry. * @throws IOException on I/O error. */ private synchronized SchemaEntry getOrCreateSchemaEntry(final Schema schema) throws IOException { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot get or create schema entry from SchemaTable instance in state %s.", state); final BytesKey schemaHash = getSchemaHash(schema); final SchemaEntry knownEntry = getSchemaEntry(schemaHash); if (knownEntry != null) { return knownEntry; } // Schema is unknown, both in-memory and in-table. // Allocate a new schema ID and write it down to the tables: return storeInMemory(registerNewSchemaInTable(schema, schemaHash)); }