Package io.permazen.core
Class Layout
java.lang.Object
io.permazen.core.Layout
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe currentDatabaselayout format version (1).static final intThe originalDatabaselayout format version #1.static final intThe single byte that followsMETADATA_PREFIX_BYTEto form the format version key.static final intThe single byte value that is a prefix of all meta-data keys.static final intThe single byte that followsMETADATA_PREFIX_BYTEto indicate the object schema index.static final intThe single byte that followsMETADATA_PREFIX_BYTEto indicate the schema table.static final intThe single byte that followsMETADATA_PREFIX_BYTEto indicate the storage ID table.static final intThe single byte that followsMETADATA_PREFIX_BYTEto indicate the user meta-data area.static final intObject meta-data flags byte valid bits. -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteDatabuildSchemaIndexKey(ObjId id, int schemaIndex) Build the key for an object schema index entry.static ByteDatabuildTableKey(ByteData prefix, int index) Get the key corresponding to an entry in an indexed table (e.g., schema table or storage ID table).static voidcopyMetaData(KVStore src, KVStore dst) Copy non-object meta-data from oneKVStoreto another.static SchemaModeldecodeSchema(ByteData schemaData) Decode schema XML from a schema table entry.static voidDelete all object and index data from the givenKVStore.static voidencodeSchema(ByteData.Writer writer, SchemaModel schemaModel) Encode schema XML for a schema table entry.static ByteDataGet the key under which the database format version is encoded.static ByteDataGet the common prefix of all meta-data keys.static CoreIndex1<Integer,ObjId> Get aCoreIndex1view of the object schema index in a key/value database.static ByteDataGet the common prefix of all object schema index entries.static ByteDataGet the common prefix of all schema table keys.static ByteDataGet the common prefix of all storage ID table keys.static ByteDataGet the common prefix of all user-defined meta-data keys.
-
Field Details
-
FORMAT_VERSION_1
public static final int FORMAT_VERSION_1The originalDatabaselayout format version #1.- See Also:
-
CURRENT_FORMAT_VERSION
public static final int CURRENT_FORMAT_VERSIONThe currentDatabaselayout format version (1).- See Also:
-
METADATA_PREFIX_BYTE
public static final int METADATA_PREFIX_BYTEThe 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_BYTEThe single byte that followsMETADATA_PREFIX_BYTEto form the format version key.- See Also:
-
METADATA_SCHEMA_TABLE_BYTE
public static final int METADATA_SCHEMA_TABLE_BYTEThe single byte that followsMETADATA_PREFIX_BYTEto indicate the schema table.- See Also:
-
METADATA_STORAGE_ID_TABLE_BYTE
public static final int METADATA_STORAGE_ID_TABLE_BYTEThe single byte that followsMETADATA_PREFIX_BYTEto indicate the storage ID table.- See Also:
-
METADATA_SCHEMA_INDEX_BYTE
public static final int METADATA_SCHEMA_INDEX_BYTEThe single byte that followsMETADATA_PREFIX_BYTEto indicate the object schema index.- See Also:
-
METADATA_USER_META_DATA_BYTE
public static final int METADATA_USER_META_DATA_BYTEThe single byte that followsMETADATA_PREFIX_BYTEto indicate the user meta-data area.- See Also:
-
OBJECT_FLAGS_VALID_BITS
public static final int OBJECT_FLAGS_VALID_BITSObject meta-data flags byte valid bits.All bits must be zero.
- See Also:
-
-
Method Details
-
getMetaDataKeyPrefix
Get the common prefix of all meta-data keys.- Returns:
- meta-data prefix bytes
-
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
Get the common prefix of all schema table keys.- Returns:
- schema table key prefix
-
getStorageIdTablePrefix
Get the common prefix of all storage ID table keys.- Returns:
- storage ID table key prefix
-
buildTableKey
Get the key corresponding to an entry in an indexed table (e.g., schema table or storage ID table).- Parameters:
prefix- table key range prefixindex- table index- Returns:
- key/value store key
- Throws:
IllegalArgumentException- ifindexis zero or negativeIllegalArgumentException- ifprefixis null
-
getSchemaIndexKeyPrefix
Get the common prefix of all object schema index entries.- Returns:
- object schema index key prefix
-
getUserMetaDataKeyPrefix
Get the common prefix of all user-defined meta-data keys.- Returns:
- user meta-data key prefix
-
getSchemaIndex
Get aCoreIndex1view of the object schema index in a key/value database.- Parameters:
kv- key/value data- Returns:
- object schema index
- Throws:
IllegalArgumentException- ifkvis null
-
buildSchemaIndexKey
Build the key for an object schema index entry.- Parameters:
id- object IDschemaIndex- object schema index- Returns:
- schemaIndex index entry key
- Throws:
IllegalArgumentException- ifidis nullIllegalArgumentException- ifschemaIndexis non-positive
-
decodeSchema
Decode schema XML from a schema table entry.- Parameters:
schemaData- compressed XML input- Returns:
- decoded schema model
- Throws:
InvalidSchemaException- if data or schema is invalidIllegalArgumentException- ifschemaDatais null
-
encodeSchema
Encode schema XML for a schema table entry.- Parameters:
writer- compressed XML outputschemaModel- schema model- Throws:
IllegalArgumentException- if either parameter is null
-
deleteObjectData
Delete all object and index data from the givenKVStore.Upon return, the
KVStorewill still contain meta-data, but not any objects.- Parameters:
kv- key/value database
-
copyMetaData
Copy non-object meta-data from oneKVStoreto 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 databasedst- destination key/value database
-