From 1e8c4e58774bffeb3f8e0ee88e347f9579aff5ce Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Fri, 23 Feb 2007 21:50:34 +0000
Subject: [PATCH] Recommit for issue 740. A debug logging helper method (EntryContainer#debugAccess) did not check for null OperationStatus objects being passed in and caused an NullPointerException whenever EntryCount was called. Added a null check.
---
opends/src/server/org/opends/server/backends/jeb/EntryContainer.java | 40 ++++++---
opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java | 36 +--------
opends/src/server/org/opends/server/backends/jeb/ImportJob.java | 8 -
opends/src/server/org/opends/server/backends/jeb/VerifyJob.java | 58 +++++---------
opends/src/server/org/opends/server/backends/jeb/ID2Entry.java | 64 ---------------
5 files changed, 56 insertions(+), 150 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/jeb/EntryContainer.java b/opends/src/server/org/opends/server/backends/jeb/EntryContainer.java
index b8a5a52..33a5ef7 100644
--- a/opends/src/server/org/opends/server/backends/jeb/EntryContainer.java
+++ b/opends/src/server/org/opends/server/backends/jeb/EntryContainer.java
@@ -1521,8 +1521,6 @@
}
}
- // Increment the entry count.
- id2entry.adjustRecordCount(txn, 1);
}
/**
@@ -2021,8 +2019,6 @@
id2cBuffered.flush();
id2sBuffered.flush();
- // Decrement the entry count.
- id2entry.adjustRecordCount(txn, -getDeletedEntryCount());
}
/**
@@ -3253,7 +3249,7 @@
*/
public long getEntryCount() throws DatabaseException
{
- return id2entry.getRecordCount(null);
+ return id2entry.getRecordCount();
}
/**
@@ -3538,15 +3534,18 @@
// DATABASE_READ/DATABASE_WRITE
StringBuilder builder = new StringBuilder();
builder.append(operation);
- if (status == OperationStatus.SUCCESS)
+ if(status != null)
{
- builder.append(" (ok)");
- }
- else
- {
- builder.append(" (");
- builder.append(status.toString());
- builder.append(")");
+ if (status == OperationStatus.SUCCESS)
+ {
+ builder.append(" (ok)");
+ }
+ else
+ {
+ builder.append(" (");
+ builder.append(status.toString());
+ builder.append(")");
+ }
}
builder.append(" db=");
builder.append(database.getDatabaseName());
@@ -3737,6 +3736,21 @@
}
/**
+ * Get the count of key/data pairs in the database in a JE database.
+ * This is a simple wrapper around the JE Database.count method.
+ * @param database the JE database handle.
+ * @return The count of key/data pairs in the database.
+ * @throws DatabaseException If an error occurs in the JE operation.
+ */
+ public static long count(Database database) throws DatabaseException
+ {
+ long count = database.count();
+ assert debugAccess("count", DATABASE_READ, null, database,
+ null, null, null);
+ return count;
+ }
+
+ /**
* Remove a database from disk.
*
* @param name The short database name, to which the entryContainer name will
diff --git a/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java b/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
index f2439af..036bcd1 100644
--- a/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
+++ b/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Portions Copyright 2006 Sun Microsystems, Inc.
+ * Portions Copyright 2006 - 2007 Sun Microsystems, Inc.
*/
package org.opends.server.backends.jeb;
@@ -296,70 +296,12 @@
/**
* Get the count of the number of entries stored.
*
- * @param txn A JE database transaction to be used for database access, or
- * null if none is required.
* @return The number of entries stored.
*
* @throws DatabaseException If an error occurs in the JE database.
*/
- public long getRecordCount(Transaction txn) throws DatabaseException
+ public long getRecordCount() throws DatabaseException
{
- DatabaseEntry key;
- DatabaseEntry data = new DatabaseEntry();
-
- // The count is stored in a special record whose key is entry ID zero.
- EntryID id = new EntryID(0);
- key = id.getDatabaseEntry();
-
- // Read the current count, if any.
- OperationStatus status = EntryContainer.read(getDatabase(), txn,
- key, data, LockMode.DEFAULT);
-
- // Parse the current count.
- long count = 0;
- if (status == OperationStatus.SUCCESS)
- {
- count = JebFormat.entryIDFromDatabase(data.getData());
- }
-
- return count;
- }
-
- /**
- * Adjust the count of the number of entries stored.
- *
- * @param txn A database transaction, required to be non-null if multiple
- * threads are calling this method concurrently.
- * @param deltaCount Amount to increment (or decrement if negative).
- * @throws DatabaseException If an error occurs in the JE database.
- */
- public void adjustRecordCount(Transaction txn, long deltaCount)
- throws DatabaseException
- {
- DatabaseEntry key;
- DatabaseEntry data = new DatabaseEntry();
-
- // The count is stored in a special record whose key is entry ID zero.
- EntryID id = new EntryID(0);
- key = id.getDatabaseEntry();
-
- // Read the current count, if any.
- OperationStatus status = EntryContainer.read(getDatabase(), txn,
- key, data, LockMode.RMW);
-
- // Parse the current count.
- long count = 0;
- if (status == OperationStatus.SUCCESS)
- {
- count = JebFormat.entryIDFromDatabase(data.getData());
- }
-
- // Adjust the count.
- count += deltaCount;
-
- // Write it.
- byte[] bytes = JebFormat.entryIDToDatabase(count);
- data.setData(bytes);
- EntryContainer.put(getDatabase(), txn, key, data);
+ return EntryContainer.count(getDatabase());
}
}
diff --git a/opends/src/server/org/opends/server/backends/jeb/ImportJob.java b/opends/src/server/org/opends/server/backends/jeb/ImportJob.java
index c8ae959..07c0989 100644
--- a/opends/src/server/org/opends/server/backends/jeb/ImportJob.java
+++ b/opends/src/server/org/opends/server/backends/jeb/ImportJob.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Portions Copyright 2006 Sun Microsystems, Inc.
+ * Portions Copyright 2006 - 2007 Sun Microsystems, Inc.
*/
package org.opends.server.backends.jeb;
@@ -581,12 +581,6 @@
}
}
- // Record the entry count for each base DN.
- for (ImportContext ic : importMap.values())
- {
- ID2Entry id2e = ic.getEntryContainer().getID2Entry();
- id2e.adjustRecordCount(null, ic.getEntryInsertCount());
- }
return moreData;
}
diff --git a/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java b/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java
index 6a2ff16..68c53ac 100644
--- a/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java
+++ b/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Portions Copyright 2006 Sun Microsystems, Inc.
+ * Portions Copyright 2006 - 2007 Sun Microsystems, Inc.
*/
package org.opends.server.backends.jeb;
@@ -434,7 +434,7 @@
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
- Long storedEntryCount = null;
+ Long storedEntryCount = id2entry.getRecordCount();
OperationStatus status;
for (status = cursor.getFirst(key, data, LockMode.DEFAULT);
@@ -455,48 +455,32 @@
continue;
}
- if (entryID.longValue() == 0)
- {
- // This is the stored entry count.
- storedEntryCount = JebFormat.entryIDFromDatabase(data.getData());
- }
- else
- {
- keyCount++;
+ keyCount++;
- Entry entry;
- try
- {
- entry = JebFormat.entryFromDatabase(data.getData());
- }
- catch (Exception e)
- {
- assert debugException(CLASS_NAME, "iterateID2Entry", e);
- errorCount++;
- System.err.printf("Malformed id2entry record for ID %d:%n%s%n",
- entryID.longValue(),
- StaticUtils.bytesToHex(data.getData()));
- continue;
- }
-
- verifyEntry(entryID, entry);
- }
- }
- if (storedEntryCount != null)
- {
- if (keyCount != storedEntryCount)
+ Entry entry;
+ try
{
+ entry = JebFormat.entryFromDatabase(data.getData());
+ }
+ catch (Exception e)
+ {
+ assert debugException(CLASS_NAME, "iterateID2Entry", e);
errorCount++;
- System.err.printf("The stored entry count in id2entry (%d) does " +
- "not agree with the actual number of entry " +
- "records found (%d).%n",
- storedEntryCount, keyCount);
+ System.err.printf("Malformed id2entry record for ID %d:%n%s%n",
+ entryID.longValue(),
+ StaticUtils.bytesToHex(data.getData()));
+ continue;
}
+
+ verifyEntry(entryID, entry);
}
- else
+ if (keyCount != storedEntryCount)
{
errorCount++;
- System.err.printf("Missing record count in id2entry.%n");
+ System.err.printf("The stored entry count in id2entry (%d) does " +
+ "not agree with the actual number of entry " +
+ "records found (%d).%n",
+ storedEntryCount, keyCount);
}
}
finally
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java
index b2540c0..08461b6 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Portions Copyright 2006 Sun Microsystems, Inc.
+ * Portions Copyright 2006 - 2007 Sun Microsystems, Inc.
*/
package org.opends.server.backends.jeb;
@@ -389,21 +389,9 @@
assertTrue(id2entry.putRaw(txn, key1, data1));
performBECompleteVerify("telephoneNumber", 3);
}
-
- /**
- * Change the stored count to invalid value in the telephoneNumber
- * index.
- * @throws Exception if the error count is not equal 1.
- */
- @Test() public void testBadStoredCount() throws Exception {
- preTest(2);
- //whack the count
- setStoredCount(100);
- performBECompleteVerify("telephoneNumber", 1);
- }
/**
- *
+ *
* Runs complete verify against the dn2id index
* after adding various errors in the dn2id file.
*
@@ -425,7 +413,6 @@
testDN=DN.decode(noParentDN);
id=new EntryID(12);
assertTrue(dn2id.insert(txn, testDN, id));
- setStoredCount(12);
performBECompleteVerify("dn2id", 3);
}
@@ -452,8 +439,7 @@
byte[] idBytesp=new byte[16];
idBytesp[7]=(byte) 0xFF;
EntryIDSet idSetp=new EntryIDSet(null, idBytesp);
- id2child.writeKey(txn, keyp, idSetp);
- setStoredCount(12);
+ id2child.writeKey(txn, keyp, idSetp);
performBECompleteVerify("id2children", 3);
}
@@ -475,7 +461,6 @@
EntryIDSet idSetp=new EntryIDSet();
DatabaseEntry key= new EntryID(2).getDatabaseEntry();
id2child.writeKey(txn, key, idSetp);
- setStoredCount(3);
performBECompleteVerify("id2children", 0);
}
@@ -490,8 +475,7 @@
public void testVerifyID2Subtree() throws Exception {
preTest(2);
//Add entry with no parent
- addID2EntryReturnKey(noParentDN, 3, false);
- setStoredCount(3);
+ addID2EntryReturnKey(noParentDN, 3, false);
performBECompleteVerify("id2subtree", 3);
}
@@ -513,7 +497,6 @@
EntryIDSet idSet=new EntryIDSet();
DatabaseEntry key= new EntryID(2).getDatabaseEntry();
id2subtree.writeKey(txn, key, idSet);
- setStoredCount(3);
performBECompleteVerify("id2subtree", 1);
}
@@ -680,17 +663,6 @@
/**
- * Adjust stored entry count in the id2entry file.
- * @param c new count.
- * @throws Exception if the putRaw method fails.
- */
- private void setStoredCount(long c) throws Exception {
- DatabaseEntry keyS= new EntryID(0).getDatabaseEntry();
- DatabaseEntry dataS= new EntryID(c).getDatabaseEntry();
- assertTrue(id2entry.putRaw(txn, keyS, dataS));
- }
-
- /**
* Does a pretest setup. Creates some number of entries, gets
* backend, rootcontainer, entryContainer objects, as well as
* various index objects.
--
Gitblit v1.10.0