Skip to content

Commit c97b150

Browse files
authored
Add feature config to allow dropping views without purging (apache#2369)
* Add feature config to allow dropping views without purging With tables, the client can decide whether to purge the table on drop or not. However, Polaris Servers used to unconditionally perform the purge on dropping a view. After apache#1619 that behaviour effectively prevents dropping views if the admin user does not set `DROP_WITH_PURGE_ENABLED`. The latter, though, is not currently advisable per apache#1617. This change introduces a new feature configuration (`PURGE_VIEWS_ON_DROP`) that allows the admin user to instruct Polaris servers to drop views without purging to achieve operational parity with tables. Fixes apache#2367 * review: rename to PURGE_VIEW_METADATA_ON_DROP * review: re-fix description
1 parent a75229c commit c97b150

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ at locations that better optimize for object storage.
5050
- The Helm chart now supports Pod Disruption Budgets (PDBs) for Polaris components. This allows users to define
5151
the minimum number of pods that must be available during voluntary disruptions, such as node maintenance.
5252

53+
- Feature configuration `PURGE_VIEW_METADATA_ON_DROP` was added to allow dropping views without purging their metadata files.
54+
5355
### Changes
5456

5557
- Polaris Management API clients must be prepared to deal with new attributes in `AwsStorageConfigInfo` objects.

integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisRestCatalogIntegrationBase.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,32 @@ public void testDropViewStatus() {
11991199
}
12001200
}
12011201

1202+
@Test
1203+
public void testDropViewWithPurge() {
1204+
restCatalog.createNamespace(Namespace.of("ns1"));
1205+
TableIdentifier id = TableIdentifier.of(Namespace.of("ns1"), "view1");
1206+
restCatalog
1207+
.buildView(id)
1208+
.withSchema(SCHEMA)
1209+
.withDefaultNamespace(Namespace.of("ns1"))
1210+
.withQuery("spark", VIEW_QUERY)
1211+
.create();
1212+
1213+
Catalog catalog = managementApi.getCatalog(currentCatalogName);
1214+
Map<String, String> catalogProps = new HashMap<>(catalog.getProperties().toMap());
1215+
catalogProps.put(FeatureConfiguration.DROP_WITH_PURGE_ENABLED.catalogConfig(), "false");
1216+
catalogProps.put(FeatureConfiguration.PURGE_VIEW_METADATA_ON_DROP.catalogConfig(), "true");
1217+
managementApi.updateCatalog(catalog, catalogProps);
1218+
1219+
assertThatThrownBy(() -> restCatalog.dropView(id)).isInstanceOf(ForbiddenException.class);
1220+
1221+
catalog = managementApi.getCatalog(currentCatalogName);
1222+
catalogProps.put(FeatureConfiguration.PURGE_VIEW_METADATA_ON_DROP.catalogConfig(), "false");
1223+
managementApi.updateCatalog(catalog, catalogProps);
1224+
1225+
assertThatCode(() -> restCatalog.dropView(id)).doesNotThrowAnyException();
1226+
}
1227+
12021228
@Test
12031229
public void testRenameViewStatus() {
12041230
String tableName = "tbl1";

polaris-core/src/main/java/org/apache/polaris/core/config/FeatureConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ public static void enforceFeatureEnabledOrThrow(
191191
.defaultValue(false)
192192
.buildFeatureConfiguration();
193193

194+
public static final FeatureConfiguration<Boolean> PURGE_VIEW_METADATA_ON_DROP =
195+
PolarisConfiguration.<Boolean>builder()
196+
.key("PURGE_VIEW_METADATA_ON_DROP")
197+
.catalogConfig("polaris.config.purge-view-metadata-on-drop")
198+
.description(
199+
"If set to true, Polaris will attempt to delete view metadata files when a view is dropped.")
200+
.defaultValue(true)
201+
.buildFeatureConfiguration();
202+
194203
public static final FeatureConfiguration<Integer> STORAGE_CREDENTIAL_DURATION_SECONDS =
195204
PolarisConfiguration.<Integer>builder()
196205
.key("STORAGE_CREDENTIAL_DURATION_SECONDS")

runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,13 @@ protected ViewOperations newViewOps(TableIdentifier identifier) {
801801

802802
@Override
803803
public boolean dropView(TableIdentifier identifier) {
804-
return dropTableLike(PolarisEntitySubType.ICEBERG_VIEW, identifier, Map.of(), true).isSuccess();
804+
boolean purge =
805+
callContext
806+
.getRealmConfig()
807+
.getConfig(FeatureConfiguration.PURGE_VIEW_METADATA_ON_DROP, catalogEntity);
808+
809+
return dropTableLike(PolarisEntitySubType.ICEBERG_VIEW, identifier, Map.of(), purge)
810+
.isSuccess();
805811
}
806812

807813
@Override

0 commit comments

Comments
 (0)