use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class TopicImage method write.
public void write(Consumer<List<ApiMessageAndVersion>> out) {
List<ApiMessageAndVersion> batch = new ArrayList<>();
batch.add(new ApiMessageAndVersion(new TopicRecord().setName(name).setTopicId(id), TOPIC_RECORD.highestSupportedVersion()));
for (Entry<Integer, PartitionRegistration> entry : partitions.entrySet()) {
int partitionId = entry.getKey();
PartitionRegistration partition = entry.getValue();
batch.add(partition.toRecord(id, partitionId));
}
out.accept(batch);
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class SnapshotFileReader method handleMetadataBatch.
private void handleMetadataBatch(FileChannelRecordBatch batch) {
List<ApiMessageAndVersion> messages = new ArrayList<>();
for (Record record : batch) {
ByteBufferAccessor accessor = new ByteBufferAccessor(record.value());
try {
ApiMessageAndVersion messageAndVersion = serde.read(accessor, record.valueSize());
messages.add(messageAndVersion);
} catch (Throwable e) {
log.error("unable to read metadata record at offset {}", record.offset(), e);
}
}
listener.handleCommit(MemoryBatchReader.of(Collections.singletonList(Batch.data(batch.baseOffset(), batch.partitionLeaderEpoch(), batch.maxTimestamp(), batch.sizeInBytes(), messages)), reader -> {
}));
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class AclControlManager method deleteAclsForFilter.
AclDeleteResult deleteAclsForFilter(AclBindingFilter filter, List<ApiMessageAndVersion> records) {
List<AclBindingDeleteResult> deleted = new ArrayList<>();
for (Entry<Uuid, StandardAcl> entry : idToAcl.entrySet()) {
Uuid id = entry.getKey();
StandardAcl acl = entry.getValue();
AclBinding binding = acl.toBinding();
if (filter.matches(binding)) {
deleted.add(new AclBindingDeleteResult(binding));
records.add(new ApiMessageAndVersion(new RemoveAccessControlEntryRecord().setId(id), (short) 0));
}
}
return new AclDeleteResult(deleted);
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class AclControlManager method deleteAcls.
ControllerResult<List<AclDeleteResult>> deleteAcls(List<AclBindingFilter> filters) {
List<AclDeleteResult> results = new ArrayList<>();
List<ApiMessageAndVersion> records = new ArrayList<>();
for (AclBindingFilter filter : filters) {
try {
validateFilter(filter);
AclDeleteResult result = deleteAclsForFilter(filter, records);
results.add(result);
} catch (Throwable e) {
results.add(new AclDeleteResult(ApiError.fromThrowable(e).exception()));
}
}
return ControllerResult.atomicOf(records, results);
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class FeatureControlManager method updateFeature.
private ApiError updateFeature(String featureName, VersionRange newRange, boolean downgradeable, Map<Integer, Map<String, VersionRange>> brokerFeatures, List<ApiMessageAndVersion> records) {
if (newRange.min() <= 0) {
return new ApiError(Errors.INVALID_UPDATE_VERSION, "The lower value for the new range cannot be less than 1.");
}
if (newRange.max() <= 0) {
return new ApiError(Errors.INVALID_UPDATE_VERSION, "The upper value for the new range cannot be less than 1.");
}
VersionRange localRange = supportedFeatures.get(featureName);
if (localRange == null || !localRange.contains(newRange)) {
return new ApiError(Errors.INVALID_UPDATE_VERSION, "The controller does not support the given feature range.");
}
for (Entry<Integer, Map<String, VersionRange>> brokerEntry : brokerFeatures.entrySet()) {
VersionRange brokerRange = brokerEntry.getValue().get(featureName);
if (brokerRange == null || !brokerRange.contains(newRange)) {
return new ApiError(Errors.INVALID_UPDATE_VERSION, "Broker " + brokerEntry.getKey() + " does not support the given " + "feature range.");
}
}
VersionRange currentRange = finalizedVersions.get(featureName);
if (currentRange != null && currentRange.max() > newRange.max()) {
if (!downgradeable) {
return new ApiError(Errors.INVALID_UPDATE_VERSION, "Can't downgrade the maximum version of this feature without " + "setting downgradable to true.");
}
}
records.add(new ApiMessageAndVersion(new FeatureLevelRecord().setName(featureName).setMinFeatureLevel(newRange.min()).setMaxFeatureLevel(newRange.max()), FEATURE_LEVEL_RECORD.highestSupportedVersion()));
return ApiError.NONE;
}
Aggregations