[
https://issues.apache.org/jira/browse/AMQ-9646?focusedWorklogId=955968&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-955968
]
ASF GitHub Bot logged work on AMQ-9646:
---------------------------------------
Author: ASF GitHub Bot
Created on: 07/Feb/25 00:05
Start Date: 07/Feb/25 00:05
Worklog Time Spent: 10m
Work Description: cshannon commented on code in PR #1377:
URL: https://github.com/apache/activemq/pull/1377#discussion_r1945619851
##########
activemq-broker/src/main/java/org/apache/activemq/store/MessageRecoveryContext.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.store;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.activemq.command.Message;
+import org.apache.activemq.command.MessageId;
+
+public class MessageRecoveryContext implements MessageRecoveryListener {
+
+ public static final int DEFAULT_MAX_MESSAGE_COUNT_RETURNED = 100;
+ public static final boolean DEFAULT_USE_DEDICATED_CURSOR = true;
+
+ // Config
+ private boolean useDedicatedCursor;
+ private int maxMessageCountReturned;
+ private Long offset = null;
+ private String startMessageId = null;
+ private String endMessageId = null;
+ private final MessageRecoveryListener messageRecoveryListener;
+
+ // State
+ private Long endSequenceId = Long.MAX_VALUE;
+
+ // Stats
+ private AtomicInteger recoveredCount = new AtomicInteger(0);
+
+ MessageRecoveryContext(final MessageRecoveryListener
messageRecoveryListener, final String startMessageId, final String
endMessageId, final Long offset, final Integer maxMessageCountReturned, final
Boolean useDedicatedCursor) {
+ if(maxMessageCountReturned != null && maxMessageCountReturned < 0) {
+ throw new IllegalArgumentException("maxMessageCountReturned must
be a positive integer value");
+ }
+ if(messageRecoveryListener == null) {
+ throw new IllegalArgumentException("MessageRecoveryListener must
be specified");
+ }
+ if(offset != null) {
+ if(offset < 0L) {
+ throw new IllegalArgumentException("offset must be a positive
integer value");
+ }
+ if(startMessageId != null) {
+ throw new IllegalArgumentException("Only one of offset and
startMessageId may be specified");
+ }
+ }
+ this.endMessageId = endMessageId;
+ this.maxMessageCountReturned = (maxMessageCountReturned != null ?
maxMessageCountReturned : DEFAULT_MAX_MESSAGE_COUNT_RETURNED);
+ this.messageRecoveryListener = messageRecoveryListener;
+ this.offset = offset;
+ this.startMessageId = startMessageId;
+ this.useDedicatedCursor = (useDedicatedCursor != null ?
useDedicatedCursor : DEFAULT_USE_DEDICATED_CURSOR);
+ }
+
+ public boolean isUseDedicatedCursor() {
+ return this.useDedicatedCursor;
+ }
+
+ public int getMaxMessageCountReturned() {
+ return this.maxMessageCountReturned;
+ }
+
+ public Long getOffset() {
+ return this.offset;
+ }
+
+ public String getEndMessageId() {
+ return this.endMessageId;
+ }
+
+ public String getStartMessageId() {
+ return this.startMessageId;
+ }
+
+ public MessageRecoveryListener getMessageRecoveryListener() {
+ return this.messageRecoveryListener;
+ }
+
+ // MessageRecoveryContext functions
+ public void setEndSequenceId(long endSequenceId) {
+ this.endSequenceId = endSequenceId;
+ }
+
+ public boolean canRecoveryNextMessage(Long sequenceId) {
+ if (getRecoveredCount() >= getMaxMessageCountReturned() ||
+ !this.messageRecoveryListener.canRecoveryNextMessage() ||
+ sequenceId >= endSequenceId) {
+ return false;
+ }
+ return true;
+ }
+
+ // MessageRecoveryListener functions
+ public boolean recoverMessage(Message message) throws Exception {
+ boolean tmpReturned =
this.messageRecoveryListener.recoverMessage(message);
+ this.recoveredCount.incrementAndGet();
Review Comment:
Should this only increment if tmpReturned is true?
##########
activemq-broker/src/test/java/org/apache/activemq/store/MessageRecoveryContextTest.java:
##########
@@ -0,0 +1,220 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.store;
+
+import static org.junit.Assert.*;
+
+import org.apache.activemq.command.Message;
+import org.apache.activemq.command.MessageId;
+import org.junit.Test;
+
+public class MessageRecoveryContextTest {
+
+ @Test
+ public void testConfigOffset() {
+ MessageRecoveryContext messageRecoveryContext =
+ new MessageRecoveryContext.Builder()
+ .maxMessageCountReturned(999)
+ .messageRecoveryListener(new MessageRecoveryListener() {
Review Comment:
It probably makes sense to create a test impl of this as a nested class just
because it's reused multiple times
##########
activemq-broker/src/main/java/org/apache/activemq/store/MessageRecoveryContext.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.store;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.activemq.command.Message;
+import org.apache.activemq.command.MessageId;
+
+public class MessageRecoveryContext implements MessageRecoveryListener {
+
+ public static final int DEFAULT_MAX_MESSAGE_COUNT_RETURNED = 100;
+ public static final boolean DEFAULT_USE_DEDICATED_CURSOR = true;
+
+ // Config
+ private boolean useDedicatedCursor;
+ private int maxMessageCountReturned;
+ private Long offset = null;
+ private String startMessageId = null;
+ private String endMessageId = null;
+ private final MessageRecoveryListener messageRecoveryListener;
+
+ // State
+ private Long endSequenceId = Long.MAX_VALUE;
+
+ // Stats
+ private AtomicInteger recoveredCount = new AtomicInteger(0);
+
+ MessageRecoveryContext(final MessageRecoveryListener
messageRecoveryListener, final String startMessageId, final String
endMessageId, final Long offset, final Integer maxMessageCountReturned, final
Boolean useDedicatedCursor) {
+ if(maxMessageCountReturned != null && maxMessageCountReturned < 0) {
+ throw new IllegalArgumentException("maxMessageCountReturned must
be a positive integer value");
+ }
+ if(messageRecoveryListener == null) {
+ throw new IllegalArgumentException("MessageRecoveryListener must
be specified");
+ }
+ if(offset != null) {
+ if(offset < 0L) {
Review Comment:
should we make this offset <= instead? I guess 0 would work in theory as
it's just no offset but the error message says it should be positive so should
make this consistent one way or the other (change the condition or error
message)
##########
activemq-broker/src/main/java/org/apache/activemq/store/MessageRecoveryContext.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.store;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.activemq.command.Message;
+import org.apache.activemq.command.MessageId;
+
+public class MessageRecoveryContext implements MessageRecoveryListener {
+
+ public static final int DEFAULT_MAX_MESSAGE_COUNT_RETURNED = 100;
+ public static final boolean DEFAULT_USE_DEDICATED_CURSOR = true;
+
+ // Config
+ private boolean useDedicatedCursor;
Review Comment:
All of these member variables in this group should be marked as final
(except endSequence it looks like)
##########
activemq-broker/src/main/java/org/apache/activemq/store/MessageRecoveryContext.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.store;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.activemq.command.Message;
+import org.apache.activemq.command.MessageId;
+
+public class MessageRecoveryContext implements MessageRecoveryListener {
+
+ public static final int DEFAULT_MAX_MESSAGE_COUNT_RETURNED = 100;
+ public static final boolean DEFAULT_USE_DEDICATED_CURSOR = true;
+
+ // Config
+ private boolean useDedicatedCursor;
+ private int maxMessageCountReturned;
+ private Long offset = null;
+ private String startMessageId = null;
+ private String endMessageId = null;
+ private final MessageRecoveryListener messageRecoveryListener;
+
+ // State
+ private Long endSequenceId = Long.MAX_VALUE;
+
+ // Stats
+ private AtomicInteger recoveredCount = new AtomicInteger(0);
+
+ MessageRecoveryContext(final MessageRecoveryListener
messageRecoveryListener, final String startMessageId, final String
endMessageId, final Long offset, final Integer maxMessageCountReturned, final
Boolean useDedicatedCursor) {
Review Comment:
Just from a readability standpoint i'll make this more than one line
##########
activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java:
##########
@@ -733,35 +734,56 @@ public void execute(Transaction tx) throws Exception {
}
@Override
- public void recoverNextMessages(final int offset, final int
maxReturned, final MessageRecoveryListener listener) throws Exception {
+ public void recoverMessages(final MessageRecoveryContext
messageRecoveryContext) throws Exception {
indexLock.writeLock().lock();
try {
pageFile.tx().execute(new Transaction.Closure<Exception>() {
@Override
public void execute(Transaction tx) throws Exception {
StoredDestination sd = getStoredDestination(dest, tx);
+
+ Long startSequenceOffset = null;
+ Long endSequenceOffset = null;
+
+ if(messageRecoveryContext.getStartMessageId() != null
&& !messageRecoveryContext.getStartMessageId().isBlank()) {
+ startSequenceOffset = sd.messageIdIndex.get(tx,
messageRecoveryContext.getStartMessageId());
+ }
+
+ if(startSequenceOffset == null) {
+ startSequenceOffset =
messageRecoveryContext.getOffset();
+ }
+
+ if(messageRecoveryContext.getEndMessageId() != null &&
!messageRecoveryContext.getEndMessageId().isBlank()) {
Review Comment:
Same if/else comment as for startMessageId
##########
activemq-broker/src/main/java/org/apache/activemq/store/MessageRecoveryContext.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.store;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.activemq.command.Message;
+import org.apache.activemq.command.MessageId;
+
+public class MessageRecoveryContext implements MessageRecoveryListener {
+
+ public static final int DEFAULT_MAX_MESSAGE_COUNT_RETURNED = 100;
+ public static final boolean DEFAULT_USE_DEDICATED_CURSOR = true;
+
+ // Config
+ private boolean useDedicatedCursor;
+ private int maxMessageCountReturned;
+ private Long offset = null;
+ private String startMessageId = null;
+ private String endMessageId = null;
+ private final MessageRecoveryListener messageRecoveryListener;
+
+ // State
+ private Long endSequenceId = Long.MAX_VALUE;
+
+ // Stats
+ private AtomicInteger recoveredCount = new AtomicInteger(0);
Review Comment:
This can be final as well
##########
activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java:
##########
@@ -733,35 +734,56 @@ public void execute(Transaction tx) throws Exception {
}
@Override
- public void recoverNextMessages(final int offset, final int
maxReturned, final MessageRecoveryListener listener) throws Exception {
+ public void recoverMessages(final MessageRecoveryContext
messageRecoveryContext) throws Exception {
indexLock.writeLock().lock();
try {
pageFile.tx().execute(new Transaction.Closure<Exception>() {
@Override
public void execute(Transaction tx) throws Exception {
StoredDestination sd = getStoredDestination(dest, tx);
+
+ Long startSequenceOffset = null;
+ Long endSequenceOffset = null;
+
+ if(messageRecoveryContext.getStartMessageId() != null
&& !messageRecoveryContext.getStartMessageId().isBlank()) {
+ startSequenceOffset = sd.messageIdIndex.get(tx,
messageRecoveryContext.getStartMessageId());
+ }
+
+ if(startSequenceOffset == null) {
Review Comment:
I'm wondering if this should be an if/else statement when finding the
startSequenceOffset value. You can't set both offset and startMessageId so it
should be one or the other. Also, should there be an error thrown if the
startMessageId can't be found?
##########
activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java:
##########
@@ -733,35 +734,56 @@ public void execute(Transaction tx) throws Exception {
}
@Override
- public void recoverNextMessages(final int offset, final int
maxReturned, final MessageRecoveryListener listener) throws Exception {
+ public void recoverMessages(final MessageRecoveryContext
messageRecoveryContext) throws Exception {
indexLock.writeLock().lock();
try {
pageFile.tx().execute(new Transaction.Closure<Exception>() {
@Override
public void execute(Transaction tx) throws Exception {
StoredDestination sd = getStoredDestination(dest, tx);
+
+ Long startSequenceOffset = null;
+ Long endSequenceOffset = null;
+
+ if(messageRecoveryContext.getStartMessageId() != null
&& !messageRecoveryContext.getStartMessageId().isBlank()) {
+ startSequenceOffset = sd.messageIdIndex.get(tx,
messageRecoveryContext.getStartMessageId());
+ }
+
+ if(startSequenceOffset == null) {
+ startSequenceOffset =
messageRecoveryContext.getOffset();
+ }
+
+ if(messageRecoveryContext.getEndMessageId() != null &&
!messageRecoveryContext.getEndMessageId().isBlank()) {
+ endSequenceOffset = sd.messageIdIndex.get(tx,
messageRecoveryContext.getEndMessageId());
+ }
+
+ if(endSequenceOffset == null) {
+ endSequenceOffset = startSequenceOffset +
Long.valueOf(messageRecoveryContext.getMaxMessageCountReturned());
+ }
+
+ if(endSequenceOffset < startSequenceOffset) {
+ // Fast fail on invalid scenario
+ return;
Review Comment:
This is unexpected so I would think it would be better to throw something
like IllegalStateException()
##########
activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java:
##########
@@ -733,35 +734,56 @@ public void execute(Transaction tx) throws Exception {
}
@Override
- public void recoverNextMessages(final int offset, final int
maxReturned, final MessageRecoveryListener listener) throws Exception {
+ public void recoverMessages(final MessageRecoveryContext
messageRecoveryContext) throws Exception {
indexLock.writeLock().lock();
try {
pageFile.tx().execute(new Transaction.Closure<Exception>() {
@Override
public void execute(Transaction tx) throws Exception {
StoredDestination sd = getStoredDestination(dest, tx);
+
+ Long startSequenceOffset = null;
+ Long endSequenceOffset = null;
+
+ if(messageRecoveryContext.getStartMessageId() != null
&& !messageRecoveryContext.getStartMessageId().isBlank()) {
+ startSequenceOffset = sd.messageIdIndex.get(tx,
messageRecoveryContext.getStartMessageId());
+ }
+
+ if(startSequenceOffset == null) {
+ startSequenceOffset =
messageRecoveryContext.getOffset();
+ }
+
+ if(messageRecoveryContext.getEndMessageId() != null &&
!messageRecoveryContext.getEndMessageId().isBlank()) {
+ endSequenceOffset = sd.messageIdIndex.get(tx,
messageRecoveryContext.getEndMessageId());
+ }
+
+ if(endSequenceOffset == null) {
+ endSequenceOffset = startSequenceOffset +
Long.valueOf(messageRecoveryContext.getMaxMessageCountReturned());
+ }
+
+ if(endSequenceOffset < startSequenceOffset) {
+ // Fast fail on invalid scenario
+ return;
+ }
+
+
messageRecoveryContext.setEndSequenceId(endSequenceOffset);
Entry<Long, MessageKeys> entry = null;
- int position = 0;
- int counter =
recoverRolledBackAcks(destination.getPhysicalName(), sd, tx, maxReturned,
listener);
- Set ackedAndPrepared =
ackedAndPreparedMap.get(destination.getPhysicalName());
- for (Iterator<Entry<Long, MessageKeys>> iterator =
sd.orderIndex.iterator(tx); iterator.hasNext(); ) {
+ recoverRolledBackAcks(destination.getPhysicalName(),
sd, tx, messageRecoveryContext.getMaxMessageCountReturned(),
messageRecoveryContext);
+ Set<String> ackedAndPrepared =
ackedAndPreparedMap.get(destination.getPhysicalName());
+ Iterator<Entry<Long, MessageKeys>> iterator =
(messageRecoveryContext.isUseDedicatedCursor() ? sd.orderIndex.iterator(tx, new
MessageOrderCursor(startSequenceOffset)) : sd.orderIndex.iterator(tx));
Review Comment:
I'd add a new line here somewhere make it more readable as it's a long line
but just a style thing so not a big deal
Issue Time Tracking
-------------------
Worklog Id: (was: 955968)
Time Spent: 2h 20m (was: 2h 10m)
> Support selecting specific messages for command line backup
> -----------------------------------------------------------
>
> Key: AMQ-9646
> URL: https://issues.apache.org/jira/browse/AMQ-9646
> Project: ActiveMQ Classic
> Issue Type: Improvement
> Reporter: Matt Pavlovich
> Assignee: Matt Pavlovich
> Priority: Minor
> Fix For: 6.2.0, 5.19.0
>
> Time Spent: 2h 20m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact