/** * Commit offset to backing store. * This might be an async operation. * * Locality: toppar handler thread */ rd_kafka_resp_err_t rd_kafka_offset_commit (rd_kafka_toppar_t *rktp) { if (1) // FIXME rd_kafka_dbg(rktp->rktp_rkt->rkt_rk, TOPIC, "OFFSET", "%s [%"PRId32"]: commit: " "stored offset %"PRId64" > committed offset %"PRId64"?", rktp->rktp_rkt->rkt_topic->str, rktp->rktp_partition, rktp->rktp_stored_offset, rktp->rktp_committed_offset); /* Already committed */ if (rktp->rktp_stored_offset <= rktp->rktp_committed_offset) return RD_KAFKA_RESP_ERR_NO_ERROR; /* Already committing (for async ops) */ if (rktp->rktp_stored_offset <= rktp->rktp_committing_offset) return RD_KAFKA_RESP_ERR__PREV_IN_PROGRESS; switch (rktp->rktp_rkt->rkt_conf.offset_store_method) { case RD_KAFKA_OFFSET_METHOD_FILE: return rd_kafka_offset_file_commit(rktp); case RD_KAFKA_OFFSET_METHOD_BROKER: return rd_kafka_offset_broker_commit(rktp); default: /* UNREACHABLE */ return RD_KAFKA_RESP_ERR__INVALID_ARG; } }
/** * Decommissions the use of an offset file for a toppar. * The file content will not be touched and the file will not be removed. * * NOTE: toppar_lock(rktp) must be held. */ static void rd_kafka_offset_file_term (rd_kafka_toppar_t *rktp) { if (rktp->rktp_rkt->rkt_conf.offset_store_sync_interval_ms > 0) rd_kafka_timer_stop(rktp->rktp_rkt->rkt_rk, &rktp->rktp_offset_sync_tmr, 1/*lock*/); rd_kafka_timer_stop(rktp->rktp_rkt->rkt_rk, &rktp->rktp_offset_commit_tmr, 1/*lock*/); if (rktp->rktp_stored_offset > rktp->rktp_commited_offset) rd_kafka_offset_file_commit(rktp, rktp->rktp_stored_offset); rd_kafka_offset_file_close(rktp); free(rktp->rktp_offset_path); rktp->rktp_offset_path = NULL; }
/** * Offset file commit timer callback. */ static void rd_kafka_offset_file_commit_tmr_cb (rd_kafka_t *rk, void *arg) { rd_kafka_toppar_t *rktp = arg; rd_kafka_toppar_lock(rktp); rd_kafka_dbg(rk, TOPIC, "OFFSET", "%s [%"PRId32"]: periodic commit: " "stored offset %"PRId64" > commited offset %"PRId64" ?", rktp->rktp_rkt->rkt_topic->str, rktp->rktp_partition, rktp->rktp_stored_offset, rktp->rktp_commited_offset); if (rktp->rktp_stored_offset > rktp->rktp_commited_offset) rd_kafka_offset_file_commit(rktp, rktp->rktp_stored_offset); rd_kafka_toppar_unlock(rktp); }