apurtell commented on PR #2658: URL: https://github.com/apache/phoenix/pull/2658#issuecomment-6700549685
@virajjasani I reworked the patch as you suggested, and I dropped the earlier client cache changes. Your scratch IT, `AlterIndexConsistencyCrossClientIT`, passes with the fix and fails without. That’s the good news. I tested the fixed code a multi-node HBase cluster in Docker, with each client in its own JVM. The test does this: - It creates a table pre-split into four regions, with a STRONG covering index. - Two writer JVMs upsert rows continuously. One writer uses the patched client jar and the other uses the unpatched jar. - A separate DDL JVM runs the ALTERs. - It runs four steps: S→E, E→S, S→E, E→S. It splits the table after each S→E and merges two regions after each E→S, which follows you description of how the eventual consumers start. - After each ALTER, the test checks the consistency that each JVM uses, both in its cached index and in the index maintainer it sends with its writes. It checks the DDL JVM, both running writers, and a new JVM on each jar. - After each split or merge, the test pauses the writers and waits up to five minutes for the index row count to match the data row count. With the patch, every consistency check passed, in all four steps, in every client. In the control run on the base code, 15 of the 26 scenarios failed. That's the good news. However once every client really switches, I have uncovered some data loss due to other bugs in S→E and E→S cordination. In one representative test run, the index was short by 231 rows (9,447 data rows against 9,216 index rows). I traced the missing rows to three causes: 1. **S→E publishes EVENTUAL before the CDC objects exist.** Today, the ALTER commits EVENTUAL first and creates the CDC stream and CDC index after that. Writers that see EVENTUAL in the gap between these two actions skip synchronous maintenance, but their writes have no CDC record yet. Nothing later replays those writes into the index. **I measured about 30 lost rows per writer for each S→E.** 2. **After E→S, the consumer drops events that it has not applied yet.** Each consumer reloads the table and keeps only the indexes that are still asynchronous. The caller then records the batch as processed and moves the checkpoint forward. So when a region’s consumer is behind at the time of the switch, it skips all CDC events that writers produced while the index was EVENTUAL. **I measured 50 to 60 lost rows per writer for each E→S.** 3. **The consumer can read a stale table definition on the regionserver.** A consumer starts when its region opens. It checks for an eventually consistent index, and if it finds none, it exits. This check uses the server connection’s metadata cache and does not fetch from SYSTEM.CATALOG. After a region moved, a consumer read a cached STRONG definition and exited. Its region then had no consumer until the next split. **In one test this left 415 rows unindexed until the next split reopened the region.** I will keep this PR scoped to the ALTER metadata change and to the coordination between the ALTER and the consumers, in both directions: - **S→E ordering (A):** the ALTER will create the CDC stream and CDC index first, while the index is still STRONG. Only then will it commit EVENTUAL and the LAST_DDL_TIMESTAMP updates, and clear the caches. While the index is still STRONG, writers maintain the index synchronously and also produce CDC records. So no write can see EVENTUAL before its CDC record can exist. Some writes will get both synchronous maintenance and a CDC record. This is idempotent. - **E→S drain (B):** a consumer will not discard CDC events from the EVENTUAL period only because the index is now STRONG. It will continue to apply events for that index up to the point of the switch, and then stop. I am still working out how the consumer finds that point. It must also allow for clients that keep sending EVENTUAL maintainers for a short time after the switch, for example because of a non-default UPDATE_CACHE_FREQUENCY. I will post the details with the code. - **Fresh metadata in the consumer (C):** when the consumer decides whether it has work to do, it will read the table definition from SYSTEM.CATALOG, not from the region server’s cache. I will add IT coverage for each of these and then run the cluster test again. The goal is no lost rows after the change in every step. Not in scope (candidates for follow-up JIRAs) - Consumers start only when a region opens. After S→E, a region that never splits, merges, or moves gets no consumer, so its writes stay unindexed indefinitely. This is how consumers start today, so it means that S→E on a quiet table is incomplete until some region event happens. A follow-up could let an idle consumer check again later, so that it does not exit permanently. -- 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]
