Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojiebao committed Feb 6, 2024
1 parent e21cbb8 commit 76243d4
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 67 deletions.
17 changes: 10 additions & 7 deletions core/src/main/java/com/datastrato/gravitino/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
package com.datastrato.gravitino;

import com.datastrato.gravitino.config.ConfigBuilder;
import com.datastrato.gravitino.config.ConfigConstants;
import com.datastrato.gravitino.config.ConfigEntry;
import java.io.File;
import org.apache.commons.lang3.StringUtils;

public interface Configs {

String DEFAULT_ENTITY_STORE = "kv";
String RELATION_ENTITY_STORE = "rel";
String RELATIONAL_ENTITY_STORE = "relational";
String ENTITY_STORE_KEY = "gravitino.entity.store";

String DEFAULT_ENTITY_KV_STORE = "RocksDBKvBackend";
String ENTITY_KV_STORE_KEY = "gravitino.entity.store.kv";

String DEFAULT_ENTITY_RELATION_STORE = "MySQLBackend";
String ENTITY_RELATION_STORE_KEY = "gravitino.entity.store.rel";
String DEFAULT_ENTITY_RELATIONAL_STORE = "MySQLBackend";
String ENTITY_RELATIONAL_STORE_KEY = "gravitino.entity.store.relational";

String ENTITY_KV_ROCKSDB_BACKEND_PATH_KEY = "gravitino.entity.store.kv.rocksdbPath";

Expand Down Expand Up @@ -49,12 +51,13 @@ public interface Configs {
.stringConf()
.createWithDefault(DEFAULT_ENTITY_KV_STORE);

ConfigEntry<String> ENTITY_RELATION_STORE =
new ConfigBuilder(ENTITY_RELATION_STORE_KEY)
.doc("Detailed implementation of relation storage")
ConfigEntry<String> ENTITY_RELATIONAL_STORE =
new ConfigBuilder(ENTITY_RELATIONAL_STORE_KEY)
.doc("Detailed implementation of relational storage")
.version("0.5.0")
.stringConf()
.createWithDefault(DEFAULT_ENTITY_RELATION_STORE);
.checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)
.createWithDefault(DEFAULT_ENTITY_RELATIONAL_STORE);

ConfigEntry<String> ENTRY_KV_ROCKSDB_BACKEND_PATH =
new ConfigBuilder(ENTITY_KV_ROCKSDB_BACKEND_PATH_KEY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package com.datastrato.gravitino;

import com.datastrato.gravitino.storage.kv.KvEntityStore;
import com.datastrato.gravitino.storage.relation.RelationEntityStore;
import com.datastrato.gravitino.storage.relational.RelationalEntityStore;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,8 +24,8 @@ public class EntityStoreFactory {
ImmutableMap.of(
Configs.DEFAULT_ENTITY_STORE,
KvEntityStore.class.getCanonicalName(),
Configs.RELATION_ENTITY_STORE,
RelationEntityStore.class.getCanonicalName());
Configs.RELATIONAL_ENTITY_STORE,
RelationalEntityStore.class.getCanonicalName());

// Private constructor to prevent instantiation of this factory class.
private EntityStoreFactory() {}
Expand Down
18 changes: 0 additions & 18 deletions core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.datastrato.gravitino.metrics.source.JVMMetricsSource;
import com.datastrato.gravitino.storage.IdGenerator;
import com.datastrato.gravitino.storage.RandomIdGenerator;
import com.datastrato.gravitino.storage.relation.RelationEntityStore;
import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,8 +27,6 @@ public class GravitinoEnv {

private EntityStore entityStore;

private EntitySerDe entitySerDe;

private CatalogManager catalogManager;

private CatalogOperationDispatcher catalogOperationDispatcher;
Expand Down Expand Up @@ -69,15 +66,9 @@ public void initialize(Config config) {
this.metricsSystem = new MetricsSystem();
metricsSystem.register(new JVMMetricsSource());

// Initialize EntitySerDe
this.entitySerDe = EntitySerDeFactory.createEntitySerDe(config);

// Initialize EntityStore
this.entityStore = EntityStoreFactory.createEntityStore(config);
entityStore.initialize(config);
if (!(entityStore instanceof RelationEntityStore)) {
entityStore.setSerDe(entitySerDe);
}

// create and initialize a random id generator
this.idGenerator = new RandomIdGenerator();
Expand Down Expand Up @@ -106,15 +97,6 @@ public Config config() {
return config;
}

/**
* Get the EntitySerDe associated with the Gravitino environment.
*
* @return The EntitySerDe instance.
*/
public EntitySerDe entitySerDe() {
return entitySerDe;
}

/**
* Get the EntityStore associated with the Gravitino environment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.datastrato.gravitino.Entity.EntityType;
import com.datastrato.gravitino.EntityAlreadyExistsException;
import com.datastrato.gravitino.EntitySerDe;
import com.datastrato.gravitino.EntitySerDeFactory;
import com.datastrato.gravitino.EntityStore;
import com.datastrato.gravitino.HasIdentifier;
import com.datastrato.gravitino.NameIdentifier;
Expand Down Expand Up @@ -103,6 +104,7 @@ public void initialize(Config config) throws RuntimeException {
kvGarbageCollector.start();

this.storageLayoutVersion = initStorageVersionInfo();
this.serDe = EntitySerDeFactory.createEntitySerDe(config);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.storage.relation;
package com.datastrato.gravitino.storage.relational;

import com.datastrato.gravitino.Config;
import com.datastrato.gravitino.Entity;
Expand All @@ -17,17 +17,17 @@
import java.util.function.Function;

/** Interface defining the operations for a Relation Backend. */
public interface RelationBackend extends Closeable {
public interface RelationalBackend extends Closeable {

/**
* Initializes the Relation Backend environment with the provided configuration.
* Initializes the Relational Backend environment with the provided configuration.
*
* @param config The configuration for the backend.
*/
void initialize(Config config);

/**
* List the entities associated with the given parent namespace and entityType
* Lists the entities associated with the given parent namespace and entityType
*
* @param namespace The parent namespace of these entities.
* @param entityType The type of these entities.
Expand All @@ -40,7 +40,7 @@ <E extends Entity & HasIdentifier> List<E> list(Namespace namespace, Entity.Enti
throws NoSuchEntityException;

/**
* Check the entity associated with the given identifier and entityType whether exists.
* Checks the entity associated with the given identifier and entityType whether exists.
*
* @param ident The identifier of the entity.
* @param entityType The type of the entity.
Expand All @@ -59,7 +59,7 @@ <E extends Entity & HasIdentifier> void insert(E e, boolean overwritten)
throws EntityAlreadyExistsException;

/**
* Update the entity.
* Updates the entity.
*
* @param ident The identifier of the entity which need be stored.
* @param entityType The type of the entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.storage.relation;
package com.datastrato.gravitino.storage.relational;

import static com.datastrato.gravitino.Configs.ENTITY_RELATION_STORE;
import static com.datastrato.gravitino.Configs.ENTITY_RELATIONAL_STORE;

import com.datastrato.gravitino.Config;
import com.datastrato.gravitino.Configs;
Expand All @@ -17,7 +17,7 @@
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.exceptions.AlreadyExistsException;
import com.datastrato.gravitino.exceptions.NoSuchEntityException;
import com.datastrato.gravitino.storage.relation.mysql.MySQLBackend;
import com.datastrato.gravitino.storage.relational.mysql.MySQLBackend;
import com.datastrato.gravitino.utils.Executable;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
Expand All @@ -30,41 +30,43 @@
/**
* Relation store to store entities. This means we can store entities in a relational store. I.e.,
* MySQL, PostgreSQL, etc. If you want to use a different backend, you can implement the {@link
* RelationBackend} interface
* RelationalBackend} interface
*/
public class RelationEntityStore implements EntityStore {
private static final Logger LOGGER = LoggerFactory.getLogger(RelationEntityStore.class);
public static final ImmutableMap<String, String> RELATION_BACKENDS =
ImmutableMap.of(Configs.DEFAULT_ENTITY_RELATION_STORE, MySQLBackend.class.getCanonicalName());
private RelationBackend backend;
public class RelationalEntityStore implements EntityStore {
private static final Logger LOGGER = LoggerFactory.getLogger(RelationalEntityStore.class);
public static final ImmutableMap<String, String> RELATIONAL_BACKENDS =
ImmutableMap.of(
Configs.DEFAULT_ENTITY_RELATIONAL_STORE, MySQLBackend.class.getCanonicalName());
private RelationalBackend backend;

@Override
public void initialize(Config config) throws RuntimeException {
this.backend = createRelationEntityBackend(config);
}

private static RelationBackend createRelationEntityBackend(Config config) {
String backendName = config.get(ENTITY_RELATION_STORE);
String className = RELATION_BACKENDS.getOrDefault(backendName, backendName);
private static RelationalBackend createRelationEntityBackend(Config config) {
String backendName = config.get(ENTITY_RELATIONAL_STORE);
String className = RELATIONAL_BACKENDS.getOrDefault(backendName, backendName);
if (Objects.isNull(className)) {
throw new RuntimeException("Unsupported backend type..." + backendName);
}

try {
RelationBackend relationBackend =
(RelationBackend) Class.forName(className).getDeclaredConstructor().newInstance();
relationBackend.initialize(config);
return relationBackend;
RelationalBackend relationalBackend =
(RelationalBackend) Class.forName(className).getDeclaredConstructor().newInstance();
relationalBackend.initialize(config);
return relationalBackend;
} catch (Exception e) {
LOGGER.error("Failed to create and initialize RelationBackend by name '{}'.", backendName, e);
LOGGER.error(
"Failed to create and initialize RelationalBackend by name '{}'.", backendName, e);
throw new RuntimeException(
"Failed to create and initialize RelationBackend by name: " + backendName, e);
"Failed to create and initialize RelationalBackend by name: " + backendName, e);
}
}

@Override
public void setSerDe(EntitySerDe entitySerDe) {
throw new UnsupportedOperationException("Unsupported operation in relation entity store.");
throw new UnsupportedOperationException("Unsupported operation in relational entity store.");
}

@Override
Expand Down Expand Up @@ -110,7 +112,7 @@ public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolea

@Override
public <R, E extends Exception> R executeInTransaction(Executable<R, E> executable) {
throw new UnsupportedOperationException("Unsupported operation in relation entity store.");
throw new UnsupportedOperationException("Unsupported operation in relational entity store.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.storage.relation.mysql;
package com.datastrato.gravitino.storage.relational.mysql;

import com.datastrato.gravitino.Config;
import com.datastrato.gravitino.Entity;
Expand All @@ -11,23 +11,21 @@
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.exceptions.NoSuchEntityException;
import com.datastrato.gravitino.storage.relation.RelationBackend;
import com.datastrato.gravitino.storage.relational.RelationalBackend;
import java.io.IOException;
import java.util.List;
import java.util.function.Function;

/**
* {@link MySQLBackend} is a MySQL implementation of RelationBackend interface. If we want to use
* another relation implementation, We can just implement {@link RelationBackend} interface and use
* it in the Gravitino.
* {@link MySQLBackend} is a MySQL implementation of RelationalBackend interface. If we want to use
* another relational implementation, We can just implement {@link RelationalBackend} interface and
* use it in the Gravitino.
*/
public class MySQLBackend implements RelationBackend {
public class MySQLBackend implements RelationalBackend {

/** Initialize the MySQL backend instance. */
@Override
public void initialize(Config config) {
throw new UnsupportedOperationException("Unsupported operation now.");
}
public void initialize(Config config) {}

@Override
public <E extends Entity & HasIdentifier> List<E> list(
Expand Down Expand Up @@ -65,7 +63,5 @@ public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolea
}

@Override
public void close() throws IOException {
throw new UnsupportedOperationException("Unsupported operation now.");
}
public void close() throws IOException {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public void clear() {
}

@Override
public void initialize(Config config) throws RuntimeException {}
public void initialize(Config config) throws RuntimeException {
this.serde = Mockito.mock(EntitySerDe.class);
}

@Override
public void setSerDe(EntitySerDe entitySerDe) {
Expand Down
Loading

0 comments on commit 76243d4

Please sign in to comment.