s4-dsdb: take advantage of local cursor and sort
authorAndrew Tridgell <tridge@samba.org>
Sat, 16 Jan 2010 00:49:09 +0000 (11:49 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sat, 16 Jan 2010 03:10:43 +0000 (14:10 +1100)
in getncchanges and repl task we don't need the extra load and sort
any more.

source4/dsdb/repl/drepl_partitions.c
source4/rpc_server/drsuapi/getncchanges.c

index 6687effe6dfa76892d49806aa91547a732126ee2..b57a5c81c0cd4a1595fc578dc2c24c999860efbb 100644 (file)
@@ -212,40 +212,6 @@ static WERROR udv_convert(TALLOC_CTX *mem_ctx,
        return WERR_OK;
 }
 
-/*
-  add our local UDV element for the partition
- */
-static WERROR add_local_udv(struct dreplsrv_service *s,
-                           struct dreplsrv_partition *p,
-                           const struct GUID *our_invocation_id,
-                           struct drsuapi_DsReplicaCursorCtrEx *udv)
-{
-       int ret;
-       uint64_t highest_usn;
-       int i;
-
-       ret = dsdb_load_partition_usn(s->samdb, p->dn, &highest_usn, NULL);
-       if (ret != LDB_SUCCESS) {
-               /* nothing to add */
-               return WERR_OK;
-       }
-
-       for (i=0; i<udv->count; i++) {
-               if (GUID_equal(our_invocation_id, &udv->cursors[i].source_dsa_invocation_id)) {
-                       udv->cursors[i].highest_usn = highest_usn;
-                       return WERR_OK;
-               }
-       }
-
-       udv->cursors = talloc_realloc(p, udv->cursors, struct drsuapi_DsReplicaCursor, udv->count+1);
-       W_ERROR_HAVE_NO_MEMORY(udv->cursors);
-
-       udv->cursors[udv->count].source_dsa_invocation_id = *our_invocation_id;
-       udv->cursors[udv->count].highest_usn = highest_usn;
-       udv->count++;
-
-       return WERR_OK;
-}
 
 static WERROR dreplsrv_refresh_partition(struct dreplsrv_service *s,
                                         struct dreplsrv_partition *p)
@@ -296,9 +262,6 @@ static WERROR dreplsrv_refresh_partition(struct dreplsrv_service *s,
                W_ERROR_NOT_OK_RETURN(status);
        }
 
-       status = add_local_udv(s, p, samdb_ntds_invocation_id(s->samdb), &p->uptodatevector_ex);
-       W_ERROR_NOT_OK_RETURN(status);
-
        orf_el = ldb_msg_find_element(r->msgs[0], "repsFrom");
        if (orf_el) {
                for (i=0; i < orf_el->num_values; i++) {
index afa1bba3eee79211e13d607c5ec7371202fa955e..74c5d4aa9550cc5fdd8ae8fc16086b81c1889204 100644 (file)
@@ -417,13 +417,9 @@ static WERROR get_nc_changes_add_links(struct ldb_context *sam_ctx,
  */
 static WERROR get_nc_changes_udv(struct ldb_context *sam_ctx,
                                 struct ldb_dn *ncRoot_dn,
-                                struct drsuapi_DsReplicaCursor2CtrEx *udv,
-                                uint64_t highestUSN)
+                                struct drsuapi_DsReplicaCursor2CtrEx *udv)
 {
-       struct drsuapi_DsReplicaCursor2 *tmp_cursor;
-       NTTIME now;
-       time_t t = time(NULL);
-       int i, ret;
+       int ret;
 
        udv->version = 2;
        udv->reserved1 = 0;
@@ -436,32 +432,6 @@ static WERROR get_nc_changes_udv(struct ldb_context *sam_ctx,
                return WERR_DS_DRA_INTERNAL_ERROR;
        }
        
-       tmp_cursor = talloc(udv, struct drsuapi_DsReplicaCursor2);
-       tmp_cursor->source_dsa_invocation_id = *(samdb_ntds_invocation_id(sam_ctx));
-       tmp_cursor->highest_usn = highestUSN;
-       unix_to_nt_time(&now, t);
-       tmp_cursor->last_sync_success = now;
-
-       for (i=0; i<udv->count; i++) {
-               if (GUID_equal(&tmp_cursor->source_dsa_invocation_id,
-                              &udv->cursors[i].source_dsa_invocation_id)) {
-                       udv->cursors[i] = *tmp_cursor;
-                       break;
-               }
-       }
-       if (i == udv->count) {
-               udv->cursors = talloc_realloc(udv, udv->cursors, struct drsuapi_DsReplicaCursor2, udv->count+1);
-               if (!udv->cursors) {
-                       return WERR_DS_DRA_INTERNAL_ERROR;
-               }
-               udv->cursors[udv->count] = *tmp_cursor;
-               udv->count++;
-       }
-       
-       qsort(udv->cursors, udv->count,
-             sizeof(struct drsuapi_DsReplicaCursor2),
-             (comparison_fn_t)drsuapi_DsReplicaCursor2_compare);
-
        return WERR_OK;
 }
 
@@ -1030,8 +1000,7 @@ WERROR dcesrv_drsuapi_DsGetNCChanges(struct dcesrv_call_state *dce_call, TALLOC_
                r->out.ctr->ctr6.new_highwatermark.highest_usn = r->out.ctr->ctr6.new_highwatermark.tmp_highest_usn;
 
                werr = get_nc_changes_udv(b_state->sam_ctx, getnc_state->ncRoot_dn, 
-                                         r->out.ctr->ctr6.uptodateness_vector,
-                                         getnc_state->highest_usn);
+                                         r->out.ctr->ctr6.uptodateness_vector);
                if (!W_ERROR_IS_OK(werr)) {
                        return werr;
                }