Skip to content

Compressed schema keeps an attribute token whose store failed, leaving entries that reference it undecodable #890

Closed

Description

@vharseko

CompressedSchema.getAttributeId() registers a new token in the in-memory maps and only then writes it to the tree. When that write fails the exception is propagated - correctly, the operation fails - but the registration is left behind, so every later encode of the same attribute description takes the lock-free fast path and succeeds. Entries are then written referencing a token whose definition was never persisted, and after a restart they cannot be decoded.

Surfaced while reviewing #884; it does not belong to that PR.

The path

// opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java:296-303
id = mappings.adDecodeMap.size();
mappings.adDecodeMap.add(ad);
mappings.adEncodeMap.put(ad, id);
storeAttribute(encodeId(id), ad.getAttributeType().getNameOrOID(), ad.getOptions());

The store really can fail. PersistentCompressedSchema.store() wraps every failure of the write in a DirectoryException:

// opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/PersistentCompressedSchema.java:196-217
private boolean store(final TreeName treeName, final byte[] key, final ByteStringBuilder value)
    throws DirectoryException
{
  ...
  catch (final Exception e)
  {
    throw new DirectoryException(DirectoryServer.getCoreConfigManager().getServerErrorResultCode(),
        ERR_COMPSCHEMA_CANNOT_STORE_EX.get(e.getMessage()), e);
  }
}

and storeAttribute swallows only IOException (:113-116), so the failure reaches encodeAttribute and the add or modify that triggered it fails, as it should.

What is left behind is the registration. The next encode of that attribute description never reaches the lock:

// CompressedSchema.java:283-287
Integer id = mappings.adEncodeMap.get(ad);
if (id != null)
{
  return id;
}

so it returns the same id and the entry is written with it. Nothing retries the store afterwards: getAllAttributes() (:370) exists for writing the whole content out, but nothing in the server calls it.

getObjectClassId() (:339-362) has the same shape.

What it looks like after a restart

PersistentCompressedSchema.load() (:140-193) rebuilds the maps from the tree and loadAttributeToMaps (:495-524) indexes by the token carried in the key, padding gaps with null. The ids of the other attributes are therefore not shifted - but the slot of the lost token is empty, and two things follow from that:

  • The entries carrying it do not decode. If some later attribute was registered successfully, the slot holds null and decodeAttribute (:191-196) reports ERR_COMPRESSEDSCHEMA_UNRECOGNIZED_AD_TOKEN. If the lost token was the highest one, adDecodeMap is simply shorter and CopyOnWriteArrayList.get(adId) throws IndexOutOfBoundsException - an unchecked exception on the read path, rather than the DirectoryException the code below it is written for.
  • The next schema change throws an NPE. reloadAttributeTypeMaps (:154-160) walks adDecodeMap by index and dereferences ad.getAttributeType() with no null check, so a padded slot brings down reloadMappingsIfSchemaChanged(), which runs on every decode.

Impact

An entry written after the failed store is unreadable for good: the token it carries has no definition anywhere. The write that failed is reported, so the operator sees a failure - but the entries written after it look successful and only break at the next restart, which is where the loss becomes visible.

Reachable on any backend whose write can fail. The JDBC backend makes it ordinary rather than exotic: store() goes through storage.write(), which borrows a connection from the pool, and a database that is down, at its max_connections or refusing the statement fails that borrow - see #872 and #877 for the ways it does.

Expected behavior

The maps and the tree must not disagree. The registration was appended under the exclusive lock and is still the last element, so withdrawing it on failure is local:

id = mappings.adDecodeMap.size();
mappings.adDecodeMap.add(ad);
mappings.adEncodeMap.put(ad, id);
try
{
  storeAttribute(encodeId(id), ad.getAttributeType().getNameOrOID(), ad.getOptions());
}
catch (DirectoryException | RuntimeException e)
{
  mappings.adDecodeMap.remove(id);
  mappings.adEncodeMap.remove(ad);
  throw e;
}

so the next attempt allocates the id again and stores it, and no entry is ever written with a token the tree does not carry. The same for getObjectClassId().

Independently of that, decodeAttribute() should report an out-of-range token the way it reports an unknown one, rather than letting IndexOutOfBoundsException out, and reloadAttributeTypeMaps() should skip a null slot rather than dereference it - a tree written by an older server can carry gaps for other reasons.

Environment

master (5.2.x), every pluggable backend; the line numbers are of master as it stands.

Activity

  1. added
    data-loss
    on Aug 20, 2026
  2. added 3 commits that reference this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdata-loss

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions