Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't clean up streams internal topics on service exit #4655

Closed

Conversation

rodesai
Copy link
Contributor

@rodesai rodesai commented Feb 27, 2020

Description

When KSQL exits, it calls KsqlEngine.close. This patch changes the engine's
close to close all the queries but not clean up internal topics. Internal
topics are only cleaned up when queries are explicitly closed with the
clean up flag set.

part of the fix for #4654

Testing done

  • added unit tests
  • also reproduced the issue manually and verified it did not occur with this patch

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@rodesai rodesai requested a review from a team as a code owner February 27, 2020 08:53
@apurvam
Copy link
Contributor

apurvam commented Feb 27, 2020

@agavra @big-andy-coates can you prioritize reviewing and getting this merged ASAP?

3 similar comments
@apurvam
Copy link
Contributor

apurvam commented Feb 27, 2020

@agavra @big-andy-coates can you prioritize reviewing and getting this merged ASAP?

@apurvam
Copy link
Contributor

apurvam commented Feb 27, 2020

@agavra @big-andy-coates can you prioritize reviewing and getting this merged ASAP?

@apurvam
Copy link
Contributor

apurvam commented Feb 27, 2020

@agavra @big-andy-coates can you prioritize reviewing and getting this merged ASAP?

Copy link
Contributor

@agavra agavra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice catch @rodesai

Copy link
Contributor

@big-andy-coates big-andy-coates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this now not clean up internal topics for transient queries when the server stops?

We probably want different behaviour for transient vs persistent queries.

I'd be tempted to have a single close() method on QueryMetadata which deletes the internal state, and then a stop() method on PersistentQueryMetadata which stops the topology, but doesn't delete any internal state.

class QueryMetadata {
   ...

   /**
    * Stops the query and deletes any intermediate state associated with it.
  */
   public void close() {
     close(true);
   }

   void close(final boolean cleanup) {
    }
}

class PersistentQueryMetadata extends QueryMetadata {
   /**
    * stop the query, leaving any intermediate state in-place.
    */
   public void stop() {
       close(false);
   }
}

class KsqlEngine {


   void close() {

      for (query: allQueries() ) {
        if (query instanceof PersistentQuery) {
            ((PersistentQuery)query).stop();
       } else {
           query.close();
       }
     }
   }
}

Thoughts?

IMHO, this removes the boolean on the public close method - which will make the PR more targeted and the code cleaner/clearer.

If we make this change we should revert all the other changes where lambdas have been changed to method calls etc.

@big-andy-coates
Copy link
Contributor

I'm guessing this needs to target 5.5.x too.

Copy link
Contributor

@big-andy-coates big-andy-coates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, this change will leave transient query internal topics lying around.

Comment on lines 697 to 713
@Test
public void shouldNotCleanUpInternalTopicsOnEngineClose() {
// Given:
final QueryMetadata query = KsqlEngineTestUtil.executeQuery(
serviceContext,
ksqlEngine,
"select * from test1 EMIT CHANGES;",
KSQL_CONFIG, Collections.emptyMap()
);
query.start();

// When:
ksqlEngine.close();

// Then:
verifyNoMoreInteractions(topicClient);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a transient query, which should have its internal topics deleted when the engine closes. Can we update the functionality and test to reflect this?

Also, can we then add another similar test that shows persistent queries do not have their internal state deleted.

final Optional<PersistentQueryMetadata> query = ksqlEngine.getPersistentQuery(queryId.get());
query.ifPresent(PersistentQueryMetadata::close);
query.ifPresent(query -> query.close(true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line causes compilation failure.

Suggested change
query.ifPresent(query -> query.close(true));
query.ifPresent(q -> q.close(true));

When KSQL exits, it calls KsqlEngine.close. This patch changes the engine's
close to close all the queries but not clean up internal topics. Internal
topics are only cleaned up when queries are explicitly closed with the
clean up flag set.
@rodesai rodesai force-pushed the fix-topic-deletion-on-exit branch from 83cee11 to 6997894 Compare February 27, 2020 17:40
@rodesai
Copy link
Contributor Author

rodesai commented Feb 28, 2020

closing in favor of #4658

@rodesai rodesai closed this Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants