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
Modifier and TypeFieldDescriptionstatic final int
The currentDatabase
layout format version (1).static final int
The originalDatabase
layout format version #1.static final int
The single byte that followsMETADATA_PREFIX_BYTE
to form the format version key.static final int
The single byte value that is a prefix of all meta-data keys.static final int
The single byte that followsMETADATA_PREFIX_BYTE
to indicate the object schema index.static final int
The single byte that followsMETADATA_PREFIX_BYTE
to indicate the schema table.static final int
The single byte that followsMETADATA_PREFIX_BYTE
to indicate the storage ID table.static final int
The single byte that followsMETADATA_PREFIX_BYTE
to indicate the user meta-data area.static final int
Object meta-data flags byte valid bits. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
buildSchemaIndexKey
(ObjId id, int schemaIndex) Build the key for an object schema index entry.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).static void
copyMetaData
(KVStore src, KVStore dst) Copy non-object meta-data from oneKVStore
to another.static SchemaModel
decodeSchema
(ByteReader reader) Decode schema XML from a schema table entry.static void
Delete all object and index data from the givenKVStore
.static void
encodeSchema
(ByteWriter writer, SchemaModel schemaModel) Encode schema XML for a schema table entry.static byte[]
Get the key under which the database format version is encoded.static byte[]
Get the common prefix of all meta-data keys.static CoreIndex1<Integer,
ObjId> Get aCoreIndex1
view of the object schema index in a key/value database.static byte[]
Get the common prefix of all object schema index entries.static byte[]
Get the common prefix of all schema table keys.static byte[]
Get the common prefix of all storage ID table keys.static byte[]
Get the common prefix of all user-defined meta-data keys.
-
Field Details
-
FORMAT_VERSION_1
public static final int FORMAT_VERSION_1The originalDatabase
layout format version #1.- See Also:
-
CURRENT_FORMAT_VERSION
public static final int CURRENT_FORMAT_VERSIONThe currentDatabase
layout 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_BYTE
to form the format version key.- See Also:
-
METADATA_SCHEMA_TABLE_BYTE
public static final int METADATA_SCHEMA_TABLE_BYTEThe single byte that followsMETADATA_PREFIX_BYTE
to 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_BYTE
to indicate the storage ID table.- See Also:
-
METADATA_SCHEMA_INDEX_BYTE
public static final int METADATA_SCHEMA_INDEX_BYTEThe single byte that followsMETADATA_PREFIX_BYTE
to 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_BYTE
to 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
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 prefixindex
- table index- Returns:
- key/value store key
- Throws:
IllegalArgumentException
- ifindex
is zero or negativeIllegalArgumentException
- ifprefix
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
Get aCoreIndex1
view of the object schema index in a key/value database.- Parameters:
kv
- key/value data- Returns:
- object schema index
- Throws:
IllegalArgumentException
- ifkv
is 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
- ifid
is nullIllegalArgumentException
- ifschemaIndex
is non-positive
-
decodeSchema
Decode schema XML from a schema table entry.- Parameters:
reader
- compressed XML input- Returns:
- decoded schema model
- Throws:
InvalidSchemaException
- if data or schema is invalidIllegalArgumentException
- ifvalue
is 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
KVStore
will still contain meta-data, but not any objects.- Parameters:
kv
- key/value database
-
copyMetaData
Copy non-object meta-data from oneKVStore
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 databasedst
- destination key/value database
-