Remove federation location metadata
This commit is contained in:
parent
2931e35c69
commit
ed64c6ed89
|
|
@ -31,15 +31,9 @@ typedef struct {
|
|||
amduat_reference_t ref;
|
||||
} amduat_fed_record_id_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t domain_id;
|
||||
amduat_reference_t ref;
|
||||
} amduat_fed_record_location_t;
|
||||
|
||||
typedef struct {
|
||||
amduat_fed_record_meta_t meta;
|
||||
amduat_fed_record_id_t id;
|
||||
amduat_fed_record_location_t location;
|
||||
uint64_t logseq;
|
||||
uint64_t snapshot_id;
|
||||
uint64_t log_prefix;
|
||||
|
|
|
|||
|
|
@ -54,15 +54,7 @@ amduat_fed_resolve_error_t amduat_fed_resolve(
|
|||
const amduat_fed_view_t *view,
|
||||
amduat_asl_store_t *local_store,
|
||||
amduat_reference_t ref,
|
||||
amduat_artifact_t *out_artifact,
|
||||
amduat_fed_record_location_t *out_location);
|
||||
|
||||
amduat_fed_resolve_error_t amduat_fed_resolve_with_loc(
|
||||
const amduat_fed_view_t *view,
|
||||
amduat_asl_store_t *local_store,
|
||||
amduat_reference_t ref,
|
||||
amduat_artifact_t *out_artifact,
|
||||
amduat_fed_record_location_t *out_location);
|
||||
amduat_artifact_t *out_artifact);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ static bool amduat_fed_record_equivalent(const amduat_fed_record_t *a,
|
|||
a->meta.visibility == b->meta.visibility &&
|
||||
a->meta.has_source == b->meta.has_source &&
|
||||
a->meta.source_domain == b->meta.source_domain &&
|
||||
a->location.domain_id == b->location.domain_id &&
|
||||
amduat_reference_eq(a->location.ref, b->location.ref) &&
|
||||
a->logseq == b->logseq &&
|
||||
a->snapshot_id == b->snapshot_id &&
|
||||
a->log_prefix == b->log_prefix;
|
||||
|
|
|
|||
|
|
@ -53,10 +53,6 @@ static bool amduat_fed_record_clone(const amduat_fed_record_t *src,
|
|||
if (!amduat_reference_clone(src->id.ref, &out->id.ref)) {
|
||||
return false;
|
||||
}
|
||||
if (!amduat_reference_clone(src->location.ref, &out->location.ref)) {
|
||||
amduat_reference_free(&out->id.ref);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +61,6 @@ static void amduat_fed_record_free(amduat_fed_record_t *record) {
|
|||
return;
|
||||
}
|
||||
amduat_reference_free(&record->id.ref);
|
||||
amduat_reference_free(&record->location.ref);
|
||||
memset(record, 0, sizeof(*record));
|
||||
}
|
||||
|
||||
|
|
@ -155,10 +150,6 @@ bool amduat_fed_record_validate(const amduat_fed_record_t *record) {
|
|||
record->id.ref.digest.data == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (record->location.ref.digest.len != 0u &&
|
||||
record->location.ref.digest.data == NULL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,6 @@ static bool amduat_fed_record_clone(const amduat_fed_record_t *src,
|
|||
if (!amduat_reference_clone(src->id.ref, &out->id.ref)) {
|
||||
return false;
|
||||
}
|
||||
if (!amduat_reference_clone(src->location.ref, &out->location.ref)) {
|
||||
amduat_reference_free(&out->id.ref);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +20,6 @@ static void amduat_fed_record_free(amduat_fed_record_t *record) {
|
|||
return;
|
||||
}
|
||||
amduat_reference_free(&record->id.ref);
|
||||
amduat_reference_free(&record->location.ref);
|
||||
memset(record, 0, sizeof(*record));
|
||||
}
|
||||
|
||||
|
|
@ -36,8 +31,6 @@ static bool amduat_fed_record_equivalent(const amduat_fed_record_t *a,
|
|||
a->meta.source_domain == b->meta.source_domain &&
|
||||
a->id.type == b->id.type &&
|
||||
amduat_reference_eq(a->id.ref, b->id.ref) &&
|
||||
a->location.domain_id == b->location.domain_id &&
|
||||
amduat_reference_eq(a->location.ref, b->location.ref) &&
|
||||
a->logseq == b->logseq &&
|
||||
a->snapshot_id == b->snapshot_id &&
|
||||
a->log_prefix == b->log_prefix;
|
||||
|
|
@ -334,30 +327,16 @@ amduat_fed_resolve_error_t amduat_fed_resolve(
|
|||
const amduat_fed_view_t *view,
|
||||
amduat_asl_store_t *local_store,
|
||||
amduat_reference_t ref,
|
||||
amduat_artifact_t *out_artifact,
|
||||
amduat_fed_record_location_t *out_location) {
|
||||
amduat_artifact_t *out_artifact) {
|
||||
amduat_asl_store_error_t store_err;
|
||||
const amduat_fed_record_t *record;
|
||||
amduat_fed_record_location_t empty_location;
|
||||
|
||||
if (local_store == NULL || out_artifact == NULL) {
|
||||
return AMDUAT_FED_RESOLVE_STORE_ERROR;
|
||||
}
|
||||
|
||||
if (out_location != NULL) {
|
||||
empty_location.domain_id = 0u;
|
||||
empty_location.ref = amduat_reference(0, amduat_octets(NULL, 0u));
|
||||
*out_location = empty_location;
|
||||
}
|
||||
|
||||
store_err = amduat_asl_store_get(local_store, ref, out_artifact);
|
||||
if (store_err == AMDUAT_ASL_STORE_OK) {
|
||||
if (out_location != NULL && view != NULL) {
|
||||
out_location->domain_id = view->local_domain_id;
|
||||
if (!amduat_reference_clone(ref, &out_location->ref)) {
|
||||
out_location->ref = amduat_reference(0, amduat_octets(NULL, 0u));
|
||||
}
|
||||
}
|
||||
return AMDUAT_FED_RESOLVE_OK;
|
||||
}
|
||||
if (store_err == AMDUAT_ASL_STORE_ERR_INTEGRITY) {
|
||||
|
|
@ -376,27 +355,7 @@ amduat_fed_resolve_error_t amduat_fed_resolve(
|
|||
return AMDUAT_FED_RESOLVE_NOT_FOUND;
|
||||
}
|
||||
if (record->meta.domain_id != view->local_domain_id) {
|
||||
if (out_location != NULL) {
|
||||
out_location->domain_id = record->location.domain_id;
|
||||
if (!amduat_reference_clone(record->location.ref,
|
||||
&out_location->ref)) {
|
||||
out_location->ref = amduat_reference(0, amduat_octets(NULL, 0u));
|
||||
}
|
||||
}
|
||||
return AMDUAT_FED_RESOLVE_FOUND_REMOTE_NO_BYTES;
|
||||
}
|
||||
return AMDUAT_FED_RESOLVE_NOT_FOUND;
|
||||
}
|
||||
|
||||
amduat_fed_resolve_error_t amduat_fed_resolve_with_loc(
|
||||
const amduat_fed_view_t *view,
|
||||
amduat_asl_store_t *local_store,
|
||||
amduat_reference_t ref,
|
||||
amduat_artifact_t *out_artifact,
|
||||
amduat_fed_record_location_t *out_location) {
|
||||
return amduat_fed_resolve(view,
|
||||
local_store,
|
||||
ref,
|
||||
out_artifact,
|
||||
out_location);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ static amduat_fed_record_t make_record(uint32_t domain_id,
|
|||
record.meta.has_source = 0;
|
||||
record.id.type = type;
|
||||
record.id.ref = ref;
|
||||
record.location.domain_id = domain_id;
|
||||
record.location.ref = ref;
|
||||
record.logseq = logseq;
|
||||
record.snapshot_id = 1;
|
||||
record.log_prefix = 10;
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ static amduat_fed_record_t make_record(uint32_t domain_id,
|
|||
record.meta.has_source = 0;
|
||||
record.id.type = type;
|
||||
record.id.ref = ref;
|
||||
record.location.domain_id = domain_id;
|
||||
record.location.ref = ref;
|
||||
record.logseq = logseq;
|
||||
record.snapshot_id = snapshot_id;
|
||||
record.log_prefix = log_prefix;
|
||||
|
|
@ -122,6 +120,57 @@ static int test_bounds(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int test_multi_domain_ordering(void) {
|
||||
uint8_t d0[] = {0x00};
|
||||
uint8_t d1[] = {0x01};
|
||||
uint8_t d2[] = {0x02};
|
||||
amduat_fed_record_t records[4];
|
||||
amduat_fed_replay_view_t view_a;
|
||||
amduat_fed_replay_view_t view_b;
|
||||
|
||||
records[0] = make_record(1, 2, 1, 10, AMDUAT_FED_REC_ARTIFACT,
|
||||
make_ref(1, d2, sizeof(d2)));
|
||||
records[1] = make_record(1, 1, 1, 10, AMDUAT_FED_REC_ARTIFACT,
|
||||
make_ref(1, d1, sizeof(d1)));
|
||||
records[2] = make_record(2, 1, 1, 10, AMDUAT_FED_REC_ARTIFACT,
|
||||
make_ref(1, d0, sizeof(d0)));
|
||||
records[3] = make_record(2, 2, 1, 10, AMDUAT_FED_REC_ARTIFACT,
|
||||
make_ref(1, d2, sizeof(d2)));
|
||||
|
||||
if (!amduat_fed_replay_domain(records, 4, 1, 1, 10, &view_a)) {
|
||||
fprintf(stderr, "replay domain 1 failed\n");
|
||||
return 1;
|
||||
}
|
||||
if (!amduat_fed_replay_domain(records, 4, 2, 1, 10, &view_b)) {
|
||||
fprintf(stderr, "replay domain 2 failed\n");
|
||||
amduat_fed_replay_view_free(&view_a);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (view_a.len != 2 || view_b.len != 2) {
|
||||
fprintf(stderr, "multi-domain lengths mismatch\n");
|
||||
amduat_fed_replay_view_free(&view_a);
|
||||
amduat_fed_replay_view_free(&view_b);
|
||||
return 1;
|
||||
}
|
||||
if (view_a.records[0].logseq != 1 || view_a.records[1].logseq != 2) {
|
||||
fprintf(stderr, "domain 1 ordering mismatch\n");
|
||||
amduat_fed_replay_view_free(&view_a);
|
||||
amduat_fed_replay_view_free(&view_b);
|
||||
return 1;
|
||||
}
|
||||
if (view_b.records[0].logseq != 1 || view_b.records[1].logseq != 2) {
|
||||
fprintf(stderr, "domain 2 ordering mismatch\n");
|
||||
amduat_fed_replay_view_free(&view_a);
|
||||
amduat_fed_replay_view_free(&view_b);
|
||||
return 1;
|
||||
}
|
||||
|
||||
amduat_fed_replay_view_free(&view_a);
|
||||
amduat_fed_replay_view_free(&view_b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
if (test_ordering() != 0) {
|
||||
return 1;
|
||||
|
|
@ -132,5 +181,8 @@ int main(void) {
|
|||
if (test_bounds() != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (test_multi_domain_ordering() != 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,8 +65,6 @@ static amduat_fed_record_t make_record(uint32_t domain_id,
|
|||
record.meta.has_source = 0;
|
||||
record.id.type = AMDUAT_FED_REC_ARTIFACT;
|
||||
record.id.ref = ref;
|
||||
record.location.domain_id = domain_id;
|
||||
record.location.ref = ref;
|
||||
record.logseq = logseq;
|
||||
record.snapshot_id = 1;
|
||||
record.log_prefix = 10;
|
||||
|
|
@ -126,7 +124,7 @@ static int test_view_and_resolve(void) {
|
|||
ops.get = stub_store_get;
|
||||
amduat_asl_store_init(&store, stub.config, ops, &stub);
|
||||
|
||||
if (amduat_fed_resolve(&view, &store, ref_a, &artifact, NULL) !=
|
||||
if (amduat_fed_resolve(&view, &store, ref_a, &artifact) !=
|
||||
AMDUAT_FED_RESOLVE_OK) {
|
||||
fprintf(stderr, "resolve local failed\n");
|
||||
amduat_fed_view_free(&view);
|
||||
|
|
@ -134,14 +132,14 @@ static int test_view_and_resolve(void) {
|
|||
}
|
||||
amduat_artifact_free(&artifact);
|
||||
|
||||
if (amduat_fed_resolve(&view, &store, ref_c, &artifact, NULL) !=
|
||||
if (amduat_fed_resolve(&view, &store, ref_c, &artifact) !=
|
||||
AMDUAT_FED_RESOLVE_FOUND_REMOTE_NO_BYTES) {
|
||||
fprintf(stderr, "resolve remote mismatch\n");
|
||||
amduat_fed_view_free(&view);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (amduat_fed_resolve(&view, &store, ref_d, &artifact, NULL) !=
|
||||
if (amduat_fed_resolve(&view, &store, ref_d, &artifact) !=
|
||||
AMDUAT_FED_RESOLVE_POLICY_DENIED) {
|
||||
fprintf(stderr, "resolve policy denied mismatch\n");
|
||||
amduat_fed_view_free(&view);
|
||||
|
|
@ -177,6 +175,54 @@ static int test_view_conflict(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int test_view_rebuild_metadata(void) {
|
||||
uint8_t key[] = {0x08};
|
||||
amduat_reference_t ref = make_ref(1, key, sizeof(key));
|
||||
amduat_fed_record_t records[1];
|
||||
amduat_fed_view_bounds_t bounds[1];
|
||||
amduat_fed_view_t view_a;
|
||||
amduat_fed_view_t view_b;
|
||||
|
||||
records[0] = make_record(1, 1, 1, ref);
|
||||
records[0].meta.has_source = 1;
|
||||
records[0].meta.source_domain = 5;
|
||||
|
||||
bounds[0].domain_id = 1;
|
||||
bounds[0].snapshot_id = 1;
|
||||
bounds[0].log_prefix = 10;
|
||||
|
||||
if (!amduat_fed_view_build(records, 1, 1, bounds, 1, NULL, 0, &view_a)) {
|
||||
fprintf(stderr, "view rebuild build A failed\n");
|
||||
return 1;
|
||||
}
|
||||
if (!amduat_fed_view_build(records, 1, 1, bounds, 1, NULL, 0, &view_b)) {
|
||||
fprintf(stderr, "view rebuild build B failed\n");
|
||||
amduat_fed_view_free(&view_a);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (view_a.len != 1 || view_b.len != 1) {
|
||||
fprintf(stderr, "view rebuild length mismatch\n");
|
||||
amduat_fed_view_free(&view_a);
|
||||
amduat_fed_view_free(&view_b);
|
||||
return 1;
|
||||
}
|
||||
if (view_a.records[0].meta.has_source !=
|
||||
view_b.records[0].meta.has_source ||
|
||||
view_a.records[0].meta.source_domain !=
|
||||
view_b.records[0].meta.source_domain ||
|
||||
view_a.records[0].meta.visibility != view_b.records[0].meta.visibility) {
|
||||
fprintf(stderr, "view rebuild metadata mismatch\n");
|
||||
amduat_fed_view_free(&view_a);
|
||||
amduat_fed_view_free(&view_b);
|
||||
return 1;
|
||||
}
|
||||
|
||||
amduat_fed_view_free(&view_a);
|
||||
amduat_fed_view_free(&view_b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
if (test_view_and_resolve() != 0) {
|
||||
return 1;
|
||||
|
|
@ -184,5 +230,8 @@ int main(void) {
|
|||
if (test_view_conflict() != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (test_view_rebuild_metadata() != 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue