From 66addc74b0af03b0d7b047b62f61518d999f501f Mon Sep 17 00:00:00 2001 From: xloya <982052490@qq.com> Date: Wed, 27 Mar 2024 16:46:57 +0800 Subject: [PATCH] [#2674] fix(jdbc backend): Save millisecond timestamp on mysql soft delete (#2685) ### What changes were proposed in this pull request? The current way of saving second-level timestamps will cause multiple deletion operations fails in the same second because of the duplicate key. This pr will save millisecond timestamp. ### Why are the changes needed? Fix: #2674 Co-authored-by: xiaojiebao --- .../storage/relational/mapper/CatalogMetaMapper.java | 4 ++-- .../storage/relational/mapper/FilesetMetaMapper.java | 8 ++++---- .../storage/relational/mapper/FilesetVersionMapper.java | 8 ++++---- .../storage/relational/mapper/MetalakeMetaMapper.java | 2 +- .../storage/relational/mapper/SchemaMetaMapper.java | 6 +++--- .../storage/relational/mapper/TableMetaMapper.java | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/CatalogMetaMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/CatalogMetaMapper.java index 652cf52cadd..038b4256f0b 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/CatalogMetaMapper.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/CatalogMetaMapper.java @@ -137,14 +137,14 @@ Integer updateCatalogMeta( @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE catalog_id = #{catalogId} AND deleted_at = 0") Integer softDeleteCatalogMetasByCatalogId(@Param("catalogId") Long catalogId); @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0") Integer softDeleteCatalogMetasByMetalakeId(@Param("metalakeId") Long metalakeId); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetMetaMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetMetaMapper.java index 33906f8b305..885a8d89908 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetMetaMapper.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetMetaMapper.java @@ -190,28 +190,28 @@ Integer updateFilesetMeta( @Update( "UPDATE " + META_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0") Integer softDeleteFilesetMetasByMetalakeId(@Param("metalakeId") Long metalakeId); @Update( "UPDATE " + META_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE catalog_id = #{catalogId} AND deleted_at = 0") Integer softDeleteFilesetMetasByCatalogId(@Param("catalogId") Long catalogId); @Update( "UPDATE " + META_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE schema_id = #{schemaId} AND deleted_at = 0") Integer softDeleteFilesetMetasBySchemaId(@Param("schemaId") Long schemaId); @Update( "UPDATE " + META_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE fileset_id = #{filesetId} AND deleted_at = 0") Integer softDeleteFilesetMetasByFilesetId(@Param("filesetId") Long filesetId); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetVersionMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetVersionMapper.java index b2df6ab43cb..af08416ea09 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetVersionMapper.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetVersionMapper.java @@ -73,28 +73,28 @@ void insertFilesetVersionOnDuplicateKeyUpdate( @Update( "UPDATE " + VERSION_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0") Integer softDeleteFilesetVersionsByMetalakeId(@Param("metalakeId") Long metalakeId); @Update( "UPDATE " + VERSION_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE catalog_id = #{catalogId} AND deleted_at = 0") Integer softDeleteFilesetVersionsByCatalogId(@Param("catalogId") Long catalogId); @Update( "UPDATE " + VERSION_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE schema_id = #{schemaId} AND deleted_at = 0") Integer softDeleteFilesetVersionsBySchemaId(@Param("schemaId") Long schemaId); @Update( "UPDATE " + VERSION_TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE fileset_id = #{filesetId} AND deleted_at = 0") Integer softDeleteFilesetVersionsByFilesetId(@Param("filesetId") Long filesetId); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/MetalakeMetaMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/MetalakeMetaMapper.java index 2336a6761a6..d1cb2d1ea73 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/MetalakeMetaMapper.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/MetalakeMetaMapper.java @@ -122,7 +122,7 @@ Integer updateMetalakeMeta( @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0") Integer softDeleteMetalakeMetaByMetalakeId(@Param("metalakeId") Long metalakeId); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/SchemaMetaMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/SchemaMetaMapper.java index 3e8723b053d..009cdcb20e5 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/SchemaMetaMapper.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/SchemaMetaMapper.java @@ -132,21 +132,21 @@ Integer updateSchemaMeta( @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE schema_id = #{schemaId} AND deleted_at = 0") Integer softDeleteSchemaMetasBySchemaId(@Param("schemaId") Long schemaId); @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0") Integer softDeleteSchemaMetasByMetalakeId(@Param("metalakeId") Long metalakeId); @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE catalog_id = #{catalogId} AND deleted_at = 0") Integer softDeleteSchemaMetasByCatalogId(@Param("catalogId") Long catalogId); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/TableMetaMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/TableMetaMapper.java index f1de8a51bd5..331847f8cdc 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/TableMetaMapper.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/TableMetaMapper.java @@ -127,28 +127,28 @@ Integer updateTableMeta( @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE table_id = #{tableId} AND deleted_at = 0") Integer softDeleteTableMetasByTableId(@Param("tableId") Long tableId); @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0") Integer softDeleteTableMetasByMetalakeId(@Param("metalakeId") Long metalakeId); @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE catalog_id = #{catalogId} AND deleted_at = 0") Integer softDeleteTableMetasByCatalogId(@Param("catalogId") Long catalogId); @Update( "UPDATE " + TABLE_NAME - + " SET deleted_at = UNIX_TIMESTAMP()" + + " SET deleted_at = UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000.0" + " WHERE schema_id = #{schemaId} AND deleted_at = 0") Integer softDeleteTableMetasBySchemaId(@Param("schemaId") Long schemaId); }