World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#203] Fix bugs of new ID allocation in store entities (#204)
Qi Yu714c79fafe71
diff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java b/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.javaindex 1e8b0c8822..a2c509910d 100644--- a/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java@@ -91,10 +91,14 @@ public class KvEntityStore implements EntityStore {@Overridepublic <E extends Entity & HasIdentifier> void put(E e, boolean overwritten)throws IOException, EntityAlreadyExistsException {- // Simple implementation, just use the entity's identifier as the key- byte[] key = entityKeyEncoder.encode(EntityIdentifer.of(e.nameIdentifier(), e.type()), true);- byte[] value = serDe.serialize(e);- backend.put(key, value, overwritten);+ executeInTransaction(+ () -> {+ byte[] key =+ entityKeyEncoder.encode(EntityIdentifer.of(e.nameIdentifier(), e.type()), true);+ byte[] value = serDe.serialize(e);+ backend.put(key, value, overwritten);+ return null;+ });}@Overridediff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/RocksDBKvBackend.java b/core/src/main/java/com/datastrato/graviton/storage/kv/RocksDBKvBackend.javaindex f4f5a9f01d..e77f368286 100644--- a/core/src/main/java/com/datastrato/graviton/storage/kv/RocksDBKvBackend.java+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/RocksDBKvBackend.java@@ -204,6 +204,11 @@ public class RocksDBKvBackend implements KvBackend {@Overridepublic <R, E extends Exception> R executeInTransaction(Executable<R, E> executable)throws E, IOException {+ // Already in tx, directly execute it without creating a new tx+ if (TX_LOCAL.get() != null) {+ return executable.execute();+ }+Transaction tx = db.beginTransaction(new WriteOptions());LOGGER.info("Starting transaction: {}", tx);TX_LOCAL.set(tx);diff --git a/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityStorageBackend.java b/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityStorageBackend.javaindex 975302a4fb..87c42d2601 100644--- a/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityStorageBackend.java+++ b/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityStorageBackend.java@@ -189,6 +189,16 @@ public class TestEntityStorageBackend {NoSuchEntityException.class,() -> store.get(metalake.nameIdentifier(), EntityType.METALAKE, BaseMetalake.class));+ // Add new updateMetaLake.+ // 'updatedMetalake2' is a new name, which will trigger id allocation+ BaseMetalake updatedMetalake2 =+ new BaseMetalake.Builder()+ .withId(metalake.getId())+ .withName("updatedMetalake2")+ .withAuditInfo(auditInfo)+ .withVersion(SchemaVersion.V_0_1)+ .build();+ store.put(updatedMetalake2);} catch (Exception e) {Assertions.fail(e.getMessage());}