Skip to content

DROP TYPE leaves the type's ALIASES in the schema type map, so the dropped type is re-serialised into schema.json and comes back alive after a restart #8169

Closed

Description

@ruispereira

Summary

DROP TYPE does not remove the dropped type's ALIASES from the schema's shared type map. LocalSchema.dropType
removes exactly one key - the type's own name - and nothing anywhere removes the alias keys, which still point
at the dropped LocalDocumentType instance.

Three consequences, all reproduced:

  1. existsType("<alias>") keeps answering true and getType("<alias>") keeps returning the dropped,
    bucket-less type.
  2. A later ALTER TYPE Other ALIASES <alias> is refused with "already used by type 'Order'", naming a type
    that no longer exists. This one is new: LocalDocumentType.setAliases does a check-then-put on the shared type map with no write lock, the two holes just closed in rename(), createProperty and dropProperty #8064's fix replaced the check-then-put with an atomic
    putIfAbsent, so the stale entry is now a hard refusal rather than a silently overwritten map value.
  3. Worse than either, the dropped type is written back into schema.json and comes back alive after a
    restart. serializeConfiguration iterates typeMap().values() and keys each entry by t.getName(), and
    the dropped instance is still reachable through its alias key - so it is re-serialised under its own name,
    with zero buckets, and existsType("Order") answers true again on the next open.

This is a different mechanism from #8064 (which was about the reservation in setAliases not being atomic) and
is not a regression from it; #8064's fix only turns consequence 2 from silent into loud.

Where (HEAD 9a88be7)

The drop removes one key, the type's own name -
engine/src/main/java/com/arcadedb/schema/LocalSchema.java:2465-2466

        if (typeMap().remove(typeName) == null)
          throw new SchemaException("Type '" + typeName + "' not found");

Everything else the drop tears down is enumerated just above it (indexes, edge files, buckets, the TimeSeries
engine); aliases are not among them. The only other typeMap().remove call sites in the tree are inside
LocalDocumentType - :376 and :385 for rename(), :589 and :596 inside setAliases - so no path
deregisters an alias on drop.

The lookups that then answer for a dropped type -
engine/src/main/java/com/arcadedb/schema/LocalSchema.java:2355-2359 and :2388-2390

  public LocalDocumentType getType(final String typeName) {
    final LocalDocumentType t = typeMap().get(typeName);
    if (t == null)
      throw new SchemaException("Type with name '" + typeName + "' was not found");
    return t;
  }
  public boolean existsType(final String typeName) {
    return typeMap().containsKey(typeName);
  }

The refusal that now names a non-existent type, from #8064's atomic reservation -
engine/src/main/java/com/arcadedb/schema/LocalDocumentType.java:575-583

          final LocalDocumentType owner = schema.typeMap().putIfAbsent(alias, this);
          if (owner != null)
            ...
            throw new SchemaException(owner == this ?
                "Cannot set alias '" + alias + "' for type '" + name + "' because it is the name of the type itself" :
                "Cannot set alias '" + alias + "' for type '" + name + "' because it is already used by type '"
                    + owner.getName() + "'");

And the resurrection, in the serialiser that dropType's own finally calls through saveConfiguration() -
engine/src/main/java/com/arcadedb/schema/LocalSchema.java:3534-3538

    final JSONObject types = new JSONObject();
    root.put("types", types);

    for (final DocumentType t : typeMap().values())
      types.put(t.getName(), t.toJSON());

typeMap().values() still contains the dropped instance, once for each alias key that survived.

Repro

On a fresh embedded database:

CREATE DOCUMENT TYPE Order;
CREATE DOCUMENT TYPE Invoice;
ALTER TYPE Order ALIASES PO;
DROP TYPE Order;

Same session:

before drop: existsType(PO)=true
after  drop: existsType(Order)=false
after  drop: existsType(PO)=true
after  drop: getType(PO)=Order buckets=0
ALTER TYPE Invoice ALIASES PO -> SchemaException: Cannot set alias 'PO' for type 'Invoice' because it is already used by type 'Order'

The refusal names Order, which the line above proves does not exist.

Close the database and reopen it. schema.json as written by the drop:

{"Invoice":{"type":"d","parents":[],"buckets":["Invoice_0"],"aliases":[],"properties":{},"indexes":{},"custom":{}},
 "Order":{"type":"d","parents":[],"buckets":[],"aliases":["PO"],"properties":{},"indexes":{},"custom":{}}}

and after the reopen:

after reopen : existsType(Order)=true existsType(PO)=true
after reopen : INSERT INTO Order -> SchemaException: Cannot retrieve a bucket for type 'Order' because there are no buckets associated

The dropped type is back, permanently, as an unusable bucket-less type that has to be dropped a second time -
and dropping it a second time leaves the alias behind again.

Suggested fix

Deregister the type's aliases in dropType, alongside the name:

        for (final String alias : type.getAliases())
          typeMap().remove(alias, type);
        if (typeMap().remove(typeName, type) == null)
          throw new SchemaException("Type '" + typeName + "' not found");

remove(key, value) rather than remove(key) for the same reason setAliases uses it: an alias that has
since been reassigned to another type must not be taken away from it.

A regression test should assert, after DROP TYPE of a type carrying an alias: existsType(alias) is false,
getType(alias) throws, a later ALTER TYPE Other ALIASES <alias> succeeds, and - the one that matters most -
the type does not reappear after a close and reopen. It is also worth asserting that getTypes() no longer
contains the dropped instance; it is deduplicated by LinkedHashSet (LocalSchema.java:2352) but the stale
alias entry keeps the instance in values(), so it is listed today.

Scope / confidence

Reproduced end to end against this HEAD; every line of output above is from the run, including the
schema.json contents. Pre-existing, and independent of #8064 - that fix is only what turns the alias
collision into a loud refusal instead of a silent overwrite. Severity is medium to high: the on-disk schema
is corrupted by an ordinary DROP TYPE, the corruption survives restarts, and the only symptom an operator
sees is a nonsensical error message naming a type they deleted.

Activity

  1. added
    engine
    severity:critical
    storage
    on Sep 22, 2026
  2. added this to the 26.10.1 milestone on Sep 22, 2026
  3. self-assigned this
    on Sep 22, 2026
  4. added
    in progress
    on Sep 22, 2026
  5. added a commit that references this issue on Sep 22, 2026
  6. robfrank commented on Sep 22, 2026

    @robfrank
    Collaborator

    Fixed in #8195.

    DROP TYPE removed only the type's own key from the schema's type map and left every alias key still pointing at the dropped, bucket-less instance. The save that dropType performs in its own finally then serialised that instance straight back into schema.json under the type's real name with zero buckets, which is why the type reappeared at the next open, why existsType(<alias>) kept answering true, why a later ALTER TYPE ... ALIASES refused the alias while naming a type that no longer existed, and why CHECK DATABASE still walked it. The type is now deregistered under every name it answers to, so nothing survives the drop to be written back.

    Working on it turned up a second way in that you did not report: getType() resolves aliases, so the argument to DROP TYPE can itself be an alias, and three places compared the caller's raw string against the canonical one. That meant DROP TYPE <alias> could drop a materialized view's or continuous aggregate's source type out from under it. The canonical name is now resolved once up front and used for those guards.

    Still open


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengineseverity:criticalstorage

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions