Fix query TVList snapshot race during working memtable reads
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java
index 6a2e554..ee5cd1a 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java
@@ -171,11 +171,17 @@
         list.getQueryContextSet().add(context);
         tvListQueryMap.put(list, list.rowCount());
       } else {
-        if (list.isSorted() || list.getQueryContextSet().isEmpty()) {
+        boolean isSorted;
+        int rowCount;
+        synchronized (list) {
+          isSorted = list.isSorted();
+          rowCount = list.rowCount();
+        }
+        if (isSorted || list.getQueryContextSet().isEmpty()) {
           LOGGER.debug(
               "Working MemTable - add current query context to mutable TVList's query list when it's sorted or no other query on it");
           list.getQueryContextSet().add(context);
-          tvListQueryMap.put(list, list.rowCount());
+          tvListQueryMap.put(list, rowCount);
         } else {
           /*
            * +----------------------+