From c32dde17d3b5bb7cc307e3d7d66918b8427988a4 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Fri, 25 Jun 2010 09:47:13 +0000
Subject: [PATCH] This fix resolves an issue with replication between Windows and Unix systems. The GenerationID was different on the systems for the same input due to differences in line separators and an inappropriate exception handling.

---
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/GenerationIdChecksum.java |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/GenerationIdChecksum.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/GenerationIdChecksum.java
index 9bd1bb3..0ba859c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/GenerationIdChecksum.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/GenerationIdChecksum.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.replication.plugin;
 
@@ -43,11 +43,24 @@
   private long checksum = 0L;
 
   /**
+   * This is the generation id for an empty backend.
+   */
+  public static final long EMPTY_BACKEND_GENERATION_ID = 48L;
+
+  /**
    * Update the checksum with one added byte.
    */
   private void updateWithOneByte(byte b)
   {
-    checksum += (long) b;
+    /**
+     * The "end of line" code is CRLF under windows but LF on UNIX. So to get
+     * the same checksum value on every platforms, we always exclude the CR and
+     * LF characters from the computation.
+     */
+    if ((b != 0x0D) && (b != 0x0A)) // CR=0D and LF=0A
+    {
+      checksum += (long) b;
+    }
   }
 
   /**
@@ -74,7 +87,18 @@
    */
   public long getValue()
   {
-    return checksum;
+    if (checksum != 0L)
+    {
+      return checksum;
+    } else
+    {
+      // Computing an empty backend writes the number of entries (0) only, which
+      // will not be added to the checksum as no entries will follow. To treat
+      // this special case, and to keep consistency with old versions, in that
+      // case we hardcode and return the generation id value for an empty
+      // backend.
+      return EMPTY_BACKEND_GENERATION_ID;
+    }
   }
 
   /**

--
Gitblit v1.10.0