Gate log head CAS on readable chunk verification
This commit is contained in:
parent
327812ca96
commit
d0e53170f3
|
|
@ -8,12 +8,15 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
enum {
|
||||
AMDUAT_ASL_LOG_MAGIC_LEN = 8,
|
||||
AMDUAT_ASL_LOG_VERSION = 1,
|
||||
AMDUAT_ASL_LOG_CHUNK_MAX_ENTRIES = 1024u,
|
||||
AMDUAT_ASL_LOG_MAX_RETRIES = 8u
|
||||
AMDUAT_ASL_LOG_MAX_RETRIES = 8u,
|
||||
AMDUAT_ASL_LOG_VERIFY_MAX_RETRIES = 6u,
|
||||
AMDUAT_ASL_LOG_VERIFY_RETRY_US = 2000u
|
||||
};
|
||||
|
||||
static const uint8_t k_amduat_asl_log_magic[AMDUAT_ASL_LOG_MAGIC_LEN] = {
|
||||
|
|
@ -656,21 +659,39 @@ amduat_asl_store_error_t amduat_asl_log_append(
|
|||
{
|
||||
amduat_artifact_t verify_artifact;
|
||||
amduat_asl_store_error_t verify_err;
|
||||
uint32_t verify_attempt = 0u;
|
||||
char *new_ref_hex = NULL;
|
||||
(void)amduat_asl_ref_encode_hex(new_ref, &new_ref_hex);
|
||||
verify_err = amduat_asl_store_get(log_store->store, new_ref,
|
||||
&verify_artifact);
|
||||
if (verify_err == AMDUAT_ASL_STORE_OK) {
|
||||
amduat_artifact_free(&verify_artifact);
|
||||
} else {
|
||||
while (verify_attempt < AMDUAT_ASL_LOG_VERIFY_MAX_RETRIES) {
|
||||
verify_err = amduat_asl_store_get(log_store->store, new_ref,
|
||||
&verify_artifact);
|
||||
if (verify_err == AMDUAT_ASL_STORE_OK) {
|
||||
break;
|
||||
}
|
||||
if (verify_err != AMDUAT_ASL_STORE_ERR_NOT_FOUND ||
|
||||
verify_attempt + 1u >= AMDUAT_ASL_LOG_VERIFY_MAX_RETRIES) {
|
||||
break;
|
||||
}
|
||||
usleep(AMDUAT_ASL_LOG_VERIFY_RETRY_US);
|
||||
verify_attempt++;
|
||||
}
|
||||
if (verify_err != AMDUAT_ASL_STORE_OK) {
|
||||
amduat_log(AMDUAT_LOG_ERROR,
|
||||
"asl_log_append: store_put verify get failed (log=%s pointer=%s attempt=%u err=%d new_ref=%s)",
|
||||
"asl_log_append: store_put verify get failed (log=%s pointer=%s attempt=%u verify_attempts=%u err=%d new_ref=%s)",
|
||||
log_name != NULL ? log_name : "(null)",
|
||||
pointer_name != NULL ? pointer_name : "(null)",
|
||||
(unsigned)attempt,
|
||||
(unsigned)(verify_attempt + 1u),
|
||||
(int)verify_err,
|
||||
new_ref_hex != NULL ? new_ref_hex : "(hex-encode-failed)");
|
||||
free(new_ref_hex);
|
||||
if (head_exists) {
|
||||
amduat_reference_free(&head_ref);
|
||||
}
|
||||
free(pointer_name);
|
||||
return AMDUAT_ASL_STORE_ERR_IO;
|
||||
}
|
||||
amduat_artifact_free(&verify_artifact);
|
||||
free(new_ref_hex);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue