CatalogHolder

internal class CatalogHolder

The one mutable thing in the type system: which TypeCatalog is the current one for a database.

A catalog is a value and is replaced whole rather than edited, so something has to hold which value is current, and that something cannot be the catalog. This is it, and it is deliberately the whole of it - it does not know that a converter or a codec exists, only how to put one catalog in the place of another, and, where the database is listed as several servers, which cluster those catalogs are read from.

lock guards more than the swap, which is why it is a lock rather than a compare-and-set: GlobalCatalogStore.ensureLoaded holds it across the round trip that reads the catalog out of the database, so twenty connections opening at once read it once between them. A lock that spans that has to live on something outlasting any single catalog, which is the second reason this class exists.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Everything the driver knows about this database, as one value. Read without a lock, from anywhere.

Link copied to clipboard

Whether the catalog has been read from the database yet, for the double-checked guard around that read.

Link copied to clipboard

Held across a catalog load as well as across a swap - see the note on the class.

Link copied to clipboard

The system identifier of the cluster this catalog belongs to, fixed by the first server admitted. null until then - and for good where the database is a single server, which is never asked.

Functions

Link copied to clipboard
fun admit(server: ServerAddress, identifier: Long): Long

Admits server, which reported identifier, if that is the cluster this catalog belongs to - which the first server admitted decides.

Link copied to clipboard

Whether server has been admitted already, and need not be asked again.

Link copied to clipboard
fun update(transform: (TypeCatalog) -> TypeCatalog)

Puts the catalog transform derives in the place of the current one.