Skip to content

Commit

Permalink
Fix range update to legacy2 with clone
Browse files Browse the repository at this point in the history
When a new clone is deployed it get the initial allocation from the
current range or the next range already allocated. The code was not
considering the case of next range so it could generate a range overlap.

The fix will check if the next range is totally allocate for the service
or it is partial and in this case only the remaining part is used.
  • Loading branch information
fmarco76 committed Nov 14, 2024
1 parent 1e824d9 commit 475b58c
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected void updateSerialNumberRangeGenerator(LdapBoundConnection conn,

String serialIncrement = dbConfig.getSerialIncrement();
dbConfig.setSerialIncrement("0x" + serialIncrement);
BigInteger incremennt = new BigInteger(serialIncrement, 16);
BigInteger increment = new BigInteger(serialIncrement, 16);

String serialLowWaterMark = dbConfig.getSerialLowWaterMark();
dbConfig.setSerialLowWaterMark("0x" + serialLowWaterMark);
Expand All @@ -176,7 +176,7 @@ protected void updateSerialNumberRangeGenerator(LdapBoundConnection conn,
BigInteger beginSerialNo = new BigInteger(beginSerialNumber, 16);
String endSerialNumber = dbConfig.getEndSerialNumber();
BigInteger endSerialNo = new BigInteger(endSerialNumber, 16);
if (endSerialNo.equals(beginSerialNo.add(incremennt).subtract(BigInteger.ONE))){
if (endSerialNo.equals(beginSerialNo.add(increment).subtract(BigInteger.ONE))){
try {
LDAPEntry entrySerial = conn.read("cn=" + beginSerialNumber+"," + rangeDN);
LDAPAttribute attrEnd = entrySerial.getAttribute("endRange");
Expand All @@ -198,22 +198,24 @@ protected void updateSerialNumberRangeGenerator(LdapBoundConnection conn,
String nextBeginSerial = dbConfig.getNextBeginSerialNumber();
String nextEndSerial = dbConfig.getNextEndSerialNumber();
if (nextBeginSerial != null && !nextBeginSerial.equals("-1")) {
BigInteger nextBeginSerialNo = new BigInteger(nextBeginSerial, 16);
dbConfig.setNextBeginSerialNumber("0x" + nextBeginSerial);

try {
LDAPEntry entryNextSerial = conn.read("cn=" + nextBeginSerial + "," + rangeDN);
LDAPAttribute attrNextEnd = entryNextSerial.getAttribute("endRange");
if (attrNextEnd != null) {
nextEndSerial = attrNextEnd.getStringValues().nextElement();
BigInteger nextEndSerialNo = new BigInteger(nextEndSerial, 16);
if (nextEndSerialNo.equals(nextBeginSerialNo.add(increment).subtract(BigInteger.ONE))) {
try {
LDAPEntry entryNextSerial = conn.read("cn=" + nextBeginSerial + "," + rangeDN);
LDAPAttribute attrNextEnd = entryNextSerial.getAttribute("endRange");
if (attrNextEnd != null) {
nextEndSerial = attrNextEnd.getStringValues().nextElement();
}
} catch (LDAPException ldae) {
if (ldae.getLDAPResultCode() == 32) {
logger.debug("No range available, using config vaules");
} else {
logger.error("LDAP error", ldae);
return;
}
}
} catch (LDAPException ldae) {
if (ldae.getLDAPResultCode() == 32) {
logger.debug("No range available, using config vaules");
} else {
logger.error("LDAP error", ldae);
return;
}

}
dbConfig.setNextEndSerialNumber("0x" + nextEndSerial);
endSerialNumber = nextEndSerial;
Expand Down Expand Up @@ -515,4 +517,4 @@ private String createRangesEntry(LdapBoundConnection conn, String newRangeObject
}
return newRangeEntry;
}
}
}

0 comments on commit 475b58c

Please sign in to comment.