Copilot commented on code in PR #2658:
URL: https://github.com/apache/phoenix/pull/2658#discussion_r4474068394
##########
phoenix-core/src/test/java/org/apache/phoenix/schema/PMetaDataImplTest.java:
##########
@@ -200,6 +208,83 @@ public void testSchema() throws Exception {
}
}
+ private static PTable newTable(String name, PTableType type, String
parentName, long timeStamp,
+ List<PTable> indexes) throws SQLException {
+ PColumn pkColumn =
+ new PColumnImpl(PNameFactory.newName("K"), null, PVarchar.INSTANCE,
null, null, false, 0,
+ SortOrder.ASC, null, null, false, null, false, false, null,
HConstants.LATEST_TIMESTAMP);
+ return new PTableImpl.Builder().setType(type).setTimeStamp(timeStamp)
+ .setIndexDisableTimestamp(0L).setSequenceNumber(PTable.INITIAL_SEQ_NUM)
+
.setImmutableRows(false).setDisableWAL(false).setMultiTenant(false).setStoreNulls(false)
+
.setUpdateCacheFrequency(0).setNamespaceMapped(false).setAppendOnlySchema(false)
+ .setImmutableStorageScheme(ImmutableStorageScheme.ONE_CELL_PER_COLUMN)
+
.setQualifierEncodingScheme(QualifierEncodingScheme.NON_ENCODED_QUALIFIERS)
+ .setBaseColumnCount(BASE_TABLE_BASE_COLUMN_COUNT)
+
.setEncodedCQCounter(EncodedCQCounter.NULL_COUNTER).setUseStatsForParallelization(true)
+ .setExcludedColumns(ImmutableList.of()).setSchemaName(PName.EMPTY_NAME)
+ .setTableName(PNameFactory.newName(name))
+ .setParentTableName(parentName == null ? null :
PNameFactory.newName(parentName))
+
.setRowKeyOrderOptimizable(true).setIndexes(indexes).setPhysicalNames(ImmutableList.of())
+ .setColumns(Collections.singletonList(pkColumn)).build();
+ }
+
+ private static PTableRef getRefOrNull(PMetaData metaData, String name) {
+ try {
+ return metaData.getTableRef(new PTableKey(null, name));
+ } catch (TableNotFoundException e) {
+ return null;
+ }
+ }
+
+ @Test
+ public void testRemoveIndexWithoutTimestampEvictsParent() throws Exception {
+ long tableTimeStamp = MetaDataProtocol.MIN_TABLE_TIMESTAMP + 100;
+ PMetaData metaData = new PMetaDataImpl(5, Long.MAX_VALUE, new
TestTimeKeeper(),
+ new ReadOnlyProps(Collections.EMPTY_MAP));
+ PTable index = newTable("I", PTableType.INDEX, "T", tableTimeStamp,
Collections.emptyList());
+ PTable table =
+ newTable("T", PTableType.TABLE, null, tableTimeStamp,
Collections.singletonList(index));
+ metaData.addTable(table, tableTimeStamp);
+ PTable snapshot = metaData.getTableRef(table.getKey()).getTable();
+
+ metaData.removeTable(null, "I", "T", HConstants.LATEST_TIMESTAMP);
+
+ // A cached parent without the index must not keep the server timestamp.
Otherwise the
+ // server reports no change and does not send the full table.
+ PTableRef parentRef = getRefOrNull(metaData, "T");
+ if (parentRef != null) {
+ PTable parent = parentRef.getTable();
+ boolean hasIndex = false;
+ for (PTable i : parent.getIndexes()) {
+ hasIndex |= i.getName().getString().equals("I");
+ }
+ if (!hasIndex) {
+ fail("Parent without the index kept timestamp " +
parent.getTimeStamp());
+ }
+ }
Review Comment:
This check also passes if `removeTable` leaves the original parent
completely untouched, because that parent still contains `I`. Such a regression
would retain the old consistency descriptor and timestamp while this eviction
test remains green. Assert that the parent reference is null before restoring
the snapshot so the test actually enforces the required eviction.
--
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]