diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java index 37059ba4600..20f5949f1a0 100644 --- a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java +++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java @@ -38,7 +38,6 @@ import org.apache.hadoop.hdds.utils.db.cache.CacheKey; import org.apache.hadoop.hdds.utils.db.cache.CacheValue; import org.apache.hadoop.ozone.common.BlockGroup; -import org.apache.hadoop.ozone.om.exceptions.OMException; import org.apache.hadoop.ozone.om.helpers.BucketLayout; import org.apache.hadoop.ozone.om.helpers.ListKeysResult; import org.apache.hadoop.ozone.om.helpers.ListOpenFilesResult; @@ -510,7 +509,7 @@ String getMultipartKeyFSO(String volume, String bucket, String key, String /** * @return list all LifecycleConfigurations. */ - List listLifecycleConfigurations() throws OMException; + List listLifecycleConfigurations() throws IOException; /** * Fetches the lifecycle configuration by bucketName. diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java index ecbfc7ac395..dc0bba895eb 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java @@ -546,8 +546,8 @@ protected void initializeOmTables(CacheType cacheType, s3RevokedStsTokenTable = initializer.get( OMDBDefinition.S3_REVOKED_STS_TOKEN_TABLE_DEF, cacheType); - lifecycleConfigurationTable = initializer.get(OMDBDefinition.LIFECYCLE_CONFIGURATION_TABLE_DEF, cacheType); - lifecycleScanStateTable = initializer.get(OMDBDefinition.LIFECYCLE_SCAN_STATE_TABLE_DEF, cacheType); + lifecycleConfigurationTable = initializer.get(OMDBDefinition.LIFECYCLE_CONFIGURATION_TABLE_DEF); + lifecycleScanStateTable = initializer.get(OMDBDefinition.LIFECYCLE_SCAN_STATE_TABLE_DEF); } /** @@ -1779,25 +1779,39 @@ public Table getLifecycleScanStateTable() { * @return list all LifecycleConfigurations. */ @Override - public List listLifecycleConfigurations() { + public List listLifecycleConfigurations() throws IOException { List result = Lists.newArrayList(); + Set cachedKeys = new HashSet<>(); - /* lifecycleConfigurationTable is full-cache, so we use cacheIterator. */ + // lifecycleConfigurationTable uses partial cache, so cacheIterator() only returns + // entries that are currently in memory. Process cache entries first to handle + // any pending writes or pending deletes that have not yet been flushed to RocksDB. Iterator, CacheValue>> cacheIterator = getLifecycleConfigurationTable().cacheIterator(); - - OmLifecycleConfiguration lifecycleConfiguration; while (cacheIterator.hasNext()) { Map.Entry, CacheValue> entry = cacheIterator.next(); - lifecycleConfiguration = entry.getValue().getCacheValue(); + cachedKeys.add(entry.getKey().getCacheKey()); + OmLifecycleConfiguration lifecycleConfiguration = entry.getValue().getCacheValue(); if (lifecycleConfiguration == null) { - // lifecycleConfiguration null means it's a deleted. + // null means it's a pending delete. continue; } result.add(lifecycleConfiguration); } + // Also iterate RocksDB to pick up entries that have been evicted from (or were + // never loaded into) the partial cache. + try (TableIterator> + iter = getLifecycleConfigurationTable().iterator()) { + while (iter.hasNext()) { + KeyValue kv = iter.next(); + if (!cachedKeys.contains(kv.getKey())) { + result.add(kv.getValue()); + } + } + } + return result; } diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java index f3c86851a85..ade0b0d72f6 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java @@ -202,7 +202,7 @@ public BackgroundTaskQueue getTasks() { List lifecycleConfigurationList = null; try { lifecycleConfigurationList = omMetadataManager.listLifecycleConfigurations(); - } catch (OMException e) { + } catch (IOException e) { LOG.error("Failed to list lifecycle configurations", e); return queue; }