Record Class DbTenantAwareKey<WrappedKey extends DbKey>

java.lang.Object
java.lang.Record
io.camunda.zeebe.db.impl.DbTenantAwareKey<WrappedKey>
All Implemented Interfaces:
ContainsForeignKeys, DbKey, BufferReader, BufferWriter

public record DbTenantAwareKey<WrappedKey extends DbKey>(DbString tenantKey, WrappedKey extends DbKey wrappedKey, DbTenantAwareKey.PlacementType placementType) extends Record implements DbKey, ContainsForeignKeys
The DbTenantAwareKey wraps any given key and, depending on the PlacementType, append or prepends the tenant to it.

Depending on the use case you want to choose whether you need to use PREFIX or SUFFIX. PREFIX is suitable when you want the ability to search values by tenant. Use SUFFIX when you want to search for values irrelevant of tenant.

When using PREFIX it's important to be aware that we could have preferential treatment. Keys in RocksDb are sorted. If we take Jobs as an example, when activating we iterate over all activatable jobs to return to the worker. We don't want to Jobs of tenant AAA to take priority over Jobs of tenant ZZZ. SUFFIX is more suitable for this case.

  • Constructor Details

    • DbTenantAwareKey

      public DbTenantAwareKey(DbString tenantKey, WrappedKey wrappedKey, DbTenantAwareKey.PlacementType placementType)
      Creates an instance of a DbTenantAwareKey record class.
      Parameters:
      tenantKey - the value for the tenantKey record component
      wrappedKey - the value for the wrappedKey record component
      placementType - the value for the placementType record component
  • Method Details

    • tenantKey

      public DbString tenantKey()
      Returns the value of the tenantKey record component.
      Returns:
      the value of the tenantKey record component
    • wrappedKey

      public WrappedKey wrappedKey()
      Returns the value of the wrappedKey record component.
      Returns:
      the value of the wrappedKey record component
    • wrap

      public void wrap(org.agrona.DirectBuffer buffer, int offset, int length)
      Specified by:
      wrap in interface BufferReader
    • getLength

      public int getLength()
      Specified by:
      getLength in interface BufferWriter
    • write

      public void write(org.agrona.MutableDirectBuffer buffer, int offset)
      Specified by:
      write in interface BufferWriter
    • containedForeignKeys

      public Collection<DbForeignKey<DbKey>> containedForeignKeys()
      Specified by:
      containedForeignKeys in interface ContainsForeignKeys
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • placementType

      public DbTenantAwareKey.PlacementType placementType()
      Returns the value of the placementType record component.
      Returns:
      the value of the placementType record component