|
1 | 1 | package com.altinity.ice.rest.catalog.internal.maintenance; |
2 | 2 |
|
3 | 3 | import java.util.HashMap; |
| 4 | +import java.util.List; |
4 | 5 | import java.util.Map; |
5 | 6 | import java.util.Properties; |
6 | 7 | import java.util.concurrent.TimeUnit; |
7 | 8 | import java.util.concurrent.atomic.AtomicBoolean; |
| 9 | + |
| 10 | +import org.apache.iceberg.Table; |
| 11 | +import org.apache.iceberg.actions.Action; |
8 | 12 | import org.apache.iceberg.catalog.Catalog; |
| 13 | +import org.apache.iceberg.catalog.Namespace; |
| 14 | +import org.apache.iceberg.catalog.SupportsNamespaces; |
| 15 | +import org.apache.iceberg.catalog.TableIdentifier; |
9 | 16 | import org.quartz.CronScheduleBuilder; |
10 | 17 | import org.quartz.JobBuilder; |
11 | 18 | import org.quartz.JobDetail; |
@@ -172,6 +179,39 @@ public void performMaintenance() { |
172 | 179 | // - Compact small files |
173 | 180 |
|
174 | 181 | // For now, just log that we're performing maintenance |
| 182 | + // get the list of namespaces. |
| 183 | + List<Namespace> namespaces; |
| 184 | + if (catalog instanceof SupportsNamespaces) { |
| 185 | + SupportsNamespaces nsCatalog = (SupportsNamespaces) catalog; |
| 186 | + namespaces = nsCatalog.listNamespaces(); |
| 187 | + for (Namespace ns : namespaces) { |
| 188 | + logger.debug("Namespace: " + ns); |
| 189 | + } |
| 190 | + } else { |
| 191 | + logger.error("Catalog does not support namespace operations."); |
| 192 | + return; |
| 193 | + } // Iterate through namespace |
| 194 | + |
| 195 | + for (Namespace namespace : namespaces) { |
| 196 | + // Get the table |
| 197 | + List<TableIdentifier> tables = catalog.listTables(namespace); |
| 198 | + for (TableIdentifier tableIdent : tables) { |
| 199 | + long olderThanMillis = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30); |
| 200 | + // Get the table |
| 201 | + Table table = catalog.loadTable(tableIdent); |
| 202 | + // Expire snapshots older than 30 days |
| 203 | + table.expireSnapshots() |
| 204 | + .expireOlderThan(olderThanMillis) |
| 205 | + .commit(); |
| 206 | + // Remove Orphan Files |
| 207 | + |
| 208 | + // Rewrite Manifests |
| 209 | + table.rewriteManifests() |
| 210 | + .rewriteIf(manifest -> true) |
| 211 | + .commit(); |
| 212 | + } |
| 213 | + |
| 214 | + } |
175 | 215 | logger.info("Maintenance operations completed for catalog: {}", catalog.name()); |
176 | 216 | } else { |
177 | 217 | logger.warn("No catalog available for maintenance operations"); |
|
0 commit comments