• RockeMQ-存储机制-可用性策略


    broker的可用性策略-快速失败机制

    具体实现在BrokerFastFailure,会执行一个定时任务扫描写消息任务的队列,当发现ospagecache繁忙的时候,就取出一个请求任务快速返回,直到OSPageCache不在繁忙。

    然后会遍历任务队列,如果发现某一个请求任务已经超时,那么也会立即返回避免producer堵塞。

    具体实现逻辑:

        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) {
                }
            }
    
            while (true) {
                try {
                    if (!this.brokerController.getSendThreadPoolQueue().isEmpty()) {
                        // peek不删除元素
                        final Runnable runnable = this.brokerController.getSendThreadPoolQueue().peek();
                        if (null == runnable) {
                            break;
                        }
                        final RequestTask rt = castRunnable(runnable);
                        if (rt == null || rt.isStopRun()) {
                            break;
                        }
    
                        final long behind = System.currentTimeMillis() - rt.getCreateTimestamp();
                        if (behind >= this.brokerController.getBrokerConfig().getWaitTimeMillsInSendQueue()) {
                            if (this.brokerController.getSendThreadPoolQueue().remove(runnable)) {
                                rt.setStopRun(true);
                                rt.returnResponse(RemotingSysResponseCode.SYSTEM_BUSY, String.format("[TIMEOUT_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: %sms, size of queue: %d", behind, this.brokerController.getSendThreadPoolQueue().size()));
                            }
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                } catch (Throwable ignored) {
                }
            }
        }

    在remote的NettyRemotingAbstract类中的processRequestCommand,会把远程请求处理包装成一个RequestTask 然后放到sendMessageExecutor中

     final RequestTask requestTask = new RequestTask(run, ctx.channel(), cmd);
                    pair.getObject2().submit(requestTask);
    
    

    实际上会把任务放到队列中 this.sendThreadPoolQueue = new LinkedBlockingQueue<Runnable>(this.brokerConfig.getSendThreadPoolQueueCapacity());

    取出来的时候,进行强转。final RequestTask rt = castRunnable(runnable);

  • 相关阅读:
    Ubuntu 下安装 PHP Solr 扩展的安装与使用
    转载:Ubuntu14-04安装redis和php5-redis扩展
    Datagridview全选,更新数据源代码
    sftp不识别的问题ssh命令找不到
    linux:如何修改用户的密码
    win7.wifi热点
    Rico Board.1.环境配置
    linux学习记录.6.vscode调试c makefile
    linux学习记录.5.git & github
    linux学习记录.3.virtualbox 共享文件夹
  • 原文地址:https://www.cnblogs.com/gaojy/p/15096810.html
Copyright © 2020-2023  润新知