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

Faster topic removal in MultiDC setup #1884

Merged
merged 13 commits into from
Aug 5, 2024
Merged

Faster topic removal in MultiDC setup #1884

merged 13 commits into from
Aug 5, 2024

Conversation

moscicky
Copy link
Collaborator

@moscicky moscicky commented Jul 30, 2024

Fixes a race condition due to which topic/group removal in remote DC was taking up to 150s. Exact bug is described in pl.allegro.tech.hermes.infrastructure.zookeeper.ZookeeperTopicRepository#removeTopic. After this change group/topic removal takes tens of ms in remote DC.

@moscicky moscicky changed the title Consisteny analysis Faster topic removal in MultiDC setup Jul 30, 2024
@moscicky moscicky marked this pull request as ready for review July 30, 2024 14:43
try {
remove(paths.topicPath(topicName));
deleteInTransaction(pathsForRemoval);
Copy link
Contributor

@faderskd faderskd Aug 2, 2024

Choose a reason for hiding this comment

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

should we also use this method in other places ? because now we have two different methods for removing paths🤔 for paths without children it will be no-brainer (just use a simple remove), but for those with children we now have a choice

Copy link
Collaborator Author

@moscicky moscicky Aug 2, 2024

Choose a reason for hiding this comment

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

Transactional removal should only be used when needed - it has a higher overhead + it is required to supply all the paths. Most of the time we remove nodes with prefix e.g. delete all nodes for topic ((like /hermes/groups/group/topic/*) and this requires deleteChildrenIfNeeded which is not available in transactions. So imo these two methods have different usage scenarios

@@ -58,7 +61,7 @@ private <T> void execute(RepositoryCommand<T> command, boolean isRollbackEnabled
throw ExceptionWrapper.wrapInInternalProcessingExceptionIfNeeded(e, command.toString(), repoHolder.getDatacenterName());
}
} catch (Exception e) {
logger.warn("Execute failed with an error", e);
logger.warn("Failed to execute repository command: {} in ZK dc: {}", command, System.currentTimeMillis() - start, e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Failed to execute repository command: {} in ZK dc: {} in: {} ms", repoHolder.getDatacenterName(), System.currentTimeMillis() - start

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

throw new InternalProcessingException("Attempting to remove empty set of paths from ZK");
}
ensureConnected();
CuratorTransactionFinal transaction = zookeeper.inTransaction().delete().forPath(paths.get(0)).and();
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: ZooKeeper API mentions that inTransaction method is deprecated.

/**
 * Start a transaction builder
 *
 * @return builder object
 * @deprecated use {@link #transaction()} instead
 */
public CuratorTransaction inTransaction();

Can we use transaction() method here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Will be resolved here: #1886

}

transaction.commit();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

note: Here is my proposition for refactor:

protected void deleteInTransaction(List<String> paths) throws Exception {
    if (paths.isEmpty()) {
        throw new InternalProcessingException("Attempting to remove empty set of paths from ZK");
    }
    ensureConnected();
    zookeeper.transaction().forOperations(
            paths.stream().map(x -> {
                try {
                    return zookeeper.transactionOp().delete().forPath(x);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }).collect(Collectors.toList())
    );
}

Feel free to tweak with it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Will be resolved here: #1886

@moscicky moscicky merged commit a3cf6fd into master Aug 5, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants