Class Layout

java.lang.Object
io.permazen.core.Layout

public final class Layout extends Object
Constants and utility methods relating to the encoding and layout of a Database in a key/value store.

The key/value space is divided into a data area and a meta-data area. The data area contains object data as well as simple and composite index data. The meta-data area contains a recognizable signature, database format version, all recorded schemas, the object schema index, and a range reserved for user applications.

See Also:
  • Field Details

    • FORMAT_VERSION_1

      public static final int FORMAT_VERSION_1
      The original Database layout format version #1.
      See Also:
    • CURRENT_FORMAT_VERSION

      public static final int CURRENT_FORMAT_VERSION
      The current Database layout format version (1).
      See Also:
    • METADATA_PREFIX_BYTE

      public static final int METADATA_PREFIX_BYTE
      The single byte value that is a prefix of all meta-data keys.
      See Also:
    • METADATA_FORMAT_VERSION_BYTE

      public static final int METADATA_FORMAT_VERSION_BYTE
      The single byte that follows METADATA_PREFIX_BYTE to form the format version key.
      See Also:
    • METADATA_SCHEMA_TABLE_BYTE

      public static final int METADATA_SCHEMA_TABLE_BYTE
      The single byte that follows METADATA_PREFIX_BYTE to indicate the schema table.
      See Also:
    • METADATA_STORAGE_ID_TABLE_BYTE

      public static final int METADATA_STORAGE_ID_TABLE_BYTE
      The single byte that follows METADATA_PREFIX_BYTE to indicate the storage ID table.
      See Also:
    • METADATA_SCHEMA_INDEX_BYTE

      public static final int METADATA_SCHEMA_INDEX_BYTE
      The single byte that follows METADATA_PREFIX_BYTE to indicate the object schema index.
      See Also:
    • METADATA_USER_META_DATA_BYTE

      public static final int METADATA_USER_META_DATA_BYTE
      The single byte that follows METADATA_PREFIX_BYTE to indicate the user meta-data area.
      See Also:
    • OBJECT_FLAG_DELETE_NOTIFIED

      public static final int OBJECT_FLAG_DELETE_NOTIFIED
      Object meta-data flags byte: delete notified.
      See Also:
    • OBJECT_FLAGS_VALID_BITS

      public static final int OBJECT_FLAGS_VALID_BITS
      Object meta-data flags byte valid bits.

      All other bits must be zero.

      See Also:
  • Method Details

    • getMetaDataKeyPrefix

      public static byte[] getMetaDataKeyPrefix()
      Get the common prefix of all meta-data keys.
      Returns:
      meta-data prefix bytes
    • getFormatVersionKey

      public static byte[] getFormatVersionKey()
      Get the key under which the database format version is encoded.

      The existence of this key also serves to identify a Permazen database.

      Returns:
      meta-data prefix bytes
    • getSchemaTablePrefix

      public static byte[] getSchemaTablePrefix()
      Get the common prefix of all schema table keys.
      Returns:
      schema table key prefix
    • getStorageIdTablePrefix

      public static byte[] getStorageIdTablePrefix()
      Get the common prefix of all storage ID table keys.
      Returns:
      storage ID table key prefix
    • buildTableKey

      public static byte[] buildTableKey(byte[] prefix, int index)
      Get the key corresponding to an entry in an indexed table (e.g., schema table or storage ID table).
      Parameters:
      prefix - table key range prefix
      index - table index
      Returns:
      key/value store key
      Throws:
      IllegalArgumentException - if index is zero or negative
      IllegalArgumentException - if prefix is null
    • getSchemaIndexKeyPrefix

      public static byte[] getSchemaIndexKeyPrefix()
      Get the common prefix of all object schema index entries.
      Returns:
      object schema index key prefix
    • getUserMetaDataKeyPrefix

      public static byte[] getUserMetaDataKeyPrefix()
      Get the common prefix of all user-defined meta-data keys.
      Returns:
      user meta-data key prefix
    • getSchemaIndex

      public static CoreIndex1<Integer,ObjId> getSchemaIndex(KVStore kv)
      Get a CoreIndex1 view of the object schema index in a key/value database.
      Parameters:
      kv - key/value data
      Returns:
      object schema index
      Throws:
      IllegalArgumentException - if kv is null
    • buildSchemaIndexKey

      public static byte[] buildSchemaIndexKey(ObjId id, int schemaIndex)
      Build the key for an object schema index entry.
      Parameters:
      id - object ID
      schemaIndex - object schema index
      Returns:
      schemaIndex index entry key
      Throws:
      IllegalArgumentException - if id is null
      IllegalArgumentException - if schemaIndex is non-positive
    • decodeSchema

      public static SchemaModel decodeSchema(ByteReader reader)
      Decode schema XML from a schema table entry.
      Parameters:
      reader - compressed XML input
      Returns:
      decoded schema model
      Throws:
      InvalidSchemaException - if data or schema is invalid
      IllegalArgumentException - if value is null
    • encodeSchema

      public static void encodeSchema(ByteWriter writer, SchemaModel schemaModel)
      Encode schema XML for a schema table entry.
      Parameters:
      writer - compressed XML output
      schemaModel - schema model
      Throws:
      IllegalArgumentException - if either parameter is null
    • deleteObjectData

      public static void deleteObjectData(KVStore kv)
      Delete all object and index data from the given KVStore.

      Upon return, the KVStore will still contain meta-data, but not any objects.

      Parameters:
      kv - key/value database
    • copyMetaData

      public static void copyMetaData(KVStore src, KVStore dst)
      Copy non-object meta-data from one KVStore to another.

      This copies all meta-data except the object schema index. Any existing key/value pairs in the destination meta-data range are not removed prior to the copy.

      Parameters:
      src - source key/value database
      dst - destination key/value database