// by aborted by a DeadlockException. This is a transient error and
// the transaction should be attempted again.
// We will try DEADLOCK_RETRIES times before failing.
while ((tries++ < DEADLOCK_RETRIES) && (!done))
{
DraftCNDBCursor cursor = db.openDeleteCursor();
try
{
while ((size < 5000 ) && (!finished))
{
// let's traverse the DraftCNDb
if (!cursor.next())
{
finished=true;
}
else
{
ChangeNumber cn = cursor.currentChangeNumber();
// From the draftCNDb change record, get the domain and changeNumber
String serviceID = cursor.currentServiceID();
if ((serviceIDToClear!=null) &&
(serviceIDToClear.equalsIgnoreCase(serviceID)))
{
size++;
cursor.delete();
continue;
}
ReplicationServerDomain domain =
replicationServer.getReplicationServerDomain(serviceID, false);
if (domain==null)
{
// the domain has been removed since the record was written in the
// draftCNDb, thus it makes no sense to keep the record in the
// draftCNDb.
size++;
cursor.delete();
}
else
{
// let's get the eligible part of the domain
ServerState startSS = domain.getStartState();
ServerState endSS= domain.getEligibleState(crossDomainEligibleCN,
true);
ChangeNumber fcn = startSS.getMaxChangeNumber(cn.getServerId());
ChangeNumber lcn = endSS.getMaxChangeNumber(cn.getServerId());
// if the draftCNDb change record, is out of the eligible part
// of the domain, then it can be removed.
if (cn.older(fcn)||cn.newer(lcn))
{
size++;
cursor.delete();
}
}
}
}
cursor.close();
done = true;
}
catch (LockConflictException e)
{
cursor.abort();
if (tries == DEADLOCK_RETRIES)
{
// could not handle the Deadlock after DEADLOCK_RETRIES tries.
// shutdown the ReplicationServer.
shutdown = true;
throw (e);
}
}
catch (DatabaseException e)
{
// mark shutdown for this db so that we don't try again to
// stop it from cursor.close() or methods called by cursor.close()
shutdown = true;
cursor.abort();
throw (e);
}
}
}