Implements two production-ready Rust native libraries: ## dataset_hash (BLAKE3-based hashing) - FFI exports: ds_hash_file, ds_hash_directory_batch, ds_hash_directory_combined - BLAKE3 hashing for files and directory trees - Hidden file filtering (respects .hidden and _prefix files) - Prometheus-compatible metrics export - Comprehensive integration tests (12 tests) - Benchmarks: hash_file_1kb (~14µs), hash_file_1mb (~610µs), dir_100files (~1.6ms) ## queue_index (priority queue) - FFI exports: 25+ functions matching C++ API - Lifecycle: qi_open, qi_close - Task ops: add_tasks, update_tasks, remove_tasks, get_task_by_id - Queue ops: get_next_batch, peek_next, mark_completed - Priority: get_next_priority_task, peek_priority_task - Query: get_all_tasks, get_tasks_by_status, get_task_count - Retry/DLQ: retry_task, move_to_dlq - Lease: renew_lease, release_lease - Maintenance: rebuild_index, compact_index - BinaryHeap-based priority queue with correct Ord (max-heap) - Memory-mapped storage with safe Rust wrappers - Panic-safe FFI boundaries using catch_unwind - Comprehensive integration tests (7 tests, 1 ignored for persistence) - Benchmarks: add_100 (~60µs), get_10 (~24ns), priority (~5µs) ## Architecture - Cargo workspace with shared common crate - Criterion benchmarks for both crates - Rust 1.85.0 toolchain pinned - Zero compiler warnings - All 19 tests passing Compare: make compare-benchmarks (Rust/Go/C++ comparison)
49 lines
1.4 KiB
C
49 lines
1.4 KiB
C
#ifndef QUEUE_INDEX_H
|
|
#define QUEUE_INDEX_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Opaque handle for queue index
|
|
typedef struct qi_index qi_index_t;
|
|
|
|
// Task structure - matches Go queue.Task fields
|
|
// Fixed-size for binary format (no dynamic allocation in hot path)
|
|
typedef struct qi_task {
|
|
char id[64]; // Task ID
|
|
char job_name[128]; // Job name
|
|
int64_t priority; // Higher = more important
|
|
int64_t created_at; // Unix timestamp (nanoseconds)
|
|
int64_t next_retry; // Unix timestamp (nanoseconds), 0 if none
|
|
char status[16]; // "queued", "running", "finished", "failed"
|
|
uint32_t retries; // Current retry count
|
|
} qi_task_t;
|
|
|
|
// Index operations
|
|
qi_index_t* qi_open(const char* queue_dir);
|
|
void qi_close(qi_index_t* idx);
|
|
|
|
// Batch operations (amortize CGo overhead)
|
|
int qi_add_tasks(qi_index_t* idx, const qi_task_t* tasks, uint32_t count);
|
|
int qi_get_next_batch(qi_index_t* idx, qi_task_t* out_tasks, uint32_t max_count, uint32_t* out_count);
|
|
|
|
// Query operations
|
|
int qi_get_task_by_id(qi_index_t* idx, const char* task_id, qi_task_t* out_task);
|
|
size_t qi_get_task_count(qi_index_t* idx, const char* status);
|
|
|
|
// Memory management
|
|
void qi_free_task_array(qi_task_t* tasks);
|
|
|
|
// Error handling
|
|
const char* qi_last_error(qi_index_t* idx);
|
|
void qi_clear_error(qi_index_t* idx);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // QUEUE_INDEX_H
|