Repository: Alluxio/alluxio (language: java)

Issue:
NPE at DefaultStorageTierAssoc.getOrdinal when using paged block store
**Alluxio Version:**
What version of Alluxio are you using?
current master

**Describe the bug**

When using the paged block store, block master cannot find a tier in the global tier list. This causes a NPE.

```
2022-07-21 09:25:28,311 ERROR FileSystemMasterClientServiceHandler - Exit (Error): ListStatus: request=path: "/"
options {
  loadMetadataType: ONCE
  commonOptions {
    syncIntervalMs: -1
    ttl: -1
    ttlAction: DELETE
  }
  recursive: true
  loadMetadataOnly: false
}

java.lang.NullPointerException
 at alluxio.DefaultStorageTierAssoc.getOrdinal(DefaultStorageTierAssoc.java:99)
 at alluxio.master.file.DefaultFileSystemMaster.isInTopStorageTier(DefaultFileSystemMaster.java:2401)
 at alluxio.master.file.DefaultFileSystemMaster.getFileInMemoryPercentageInternal(DefaultFileSystemMaster.java:2351)
 at alluxio.master.file.DefaultFileSystemMaster.getFileInfoInternal(DefaultFileSystemMaster.java:965)
 at alluxio.master.file.DefaultFileSystemMaster.listStatusInternal(DefaultFileSystemMaster.java:1213)
 at alluxio.master.file.DefaultFileSystemMaster.listStatusInternal(DefaultFileSystemMaster.java:1201)
 at alluxio.master.file.DefaultFileSystemMaster.listStatusInternal(DefaultFileSystemMaster.java:1201)
 at alluxio.master.file.DefaultFileSystemMaster.listStatus(DefaultFileSystemMaster.java:1124)
 at alluxio.master.file.FileSystemMasterClientServiceHandler.lambda$listStatus$10(FileSystemMasterClientServiceHandler.java:255)
 at alluxio.RpcUtils.callAndReturn(RpcUtils.java:123)
 at alluxio.master.file.FileSystemMasterClientServiceHandler.listStatus(FileSystemMasterClientServiceHandler.java:253)

<snip>
```

**To Reproduce**
Use paged block store and do a `ls` on a file.

**Additional context**

Current tier of paged block store is `DefaultTier`, but `alluxio.master.block.DefaultBlockMaster#MASTER_STORAGE_TIER_ASSOC` expects it to be one of `MEM` `SSD` `HDD`.



Discussion / hints:
@beinan FYI.

Fix patch:
diff --git a/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStore.java b/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStore.java
index 56c4a42982e3..7295540e8387 100644
--- a/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStore.java
+++ b/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStore.java
@@ -11,7 +11,6 @@
 
 package alluxio.worker.page;
 
-import static alluxio.worker.page.PagedBlockStoreMeta.DEFAULT_DIR;
 import static alluxio.worker.page.PagedBlockStoreMeta.DEFAULT_TIER;
 
 import alluxio.client.file.cache.CacheManager;
@@ -292,13 +291,14 @@ public void removeInaccessibleStorage() {
     for (BlockStoreEventListener listener : mBlockStoreEventListeners) {
       synchronized (listener) {
         List<Long> lostBlocks = ImmutableList.of();
-        String lostStorageTier = DEFAULT_TIER;
-        String lostStoragePath = DEFAULT_DIR;
+        // TODO(bowen): lost directories can be obtained by iterating dirs in PageMetaStore
+        // and check their health
+        String lostStoragePath = "lostDir";
         BlockStoreLocation lostStoreLocation = new BlockStoreLocation(DEFAULT_TIER, 1);
         for (long lostBlock : lostBlocks) {
           listener.onBlockLost(lostBlock);
         }
-        listener.onStorageLost(lostStorageTier, lostStoragePath);
+        listener.onStorageLost(DEFAULT_TIER, lostStoragePath);
         listener.onStorageLost(lostStoreLocation);
       }
     }
diff --git a/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStoreMeta.java b/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStoreMeta.java
index 68967c839003..0868e8d3a8fc 100644
--- a/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStoreMeta.java
+++ b/core/server/worker/src/main/java/alluxio/worker/page/PagedBlockStoreMeta.java
@@ -11,6 +11,7 @@
 
 package alluxio.worker.page;
 
+import alluxio.Constants;
 import alluxio.DefaultStorageTierAssoc;
 import alluxio.StorageTierAssoc;
 import alluxio.client.file.cache.PageId;
@@ -18,6 +19,8 @@
 import alluxio.client.file.cache.PageMetaStore;
 import alluxio.client.file.cache.store.PageStoreDir;
 import alluxio.collections.Pair;
+import alluxio.conf.Configuration;
+import alluxio.conf.PropertyKey;
 import alluxio.exception.PageNotFoundException;
 import alluxio.resource.LockResource;
 import alluxio.worker.block.BlockStoreLocation;
@@ -41,9 +44,11 @@
  * Metadata of the paged block store.
  */
 public class PagedBlockStoreMeta implements BlockStoreMeta {
-  public static final String DEFAULT_TIER = "DefaultTier";
-  public static final String DEFAULT_DIR = "DefaultDir";
-  public static final String DEFAULT_MEDIUM = "SSD";
+  // Paged block store does not support multiple tiers, so assume everything is in the top tier
+  public static final String DEFAULT_TIER =
+      Configuration.getString(PropertyKey.MASTER_TIERED_STORE_GLOBAL_LEVEL0_ALIAS);
+  // top tier is conventionally ramdisk
+  public static final String DEFAULT_MEDIUM = Constants.MEDIUM_MEM;
   public static final DefaultStorageTierAssoc DEFAULT_STORAGE_TIER_ASSOC =
       new DefaultStorageTierAssoc(ImmutableList.of(DEFAULT_MEDIUM));
 


Test patch: