Update assert to debug assert, add Makefile, and resolve an issue with reindexing

This commit is contained in:
William Brown 2019-11-30 18:43:01 +10:00
parent 000a24b49e
commit e670924324
5 changed files with 89 additions and 18 deletions

11
Makefile Normal file
View file

@ -0,0 +1,11 @@
docker-kanidmd:
docker build -f kanidmd/Dockerfile -t kanidmd:latest .
docker-radiusd:
docker build -f kanidm_rlm_python/Dockerfile -t kanidm_radius:latest kanidm_rlm_python
vendor-prep:
cargo vendor
tar -czf vendor.tar.gz vendor

View file

@ -174,6 +174,13 @@ pub trait IdlSqliteTransaction {
// have a corrupted index ..... // have a corrupted index .....
None => IDLBitRange::new(), None => IDLBitRange::new(),
}; };
audit_log!(
audit,
"Got idl for index {:?} {:?} -> {:?}",
itype,
attr,
idl
);
Ok(Some(idl)) Ok(Some(idl))
} }
@ -497,7 +504,7 @@ impl IdlSqliteWriteTransaction {
audit_log!(audit, "removing idx_table -> {:?}", idx_table); audit_log!(audit, "removing idx_table -> {:?}", idx_table);
self.conn self.conn
.prepare(format!("DROP TABLE {}", idx_table).as_str()) .prepare(format!("DROP TABLE {}", idx_table).as_str())
.and_then(|mut stmt| stmt.query(NO_PARAMS).map(|_| ())) .and_then(|mut stmt| stmt.execute(NO_PARAMS).map(|_| ()))
.map_err(|e| { .map_err(|e| {
audit_log!(audit, "sqlite error {:?}", e); audit_log!(audit, "sqlite error {:?}", e);
OperationError::SQLiteError OperationError::SQLiteError
@ -512,6 +519,7 @@ impl IdlSqliteWriteTransaction {
"rustqlite error {:?}", "rustqlite error {:?}",
OperationError::SQLiteError OperationError::SQLiteError
); );
audit_log!(audit, "purge id2entry ...");
Ok(()) Ok(())
} }

View file

@ -474,7 +474,9 @@ impl BackendWriteTransaction {
.into_iter() .into_iter()
.map(|e| { .map(|e| {
id_max = id_max + 1; id_max = id_max + 1;
e.to_valid_committed_id(id_max) let ev = e.to_valid_committed_id(id_max);
// audit_log!(au, "assigned {} to {}", id_max, ev.get_uuid());
ev
}) })
.collect(); .collect();
@ -809,6 +811,35 @@ impl BackendWriteTransaction {
OperationError::SerdeJsonError OperationError::SerdeJsonError
); );
// Filter all elements that have a UUID in the system range.
/*
use crate::constants::UUID_ANONYMOUS;
use crate::be::dbentry::DbEntryVers;
use crate::be::dbvalue::DbValueV1;
let uuid_anonymous = UUID_ANONYMOUS.clone();
let dbentries: Vec<DbEntry> = dbentries.into_iter()
.filter(|e| {
let e_uuid = match &e.ent {
DbEntryVers::V1(dbe) => dbe.attrs.get("uuid")
.and_then(|dbvs| dbvs.first())
.and_then(|dbv| {
match dbv {
DbValueV1::UU(u) => Some(u),
_ => panic!(),
}
})
.unwrap()
};
e_uuid > &uuid_anonymous
})
.collect();
dbentries.iter().for_each(|e| {
audit_log!(audit, "importing -> {:?}", e);
});
*/
// Now, we setup all the entries with new ids. // Now, we setup all the entries with new ids.
let mut id_max = 0; let mut id_max = 0;
let identries: Result<Vec<IdEntry>, _> = dbentries let identries: Result<Vec<IdEntry>, _> = dbentries
@ -827,6 +858,16 @@ impl BackendWriteTransaction {
self.idlayer.write_identries(audit, identries?)?; self.idlayer.write_identries(audit, identries?)?;
// for debug
/*
self.idlayer.get_identry(audit, &IDL::ALLIDS)
.unwrap()
.iter()
.for_each(|dbe| {
audit_log!(audit, "dbe -> {:?}", dbe.id);
});
*/
// Reindex now we are loaded. // Reindex now we are loaded.
self.reindex(audit)?; self.reindex(audit)?;

View file

@ -1108,15 +1108,9 @@ impl SchemaInner {
uuid: Uuid::parse_str(UUID_SCHEMA_CLASS_ACCESS_CONTROL_PROFILE) uuid: Uuid::parse_str(UUID_SCHEMA_CLASS_ACCESS_CONTROL_PROFILE)
.expect("unable to parse static uuid"), .expect("unable to parse static uuid"),
description: String::from("System Access Control Profile Class"), description: String::from("System Access Control Profile Class"),
systemmay: vec![ systemmay: vec!["acp_enable".to_string(), "description".to_string()],
"acp_enable".to_string(),
"description".to_string()
],
may: vec![], may: vec![],
systemmust: vec![ systemmust: vec!["acp_receiver".to_string(), "acp_targetscope".to_string()],
"acp_receiver".to_string(),
"acp_targetscope".to_string(),
],
must: vec![], must: vec![],
}, },
); );

View file

