[SCM] Samba Shared Repository - branch master updated

Kamen Mazdrashki kamenim at samba.org
Sun Jun 20 18:03:11 MDT 2010


The branch, master has been updated
       via  3aa8853... s4/dsdb: msg_idx->dn should be allocated in msg_idx mem context
       via  cc7e2c1... s4/dsdb: Move schema accessors cleanup in separate function
       via  267645c... s4/dsdb-schema: Index attributes on msDS-IntId value
      from  ecbe9a7... s4:kdc/db-glue.c - remove unreachable code

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 3aa8853f58b32c5430cd03164a0c2bc26c1b04c0
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Sun Jun 20 23:31:43 2010 +0300

    s4/dsdb: msg_idx->dn should be allocated in msg_idx mem context

commit cc7e2c10f2b944fd7eac4ff11e9d48fac0043030
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Sat Jun 19 12:30:36 2010 +0300

    s4/dsdb: Move schema accessors cleanup in separate function
    
    This way dsdb_setup_sorted_accessors() will
    free memory allocated for accessor arrays correctly
    in case of failure,

commit 267645ca55f7825e87a098c9dc51f132aac1f452
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Sat Jun 19 00:00:08 2010 +0300

    s4/dsdb-schema: Index attributes on msDS-IntId value
    
    O(n) search for dsdb_attribute by msDS-IntId value was
    replaced by binary-search in ordered index.
    
    I've choosen the approach of separate index on msDS-IntId values
    as I think it is more clear what we are searching for.
    And it should little bit faster as we can clearly determine
    in which index to perform the search based on ATTID value -
    ATTIDs based on prefixMap and ATTIDs based on msDS-IntId
    are in separate ranges.
    
    Other way to implement this index was to merge msDS-IntId values
    in attributeID_id index.
    This led me to a shorted but not so obvious implementation.

-----------------------------------------------------------------------

Summary of changes:
 source4/dsdb/schema/schema.h       |    2 +
 source4/dsdb/schema/schema_query.c |    8 ++---
 source4/dsdb/schema/schema_set.c   |   62 +++++++++++++++++++++++++-----------
 3 files changed, 48 insertions(+), 24 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/schema/schema.h b/source4/dsdb/schema/schema.h
