Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,33 @@ CompletableFuture<CommitConsumerOffsetsResponse> commitConsumerOffsets(
CompletableFuture<GetConsumerOffsetsResponse> getConsumerOffsets(
GetConsumerOffsetsRequest request);

/** Delete committed offsets for selected buckets of a consumer group. */
/**
* Deletes committed offsets for selected buckets of a consumer group. Requires Group {@code
* WRITE}; no source-table permission is required.
*/
@RPC(api = ApiKeys.DELETE_CONSUMER_OFFSETS)
CompletableFuture<DeleteConsumerOffsetsResponse> deleteConsumerOffsets(
DeleteConsumerOffsetsRequest request);

/**
* Lists consumer groups currently owned by this tablet server.
*
* <p>This is not a cluster-wide listing. Callers that need a cluster-wide view must query every
* tablet server and merge the responses.
* <p>Cluster {@code DESCRIBE} grants visibility to all locally owned groups; otherwise only
* groups with Group {@code DESCRIBE} are returned. This is not a cluster-wide listing. Callers
* that need a cluster-wide view must query every tablet server and merge the responses.
*/
@RPC(api = ApiKeys.LIST_CONSUMER_GROUPS)
CompletableFuture<ListConsumerGroupsResponse> listConsumerGroups(
ListConsumerGroupsRequest request);

/** Delete consumer groups and all of their committed offsets. */
/**
* Deletes consumer-group metadata and all committed offsets for each requested group. A later
* offset commit may recreate a deleted group.
*
* <p>No source-table permission is required. This is not a cluster-wide request. Callers must
* route each group to the tablet server that owns the group's consumer-offsets bucket; groups
* not owned by this server are reported with {@code NOT_CONSUMER_GROUP_OWNER}.
*/
@RPC(api = ApiKeys.DELETE_CONSUMER_GROUPS)
CompletableFuture<DeleteConsumerGroupsResponse> deleteConsumerGroups(
DeleteConsumerGroupsRequest request);
Expand Down
12 changes: 7 additions & 5 deletions fluss-rpc/src/main/proto/FlussApi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ message GetConsumerOffsetsResponse {
repeated PbGetConsumerOffsetsResponseTable tables = 1;
}

// Delete consumer offsets request and response.
// Delete committed offsets for selected buckets. Requires Group WRITE; no source-table permission.
message DeleteConsumerOffsetsRequest {
required string group_id = 1;
// An empty list, or tables containing no buckets, is a valid no-op and produces an empty
Expand All @@ -518,17 +518,19 @@ message DeleteConsumerOffsetsResponse {
repeated PbDeleteConsumerOffsetsResponseTable tables = 1;
}

// Lists consumer groups currently owned by the tablet server receiving this request. This is not
// a cluster-wide listing; callers that need a cluster-wide view must query every tablet server and
// merge the responses.
// Lists consumer groups currently owned by the tablet server receiving this request. Cluster
// DESCRIBE grants visibility to all locally owned groups; otherwise only groups with Group
// DESCRIBE are returned. This is not a cluster-wide listing; callers that need a cluster-wide
// view must query every tablet server and merge the responses.
message ListConsumerGroupsRequest {}

// All failures are returned through the RPC ErrorResponse envelope.
message ListConsumerGroupsResponse {
repeated PbListedGroup groups = 1;
}

// Delete consumer groups request and response.
// Deletes consumer-group metadata and all committed offsets. A later offset commit may
// recreate a deleted group. No source-table permission is required.
message DeleteConsumerGroupsRequest {
// An empty list is a valid no-op and produces an empty successful response.
repeated string groups = 1;
Expand Down
12 changes: 7 additions & 5 deletions fluss-rust/crates/fluss/src/proto/fluss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ pub struct GetConsumerOffsetsResponse {
#[prost(message, repeated, tag = "1")]
pub tables: ::prost::alloc::vec::Vec<PbGetConsumerOffsetsResponseTable>,
}
/// Delete consumer offsets request and response.
/// Delete committed offsets for selected buckets. Requires Group WRITE; no source-table permission.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteConsumerOffsetsRequest {
#[prost(string, required, tag = "1")]
Expand All @@ -668,9 +668,10 @@ pub struct DeleteConsumerOffsetsResponse {
#[prost(message, repeated, tag = "1")]
pub tables: ::prost::alloc::vec::Vec<PbDeleteConsumerOffsetsResponseTable>,
}
/// Lists consumer groups currently owned by the tablet server receiving this request. This is not
/// a cluster-wide listing; callers that need a cluster-wide view must query every tablet server and
/// merge the responses.
/// Lists consumer groups currently owned by the tablet server receiving this request. Cluster
/// DESCRIBE grants visibility to all locally owned groups; otherwise only groups with Group
/// DESCRIBE are returned. This is not a cluster-wide listing; callers that need a cluster-wide
/// view must query every tablet server and merge the responses.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ListConsumerGroupsRequest {}
/// All failures are returned through the RPC ErrorResponse envelope.
Expand All @@ -679,7 +680,8 @@ pub struct ListConsumerGroupsResponse {
#[prost(message, repeated, tag = "1")]
pub groups: ::prost::alloc::vec::Vec<PbListedGroup>,
}
/// Delete consumer groups request and response.
/// Deletes consumer-group metadata and all committed offsets. A later offset commit may
/// recreate a deleted group. No source-table permission is required.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteConsumerGroupsRequest {
/// An empty list is a valid no-op and produces an empty successful response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.fluss.cluster.ServerType;
import org.apache.fluss.exception.ApiException;
import org.apache.fluss.exception.AuthorizationException;
import org.apache.fluss.exception.InvalidRequestException;
import org.apache.fluss.exception.InvalidScanRequestException;
import org.apache.fluss.exception.InvalidTableException;
import org.apache.fluss.exception.NotLeaderOrFollowerException;
Expand Down Expand Up @@ -134,14 +135,14 @@
import org.apache.fluss.server.tablet.consumer.group.ConsumerOffsetTableConfig;
import org.apache.fluss.server.utils.ServerRpcMessageUtils;
import org.apache.fluss.server.zk.ZooKeeperClient;
import org.apache.fluss.utils.concurrent.FutureUtils;

import javax.annotation.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -158,11 +159,13 @@
import static org.apache.fluss.rpc.util.CommonRpcMessageUtils.hasHistoricalProduce;
import static org.apache.fluss.rpc.util.CommonRpcMessageUtils.hasHistoricalPut;
import static org.apache.fluss.security.acl.OperationType.DESCRIBE;
import static org.apache.fluss.security.acl.OperationType.DROP;
import static org.apache.fluss.security.acl.OperationType.READ;
import static org.apache.fluss.security.acl.OperationType.WRITE;
import static org.apache.fluss.server.coordinator.CoordinatorContext.INITIAL_COORDINATOR_EPOCH;
import static org.apache.fluss.server.log.FetchParams.DEFAULT_MAX_WAIT_MS_WHEN_MIN_BYTES_ENABLE;
import static org.apache.fluss.server.utils.ServerRpcMessageUtils.decodeCommitConsumerOffsetsRequest;
import static org.apache.fluss.server.utils.ServerRpcMessageUtils.decodeDeleteConsumerOffsetsRequest;
import static org.apache.fluss.server.utils.ServerRpcMessageUtils.decodeGetConsumerOffsetsRequest;
import static org.apache.fluss.server.utils.ServerRpcMessageUtils.getFetchLogData;
import static org.apache.fluss.server.utils.ServerRpcMessageUtils.getListOffsetsData;
Expand Down Expand Up @@ -816,37 +819,27 @@ public CompletableFuture<FindConsumerGroupOwnerResponse> findConsumerGroupOwner(
FindConsumerGroupOwnerRequest request) {
// Copy request/session values before returning: the request buffer is released after this
// method and the current session is bound to the RPC worker thread.
try {
final GroupId groupId = GroupId.of(request.getGroupId());
final String listenerName = currentListenerName();
if (authorizer != null) {
authorizer.authorize(currentSession(), DESCRIBE, Resource.group(groupId));
}

return groupManager
.findOwner(groupId, listenerName)
.thenApply(ServerRpcMessageUtils::makeFindConsumerGroupOwnerResponse);
} catch (ApiException e) {
return FutureUtils.completedExceptionally(e);
final GroupId groupId = GroupId.of(request.getGroupId());
final String listenerName = currentListenerName();
if (authorizer != null) {
authorizer.authorize(currentSession(), DESCRIBE, Resource.group(groupId));
}

return groupManager
.findOwner(groupId, listenerName)
.thenApply(ServerRpcMessageUtils::makeFindConsumerGroupOwnerResponse);
}

@Override
public CompletableFuture<CommitConsumerOffsetsResponse> commitConsumerOffsets(
CommitConsumerOffsetsRequest request) {
final GroupId groupId;
final Replica offsetsReplica;
final Map<TableBucket, ConsumerOffsetAndMetadata> offsets;
try {
groupId = GroupId.of(request.getGroupId());
if (authorizer != null) {
authorizer.authorize(currentSession(), READ, Resource.group(groupId));
}
offsetsReplica = groupManager.validateGroupId(groupId);
offsets = decodeCommitConsumerOffsetsRequest(request);
} catch (ApiException e) {
return FutureUtils.completedExceptionally(e);
final GroupId groupId = GroupId.of(request.getGroupId());
if (authorizer != null) {
authorizer.authorize(currentSession(), READ, Resource.group(groupId));
}
final Replica offsetsReplica = groupManager.validateGroupId(groupId);
final Map<TableBucket, ConsumerOffsetAndMetadata> offsets =
decodeCommitConsumerOffsetsRequest(request);
if (offsets.isEmpty()) {
return CompletableFuture.completedFuture(
makeCommitConsumerOffsetsResponse(Collections.emptyMap()));
Expand All @@ -868,19 +861,12 @@ public CompletableFuture<CommitConsumerOffsetsResponse> commitConsumerOffsets(
@Override
public CompletableFuture<GetConsumerOffsetsResponse> getConsumerOffsets(
GetConsumerOffsetsRequest request) {
final GroupId groupId;
final Replica offsetsReplica;
final List<TableBucket> requestedBuckets;
try {
groupId = GroupId.of(request.getGroupId());
if (authorizer != null) {
authorizer.authorize(currentSession(), DESCRIBE, Resource.group(groupId));
}
offsetsReplica = groupManager.validateGroupId(groupId);
requestedBuckets = decodeGetConsumerOffsetsRequest(request);
} catch (ApiException e) {
return FutureUtils.completedExceptionally(e);
final GroupId groupId = GroupId.of(request.getGroupId());
if (authorizer != null) {
authorizer.authorize(currentSession(), DESCRIBE, Resource.group(groupId));
}
final Replica offsetsReplica = groupManager.validateGroupId(groupId);
final List<TableBucket> requestedBuckets = decodeGetConsumerOffsetsRequest(request);

if (requestedBuckets != null && requestedBuckets.isEmpty()) {
return CompletableFuture.completedFuture(new GetConsumerOffsetsResponse());
Expand Down Expand Up @@ -928,28 +914,69 @@ private Map<TableBucket, ConsumerOffsetAndMetadata> filterOffsetsByAuthorizedTab
@Override
public CompletableFuture<DeleteConsumerOffsetsResponse> deleteConsumerOffsets(
DeleteConsumerOffsetsRequest request) {
CompletableFuture<DeleteConsumerOffsetsResponse> response = new CompletableFuture<>();
response.completeExceptionally(
new UnsupportedOperationException("deleteConsumerOffsets is not supported yet"));
return response;
final GroupId groupId = GroupId.of(request.getGroupId());
if (authorizer != null) {
authorizer.authorize(currentSession(), WRITE, Resource.group(groupId));
}
final Replica offsetsReplica = groupManager.validateGroupId(groupId);
final List<TableBucket> requestedBuckets = decodeDeleteConsumerOffsetsRequest(request);
if (requestedBuckets.isEmpty()) {
return CompletableFuture.completedFuture(new DeleteConsumerOffsetsResponse());
}

return groupManager
.handleDeleteConsumerOffsets(groupId, offsetsReplica, requestedBuckets)
.thenApply(ServerRpcMessageUtils::makeDeleteConsumerOffsetsResponse);
}

@Override
public CompletableFuture<ListConsumerGroupsResponse> listConsumerGroups(
ListConsumerGroupsRequest request) {
CompletableFuture<ListConsumerGroupsResponse> response = new CompletableFuture<>();
response.completeExceptionally(
new UnsupportedOperationException("listConsumerGroups is not supported yet"));
return response;
List<String> groupIds = groupManager.handleListConsumerGroups();
if (authorizer != null) {
List<Resource> resources =
groupIds.stream().map(Resource::group).collect(Collectors.toList());
groupIds =
authorizer.filterByAuthorized(currentSession(), DESCRIBE, resources).stream()
.map(Resource::getName)
.collect(Collectors.toList());
}
return CompletableFuture.completedFuture(
ServerRpcMessageUtils.makeListConsumerGroupsResponse(groupIds));
}

@Override
public CompletableFuture<DeleteConsumerGroupsResponse> deleteConsumerGroups(
DeleteConsumerGroupsRequest request) {
CompletableFuture<DeleteConsumerGroupsResponse> response = new CompletableFuture<>();
response.completeExceptionally(
new UnsupportedOperationException("deleteConsumerGroups is not supported yet"));
return response;
List<GroupId> groupIds = new ArrayList<>();
for (String groupId : request.getGroupsList()) {
groupIds.add(GroupId.of(groupId));
}
if (new HashSet<>(groupIds).size() != groupIds.size()) {
CompletableFuture<DeleteConsumerGroupsResponse> failed = new CompletableFuture<>();
failed.completeExceptionally(
new InvalidRequestException(
"DeleteConsumerGroups request contains duplicate group IDs"));
return failed;
}
if (groupIds.isEmpty()) {
return CompletableFuture.completedFuture(new DeleteConsumerGroupsResponse());
}

if (authorizer != null) {
for (GroupId groupId : groupIds) {
authorizer.authorize(currentSession(), DROP, Resource.group(groupId));
}
}

final Map<GroupId, Replica> offsetsReplicasByGroup = new HashMap<>();
for (GroupId groupId : groupIds) {
offsetsReplicasByGroup.put(groupId, groupManager.validateGroupId(groupId));
}

return groupManager
.handleDeleteConsumerGroups(offsetsReplicasByGroup)
.thenApply(ServerRpcMessageUtils::makeDeleteConsumerGroupsResponse);
}

@Override
Expand Down
Loading
Loading