* @throws IOException If IO error occurred.
*/
public void changeStatusForResetGenId(long newGenId)
throws IOException
{
StatusMachineEvent event = null;
if (newGenId == -1)
{
// The generation id is being made invalid, let's put the DS
// into BAD_GEN_ID_STATUS
event = StatusMachineEvent.TO_BAD_GEN_ID_STATUS_EVENT;
} else
{
if (newGenId == generationId)
{
if (status == ServerStatus.BAD_GEN_ID_STATUS)
{
// This server has the good new reference generation id.
// Close connection with him to force his reconnection: DS will
// reconnect in NORMAL_STATUS or DEGRADED_STATUS.
if (debugEnabled())
{
TRACER.debugInfo(
"In RS " +
replicationServerDomain.getReplicationServer().getServerId() +
". Closing connection to DS " + getServerId() +
" for baseDn " + getServiceId() +
" to force reconnection as new local" +
" generationId and remote one match and DS is in bad gen id: " +
newGenId);
}
// Connection closure must not be done calling RSD.stopHandler() as it
// would rewait the RSD lock that we already must have entering this
// method. This would lead to a reentrant lock which we do not want.
// So simply close the session, this will make the hang up appear
// after the reader thread that took the RSD lock realeases it.
if (session != null)
{
// V4 protocol introduces a StopMsg to properly close the
// connection between servers
if (protocolVersion >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
{
try
{
session.publish(new StopMsg());
} catch (IOException ioe)
{
// Anyway, going to close session, so nothing to do
}
}
}
// NOT_CONNECTED_STATUS is the last one in RS session life: handler
// will soon disappear after this method call...
status = ServerStatus.NOT_CONNECTED_STATUS;
return;
} else
{
if (debugEnabled())
{
TRACER.debugInfo(
"In RS " +
replicationServerDomain.getReplicationServer().getServerId() +
". DS " + getServerId() + " for baseDn " + getServiceId() +
" has already generation id " + newGenId +
" so no ChangeStatusMsg sent to him.");
}
return;
}
} else
{
// This server has a bad generation id compared to new reference one,
// let's put it into BAD_GEN_ID_STATUS
event = StatusMachineEvent.TO_BAD_GEN_ID_STATUS_EVENT;
}
}
if ((event == StatusMachineEvent.TO_BAD_GEN_ID_STATUS_EVENT) &&
(status == ServerStatus.FULL_UPDATE_STATUS))
{
// Prevent useless error message (full update status cannot lead to bad
// gen status)
Message message = NOTE_BAD_GEN_ID_IN_FULL_UPDATE.get(
Integer.toString(replicationServerDomain.
getReplicationServer().getServerId()),
getServiceId().toString(),
Integer.toString(serverId),
Long.toString(generationId),
Long.toString(newGenId));
logError(message);
return;
}
ServerStatus newStatus = StatusMachine.computeNewStatus(status, event);
if (newStatus == ServerStatus.INVALID_STATUS)
{
Message msg = ERR_RS_CANNOT_CHANGE_STATUS.get(getServiceId().toString(),
Integer.toString(serverId), status.toString(), event.toString());
logError(msg);
return;
}
// Send message requesting to change the DS status