@Override public ReplicationState getCurrentState() { ReplicationState state = new ReplicationState(); state.load(currentStatePersister.loadMap()); return state; }
/** * Writes all state into a new properties object. * * @return The properties. */ public Map<String, String> store() { Map<String, String> properties = new HashMap<String, String>(); store(properties); return properties; }
@Override public void initialize(Map<String, Object> metaData) { // Initialise the replication meta data. stateWriter.initialize(metaData); // Get the replication state for this pipeline run. state = (ReplicationState) metaData.get(ReplicationState.META_DATA_KEY); // Initialize a new change writer for the current sequence number. if (state.getSequenceNumber() > 0) { changeWriter = replicationStore.saveData(state.getSequenceNumber()); } }
@Override public void saveState(ReplicationState state) { File stateFile = sequenceFormatter.getFormattedName(state.getSequenceNumber(), ".state.txt"); new PropertiesPersister(stateFile).store(state.store()); if (saveCurrentState) { currentStatePersister.store(state.store()); } }
@Override public void initialize(Map<String, Object> metaData) { if (lockObtained) { throw new OsmosisRuntimeException("initialize has already been called"); } // Lock the working directory. fileLock.lock(); lockObtained = true; // Get the replication state from the upstream task. if (!metaData.containsKey(ReplicationState.META_DATA_KEY)) { throw new OsmosisRuntimeException("No replication state has been provided in metadata key " + ReplicationState.META_DATA_KEY + "."); } state = (ReplicationState) metaData.get(ReplicationState.META_DATA_KEY); // Populate the state from the existing state if it exists. if (statePersistor.exists()) { state.load(statePersistor.loadMap()); // The current sequence number must now be incremented. state.setSequenceNumber(state.getSequenceNumber() + 1); if (LOG.isLoggable(Level.FINER)) { LOG.finer("Replication sequence number is " + state.getSequenceNumber() + "."); } } }
currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1); LOG.finer("Opening change sink for interval with sequence number " + currentDataState.getSequenceNumber()); changeSink = buildResultWriter(currentDataState.getSequenceNumber()); Date intervalEnd; intervalEnd = new Date(currentDataState.getTimestamp().getTime() + intervalLength); intervalEnd = alignDateToIntervalBoundary(intervalEnd, intervalLength); currentDataState.setTimestamp(intervalEnd); LOG.finer("End of current interval is " + intervalEnd); while (replicationState.getTimestamp().compareTo(currentDataState.getTimestamp()) > 0) { + currentDataState.getSequenceNumber()); changeSink.complete(); changeSink.close(); currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1); currentDataState.setTimestamp(new Date(currentDataState.getTimestamp().getTime() + configuration.getIntervalLength())); + currentDataState.getSequenceNumber()); changeSink = buildResultWriter(currentDataState.getSequenceNumber()); LOG.finer("End of current interval is " + replicationState.getTimestamp()); currentDataState.setTimestamp(replicationState.getTimestamp());
LOG.finer("Received replication state " + serverReplicationState.getSequenceNumber()); if (serverReplicationState.getSequenceNumber() != replicationState.getSequenceNumber()) { throw new OsmosisRuntimeException("Received sequence number " + serverReplicationState.getSequenceNumber() + " from server, expected " + replicationState.getSequenceNumber()); replicationState.setTimestamp(serverReplicationState.getTimestamp()); replicationStateReceived = true; if (replicationState.getSequenceNumber() == 0) { sendReplicationData(null);
ReplicationState state = new ReplicationState(); Map<String, Object> metaData = new HashMap<String, Object>(1); metaData.put(ReplicationState.META_DATA_KEY, state); if (state.getSequenceNumber() > 0) { if (state.getSequenceNumber() == 1) { action = ChangeAction.Create; } else { (int) state.getSequenceNumber(), new Date(state.getSequenceNumber() * 1000), new OsmUser(11, "test"), state.getSequenceNumber() * 2), state.getSequenceNumber() * 3, state.getSequenceNumber() * 4)), action); state.setTimestamp(new Date(state.getSequenceNumber() * 1000));
/** * {@inheritDoc} */ @Override protected void processInitializeState(ReplicationState initialState) { Date initialDate; Date alignedDate; long intervalLength; intervalLength = getConfiguration().getIntervalLength(); initialDate = initialState.getTimestamp(); // Align the date to an interval boundary. alignedDate = alignDateToIntervalBoundary(initialDate, intervalLength); // If the date has been moved, then advance it to the next interval. We // do this because // during replication we never claim to have covered a time period that // we haven't received // data for. We may include extra data from a previous interval. By // advancing the stated // initial timestamp to the next interval our first replication will // include some data from // the previous interval. if (alignedDate.compareTo(initialDate) < 0) { alignedDate = new Date(alignedDate.getTime() + intervalLength); } // Create an initial replication state object. currentDataState = new ReplicationState(alignedDate, 0); // Write out the initial "0" state file. replicationStore.saveState(currentDataState); }
calculateMaximumTimestamp(configuration, serverState.getTimestamp(), localState.getTimestamp()); LOG.fine("The maximum timestamp to be downloaded is " + maximumDownloadTimestamp + "."); while (localState.getSequenceNumber() < serverState.getSequenceNumber()) { File replicationFile; long sequenceNumber; if (localState.getTimestamp().compareTo(maximumDownloadTimestamp) >= 0) { break; sequenceNumber = localState.getSequenceNumber() + 1; LOG.finer("Processing replication sequence " + sequenceNumber + "."); if (fileReplicationState.getTimestamp().compareTo(maximumDownloadTimestamp) > 0) { if (localState.getSequenceNumber() != initialLocalState.getSequenceNumber()) { break;
localState = new ReplicationState(localStatePersistor.loadMap()); localStatePersistor.store(localState.store());
/** * Creates a new instance. * * @param properties * The properties to load state from. */ public ReplicationState(Map<String, String> properties) { load(properties); }
private void invokeSinkInit() { replicationState = new ReplicationState(); Map<String, Object> metaData = new HashMap<String, Object>(1); metaData.put(ReplicationState.META_DATA_KEY, replicationState); changeSink.initialize(metaData); sinkInitInvoked = true; }
if (lastDate.compareTo(getReplicationState(endBound).getTimestamp()) >= 0) { return endBound; int comparison = lastDate.compareTo(getReplicationState(midPoint).getTimestamp()); if (comparison == 0) { && lastDate.compareTo(getReplicationState(startBound).getTimestamp()) >= 0) { return startBound; } else {
@Override public int hashCode() { return super.hashCode() + (int) txnMax + (int) txnMaxQueried; }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { boolean result; if (obj instanceof ReplicationState) { ReplicationState compareState = (ReplicationState) obj; if (super.equals(obj) && txnMax == compareState.txnMax && txnMaxQueried == compareState.txnMaxQueried && txnActive.equals(compareState.txnActive) && txnReady.equals(compareState.txnReady)) { result = true; } else { result = false; } } else { result = false; } return result; }
@Override public void initialize(Map<String, Object> metaData) { if (lockObtained) { throw new OsmosisRuntimeException("initialize has already been called"); } // Lock the working directory. fileLock.lock(); lockObtained = true; // Get the replication state from the upstream task. if (!metaData.containsKey(ReplicationState.META_DATA_KEY)) { throw new OsmosisRuntimeException("No replication state has been provided in metadata key " + ReplicationState.META_DATA_KEY + "."); } state = (ReplicationState) metaData.get(ReplicationState.META_DATA_KEY); // Populate the state from the existing state if it exists. if (statePersistor.exists()) { state.load(statePersistor.loadMap()); // The current sequence number must now be incremented. state.setSequenceNumber(state.getSequenceNumber() + 1); if (LOG.isLoggable(Level.FINER)) { LOG.finer("Replication sequence number is " + state.getSequenceNumber() + "."); } } }
currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1); LOG.finer("Opening change sink for interval with sequence number " + currentDataState.getSequenceNumber()); changeSink = buildResultWriter(currentDataState.getSequenceNumber()); Date intervalEnd; intervalEnd = new Date(currentDataState.getTimestamp().getTime() + intervalLength); intervalEnd = alignDateToIntervalBoundary(intervalEnd, intervalLength); currentDataState.setTimestamp(intervalEnd); LOG.finer("End of current interval is " + intervalEnd); while (replicationState.getTimestamp().compareTo(currentDataState.getTimestamp()) > 0) { + currentDataState.getSequenceNumber()); changeSink.complete(); changeSink.close(); currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1); currentDataState.setTimestamp(new Date(currentDataState.getTimestamp().getTime() + configuration.getIntervalLength())); + currentDataState.getSequenceNumber()); changeSink = buildResultWriter(currentDataState.getSequenceNumber()); LOG.finer("End of current interval is " + replicationState.getTimestamp()); currentDataState.setTimestamp(replicationState.getTimestamp());
/** * {@inheritDoc} */ @Override protected void processInitializeState(ReplicationState initialState) { Date initialDate; Date alignedDate; long intervalLength; intervalLength = getConfiguration().getIntervalLength(); initialDate = initialState.getTimestamp(); // Align the date to an interval boundary. alignedDate = alignDateToIntervalBoundary(initialDate, intervalLength); // If the date has been moved, then advance it to the next interval. We // do this because // during replication we never claim to have covered a time period that // we haven't received // data for. We may include extra data from a previous interval. By // advancing the stated // initial timestamp to the next interval our first replication will // include some data from // the previous interval. if (alignedDate.compareTo(initialDate) < 0) { alignedDate = new Date(alignedDate.getTime() + intervalLength); } // Create an initial replication state object. currentDataState = new ReplicationState(alignedDate, 0); // Write out the initial "0" state file. replicationStore.saveState(currentDataState); }
calculateMaximumTimestamp(configuration, serverState.getTimestamp(), localState.getTimestamp()); LOG.fine("The maximum timestamp to be downloaded is " + maximumDownloadTimestamp + "."); while (localState.getSequenceNumber() < serverState.getSequenceNumber()) { File replicationFile; long sequenceNumber; if (localState.getTimestamp().compareTo(maximumDownloadTimestamp) >= 0) { break; sequenceNumber = localState.getSequenceNumber() + 1; LOG.finer("Processing replication sequence " + sequenceNumber + "."); if (fileReplicationState.getTimestamp().compareTo(maximumDownloadTimestamp) > 0) { if (localState.getSequenceNumber() != initialLocalState.getSequenceNumber()) { break;