virajjasani commented on code in PR #1976:
URL: https://github.com/apache/phoenix/pull/1976#discussion_r1753117587


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/MetaDataEndPointIT.java:
##########
@@ -54,4 +60,107 @@ public void testUpdateIndexState() throws Throwable {
             assertEquals(MutationCode.UNALLOWED_TABLE_MUTATION, code);
         }
        }
+
+    @Test
+    public void testMetadataMetricsOfCreateTable() throws Throwable {
+        String schemaName = generateUniqueName();
+        String tableName = generateUniqueName();
+        final String fullTableName = SchemaUtil.getTableName(schemaName, 
tableName);
+        try (PhoenixConnection conn = (PhoenixConnection) 
DriverManager.getConnection(getUrl())) {
+            MetricsMetadataSourceImpl metricsSource = 
(MetricsMetadataSourceImpl) 
MetricsMetadataSourceFactory.getMetadataMetricsSource();
+            DynamicMetricsRegistry registry = 
metricsSource.getMetricsRegistry();
+            long expectedCreateTableCount =
+                    
IndexMetricsIT.getCounterValueByName(MetricsMetadataSource.CREATE_TABLE_COUNT, 
registry);
+            long expectedCacheUsedSize =
+                    
IndexMetricsIT.getCounterValueByName(MetricsMetadataSource.METADATA_CACHE_USED_SIZE,
 registry);
+            long expectedCacheAddCount =
+                    
IndexMetricsIT.getCounterValueByName(MetricsMetadataSource.METADATA_CACHE_ADD_COUNT,
 registry);
+
+            String ddl = "CREATE TABLE " + fullTableName + "(k INTEGER PRIMARY 
KEY, v1 INTEGER, " +
+                    "v2 INTEGER) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true, 
GUIDE_POSTS_WIDTH=1000";
+            conn.createStatement().execute(ddl);
+
+            expectedCreateTableCount += 1;
+            
IndexMetricsIT.verifyCounterWithValue(MetricsMetadataSource.CREATE_TABLE_COUNT,
+                    registry, expectedCreateTableCount);
+
+            PTable table = conn.getTableNoCache(fullTableName);
+            expectedCacheUsedSize += table.getEstimatedSize();
+            
IndexMetricsIT.verifyCounterWithValue(MetricsMetadataSource.METADATA_CACHE_USED_SIZE,
+                    registry, expectedCacheUsedSize);
+
+            expectedCacheAddCount += 1;
+            
IndexMetricsIT.verifyCounterWithValue(MetricsMetadataSource.METADATA_CACHE_ADD_COUNT,
+                    registry, expectedCacheAddCount);
+        }
+    }
+
+    @Test
+    public void testMetadataMetricsOfDropTable() throws Throwable {
+        String schemaName = generateUniqueName();
+        String tableName = generateUniqueName();
+        final String fullTableName = SchemaUtil.getTableName(schemaName, 
tableName);
+        try (PhoenixConnection conn = (PhoenixConnection) 
DriverManager.getConnection(getUrl())) {
+            MetricsMetadataSourceImpl metricsSource = 
(MetricsMetadataSourceImpl) 
MetricsMetadataSourceFactory.getMetadataMetricsSource();
+            DynamicMetricsRegistry registry = 
metricsSource.getMetricsRegistry();
+
+            String ddl = "CREATE TABLE " + fullTableName + "(k INTEGER PRIMARY 
KEY, v1 INTEGER, " +
+                    "v2 INTEGER) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true, 
GUIDE_POSTS_WIDTH=1000";
+            conn.createStatement().execute(ddl);
+
+            long expectedDropTableCount =
+                    
IndexMetricsIT.getCounterValueByName(MetricsMetadataSource.DROP_TABLE_COUNT, 
registry);
+            long expectedCacheUsedSize =
+                    
IndexMetricsIT.getCounterValueByName(MetricsMetadataSource.METADATA_CACHE_USED_SIZE,
 registry);
+            PTable table = conn.getTableNoCache(fullTableName);
+
+            ddl = "DROP TABLE " + fullTableName;
+            conn.createStatement().execute(ddl);
+
+            expectedDropTableCount += 1;
+            
IndexMetricsIT.verifyCounterWithValue(MetricsMetadataSource.DROP_TABLE_COUNT,
+                    registry, expectedDropTableCount);
+
+            expectedCacheUsedSize -= table.getEstimatedSize();
+            
IndexMetricsIT.verifyCounterWithValue(MetricsMetadataSource.METADATA_CACHE_USED_SIZE,
+                    registry, expectedCacheUsedSize);
+        }
+    }
+
+    @Test
+    public void testMetadataMetricsOfAlterTableAddCol() throws Throwable {
+        String schemaName = generateUniqueName();
+        String tableName = generateUniqueName();
+        final String fullTableName = SchemaUtil.getTableName(schemaName, 
tableName);
+        try (PhoenixConnection conn = (PhoenixConnection) 
DriverManager.getConnection(getUrl())) {
+            MetricsMetadataSourceImpl metricsSource = 
(MetricsMetadataSourceImpl) 
MetricsMetadataSourceFactory.getMetadataMetricsSource();
+            DynamicMetricsRegistry registry = 
metricsSource.getMetricsRegistry();
+
+            String ddl = "CREATE TABLE " + fullTableName +
+                    "  (a_string varchar not null, col1 integer" +
+                    "  CONSTRAINT pk PRIMARY KEY (a_string)) ";
+            conn.createStatement().execute(ddl);
+
+            long expectedDropTableCount =
+                    
IndexMetricsIT.getCounterValueByName(MetricsMetadataSource.ALTER_ADD_COLUMN_COUNT,
 registry);
+//            long expectedCacheUsedSize =
+//                    
IndexMetricsIT.getCounterValueByName(MetricsMetadataSource.METADATA_CACHE_USED_SIZE,
 registry);
+//            int tableEstimatedSize = 
conn.getTableNoCache(fullTableName).getEstimatedSize();
+
+            ddl = "ALTER TABLE " + fullTableName + " ADD  b_string VARCHAR  
NULL PRIMARY KEY  ";
+            conn.createStatement().execute(ddl);
+//            int newTableEstimatedSize = 
conn.getTableNoCache(fullTableName).getEstimatedSize();
+
+            expectedDropTableCount += 1;
+            
IndexMetricsIT.verifyCounterWithValue(MetricsMetadataSource.ALTER_ADD_COLUMN_COUNT,
+                    registry, expectedDropTableCount);
+
+//            System.out.println(expectedCacheUsedSize);
+//            System.out.println(tableEstimatedSize);
+//            System.out.println(newTableEstimatedSize);
+//            expectedCacheUsedSize = expectedCacheUsedSize - 
tableEstimatedSize + newTableEstimatedSize;
+//            
IndexMetricsIT.verifyCounterWithValue(MetricsMetadataSource.METADATA_CACHE_USED_SIZE,
+//                    registry, expectedCacheUsedSize);

Review Comment:
   Correct @jinggou, it is not required that we compare the exact cache used 
size metric, but what we can do is measure that the value of used cache is 
higher or lower from previous value.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to