Search in sources :

Example 6 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq by apache.

the class BrokerFastFailureTest method testCleanExpiredRequestInQueue.

@Test
public void testCleanExpiredRequestInQueue() throws Exception {
    BrokerFastFailure brokerFastFailure = new BrokerFastFailure(null);
    BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
    brokerFastFailure.cleanExpiredRequestInQueue(queue, 1);
    assertThat(queue.size()).isZero();
    // Normal Runnable
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
        }
    };
    queue.add(runnable);
    assertThat(queue.size()).isEqualTo(1);
    brokerFastFailure.cleanExpiredRequestInQueue(queue, 1);
    assertThat(queue.size()).isEqualTo(1);
    queue.clear();
    // With expired request
    RequestTask expiredRequest = new RequestTask(runnable, null, null);
    queue.add(new FutureTaskExt<>(expiredRequest, null));
    TimeUnit.MILLISECONDS.sleep(100);
    RequestTask requestTask = new RequestTask(runnable, null, null);
    queue.add(new FutureTaskExt<>(requestTask, null));
    assertThat(queue.size()).isEqualTo(2);
    brokerFastFailure.cleanExpiredRequestInQueue(queue, 100);
    assertThat(queue.size()).isEqualTo(1);
    assertThat(((FutureTaskExt) queue.peek()).getRunnable()).isEqualTo(requestTask);
}
Also used : RequestTask(org.apache.rocketmq.remoting.netty.RequestTask) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Test(org.junit.Test)

Example 7 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq by apache.

the class BrokerController method headSlowTimeMills.

public long headSlowTimeMills(BlockingQueue<Runnable> q) {
    long slowTimeMills = 0;
    final Runnable peek = q.peek();
    if (peek != null) {
        RequestTask rt = BrokerFastFailure.castRunnable(peek);
        slowTimeMills = rt == null ? 0 : this.messageStore.now() - rt.getCreateTimestamp();
    }
    if (slowTimeMills < 0)
        slowTimeMills = 0;
    return slowTimeMills;
}
Also used : RequestTask(org.apache.rocketmq.remoting.netty.RequestTask)

Example 8 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq by apache.

the class BrokerFastFailure method cleanExpiredRequest.

private void cleanExpiredRequest() {
    while (this.brokerController.getMessageStore().isOSPageCacheBusy()) {
        try {
            if (!this.brokerController.getSendThreadPoolQueue().isEmpty()) {
                final Runnable runnable = this.brokerController.getSendThreadPoolQueue().poll(0, TimeUnit.SECONDS);
                if (null == runnable) {
                    break;
                }
                final RequestTask rt = castRunnable(runnable);
                rt.returnResponse(RemotingSysResponseCode.SYSTEM_BUSY, String.format("[PCBUSY_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: %sms, size of queue: %d", System.currentTimeMillis() - rt.getCreateTimestamp(), this.brokerController.getSendThreadPoolQueue().size()));
            } else {
                break;
            }
        } catch (Throwable ignored) {
        }
    }
    cleanExpiredRequestInQueue(this.brokerController.getSendThreadPoolQueue(), this.brokerController.getBrokerConfig().getWaitTimeMillsInSendQueue());
    cleanExpiredRequestInQueue(this.brokerController.getPullThreadPoolQueue(), this.brokerController.getBrokerConfig().getWaitTimeMillsInPullQueue());
}
Also used : RequestTask(org.apache.rocketmq.remoting.netty.RequestTask)

Aggregations

RequestTask (org.apache.rocketmq.remoting.netty.RequestTask)8 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Test (org.junit.Test)1