virajjasani commented on code in PR #2658:
URL: https://github.com/apache/phoenix/pull/2658#discussion_r4509180048
##########
phoenix-core-server/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java:
##########
@@ -633,8 +635,39 @@ public void stop(CoprocessorEnvironment e) throws
IOException {
this.builder.stop(msg);
this.preWriter.stop(msg);
this.postWriter.stop(msg);
- if (this.indexCDCConsumer != null) {
- this.indexCDCConsumer.stop();
+ synchronized (indexCDCConsumerLock) {
+ if (this.indexCDCConsumer != null) {
+ this.indexCDCConsumer.stop();
+ }
+ }
+ }
+
+ /**
+ * Starts a new consumer when the consumer of the region has exited. A
consumer starts when its
+ * region opens, and it exits when no index needs the CDC events of the
region. An index can
+ * change to EVENTUAL later. The writers see that change in their index
maintainers, so a batch
+ * with an EVENTUAL index calls this method. The new consumer then reads the
current metadata.
+ */
+ private void restartIndexCDCConsumerIfExited() {
+ IndexCDCConsumer consumer = indexCDCConsumer;
+ if (consumer == null || !consumer.canRestart()) {
+ return;
+ }
+ synchronized (indexCDCConsumerLock) {
+ if (stopped || indexCDCConsumer != consumer) {
+ return;
+ }
+ try {
+ IndexCDCConsumer newConsumer = consumer.newInstance();
+ consumer.stop();
+ indexCDCConsumer = newConsumer;
+ newConsumer.start();
+ LOG.info("Restarted IndexCDCConsumer for table {} region {}",
dataTableName,
+ Bytes.toString(encodedRegionName));
+ } catch (IOException e) {
+ // The CDC keeps the events, so a later batch can try again.
+ LOG.warn("Cannot restart IndexCDCConsumer for table {}",
dataTableName, e);
+ }
Review Comment:
Can we not live without touching IndexRegionObserver for the purpose of this
PR? :)
--
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]