You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

binlog.h 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef RSPAMD_BINLOG_H
  2. #define RSPAMD_BINLOG_H
  3. #include "config.h"
  4. #include "main.h"
  5. #include "statfile.h"
  6. /* How much records are in a single index */
  7. #define BINLOG_IDX_LEN 200
  8. #define METAINDEX_LEN 1024
  9. /* Assume 8 bytes words */
  10. struct rspamd_binlog_header {
  11. gchar magic[3];
  12. gchar version[2];
  13. gchar padding[3];
  14. guint64 create_time;
  15. };
  16. struct rspamd_binlog_index {
  17. guint64 time;
  18. guint64 seek;
  19. guint32 len;
  20. };
  21. struct rspamd_index_block {
  22. struct rspamd_binlog_index indexes[BINLOG_IDX_LEN];
  23. guint32 last_index;
  24. };
  25. struct rspamd_binlog_metaindex {
  26. guint64 indexes[METAINDEX_LEN];
  27. guint64 last_index;
  28. };
  29. struct rspamd_binlog_element {
  30. guint32 h1;
  31. guint32 h2;
  32. float value;
  33. } __attribute__((__packed__));
  34. struct rspamd_binlog {
  35. gchar *filename;
  36. time_t rotate_time;
  37. gint rotate_jitter;
  38. guint64 cur_seq;
  39. guint64 cur_time;
  40. gint fd;
  41. memory_pool_t *pool;
  42. struct rspamd_binlog_header header;
  43. struct rspamd_binlog_metaindex *metaindex;
  44. struct rspamd_index_block *cur_idx;
  45. };
  46. struct classifier_config;
  47. /*
  48. * Open binlog at specified path with specified rotate params
  49. */
  50. struct rspamd_binlog* binlog_open (memory_pool_t *pool, const gchar *path, time_t rotate_time, gint rotate_jitter);
  51. /*
  52. * Get and open binlog for specified statfile
  53. */
  54. struct rspamd_binlog* get_binlog_by_statfile (struct statfile *st);
  55. /*
  56. * Close binlog
  57. */
  58. void binlog_close (struct rspamd_binlog *log);
  59. /*
  60. * Insert new nodes inside binlog
  61. */
  62. gboolean binlog_insert (struct rspamd_binlog *log, GTree *nodes);
  63. /*
  64. * Sync binlog from specified revision
  65. * @param log binlog structure
  66. * @param from_rev from revision
  67. * @param from_time from time
  68. * @param rep a portion of changes for revision is stored here
  69. * @return TRUE if there are more revisions to get and FALSE if synchronization is complete
  70. */
  71. gboolean binlog_sync (struct rspamd_binlog *log, guint64 from_rev, guint64 *from_time, GByteArray **rep);
  72. /*
  73. * Conditional write to a binlog for specified statfile
  74. */
  75. gboolean maybe_write_binlog (struct classifier_config *ccf, struct statfile *st, stat_file_t *file, GTree *nodes);
  76. #endif