index 0cbc218..34423be 100644
--- a/source4/dsdb/schema/schema.h
+++ b/source4/dsdb/schema/schema.h
@@ -209,6 +209,8 @@ struct dsdb_schema {
 	struct dsdb_attribute **attributes_by_attributeID_id;
 	struct dsdb_attribute **attributes_by_attributeID_oid;
 	struct dsdb_attribute **attributes_by_linkID;
+	uint32_t num_int_id_attr;
+	struct dsdb_attribute **attributes_by_msDS_IntId;
 
 	struct {
 		bool we_are_master;
diff --git a/source4/dsdb/schema/schema_query.c b/source4/dsdb/schema/schema_query.c
index 4ff8418..8ea79ff 100644
--- a/source4/dsdb/schema/schema_query.c
+++ b/source4/dsdb/schema/schema_query.c
@@ -65,11 +65,9 @@ const struct dsdb_attribute *dsdb_attribute_by_attributeID_id(const struct dsdb_
 
 	/* check for msDS-IntId type attribute */
 	if (dsdb_pfm_get_attid_type(id) == dsdb_attid_type_intid) {
-		for (c = schema->attributes; c; c = c->next) {
-			if (c->msDS_IntId == id) {
-				return c;
-			}
-		}
+		BINARY_ARRAY_SEARCH_P(schema->attributes_by_msDS_IntId,
+				      schema->num_int_id_attr, msDS_IntId, id, uint32_cmp, c);
+		return c;
 	}
 
 	BINARY_ARRAY_SEARCH_P(schema->attributes_by_attributeID_id,
diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c
index 5ecbad2..0e04f5b 100644
--- a/source4/dsdb/schema/schema_set.c
+++ b/source4/dsdb/schema/schema_set.c
@@ -83,7 +83,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem
 		ldb_oom(ldb);
 		goto op_error;
 	}
-	msg_idx->dn = ldb_dn_new(msg, ldb, "@INDEXLIST");
+	msg_idx->dn = ldb_dn_new(msg_idx, ldb, "@INDEXLIST");
 	if (!msg_idx->dn) {
 		ldb_oom(ldb);
 		goto op_error;
@@ -221,6 +221,24 @@ static int dsdb_compare_attribute_by_linkID(struct dsdb_attribute **a1, struct d
 	return uint32_cmp((*a1)->linkID, (*a2)->linkID);
 }
 
+/**
+ * Clean up Classes and Attributes accessor arrays
+ */
+static void dsdb_sorted_accessors_free(struct dsdb_schema *schema)
+{
+	/* free classes accessors */
+	TALLOC_FREE(schema->classes_by_lDAPDisplayName);
+	TALLOC_FREE(schema->classes_by_governsID_id);
+	TALLOC_FREE(schema->classes_by_governsID_oid);
+	TALLOC_FREE(schema->classes_by_cn);
+	/* free attribute accessors */
+	TALLOC_FREE(schema->attributes_by_lDAPDisplayName);
+	TALLOC_FREE(schema->attributes_by_attributeID_id);
+	TALLOC_FREE(schema->attributes_by_msDS_IntId);
+	TALLOC_FREE(schema->attributes_by_attributeID_oid);
+	TALLOC_FREE(schema->attributes_by_linkID);
+}
+
 /*
   create the sorted accessor arrays for the schema
  */
@@ -230,11 +248,10 @@ static int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
 	struct dsdb_class *cur;
 	struct dsdb_attribute *a;
 	unsigned int i;
+	unsigned int num_int_id;
 
-	talloc_free(schema->classes_by_lDAPDisplayName);
-	talloc_free(schema->classes_by_governsID_id);
-	talloc_free(schema->classes_by_governsID_oid);
-	talloc_free(schema->classes_by_cn);
+	/* free all caches */
+	dsdb_sorted_accessors_free(schema);
 
 	/* count the classes */
 	for (i=0, cur=schema->classes; cur; i++, cur=cur->next) /* noop */ ;
@@ -266,51 +283,58 @@ static int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
 	TYPESAFE_QSORT(schema->classes_by_cn, schema->num_classes, dsdb_compare_class_by_cn);
 
 	/* now build the attribute accessor arrays */
-	talloc_free(schema->attributes_by_lDAPDisplayName);
-	talloc_free(schema->attributes_by_attributeID_id);
-	talloc_free(schema->attributes_by_attributeID_oid);
-	talloc_free(schema->attributes_by_linkID);
 
-	/* count the attributes */
-	for (i=0, a=schema->attributes; a; i++, a=a->next) /* noop */ ;
+	/* count the attributes
+	 * and attributes with msDS-IntId set */
+	num_int_id = 0;
+	for (i=0, a=schema->attributes; a; i++, a=a->next) {
+		if (a->msDS_IntId != 0) {
+			num_int_id++;
+		}
+	}
 	schema->num_attributes = i;
+	schema->num_int_id_attr = num_int_id;
 
 	/* setup attributes_by_* */
 	schema->attributes_by_lDAPDisplayName = talloc_array(schema, struct dsdb_attribute *, i);
 	schema->attributes_by_attributeID_id    = talloc_array(schema, struct dsdb_attribute *, i);
+	schema->attributes_by_msDS_IntId        = talloc_array(schema,
+	                                                       struct dsdb_attribute *, num_int_id);
 	schema->attributes_by_attributeID_oid   = talloc_array(schema, struct dsdb_attribute *, i);
 	schema->attributes_by_linkID              = talloc_array(schema, struct dsdb_attribute *, i);
 	if (schema->attributes_by_lDAPDisplayName == NULL ||
 	    schema->attributes_by_attributeID_id == NULL ||
+	    schema->attributes_by_msDS_IntId == NULL ||
 	    schema->attributes_by_attributeID_oid == NULL ||
 	    schema->attributes_by_linkID == NULL) {
 		goto failed;
 	}
 
+	num_int_id = 0;
 	for (i=0, a=schema->attributes; a; i++, a=a->next) {
 		schema->attributes_by_lDAPDisplayName[i] = a;
 		schema->attributes_by_attributeID_id[i]    = a;
 		schema->attributes_by_attributeID_oid[i]   = a;
 		schema->attributes_by_linkID[i]          = a;
+		/* append attr-by-msDS-IntId values */
+		if (a->msDS_IntId != 0) {
+			schema->attributes_by_msDS_IntId[num_int_id] = a;
+			num_int_id++;
+		}
 	}
+	SMB_ASSERT(num_int_id == schema->num_int_id_attr);
 
 	/* sort the arrays */
 	TYPESAFE_QSORT(schema->attributes_by_lDAPDisplayName, schema->num_attributes, dsdb_compare_attribute_by_lDAPDisplayName);
 	TYPESAFE_QSORT(schema->attributes_by_attributeID_id, schema->num_attributes, dsdb_compare_attribute_by_attributeID_id);
+	TYPESAFE_QSORT(schema->attributes_by_msDS_IntId, schema->num_int_id_attr, dsdb_compare_attribute_by_attributeID_id);
 	TYPESAFE_QSORT(schema->attributes_by_attributeID_oid, schema->num_attributes, dsdb_compare_attribute_by_attributeID_oid);
 	TYPESAFE_QSORT(schema->attributes_by_linkID, schema->num_attributes, dsdb_compare_attribute_by_linkID);
 
 	return LDB_SUCCESS;
 
 failed:
-	schema->classes_by_lDAPDisplayName = NULL;
-	schema->classes_by_governsID_id = NULL;
-	schema->classes_by_governsID_oid = NULL;
-	schema->classes_by_cn = NULL;
-	schema->attributes_by_lDAPDisplayName = NULL;
-	schema->attributes_by_attributeID_id = NULL;
-	schema->attributes_by_attributeID_oid = NULL;
-	schema->attributes_by_linkID = NULL;
+	dsdb_sorted_accessors_free(schema);
 	ldb_oom(ldb);
 	return LDB_ERR_OPERATIONS_ERROR;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list