mirror of
https://github.com/apache/activemq.git
synced 2025-02-09 03:25:33 +00:00
https://issues.apache.org/jira/browse/AMQ-6277 - journal getNextLocation needs too passes to skip past if target is not initialized
This commit is contained in:
parent
a28a091c55
commit
1c4108545c
@ -111,6 +111,8 @@ import org.apache.activemq.util.ThreadPoolUtils;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.apache.activemq.store.kahadb.disk.journal.Location.NOT_SET;
|
||||||
|
|
||||||
public abstract class MessageDatabase extends ServiceSupport implements BrokerServiceAware {
|
public abstract class MessageDatabase extends ServiceSupport implements BrokerServiceAware {
|
||||||
|
|
||||||
protected BrokerService brokerService;
|
protected BrokerService brokerService;
|
||||||
@ -625,12 +627,16 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Location producerAuditPosition = recoverProducerAudit();
|
Location afterProducerAudit = recoverProducerAudit();
|
||||||
Location ackMessageFileLocation = recoverAckMessageFileMap();
|
Location afterAckMessageFile = recoverAckMessageFileMap();
|
||||||
Location lastIndoubtPosition = getRecoveryPosition();
|
Location lastIndoubtPosition = getRecoveryPosition();
|
||||||
|
|
||||||
Location recoveryPosition = startOfRecovery(producerAuditPosition, ackMessageFileLocation);
|
if (afterProducerAudit != null && afterProducerAudit.equals(metadata.ackMessageFileMapLocation)) {
|
||||||
recoveryPosition = startOfRecovery(recoveryPosition, lastIndoubtPosition);
|
// valid checkpoint, possible recover from afterAckMessageFile
|
||||||
|
afterProducerAudit = null;
|
||||||
|
}
|
||||||
|
Location recoveryPosition = minimum(afterProducerAudit, afterAckMessageFile);
|
||||||
|
recoveryPosition = minimum(recoveryPosition, lastIndoubtPosition);
|
||||||
|
|
||||||
if (recoveryPosition != null) {
|
if (recoveryPosition != null) {
|
||||||
int redoCounter = 0;
|
int redoCounter = 0;
|
||||||
@ -711,7 +717,7 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
|
|||||||
return TransactionIdConversion.convertToLocal(tx);
|
return TransactionIdConversion.convertToLocal(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location startOfRecovery(Location x,
|
private Location minimum(Location x,
|
||||||
Location y) {
|
Location y) {
|
||||||
Location min = null;
|
Location min = null;
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
@ -720,8 +726,6 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
|
|||||||
int compare = y.compareTo(x);
|
int compare = y.compareTo(x);
|
||||||
if (compare < 0) {
|
if (compare < 0) {
|
||||||
min = y;
|
min = y;
|
||||||
} else if (compare == 0) {
|
|
||||||
min = null; // no recovery needed on a matched location
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -740,7 +744,7 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
|
|||||||
metadata.producerSequenceIdTracker = (ActiveMQMessageAuditNoSync) objectIn.readObject();
|
metadata.producerSequenceIdTracker = (ActiveMQMessageAuditNoSync) objectIn.readObject();
|
||||||
metadata.producerSequenceIdTracker.setAuditDepth(maxAuditDepth);
|
metadata.producerSequenceIdTracker.setAuditDepth(maxAuditDepth);
|
||||||
metadata.producerSequenceIdTracker.setMaximumNumberOfProducersToTrack(maxNumProducers);
|
metadata.producerSequenceIdTracker.setMaximumNumberOfProducersToTrack(maxNumProducers);
|
||||||
return journal.getNextLocation(metadata.producerSequenceIdTrackerLocation);
|
return getNextInitializedLocation(metadata.producerSequenceIdTrackerLocation);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Cannot recover message audit", e);
|
LOG.warn("Cannot recover message audit", e);
|
||||||
return journal.getNextLocation(null);
|
return journal.getNextLocation(null);
|
||||||
@ -758,7 +762,7 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
|
|||||||
try {
|
try {
|
||||||
ObjectInputStream objectIn = new ObjectInputStream(audit.getAckMessageFileMap().newInput());
|
ObjectInputStream objectIn = new ObjectInputStream(audit.getAckMessageFileMap().newInput());
|
||||||
metadata.ackMessageFileMap = (Map<Integer, Set<Integer>>) objectIn.readObject();
|
metadata.ackMessageFileMap = (Map<Integer, Set<Integer>>) objectIn.readObject();
|
||||||
return journal.getNextLocation(metadata.ackMessageFileMapLocation);
|
return getNextInitializedLocation(metadata.ackMessageFileMapLocation);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Cannot recover ackMessageFileMap", e);
|
LOG.warn("Cannot recover ackMessageFileMap", e);
|
||||||
return journal.getNextLocation(null);
|
return journal.getNextLocation(null);
|
||||||
@ -986,13 +990,23 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
|
|||||||
// Perhaps there were no transactions...
|
// Perhaps there were no transactions...
|
||||||
if( metadata.lastUpdate!=null) {
|
if( metadata.lastUpdate!=null) {
|
||||||
// Start replay at the record after the last one recorded in the index file.
|
// Start replay at the record after the last one recorded in the index file.
|
||||||
return journal.getNextLocation(metadata.lastUpdate);
|
return getNextInitializedLocation(metadata.lastUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// This loads the first position.
|
// This loads the first position.
|
||||||
return journal.getNextLocation(null);
|
return journal.getNextLocation(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Location getNextInitializedLocation(Location location) throws IOException {
|
||||||
|
Location mayNotBeInitialized = journal.getNextLocation(location);
|
||||||
|
if (location.getSize() == NOT_SET && mayNotBeInitialized.getSize() != NOT_SET) {
|
||||||
|
// need to init size and type to skip
|
||||||
|
return journal.getNextLocation(mayNotBeInitialized);
|
||||||
|
} else {
|
||||||
|
return mayNotBeInitialized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void checkpointCleanup(final boolean cleanup) throws IOException {
|
protected void checkpointCleanup(final boolean cleanup) throws IOException {
|
||||||
long start;
|
long start;
|
||||||
this.indexLock.writeLock().lock();
|
this.indexLock.writeLock().lock();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user