-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiaojiebao
committed
Feb 2, 2024
1 parent
0cc0400
commit d3ce370
Showing
6 changed files
with
240 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/java/com/datastrato/gravitino/storage/relation/RelationBackend.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.storage.relation; | ||
|
||
import com.datastrato.gravitino.Config; | ||
import com.datastrato.gravitino.Entity; | ||
import com.datastrato.gravitino.EntityAlreadyExistsException; | ||
import com.datastrato.gravitino.HasIdentifier; | ||
import com.datastrato.gravitino.NameIdentifier; | ||
import com.datastrato.gravitino.Namespace; | ||
import com.datastrato.gravitino.exceptions.AlreadyExistsException; | ||
import com.datastrato.gravitino.exceptions.NoSuchEntityException; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
public interface RelationBackend extends Closeable { | ||
|
||
void initialize(Config config) throws IOException; | ||
|
||
<E extends Entity & HasIdentifier> List<E> list(Namespace namespace, Entity.EntityType entityType) | ||
throws IOException; | ||
|
||
boolean exists(NameIdentifier ident, Entity.EntityType entityType) throws IOException; | ||
|
||
<E extends Entity & HasIdentifier> void put(E e, boolean overwritten) | ||
throws IOException, EntityAlreadyExistsException; | ||
|
||
<E extends Entity & HasIdentifier> E update( | ||
NameIdentifier ident, Entity.EntityType entityType, Function<E, E> updater) | ||
throws IOException, NoSuchEntityException, AlreadyExistsException; | ||
|
||
<E extends Entity & HasIdentifier> E get(NameIdentifier ident, Entity.EntityType entityType) | ||
throws NoSuchEntityException, IOException; | ||
|
||
boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade) | ||
throws IOException; | ||
} |
111 changes: 111 additions & 0 deletions
111
core/src/main/java/com/datastrato/gravitino/storage/relation/RelationEntityStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.storage.relation; | ||
|
||
import static com.datastrato.gravitino.Configs.ENTITY_RELATION_STORE; | ||
|
||
import com.datastrato.gravitino.Config; | ||
import com.datastrato.gravitino.Entity; | ||
import com.datastrato.gravitino.EntityAlreadyExistsException; | ||
import com.datastrato.gravitino.EntitySerDe; | ||
import com.datastrato.gravitino.EntityStore; | ||
import com.datastrato.gravitino.HasIdentifier; | ||
import com.datastrato.gravitino.NameIdentifier; | ||
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.utils.Executable; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class RelationEntityStore implements EntityStore { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(RelationEntityStore.class); | ||
public static final ImmutableMap<String, String> RELATION_BACKENDS = | ||
ImmutableMap.of("MysqlBackend", MysqlBackend.class.getCanonicalName()); | ||
private RelationBackend 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); | ||
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; | ||
} catch (Exception e) { | ||
LOGGER.error("Failed to create and initialize RelationBackend by name '{}'.", backendName, e); | ||
throw new RuntimeException( | ||
"Failed to create and initialize RelationBackend by name: " + backendName, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void setSerDe(EntitySerDe entitySerDe) { | ||
throw new UnsupportedOperationException("Unsupported operation in relation entity store."); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> List<E> list( | ||
Namespace namespace, Class<E> type, Entity.EntityType entityType) throws IOException { | ||
return backend.list(namespace, entityType); | ||
} | ||
|
||
@Override | ||
public boolean exists(NameIdentifier ident, Entity.EntityType entityType) throws IOException { | ||
return backend.exists(ident, entityType); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> void put(E e, boolean overwritten) | ||
throws IOException, EntityAlreadyExistsException { | ||
backend.put(e, overwritten); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> E update( | ||
NameIdentifier ident, Class<E> type, Entity.EntityType entityType, Function<E, E> updater) | ||
throws IOException, NoSuchEntityException, AlreadyExistsException { | ||
return backend.update(ident, entityType, updater); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> E get( | ||
NameIdentifier ident, Entity.EntityType entityType, Class<E> e) | ||
throws NoSuchEntityException, IOException { | ||
return backend.get(ident, entityType); | ||
} | ||
|
||
@Override | ||
public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade) | ||
throws IOException { | ||
return backend.delete(ident, entityType, cascade); | ||
} | ||
|
||
@Override | ||
public <R, E extends Exception> R executeInTransaction(Executable<R, E> executable) | ||
throws E, IOException { | ||
throw new UnsupportedOperationException("Unsupported operation in relation entity store."); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
backend.close(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/MysqlBackend.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.storage.relation.mysql; | ||
|
||
import com.datastrato.gravitino.Config; | ||
import com.datastrato.gravitino.Entity; | ||
import com.datastrato.gravitino.EntityAlreadyExistsException; | ||
import com.datastrato.gravitino.HasIdentifier; | ||
import com.datastrato.gravitino.NameIdentifier; | ||
import com.datastrato.gravitino.Namespace; | ||
import com.datastrato.gravitino.exceptions.AlreadyExistsException; | ||
import com.datastrato.gravitino.exceptions.NoSuchEntityException; | ||
import com.datastrato.gravitino.storage.relation.RelationBackend; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
public class MysqlBackend implements RelationBackend { | ||
@Override | ||
public void initialize(Config config) throws IOException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> List<E> list( | ||
Namespace namespace, Entity.EntityType entityType) throws IOException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
|
||
@Override | ||
public boolean exists(NameIdentifier ident, Entity.EntityType entityType) throws IOException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> void put(E e, boolean overwritten) | ||
throws IOException, EntityAlreadyExistsException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> E update( | ||
NameIdentifier ident, Entity.EntityType entityType, Function<E, E> updater) | ||
throws IOException, NoSuchEntityException, AlreadyExistsException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
|
||
@Override | ||
public <E extends Entity & HasIdentifier> E get( | ||
NameIdentifier ident, Entity.EntityType entityType) | ||
throws NoSuchEntityException, IOException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
|
||
@Override | ||
public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade) | ||
throws IOException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
throw new UnsupportedOperationException("Unsupported operation now."); | ||
} | ||
} |