org.apache.rocketmq.store.CommitLog Java Examples
The following examples show how to use
org.apache.rocketmq.store.CommitLog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HAService.java From DDMQ with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); while (!transferOK && defaultMessageStore.getSystemClock().now() < req.getExpireTimestamp()) { this.notifyTransferObject.waitForRunning(1000); transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer message to slave timeout, " + req.getNextOffset()); } req.wakeupCustomer(transferOK); } this.requestsRead.clear(); } } }
Example #2
Source File: HAService.java From rocketmq with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); long waitUntilWhen = HAService.this.defaultMessageStore.getSystemClock().now() + HAService.this.defaultMessageStore.getMessageStoreConfig().getSyncFlushTimeout(); while (!transferOK && HAService.this.defaultMessageStore.getSystemClock().now() < waitUntilWhen) { this.notifyTransferObject.waitForRunning(1000); transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer messsage to slave timeout, " + req.getNextOffset()); } req.wakeupCustomer(transferOK ? PutMessageStatus.PUT_OK : PutMessageStatus.FLUSH_SLAVE_TIMEOUT); } this.requestsRead.clear(); } } }
Example #3
Source File: HAService.java From DDMQ with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); while (!transferOK && defaultMessageStore.getSystemClock().now() < req.getExpireTimestamp()) { this.notifyTransferObject.waitForRunning(1000); transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer message to slave timeout, " + req.getNextOffset()); } req.wakeupCustomer(transferOK); } this.requestsRead.clear(); } } }
Example #4
Source File: HAService.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); for (int i = 0; !transferOK && i < 5; i++) { this.notifyTransferObject.waitForRunning(1000); transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer messsage to slave timeout, " + req.getNextOffset()); } req.wakeupCustomer(transferOK); } this.requestsRead.clear(); } } }
Example #5
Source File: HAService.java From rocketmq with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { // 推送到Slave的Offset是否 >= 当前消息的Offset boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); //每次从Slave的进度提交请求能够中断wait //最多等5次Slave的Ack,如果Ack的进度 >= 当前消息的进度,则返回true for (int i = 0; !transferOK && i < 5; i++) { this.notifyTransferObject.waitForRunning(1000); // 唤醒 transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer messsage to slave timeout, " + req.getNextOffset()); } // 唤醒请求,并设置是否Slave同步成功 req.wakeupCustomer(transferOK); } this.requestsRead.clear(); } } }
Example #6
Source File: HAService.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); for (int i = 0; !transferOK && i < 5; i++) { this.notifyTransferObject.waitForRunning(1000); transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer messsage to slave timeout, " + req.getNextOffset()); } req.wakeupCustomer(transferOK); } this.requestsRead.clear(); } } }
Example #7
Source File: HAService.java From rocketmq-read with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); for (int i = 0; !transferOK && i < 5; i++) { this.notifyTransferObject.waitForRunning(1000); transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer messsage to slave timeout, " + req.getNextOffset()); } req.wakeupCustomer(transferOK); } this.requestsRead.clear(); } } }
Example #8
Source File: HAService.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
private void doWaitTransfer() { synchronized (this.requestsRead) { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { boolean transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); for (int i = 0; !transferOK && i < 5; i++) { this.notifyTransferObject.waitForRunning(1000); transferOK = HAService.this.push2SlaveMaxOffset.get() >= req.getNextOffset(); } if (!transferOK) { log.warn("transfer messsage to slave timeout, " + req.getNextOffset()); } req.wakeupCustomer(transferOK); } this.requestsRead.clear(); } } }
Example #9
Source File: HAService.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } if (hasNotified.compareAndSet(false, true)) { waitPoint.countDown(); // notify } }
Example #10
Source File: HAService.java From DDMQ with Apache License 2.0 | 5 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } if (hasNotified.compareAndSet(false, true)) { waitPoint.countDown(); // notify } }
Example #11
Source File: HAService.java From rocketmq with Apache License 2.0 | 5 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } if (hasNotified.compareAndSet(false, true)) { waitPoint.countDown(); // notify } }
Example #12
Source File: HAService.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } if (hasNotified.compareAndSet(false, true)) { waitPoint.countDown(); // notify } }
Example #13
Source File: HAService.java From rocketmq-read with Apache License 2.0 | 5 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } if (hasNotified.compareAndSet(false, true)) { waitPoint.countDown(); // notify } }
Example #14
Source File: HAService.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } if (hasNotified.compareAndSet(false, true)) { waitPoint.countDown(); // notify } }
Example #15
Source File: HAService.java From DDMQ with Apache License 2.0 | 5 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } if (hasNotified.compareAndSet(false, true)) { waitPoint.countDown(); // notify } }
Example #16
Source File: DLedgerCommitLog.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public DispatchRequest checkMessageAndReturnSize(ByteBuffer byteBuffer, final boolean checkCRC, final boolean readBody) { if (isInrecoveringOldCommitlog) { return super.checkMessageAndReturnSize(byteBuffer, checkCRC, readBody); } try { int bodyOffset = DLedgerEntry.BODY_OFFSET; int pos = byteBuffer.position(); int magic = byteBuffer.getInt(); //In dledger, this field is size, it must be gt 0, so it could prevent collision int magicOld = byteBuffer.getInt(); if (magicOld == CommitLog.BLANK_MAGIC_CODE || magicOld == CommitLog.MESSAGE_MAGIC_CODE) { byteBuffer.position(pos); return super.checkMessageAndReturnSize(byteBuffer, checkCRC, readBody); } if (magic == MmapFileList.BLANK_MAGIC_CODE) { return new DispatchRequest(0, true); } byteBuffer.position(pos + bodyOffset); DispatchRequest dispatchRequest = super.checkMessageAndReturnSize(byteBuffer, checkCRC, readBody); if (dispatchRequest.isSuccess()) { dispatchRequest.setBufferSize(dispatchRequest.getMsgSize() + bodyOffset); } else if (dispatchRequest.getMsgSize() > 0) { dispatchRequest.setBufferSize(dispatchRequest.getMsgSize() + bodyOffset); } return dispatchRequest; } catch (Throwable ignored) { } return new DispatchRequest(-1, false /* success */); }
Example #17
Source File: HAService.java From rocketmq_trans_message with Apache License 2.0 | 4 votes |
private void swapRequests() { List<CommitLog.GroupCommitRequest> tmp = this.requestsWrite; this.requestsWrite = this.requestsRead; this.requestsRead = tmp; }
Example #18
Source File: HAService.java From rocketmq with Apache License 2.0 | 4 votes |
public void putRequest(final CommitLog.GroupCommitRequest request) { this.groupTransferService.putRequest(request); }
Example #19
Source File: HAService.java From rocketmq with Apache License 2.0 | 4 votes |
public synchronized void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this.requestsWrite) { this.requestsWrite.add(request); } this.wakeup(); }
Example #20
Source File: HAService.java From rocketmq_trans_message with Apache License 2.0 | 4 votes |
public void putRequest(final CommitLog.GroupCommitRequest request) { this.groupTransferService.putRequest(request); }
Example #21
Source File: DefaultRequestProcessor.java From rocketmq_trans_message with Apache License 2.0 | 4 votes |
private ByteBuffer messageToByteBuffer(final MessageExt msg) throws IOException { int sysFlag = MessageSysFlag.clearCompressedFlag(msg.getSysFlag()); if (msg.getBody() != null) { if (msg.getBody().length >= this.filtersrvController.getFiltersrvConfig().getCompressMsgBodyOverHowmuch()) { byte[] data = UtilAll.compress(msg.getBody(), this.filtersrvController.getFiltersrvConfig().getZipCompressLevel()); if (data != null) { msg.setBody(data); sysFlag |= MessageSysFlag.COMPRESSED_FLAG; } } } final int bodyLength = msg.getBody() != null ? msg.getBody().length : 0; byte[] topicData = msg.getTopic().getBytes(MixAll.DEFAULT_CHARSET); final int topicLength = topicData.length; String properties = MessageDecoder.messageProperties2String(msg.getProperties()); byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE + 4 // 2 MAGICCODE + 4 // 3 BODYCRC + 4 // 4 QUEUEID + 4 // 5 FLAG + 8 // 6 QUEUEOFFSET + 8 // 7 PHYSICALOFFSET + 4 // 8 SYSFLAG + 8 // 9 BORNTIMESTAMP + 8 // 10 BORNHOST + 8 // 11 STORETIMESTAMP + 8 // 12 STOREHOSTADDRESS + 4 // 13 RECONSUMETIMES + 8 // 14 Prepared Transaction Offset + 4 + bodyLength // 14 BODY + 1 + topicLength // 15 TOPIC + 2 + propertiesLength // 16 propertiesLength + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); final MessageExt msgInner = msg; // 1 TOTALSIZE msgStoreItemMemory.putInt(msgLen); // 2 MAGICCODE msgStoreItemMemory.putInt(CommitLog.MESSAGE_MAGIC_CODE); // 3 BODYCRC msgStoreItemMemory.putInt(UtilAll.crc32(msgInner.getBody())); // 4 QUEUEID msgStoreItemMemory.putInt(msgInner.getQueueId()); // 5 FLAG msgStoreItemMemory.putInt(msgInner.getFlag()); // 6 QUEUEOFFSET msgStoreItemMemory.putLong(msgInner.getQueueOffset()); // 7 PHYSICALOFFSET msgStoreItemMemory.putLong(msgInner.getCommitLogOffset()); // 8 SYSFLAG msgStoreItemMemory.putInt(sysFlag); // 9 BORNTIMESTAMP msgStoreItemMemory.putLong(msgInner.getBornTimestamp()); // 10 BORNHOST msgStoreItemMemory.put(msgInner.getBornHostBytes()); // 11 STORETIMESTAMP msgStoreItemMemory.putLong(msgInner.getStoreTimestamp()); // 12 STOREHOSTADDRESS msgStoreItemMemory.put(msgInner.getStoreHostBytes()); // 13 RECONSUMETIMES msgStoreItemMemory.putInt(msgInner.getReconsumeTimes()); // 14 Prepared Transaction Offset msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset()); // 15 BODY msgStoreItemMemory.putInt(bodyLength); if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC msgStoreItemMemory.put((byte) topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES msgStoreItemMemory.putShort((short) propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); return msgStoreItemMemory; }
Example #22
Source File: HAService.java From rocketmq with Apache License 2.0 | 4 votes |
private void swapRequests() { List<CommitLog.GroupCommitRequest> tmp = this.requestsWrite; this.requestsWrite = this.requestsRead; this.requestsRead = tmp; }
Example #23
Source File: HAService.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 4 votes |
private void swapRequests() { List<CommitLog.GroupCommitRequest> tmp = this.requestsWrite; this.requestsWrite = this.requestsRead; this.requestsRead = tmp; }
Example #24
Source File: HAService.java From DDMQ with Apache License 2.0 | 4 votes |
public void putRequest(final CommitLog.GroupCommitRequest request) { this.groupTransferService.putRequest(request); }
Example #25
Source File: HAService.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 4 votes |
public void putRequest(final CommitLog.GroupCommitRequest request) { this.groupTransferService.putRequest(request); }
Example #26
Source File: DefaultRequestProcessor.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 4 votes |
private ByteBuffer messageToByteBuffer(final MessageExt msg) throws IOException { int sysFlag = MessageSysFlag.clearCompressedFlag(msg.getSysFlag()); if (msg.getBody() != null) { if (msg.getBody().length >= this.filtersrvController.getFiltersrvConfig().getCompressMsgBodyOverHowmuch()) { byte[] data = UtilAll.compress(msg.getBody(), this.filtersrvController.getFiltersrvConfig().getZipCompressLevel()); if (data != null) { msg.setBody(data); sysFlag |= MessageSysFlag.COMPRESSED_FLAG; } } } final int bodyLength = msg.getBody() != null ? msg.getBody().length : 0; byte[] topicData = msg.getTopic().getBytes(MixAll.DEFAULT_CHARSET); final int topicLength = topicData.length; String properties = MessageDecoder.messageProperties2String(msg.getProperties()); byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE + 4 // 2 MAGICCODE + 4 // 3 BODYCRC + 4 // 4 QUEUEID + 4 // 5 FLAG + 8 // 6 QUEUEOFFSET + 8 // 7 PHYSICALOFFSET + 4 // 8 SYSFLAG + 8 // 9 BORNTIMESTAMP + 8 // 10 BORNHOST + 8 // 11 STORETIMESTAMP + 8 // 12 STOREHOSTADDRESS + 4 // 13 RECONSUMETIMES + 8 // 14 Prepared Transaction Offset + 4 + bodyLength // 14 BODY + 1 + topicLength // 15 TOPIC + 2 + propertiesLength // 16 propertiesLength + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); final MessageExt msgInner = msg; // 1 TOTALSIZE msgStoreItemMemory.putInt(msgLen); // 2 MAGICCODE msgStoreItemMemory.putInt(CommitLog.MESSAGE_MAGIC_CODE); // 3 BODYCRC msgStoreItemMemory.putInt(UtilAll.crc32(msgInner.getBody())); // 4 QUEUEID msgStoreItemMemory.putInt(msgInner.getQueueId()); // 5 FLAG msgStoreItemMemory.putInt(msgInner.getFlag()); // 6 QUEUEOFFSET msgStoreItemMemory.putLong(msgInner.getQueueOffset()); // 7 PHYSICALOFFSET msgStoreItemMemory.putLong(msgInner.getCommitLogOffset()); // 8 SYSFLAG msgStoreItemMemory.putInt(sysFlag); // 9 BORNTIMESTAMP msgStoreItemMemory.putLong(msgInner.getBornTimestamp()); // 10 BORNHOST msgStoreItemMemory.put(msgInner.getBornHostBytes()); // 11 STORETIMESTAMP msgStoreItemMemory.putLong(msgInner.getStoreTimestamp()); // 12 STOREHOSTADDRESS msgStoreItemMemory.put(msgInner.getStoreHostBytes()); // 13 RECONSUMETIMES msgStoreItemMemory.putInt(msgInner.getReconsumeTimes()); // 14 Prepared Transaction Offset msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset()); // 15 BODY msgStoreItemMemory.putInt(bodyLength); if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC msgStoreItemMemory.put((byte) topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES msgStoreItemMemory.putShort((short) propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); return msgStoreItemMemory; }
Example #27
Source File: HAService.java From DDMQ with Apache License 2.0 | 4 votes |
private void swapRequests() { List<CommitLog.GroupCommitRequest> tmp = this.requestsWrite; this.requestsWrite = this.requestsRead; this.requestsRead = tmp; }
Example #28
Source File: DefaultRequestProcessor.java From DDMQ with Apache License 2.0 | 4 votes |
private ByteBuffer messageToByteBuffer(final MessageExt msg) throws IOException { int sysFlag = MessageSysFlag.clearCompressedFlag(msg.getSysFlag()); if (msg.getBody() != null) { if (msg.getBody().length >= this.filtersrvController.getFiltersrvConfig().getCompressMsgBodyOverHowmuch()) { byte[] data = UtilAll.compress(msg.getBody(), this.filtersrvController.getFiltersrvConfig().getZipCompressLevel()); if (data != null) { msg.setBody(data); sysFlag |= MessageSysFlag.COMPRESSED_FLAG; } } } final int bodyLength = msg.getBody() != null ? msg.getBody().length : 0; byte[] topicData = msg.getTopic().getBytes(MixAll.DEFAULT_CHARSET); final int topicLength = topicData.length; String properties = MessageDecoder.messageProperties2String(msg.getProperties()); byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE + 4 // 2 MAGICCODE + 4 // 3 BODYCRC + 4 // 4 QUEUEID + 4 // 5 FLAG + 8 // 6 QUEUEOFFSET + 8 // 7 PHYSICALOFFSET + 4 // 8 SYSFLAG + 8 // 9 BORNTIMESTAMP + 8 // 10 BORNHOST + 8 // 11 STORETIMESTAMP + 8 // 12 STOREHOSTADDRESS + 4 // 13 RECONSUMETIMES + 8 // 14 Prepared Transaction Offset + 4 + bodyLength // 14 BODY + 1 + topicLength // 15 TOPIC + 2 + propertiesLength // 16 propertiesLength + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); final MessageExt msgInner = msg; // 1 TOTALSIZE msgStoreItemMemory.putInt(msgLen); // 2 MAGICCODE msgStoreItemMemory.putInt(CommitLog.MESSAGE_MAGIC_CODE); // 3 BODYCRC msgStoreItemMemory.putInt(UtilAll.crc32(msgInner.getBody())); // 4 QUEUEID msgStoreItemMemory.putInt(msgInner.getQueueId()); // 5 FLAG msgStoreItemMemory.putInt(msgInner.getFlag()); // 6 QUEUEOFFSET msgStoreItemMemory.putLong(msgInner.getQueueOffset()); // 7 PHYSICALOFFSET msgStoreItemMemory.putLong(msgInner.getCommitLogOffset()); // 8 SYSFLAG msgStoreItemMemory.putInt(sysFlag); // 9 BORNTIMESTAMP msgStoreItemMemory.putLong(msgInner.getBornTimestamp()); // 10 BORNHOST msgStoreItemMemory.put(msgInner.getBornHostBytes()); // 11 STORETIMESTAMP msgStoreItemMemory.putLong(msgInner.getStoreTimestamp()); // 12 STOREHOSTADDRESS msgStoreItemMemory.put(msgInner.getStoreHostBytes()); // 13 RECONSUMETIMES msgStoreItemMemory.putInt(msgInner.getReconsumeTimes()); // 14 Prepared Transaction Offset msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset()); // 15 BODY msgStoreItemMemory.putInt(bodyLength); if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC msgStoreItemMemory.put((byte) topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES msgStoreItemMemory.putShort((short) propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); return msgStoreItemMemory; }
Example #29
Source File: DefaultRequestProcessor.java From DDMQ with Apache License 2.0 | 4 votes |
private ByteBuffer messageToByteBuffer(final MessageExt msg) throws IOException { int sysFlag = MessageSysFlag.clearCompressedFlag(msg.getSysFlag()); if (msg.getBody() != null) { if (msg.getBody().length >= this.filtersrvController.getFiltersrvConfig().getCompressMsgBodyOverHowmuch()) { byte[] data = UtilAll.compress(msg.getBody(), this.filtersrvController.getFiltersrvConfig().getZipCompressLevel()); if (data != null) { msg.setBody(data); sysFlag |= MessageSysFlag.COMPRESSED_FLAG; } } } final int bodyLength = msg.getBody() != null ? msg.getBody().length : 0; byte[] topicData = msg.getTopic().getBytes(MixAll.DEFAULT_CHARSET); final int topicLength = topicData.length; String properties = MessageDecoder.messageProperties2String(msg.getProperties()); byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE + 4 // 2 MAGICCODE + 4 // 3 BODYCRC + 4 // 4 QUEUEID + 4 // 5 FLAG + 8 // 6 QUEUEOFFSET + 8 // 7 PHYSICALOFFSET + 4 // 8 SYSFLAG + 8 // 9 BORNTIMESTAMP + 8 // 10 BORNHOST + 8 // 11 STORETIMESTAMP + 8 // 12 STOREHOSTADDRESS + 4 // 13 RECONSUMETIMES + 8 // 14 Prepared Transaction Offset + 4 + bodyLength // 14 BODY + 1 + topicLength // 15 TOPIC + 2 + propertiesLength // 16 propertiesLength + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); final MessageExt msgInner = msg; // 1 TOTALSIZE msgStoreItemMemory.putInt(msgLen); // 2 MAGICCODE msgStoreItemMemory.putInt(CommitLog.MESSAGE_MAGIC_CODE); // 3 BODYCRC msgStoreItemMemory.putInt(UtilAll.crc32(msgInner.getBody())); // 4 QUEUEID msgStoreItemMemory.putInt(msgInner.getQueueId()); // 5 FLAG msgStoreItemMemory.putInt(msgInner.getFlag()); // 6 QUEUEOFFSET msgStoreItemMemory.putLong(msgInner.getQueueOffset()); // 7 PHYSICALOFFSET msgStoreItemMemory.putLong(msgInner.getCommitLogOffset()); // 8 SYSFLAG msgStoreItemMemory.putInt(sysFlag); // 9 BORNTIMESTAMP msgStoreItemMemory.putLong(msgInner.getBornTimestamp()); // 10 BORNHOST msgStoreItemMemory.put(msgInner.getBornHostBytes()); // 11 STORETIMESTAMP msgStoreItemMemory.putLong(msgInner.getStoreTimestamp()); // 12 STOREHOSTADDRESS msgStoreItemMemory.put(msgInner.getStoreHostBytes()); // 13 RECONSUMETIMES msgStoreItemMemory.putInt(msgInner.getReconsumeTimes()); // 14 Prepared Transaction Offset msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset()); // 15 BODY msgStoreItemMemory.putInt(bodyLength); if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC msgStoreItemMemory.put((byte) topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES msgStoreItemMemory.putShort((short) propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); return msgStoreItemMemory; }
Example #30
Source File: HAService.java From rocketmq with Apache License 2.0 | 4 votes |
private void swapRequests() { List<CommitLog.GroupCommitRequest> tmp = this.requestsWrite; this.requestsWrite = this.requestsRead; this.requestsRead = tmp; }