@ -1477,7 +1477,7 @@ impl<'a> QueryServerWriteTransaction<'a> {
|e: Entry<EntryInvalid, EntryNew>| self.internal_migrate_or_create(audit, e) |e: Entry<EntryInvalid, EntryNew>| self.internal_migrate_or_create(audit, e)
)); ));
audit_log!(audit, "internal_migrate_or_create_str -> result {:?}", res); audit_log!(audit, "internal_migrate_or_create_str -> result {:?}", res);
assert!(res.is_ok()); debug_assert!(res.is_ok());
res res
} }
@ -1495,6 +1495,12 @@ impl<'a> QueryServerWriteTransaction<'a> {
// //
// NOTE: gen modlist IS schema aware and will handle multivalue // NOTE: gen modlist IS schema aware and will handle multivalue
// correctly! // correctly!
audit_log!(
audit,
"internal_migrate_or_create operating on {:?}",
e.get_uuid()
);
let filt = match e.filter_from_attrs(&vec![String::from("uuid")]) { let filt = match e.filter_from_attrs(&vec![String::from("uuid")]) {
Some(f) => f, Some(f) => f,
None => return Err(OperationError::FilterGeneration), None => return Err(OperationError::FilterGeneration),
@ -1541,7 +1547,7 @@ impl<'a> QueryServerWriteTransaction<'a> {
|e: Entry<EntryValid, EntryNew>| self.internal_assert_or_create(audit, e) |e: Entry<EntryValid, EntryNew>| self.internal_assert_or_create(audit, e)
)); ));
audit_log!(audit, "internal_assert_or_create_str -> result {:?}", res); audit_log!(audit, "internal_assert_or_create_str -> result {:?}", res);
assert!(res.is_ok()); debug_assert!(res.is_ok());
res res
} }
@ -1555,6 +1561,12 @@ impl<'a> QueryServerWriteTransaction<'a> {
// else, if not exists, create it. IE no extra or excess // else, if not exists, create it. IE no extra or excess
// attributes and classes. // attributes and classes.
audit_log!(
audit,
"internal_assert_or_create operating on {:?}",
e.get_uuid()
);
// Create a filter from the entry for assertion. // Create a filter from the entry for assertion.
let filt = match e.filter_from_attrs(&vec![String::from("uuid")]) { let filt = match e.filter_from_attrs(&vec![String::from("uuid")]) {
Some(f) => f, Some(f) => f,
@ -1601,7 +1613,8 @@ impl<'a> QueryServerWriteTransaction<'a> {
self.internal_migrate_or_create(audit, e.invalidate()) self.internal_migrate_or_create(audit, e.invalidate())
}) })
.collect(); .collect();
assert!(r.is_ok()); audit_log!(audit, "initialise_schema_core -> result {:?}", r);
debug_assert!(r.is_ok());
r r
} }
@ -1633,7 +1646,8 @@ impl<'a> QueryServerWriteTransaction<'a> {
.map(|e_str| self.internal_migrate_or_create_str(&mut audit_si, e_str)) .map(|e_str| self.internal_migrate_or_create_str(&mut audit_si, e_str))
.collect(); .collect();
audit.append_scope(audit_si); audit.append_scope(audit_si);
assert!(r.is_ok()); audit_log!(audit, "initialise_schema_idm -> result {:?}", r);
debug_assert!(r.is_ok());
r.map(|_| ()) r.map(|_| ())
} }
@ -1648,7 +1662,8 @@ impl<'a> QueryServerWriteTransaction<'a> {
.internal_assert_or_create_str(&mut audit_an, JSON_SYSTEM_INFO_V1) .internal_assert_or_create_str(&mut audit_an, JSON_SYSTEM_INFO_V1)
.and_then(|_| self.internal_migrate_or_create_str(&mut audit_an, JSON_DOMAIN_INFO_V1)); .and_then(|_| self.internal_migrate_or_create_str(&mut audit_an, JSON_DOMAIN_INFO_V1));
audit.append_scope(audit_an); audit.append_scope(audit_an);
assert!(res.is_ok()); audit_log!(audit, "initialise_idm p1 -> result {:?}", res);
debug_assert!(res.is_ok());
if res.is_err() { if res.is_err() {
return res; return res;
} }
@ -1672,7 +1687,8 @@ impl<'a> QueryServerWriteTransaction<'a> {
.map(|e_str| self.internal_migrate_or_create_str(&mut audit_an, e_str)) .map(|e_str| self.internal_migrate_or_create_str(&mut audit_an, e_str))
.collect(); .collect();
audit.append_scope(audit_an); audit.append_scope(audit_an);
assert!(res.is_ok()); audit_log!(audit, "initialise_idm p2 -> result {:?}", res);
debug_assert!(res.is_ok());
if res.is_err() { if res.is_err() {
return res; return res;
} }
@ -1735,7 +1751,8 @@ impl<'a> QueryServerWriteTransaction<'a> {
.map(|e_str| self.internal_migrate_or_create_str(&mut audit_an, e_str)) .map(|e_str| self.internal_migrate_or_create_str(&mut audit_an, e_str))
.collect(); .collect();
audit.append_scope(audit_an); audit.append_scope(audit_an);
assert!(res.is_ok()); audit_log!(audit, "initialise_idm p3 -> result {:?}", res);
debug_assert!(res.is_ok());
if res.is_err() { if res.is_err() {
return res; return res;
} }
@ -1912,7 +1929,7 @@ impl<'a> QueryServerWriteTransaction<'a> {
changed_schema: _, changed_schema: _,
changed_acp: _, changed_acp: _,
} = self; } = self;
assert!(!committed); debug_assert!(!committed);
// Begin an audit. // Begin an audit.
// Validate the schema as we just loaded it. // Validate the schema as we just loaded it.
let r = schema.validate(audit); let r = schema.validate(audit);