Skip to content

Commit

Permalink
refactor: additional simplification in index engine implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 20, 2023
1 parent aff3177 commit e0f5c37
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.orientechnologies.common.serialization.types.OBinarySerializer;
import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.encryption.OEncryption;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexDefinition;
Expand Down Expand Up @@ -36,6 +37,8 @@ void create(
OEncryption encryption)
throws IOException;

void load(IndexEngineData data);

void delete(OAtomicOperation atomicOperation) throws IOException;

void clear(OAtomicOperation atomicOperation) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package com.orientechnologies.orient.core.index.engine;

import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexKeyUpdater;
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation;
Expand Down Expand Up @@ -64,6 +63,4 @@ boolean validatedPut(
default int getEngineAPIVersion() {
return VERSION;
}

void load(IndexEngineData data);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.orientechnologies.orient.core.index.engine;

import com.orientechnologies.common.serialization.types.OBinarySerializer;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.encryption.OEncryption;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation;
import java.util.stream.Stream;

Expand All @@ -20,14 +16,5 @@ default int getEngineAPIVersion() {
return API_VERSION;
}

void load(IndexEngineData data);

void load(
final String name,
final int keySize,
final OType[] keyTypes,
final OBinarySerializer keySerializer,
final OEncryption encryption);

boolean isMultiValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.orientechnologies.common.serialization.types.OBinarySerializer;
import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.encryption.OEncryption;
import com.orientechnologies.orient.core.exception.OStorageException;
Expand Down Expand Up @@ -232,15 +231,13 @@ private void doClearSVTree(final OAtomicOperation atomicOperation) {

@Override
public void load(IndexEngineData data) {
OCurrentStorageComponentsFactory cf = storage.getComponentsFactory();
final OEncryption encryption =
OAbstractPaginatedStorage.loadEncryption(data.getEncryption(), data.getEncryptionOptions());

String name = data.getName();
int keySize = data.getKeySize();
OType[] keyTypes = data.getKeyTypes();
OBinarySerializer keySerializer =
cf.binarySerializerFactory.getObjectSerializer(data.getKeySerializedId());
OBinarySerializer keySerializer = storage.resolveObjectSerializer(data.getKeySerializedId());

if (mvTree != null) {
//noinspection unchecked
Expand All @@ -257,28 +254,6 @@ public void load(IndexEngineData data) {
}
}

@Override
public void load(
final String name,
final int keySize,
final OType[] keyTypes,
@SuppressWarnings("rawtypes") final OBinarySerializer keySerializer,
final OEncryption encryption) {
if (mvTree != null) {
//noinspection unchecked
mvTree.load(name, keySize, keyTypes, keySerializer, encryption);
} else {
assert svTree != null;
assert nullTree != null;

final OType[] sbTypes = calculateTypes(keyTypes);

svTree.load(name, keySize + 1, sbTypes, new CompositeKeySerializer(), null);
nullTree.load(
nullTreeName, 1, new OType[] {OType.LINK}, OCompactedLinkSerializer.INSTANCE, null);
}
}

@Override
public boolean remove(final OAtomicOperation atomicOperation, Object key, ORID value) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.orientechnologies.common.serialization.types.OBinarySerializer;
import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.encryption.OEncryption;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexDefinition;
Expand Down Expand Up @@ -127,15 +126,13 @@ private void doClearTree(OAtomicOperation atomicOperation) throws IOException {

@Override
public void load(IndexEngineData data) {
OCurrentStorageComponentsFactory cf = storage.getComponentsFactory();
final OEncryption encryption =
OAbstractPaginatedStorage.loadEncryption(data.getEncryption(), data.getEncryptionOptions());

String name = data.getName();
int keySize = data.getKeySize();
OType[] keyTypes = data.getKeyTypes();
OBinarySerializer keySerializer =
cf.binarySerializerFactory.getObjectSerializer(data.getKeySerializedId());
OBinarySerializer keySerializer = storage.resolveObjectSerializer(data.getKeySerializedId());
sbTree.load(name, keySize, keyTypes, keySerializer, encryption);
try {
versionPositionMap.open();
Expand All @@ -145,23 +142,6 @@ public void load(IndexEngineData data) {
}
}

@Override
public void load(
String indexName,
final int keySize,
final OType[] keyTypes,
final OBinarySerializer keySerializer,
final OEncryption encryption) {
//noinspection unchecked
sbTree.load(indexName, keySize, keyTypes, keySerializer, encryption);
try {
versionPositionMap.open();
} catch (final IOException e) {
throw OException.wrapException(
new OIndexException("Error during VPM load of index " + indexName), e);
}
}

@Override
public boolean remove(OAtomicOperation atomicOperation, Object key) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.orientechnologies.common.util.OCommonConst;
import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.encryption.OEncryption;
import com.orientechnologies.orient.core.id.ORID;
Expand Down Expand Up @@ -159,11 +158,9 @@ public void create(

@Override
public void load(IndexEngineData data) {
OCurrentStorageComponentsFactory cf = this.storage.getComponentsFactory();
OBinarySerializer keySerializer =
cf.binarySerializerFactory.getObjectSerializer(data.getValueSerializerId());
OBinarySerializer keySerializer = storage.resolveObjectSerializer(data.getKeySerializedId());
OBinarySerializer valueSerializer =
cf.binarySerializerFactory.getObjectSerializer(data.getKeySerializedId());
storage.resolveObjectSerializer(data.getValueSerializerId());
Map<String, String> engineProperties = data.getEngineProperties();

final OEncryption encryption =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2727,16 +2727,11 @@ public int loadExternalIndexEngine(
public int addIndexEngine(
final OIndexMetadata indexMetadata, final Map<String, String> engineProperties) {
final String engineName = indexMetadata.getName();
final String algorithm = indexMetadata.getAlgorithm();
final String indexType = indexMetadata.getType();
final OIndexDefinition indexDefinition = indexMetadata.getIndexDefinition();
final boolean isAutomatic = indexMetadata.getIndexDefinition().isAutomatic();
final boolean multivalue = indexMetadata.isMultivalue();
final int version = indexMetadata.getVersion();

try {
if (indexDefinition == null) {
throw new OIndexException("Index definition hav to be provided");
throw new OIndexException("Index definition has to be provided");
}
final OType[] keyTypes = indexDefinition.getTypes();
if (keyTypes == null) {
Expand All @@ -2750,8 +2745,6 @@ public int addIndexEngine(

final int keySize = determineKeySize(indexDefinition);

final boolean nullValuesSupport = !indexDefinition.isNullValuesIgnored();

checkBackupRunning();
stateLock.writeLock().lock();
try {
Expand Down Expand Up @@ -2781,25 +2774,21 @@ public int addIndexEngine(
final int binaryFormatVersion = getConfiguration().getBinaryFormatVersion();
final byte valueSerializerId =
indexMetadata.getValueSerializerId(binaryFormatVersion);
OBinarySerializer<?> valueSerializer =
getComponentsFactory()
.binarySerializerFactory
.getObjectSerializer(valueSerializerId);
final OBaseIndexEngine engine =
addIndexEngineInternal(
atomicOperation,
engineName,
algorithm,
indexType,
valueSerializer,
isAutomatic,
version,
multivalue,
indexMetadata.getAlgorithm(),
indexMetadata.getType(),
resolveObjectSerializer(valueSerializerId),
indexDefinition.isAutomatic(),
indexMetadata.getVersion(),
indexMetadata.isMultivalue(),
engineProperties,
keySerializer,
keySize,
keyTypes,
nullValuesSupport);
!indexDefinition.isNullValuesIgnored());

final OContextConfiguration ctxCfg = configuration.getContextConfiguration();
@SuppressWarnings("deprecation")
Expand All @@ -2812,25 +2801,25 @@ public int addIndexEngine(
new IndexEngineData(
engine.getId(),
engineName,
algorithm,
indexType,
indexMetadata.getAlgorithm(),
indexMetadata.getType(),
true,
version,
indexMetadata.getVersion(),
engine.getEngineAPIVersion(),
multivalue,
indexMetadata.isMultivalue(),
valueSerializerId,
keySerializer.getId(),
isAutomatic,
indexDefinition.isAutomatic(),
keyTypes,
nullValuesSupport,
!indexDefinition.isNullValuesIgnored(),
keySize,
cfgEncryption,
cfgEncryptionKey,
engineProperties);
((OClusterBasedStorageConfiguration) configuration)
.addIndexEngine(atomicOperation, engineName, engineData);

if (multivalue && engine.hasRidBagTreesSupport()) {
if (indexMetadata.isMultivalue() && engine.hasRidBagTreesSupport()) {
final OSBTreeBonsaiLocal<OIdentifiable, Boolean> tree =
new OSBTreeBonsaiLocal<>(
engineName, OIndexRIDContainerSBTree.INDEX_FILE_EXTENSION, this);
Expand All @@ -2853,6 +2842,10 @@ public int addIndexEngine(
}
}

public OBinarySerializer<?> resolveObjectSerializer(final byte serializerId) {
return getComponentsFactory().binarySerializerFactory.getObjectSerializer(serializerId);
}

private OBaseIndexEngine addIndexEngineInternal(
final OAtomicOperation atomicOperation,
final String engineName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.orientechnologies.common.util.OCommonConst;
import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.encryption.OEncryption;
import com.orientechnologies.orient.core.id.ORID;
Expand Down Expand Up @@ -215,11 +214,9 @@ private void doClearTable(OAtomicOperation atomicOperation) throws IOException {

@Override
public void load(IndexEngineData data) {
OCurrentStorageComponentsFactory cf = this.storage.getComponentsFactory();
OBinarySerializer keySerializer =
cf.binarySerializerFactory.getObjectSerializer(data.getKeySerializedId());
OBinarySerializer keySerializer = storage.resolveObjectSerializer(data.getKeySerializedId());
OBinarySerializer valueSerializer =
cf.binarySerializerFactory.getObjectSerializer(data.getValueSerializerId());
storage.resolveObjectSerializer(data.getValueSerializerId());

final OEncryption encryption =
OAbstractPaginatedStorage.loadEncryption(data.getEncryption(), data.getEncryptionOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.orientechnologies.common.serialization.types.OBinarySerializer;
import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.encryption.OEncryption;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexDefinition;
Expand Down Expand Up @@ -166,16 +165,13 @@ private void doClearTree(OAtomicOperation atomicOperation) throws IOException {

@Override
public void load(IndexEngineData data) {
OCurrentStorageComponentsFactory cf = this.storage.getComponentsFactory();
final OEncryption encryption =
OAbstractPaginatedStorage.loadEncryption(data.getEncryption(), data.getEncryptionOptions());

sbTree.load(
data.getName(),
(OBinarySerializer)
cf.binarySerializerFactory.getObjectSerializer(data.getKeySerializedId()),
(OBinarySerializer)
cf.binarySerializerFactory.getObjectSerializer(data.getValueSerializerId()),
(OBinarySerializer) storage.resolveObjectSerializer(data.getKeySerializedId()),
(OBinarySerializer) storage.resolveObjectSerializer(data.getValueSerializerId()),
data.getKeyTypes(),
data.getKeySize(),
data.isNullValuesSupport(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,18 +626,11 @@ public boolean load(final OBonsaiBucketPointer rootBucketPointer) {
this);
//noinspection unchecked
keySerializer =
(OBinarySerializer<K>)
storage
.getComponentsFactory()
.binarySerializerFactory
.getObjectSerializer(rootBucket.getKeySerializerId());
(OBinarySerializer<K>) storage.resolveObjectSerializer(rootBucket.getKeySerializerId());
//noinspection unchecked
valueSerializer =
(OBinarySerializer<V>)
storage
.getComponentsFactory()
.binarySerializerFactory
.getObjectSerializer(rootBucket.getValueSerializerId());
storage.resolveObjectSerializer(rootBucket.getValueSerializerId());

return !rootBucket.isDeleted();
}
Expand Down

0 comments on commit e0f5c37

Please sign in to comment.