Skip to content

Commit

Permalink
[C] Add semantic version to CnC file. Issue #624.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Jun 6, 2019
1 parent e1d8e36 commit 37b247d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
31 changes: 30 additions & 1 deletion aeron-driver/src/main/c/aeron_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ int aeron_version_patch()
return aeron_patch_version;
}

int32_t aeron_semantic_version_compose(uint8_t major, uint8_t minor, uint8_t patch)
{
return (major << 16) | (minor << 8) | patch;
}

uint8_t aeron_semantic_version_major(int32_t version)
{
return (uint8_t)((version >> 16) & 0xFF);
}

uint8_t aeron_semantic_version_minor(int32_t version)
{
return (uint8_t)((version >> 8) & 0xFF);
}

uint8_t aeron_semantic_version_patch(int32_t version)
{
return (uint8_t)(version & 0xFF);
}

void aeron_log_func_stderr(const char *str)
{
fprintf(stderr, "%s\n", str);
Expand Down Expand Up @@ -203,7 +223,7 @@ int aeron_report_existing_errors(aeron_mapped_file_t *cnc_map, const char *aeron

aeron_cnc_metadata_t *metadata = (aeron_cnc_metadata_t *)cnc_map->addr;

if (AERON_CNC_VERSION == metadata->cnc_version &&
if (aeron_semantic_version_major(AERON_CNC_VERSION) == aeron_semantic_version_major(metadata->cnc_version) &&
aeron_error_log_exists(aeron_cnc_error_log_buffer(cnc_map->addr), (size_t)metadata->error_log_buffer_length))
{
char datestamp[AERON_MAX_PATH];
Expand Down Expand Up @@ -1019,5 +1039,14 @@ int aeron_driver_close(aeron_driver_t *driver)
}

aeron_free(driver);

return 0;
}

extern int32_t aeron_semantic_version_compose(uint8_t major, uint8_t minor, uint8_t patch);

extern uint8_t aeron_semantic_version_major(int32_t version);

extern uint8_t aeron_semantic_version_minor(int32_t version);

extern uint8_t aeron_semantic_version_patch(int32_t version);
10 changes: 10 additions & 0 deletions aeron-driver/src/main/c/aeron_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ aeron_driver_t;
bool aeron_is_driver_active_with_cnc(
aeron_mapped_file_t *cnc_map, int64_t timeout_ms, int64_t now_ms, aeron_log_func_t log_func);

int32_t aeron_semantic_version_compose(uint8_t major, uint8_t minor, uint8_t patch);

uint8_t aeron_semantic_version_major(int32_t version);

uint8_t aeron_semantic_version_minor(int32_t version);

uint8_t aeron_semantic_version_patch(int32_t version);

#define AERON_CNC_VERSION (aeron_semantic_version_compose(0, 0, 15))

#endif //AERON_DRIVER_H
17 changes: 12 additions & 5 deletions aeron-driver/src/main/c/aeron_driver_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "protocol/aeron_udp_protocol.h"
#include "util/aeron_parse_util.h"
#include "util/aeron_fileutil.h"
#include "aeron_driver.h"
#include "aeron_driver_context.h"
#include "aeron_alloc.h"
#include "concurrent/aeron_mpsc_rb.h"
Expand Down Expand Up @@ -903,12 +904,18 @@ bool aeron_is_driver_active_with_cnc(
aeron_micro_sleep(1000);
}

if (AERON_CNC_VERSION != cnc_version)
if (aeron_semantic_version_major(AERON_CNC_VERSION) != aeron_semantic_version_major(cnc_version))
{
snprintf(
buffer, sizeof(buffer) - 1,
"ERROR: aeron cnc version does not match: file version=%d software version=%d",
cnc_version, AERON_CNC_VERSION);
"ERROR: aeron cnc version not compatible: app version=%d.%d.%d file=%d.%d.%d",
(int)aeron_semantic_version_major(AERON_CNC_VERSION),
(int)aeron_semantic_version_minor(AERON_CNC_VERSION),
(int)aeron_semantic_version_patch(AERON_CNC_VERSION),
(int)aeron_semantic_version_major(cnc_version),
(int)aeron_semantic_version_minor(cnc_version),
(int)aeron_semantic_version_patch(cnc_version));

log_func(buffer);
}
else
Expand All @@ -923,8 +930,8 @@ bool aeron_is_driver_active_with_cnc(
}
else
{
int64_t timestamp = aeron_mpsc_rb_consumer_heartbeat_time_value(&rb);
int64_t diff = now_ms - timestamp;
int64_t timestamp_ms = aeron_mpsc_rb_consumer_heartbeat_time_value(&rb);
int64_t diff = now_ms - timestamp_ms;

snprintf(buffer, sizeof(buffer) - 1, "INFO: Aeron driver heartbeat is %" PRId64 " ms old", diff);
log_func(buffer);
Expand Down
1 change: 0 additions & 1 deletion aeron-driver/src/main/c/aeron_driver_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#define AERON_CNC_FILE "cnc.dat"
#define AERON_LOSS_REPORT_FILE "loss-report.dat"
#define AERON_CNC_VERSION (15)

#pragma pack(push)
#pragma pack(4)
Expand Down

0 comments on commit 37b247d

Please # to comment.