Skip to content

Commit

Permalink
Store the previous_metadata_location for iceberg tables in polaris (N…
Browse files Browse the repository at this point in the history
  • Loading branch information
raveeram authored Jan 12, 2022
1 parent 7c4982b commit e3540f3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ create table TBLS (
id uuid default gen_random_uuid() not null primary key,
db_name varchar(255) not null,
tbl_name varchar(255) not null,
metadata_location varchar(1024),
previous_metadata_location varchar(8192),
metadata_location varchar(8192),
constraint uniq_name unique(db_name, tbl_name),
foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE
);
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class PolarisTableEntity {
@Column(name = "tbl_name", nullable = false)
private String tblName;

@Basic
@Setter
@Column(name = "previous_metadata_location", nullable = true, updatable = true)
private String previousMetadataLocation;

@Basic
@Setter
@Column(name = "metadata_location", nullable = true, updatable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ Slice<PolarisTableEntity> findAllTablesByDbNameAndTablePrefix(
* @return number of rows that are updated.
*/
@Modifying(flushAutomatically = true, clearAutomatically = true)
@Query("UPDATE PolarisTableEntity t SET t.metadataLocation = :newLocation, t.version = t.version + 1 "
+ "WHERE t.metadataLocation = :expectedLocation AND t.dbName = :dbName AND t.tblName = :tableName")
@Query("UPDATE PolarisTableEntity t SET t.metadataLocation = :newLocation, "
+ "t.previousMetadataLocation = t.metadataLocation, t.version = t.version + 1 "
+ "WHERE t.metadataLocation = :expectedLocation AND t.dbName = :dbName AND t.tblName = :tableName")
@Transactional
int updateMetadataLocation(
@Param("dbName") final String dbName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ public void updateMetadataLocation() {
// successful update should happen.
updatedSuccess = polarisConnector.updateTableMetadataLocation(dbName, tblName, metadataLocation, newLocation);
Assert.assertTrue(updatedSuccess);

final PolarisTableEntity updatedEntity = polarisConnector.
getTable(dbName, tblName).orElseThrow(() -> new RuntimeException("Expected to find saved entity"));
Assert.assertEquals(updatedEntity.getPreviousMetadataLocation(), metadataLocation);

// after the successful update, the same call should fail, since the current metadataLocation has changed.
updatedSuccess = polarisConnector.updateTableMetadataLocation(dbName, tblName, metadataLocation, newLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ create table TBLS (
id IDENTITY not null primary key,
db_name varchar(255) not null,
tbl_name varchar(255) not null,
previous_metadata_location varchar(1024),
metadata_location varchar(1024),
constraint uniq_name unique(db_name, tbl_name),
foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE
Expand Down
18 changes: 0 additions & 18 deletions metacat-functional-tests/metacat-test-cluster/crdb/sql/schema.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ create table TBLS (
id uuid default gen_random_uuid() not null primary key,
db_name varchar(255) not null,
tbl_name varchar(255) not null,
metadata_location varchar(1024),
previous_metadata_location varchar(8192),
metadata_location varchar(8192),
constraint uniq_name unique(db_name, tbl_name),
foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE
);

0 comments on commit e3540f3

Please sign in to comment.