/** * Delete records whose offset is smaller than the given offset of the corresponding partition. * * This is a convenience method for {@link #deleteRecords(Map, DeleteRecordsOptions)} with default options. * See the overload for more details. * * This operation is supported by brokers with version 0.11.0.0 or higher. * * @param recordsToDelete The topic partitions and related offsets from which records deletion starts. * @return The DeleteRecordsResult. */ public DeleteRecordsResult deleteRecords(Map<TopicPartition, RecordsToDelete> recordsToDelete) { return deleteRecords(recordsToDelete, new DeleteRecordsOptions()); }
recordsToDelete.put(myTopicPartition4, RecordsToDelete.beforeOffset(10L)); DeleteRecordsResult results = env.adminClient().deleteRecords(recordsToDelete);
void maybePurgeCommitedRecords() { // we do not check any possible exceptions since none of them are fatal // that should cause the application to fail, and we will try delete with // newer offsets anyways. if (deleteRecordsResult == null || deleteRecordsResult.all().isDone()) { if (deleteRecordsResult != null && deleteRecordsResult.all().isCompletedExceptionally()) { log.debug("Previous delete-records request has failed: {}. Try sending the new request now", deleteRecordsResult.lowWatermarks()); } final Map<TopicPartition, RecordsToDelete> recordsToDelete = new HashMap<>(); for (final Map.Entry<TopicPartition, Long> entry : active.recordsToDelete().entrySet()) { recordsToDelete.put(entry.getKey(), RecordsToDelete.beforeOffset(entry.getValue())); } deleteRecordsResult = adminClient.deleteRecords(recordsToDelete); log.trace("Sent delete-records request: {}", recordsToDelete); } }