From 8e41745b17b37a2a508ba6a016eddf9c6f219125 Mon Sep 17 00:00:00 2001
From: pgamba <pgamba@localhost>
Date: Tue, 13 Nov 2007 15:45:42 +0000
Subject: [PATCH] Fix 2588 - ReplicationBackend.getEntryCount() very inefficient
---
opends/src/server/org/opends/server/replication/server/ReplicationCache.java | 15 +++++++
opends/src/server/org/opends/server/replication/server/ReplicationBackend.java | 25 ++++--------
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java | 8 +++-
opends/src/server/org/opends/server/replication/server/DbHandler.java | 17 ++++++++
4 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/opends/src/server/org/opends/server/replication/server/DbHandler.java b/opends/src/server/org/opends/server/replication/server/DbHandler.java
index 7c95e3c..fa86cbe 100644
--- a/opends/src/server/org/opends/server/replication/server/DbHandler.java
+++ b/opends/src/server/org/opends/server/replication/server/DbHandler.java
@@ -217,6 +217,23 @@
}
/**
+ * Get the number of changes.
+ *
+ * @return Returns the number of changes.
+ */
+ public long getChangesCount()
+ {
+ try
+ {
+ return lastChange.getSeqnum() - firstChange.getSeqnum() + 1;
+ }
+ catch (Exception e)
+ {
+ return 0;
+ }
+ }
+
+ /**
* Generate a new ReplicationIterator that allows to browse the db
* managed by this dbHandler and starting at the position defined
* by a given changeNumber.
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java b/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
index 80e3822..6033b78 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
@@ -331,23 +331,14 @@
//This method only returns the number of actual change entries, the
//domain and any baseDN entries are not counted.
long retNum=0;
- try {
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- SearchFilter filter=
- SearchFilter.createFilterFromString("(changetype=*)");
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null,
- baseDNs[0],
- SearchScope.WHOLE_SUBTREE,
- DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
- filter, null, null);
- search(searchOperation);
- retNum=searchOperation.getSearchEntries().size();
- } catch (DirectoryException ex) {
- retNum=0;
+ Iterator<ReplicationCache> rcachei = server.getCacheIterator();
+ if (rcachei != null)
+ {
+ while (rcachei.hasNext())
+ {
+ ReplicationCache rc = rcachei.next();
+ retNum += rc.getChangesCount();
+ }
}
return retNum;
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationCache.java b/opends/src/server/org/opends/server/replication/server/ReplicationCache.java
index 89140e9..d27d11f 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationCache.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationCache.java
@@ -531,6 +531,21 @@
}
/**
+ * Returns the change count for that ReplicationCache.
+ *
+ * @return the change count.
+ */
+ public long getChangesCount()
+ {
+ long entryCount = 0;
+ for (DbHandler dbHandler : sourceDbHandlers.values())
+ {
+ entryCount += dbHandler.getChangesCount();
+ }
+ return entryCount;
+ }
+
+ /**
* Get the baseDn.
* @return Returns the baseDn.
*/
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
index 51f7c91..9e881f9 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
@@ -83,6 +83,10 @@
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.opends.messages.Category;
+import org.opends.messages.Message;
+import org.opends.messages.Severity;
+import org.opends.server.loggers.ErrorLogger;
/**
* Tests for the replicationServer code.
@@ -131,7 +135,7 @@
private void debugInfo(String s)
{
- // logError(Message.raw(Category.SYNC, Severity.NOTICE, "** TEST **" + s));
+ // ErrorLogger.logError(Message.raw(Category.SYNC, Severity.NOTICE, "** TEST **" + s));
if (debugEnabled())
{
TRACER.debugInfo("** TEST **" + s);
@@ -1258,7 +1262,7 @@
ReplicationBackend b =
(ReplicationBackend)DirectoryServer.getBackend("replicationChanges");
b.setServer(replicationServer);
- assertTrue(b.getEntryCount() == msgs.size());
+ assertEquals(b.getEntryCount(), msgs.size());
assertTrue(b.entryExists(DN.decode("dc=replicationChanges")));
SearchFilter filter=SearchFilter.createFilterFromString("(objectclass=*)");
assertTrue(b.isIndexed(filter));
--
Gitblit v1.10.0