repConfig.setNodeName(nodeName);
int port = Integer.parseInt(RepParams.DEFAULT_PORT.getDefault());
String hostName = host + ":" + port;
repConfig.setNodeHostPort(hostName);
repConfig.setHelperHosts(hostName);
final ReplicatedEnvironment rep =
RepInternal.createDetachedEnv(envHome, repConfig, envConfig);
try {
ReplicatedEnvironment.State state = rep.getState();
if (state != ReplicatedEnvironment.State.DETACHED) {
throw EnvironmentFailureException.unexpectedState
("joinState=" + state);
}
EnvironmentImpl envImpl =
DbInternal.getEnvironmentImpl(rep);
VLSNIndex vlsnIndex =
RepInternal.getRepImpl(rep).getVLSNIndex();
if (forward) {
startLsn = DbLsn.NULL_LSN;
} else {
startLsn = envImpl.getFileManager().getLastUsedLsn();
}
int readBufferSize =
envImpl.getConfigManager().getInt
(EnvironmentParams.LOG_ITERATOR_READ_SIZE);
FeederReader feederReader = null;
FeederSyncupReader backwardsReader = null;
VLSN scanVLSN = startVLSN;
if (startVLSN.equals(VLSN.NULL_VLSN)) {
RepImpl repImpl = RepInternal.getRepImpl(rep);
VLSNRange range = repImpl.getVLSNIndex().getRange();
if (forward) {
scanVLSN = range.getFirst();
} else {
scanVLSN = range.getLast();
}
}
if (scanVLSN.equals(VLSN.NULL_VLSN)) {
/* Give up, no VLSN entries in the index. */
System.out.println("<DbPrintLog>");
System.out.println("</DbPrintLog>");
return;
}
if (forward) {
feederReader = new FeederReader(envImpl, vlsnIndex, startLsn,
readBufferSize,
new NameIdPair("n0", 0));
feederReader.initScan(scanVLSN);
} else {
backwardsReader = new FeederSyncupReader
(envImpl, vlsnIndex,
startLsn, readBufferSize,
new NameIdPair("n0", 0),
scanVLSN,
DbLsn.NULL_LSN);
}
OutputWireRecord record = null;
System.out.println("<DbPrintLog>");
long lastLsn = 0;
do {
if (forward) {
record = feederReader.scanForwards(scanVLSN, 0);
scanVLSN = scanVLSN.getNext();
lastLsn = feederReader.getLastLsn();
} else {
record = backwardsReader.scanBackwards(scanVLSN);
scanVLSN = scanVLSN.getPrev();
lastLsn = backwardsReader.getLastLsn();
}
if (record != null) {
System.out.println
("lsn=" + DbLsn.getNoFormatString(lastLsn) + " " + record);
}
} while (record != null);
System.out.println("</DbPrintLog>");
} finally {
rep.close();
}
}