NameIdPair nameIdPair = repImpl.getRepNode().getNameIdPair();
nameIdPair.revertToNull(); /* read transaction, so null id is ok. */
/* Now delete old nodes and the group, and establish a new group */
Txn txn = new MasterTxn(repImpl, txnConfig, nameIdPair);
RepGroupImpl prevRepGroup = fetchGroupObject(txn, dbImpl);
txn.commit();
final int nodeIdSequenceStart = prevRepGroup.getNodeIdSequence();
final DatabaseEntry keyEntry = new DatabaseEntry();
final DatabaseEntry value = new DatabaseEntry();
/*
* We have the "predicted" real node id, so set it and it will be used
* in the commit lns that will be written in future.
*/
final int firstNodeId = nodeIdSequenceStart + 1;
nameIdPair.setId(firstNodeId);
RepNodeImpl firstNode = new RepNodeImpl(nodeName, hostname, port);
final BarrierState barrierState = new BarrierState(lastOldVLSN,
System.currentTimeMillis());
firstNode.setBarrierState(barrierState);
txn = new MasterTxn(repImpl, txnConfig, nameIdPair);
final CursorConfig cursorConfig = new CursorConfig();
cursorConfig.setReadCommitted(true);
Cursor mcursor = makeCursor(dbImpl, txn, cursorConfig);
while (mcursor.getNext(keyEntry, value, LockMode.DEFAULT) ==
OperationStatus.SUCCESS) {
final String key = StringBinding.entryToString(keyEntry);
if (GROUP_KEY.equals(key)) {
GroupBinding groupBinding = new GroupBinding();
RepGroupImpl repGroup = new RepGroupImpl(groupName);
repGroup.setNodeIdSequence(nodeIdSequenceStart);
DatabaseEntry groupEntry = new DatabaseEntry();
groupBinding.objectToEntry(repGroup, groupEntry);
OperationStatus status = mcursor.putCurrent(groupEntry);
if (!OperationStatus.SUCCESS.equals(status)) {
throw new IllegalStateException("Unexpected state:" +
status);
}
} else {
LoggerUtils.info(logger, repImpl, "Removing node: " + key);
mcursor.delete();
}
}
mcursor.close();
txn.commit();
/* Now add the first node of the new group. */
ensureMember(firstNode);
if (firstNodeId != firstNode.getNodeId()) {
throw new IllegalStateException("Expected nodeid:" + firstNodeId +