public ApiMessageAndVersion unregisterNodeRecord(int nodeId) {
        if (hasOpeningStreams(nodeId)) {
            throw new UnregisterNodeWithOpenStreamsException(String.format("Node %d has opening streams", nodeId));
        }
        if (lockedNodes.contains(nodeId)) {
            throw new NodeLockedException(String.format("Node %d is locked", nodeId));
        }
        RemoveKVRecord removeKVRecord = new RemoveKVRecord().setKeys(List.of(KEY_PREFIX + nodeId));
        return new ApiMessageAndVersion(removeKVRecord, (short) 0);
    }
Note: It is costly to check if a node has opening streams, so it is recommended to use this method only when necessary.
metadata/src/main/java/org/apache/kafka/controller/stream/NodeControlManager.java