You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "leizhiyuan (via GitHub)" <gi...@apache.org> on 2023/05/23 00:20:52 UTC
[GitHub] [rocketmq] leizhiyuan opened a new pull request, #6794: [ISSUE #6788] support cos tired storage
leizhiyuan opened a new pull request, #6794:
URL: https://github.com/apache/rocketmq/pull/6794
### Which Issue(s) This PR Fixes
Fixes #6788
### Brief Description
add support for cos in tired storage
if you need to use cos as tired storage, you need add these configs to broker.conf
```
messageStorePlugIn=org.apache.rocketmq.tieredstore.TieredMessageStore
tieredBackendServiceProvider=org.apache.rocketmq.tieredstore.provider.cos.CosFileSegment
cosBucketName=cosBucketName
cosAccessKey=cosAccessKey
cosSecretKey=cosSecretKey
cosRegion=cosRegion
```
and when you produce and consume messages, you will see messages were stored in cos
### How Did You Test This Change?
we can create a bucket in cos, then fill these configs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] codecov-commenter commented on pull request #6794: [ISSUE #6788] support cos tired storage
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6794:
URL: https://github.com/apache/rocketmq/pull/6794#issuecomment-1558562289
## [Codecov](https://app.codecov.io/gh/apache/rocketmq/pull/6794?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#6794](https://app.codecov.io/gh/apache/rocketmq/pull/6794?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (291f5e2) into [develop](https://app.codecov.io/gh/apache/rocketmq/commit/bd7db7ec62164882ce6db101bacd038308648e02?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (bd7db7e) will **decrease** coverage by `0.13%`.
> The diff coverage is `2.87%`.
```diff
@@ Coverage Diff @@
## develop #6794 +/- ##
=============================================
- Coverage 42.92% 42.80% -0.13%
+ Complexity 8985 8980 -5
=============================================
Files 1104 1105 +1
Lines 78376 78515 +139
Branches 10203 10208 +5
=============================================
- Hits 33645 33608 -37
- Misses 40512 40688 +176
Partials 4219 4219
```
| [Impacted Files](https://app.codecov.io/gh/apache/rocketmq/pull/6794?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...ketmq/tieredstore/provider/cos/CosFileSegment.java](https://app.codecov.io/gh/apache/rocketmq/pull/6794?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dGllcmVkc3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3RpZXJlZHN0b3JlL3Byb3ZpZGVyL2Nvcy9Db3NGaWxlU2VnbWVudC5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...q/tieredstore/common/TieredMessageStoreConfig.java](https://app.codecov.io/gh/apache/rocketmq/pull/6794?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dGllcmVkc3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3RpZXJlZHN0b3JlL2NvbW1vbi9UaWVyZWRNZXNzYWdlU3RvcmVDb25maWcuamF2YQ==) | `61.58% <25.00%> (-3.96%)` | :arrow_down: |
... and [18 files with indirect coverage changes](https://app.codecov.io/gh/apache/rocketmq/pull/6794/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] absolute8511 commented on a diff in pull request #6794: [ISSUE #6788] support cos tired storage
Posted by "absolute8511 (via GitHub)" <gi...@apache.org>.
absolute8511 commented on code in PR #6794:
URL: https://github.com/apache/rocketmq/pull/6794#discussion_r1227488087
##########
tieredstore/src/main/java/org/apache/rocketmq/tieredstore/provider/cos/CosFileSegment.java:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.rocketmq.tieredstore.provider.cos;
+
+import com.google.common.base.Stopwatch;
+import com.google.common.io.ByteStreams;
+import com.qcloud.cos.COSClient;
+import com.qcloud.cos.ClientConfig;
+import com.qcloud.cos.auth.BasicCOSCredentials;
+import com.qcloud.cos.auth.COSCredentials;
+import com.qcloud.cos.model.AppendObjectRequest;
+import com.qcloud.cos.model.AppendObjectResult;
+import com.qcloud.cos.model.COSObject;
+import com.qcloud.cos.model.GetObjectRequest;
+import com.qcloud.cos.model.ObjectMetadata;
+import com.qcloud.cos.region.Region;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufInputStream;
+import io.netty.buffer.Unpooled;
+import io.opentelemetry.api.common.Attributes;
+import io.opentelemetry.api.common.AttributesBuilder;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.logging.org.slf4j.Logger;
+import org.apache.rocketmq.logging.org.slf4j.LoggerFactory;
+import org.apache.rocketmq.tieredstore.common.TieredMessageStoreConfig;
+import org.apache.rocketmq.tieredstore.common.TieredStoreExecutor;
+import org.apache.rocketmq.tieredstore.metrics.TieredStoreMetricsManager;
+import org.apache.rocketmq.tieredstore.provider.TieredFileSegment;
+import org.apache.rocketmq.tieredstore.util.TieredStoreUtil;
+
+import static org.apache.rocketmq.tieredstore.metrics.TieredStoreMetricsConstant.LABEL_FILE_TYPE;
+import static org.apache.rocketmq.tieredstore.metrics.TieredStoreMetricsConstant.LABEL_OPERATION;
+import static org.apache.rocketmq.tieredstore.metrics.TieredStoreMetricsConstant.LABEL_SUCCESS;
+import static org.apache.rocketmq.tieredstore.metrics.TieredStoreMetricsConstant.LABEL_TOPIC;
+
+/**
+ * this class is experimental and may change without notice.
+ */
+public class CosFileSegment extends TieredFileSegment {
+ private static final Logger logger = LoggerFactory.getLogger(TieredStoreUtil.TIERED_STORE_LOGGER_NAME);
+
+ private static final String OPERATION_POSIX_READ = "read";
+ private static final String OPERATION_POSIX_WRITE = "write";
+
+ private final String basePath;
+ private final String filepath;
+ private String cosBucketName = "";
+ private String cosAccessKey = "";
+ private String cosSecretKey = "";
+ private String cosRegion = "";
+ private volatile boolean created;
+ private COSClient cosClient;
+
+ public CosFileSegment(FileSegmentType fileType, MessageQueue messageQueue,
+ long baseOffset, TieredMessageStoreConfig storeConfig) {
+ super(fileType, messageQueue, baseOffset, storeConfig);
+ this.cosAccessKey = storeConfig.getCosAccessKey();
+ this.cosSecretKey = storeConfig.getCosSecretKey();
+ this.cosBucketName = storeConfig.getCosBucketName();
+ this.cosRegion = storeConfig.getCosRegion();
+ String basePath = storeConfig.getTieredStoreFilepath();
+ if (StringUtils.isBlank(basePath) || basePath.endsWith(File.separator)) {
+ this.basePath = basePath;
+ } else {
+ this.basePath = basePath + File.separator;
+ }
+ this.filepath = this.basePath
+ + TieredStoreUtil.getHash(storeConfig.getBrokerClusterName()) + "_" + storeConfig.getBrokerClusterName() + File.separator
+ + messageQueue.getBrokerName() + File.separator
+ + messageQueue.getTopic() + File.separator
+ + messageQueue.getQueueId() + File.separator
+ + fileType + File.separator
+ + TieredStoreUtil.offset2FileName(baseOffset);
+ cosClient = buildCosClient();
+ createFile();
+ }
+
+ protected AttributesBuilder newAttributesBuilder() {
+ return TieredStoreMetricsManager.newAttributesBuilder()
+ .put(LABEL_TOPIC, messageQueue.getTopic())
+ .put(LABEL_FILE_TYPE, fileType.name().toLowerCase());
+ }
+
+ @Override
+ public String getPath() {
+ return filepath;
+ }
+
+ @Override
+ public long getSize() {
+ if (exists()) {
+ ObjectMetadata meta = cosClient.getObjectMetadata(cosBucketName, filepath);
+ return meta.getContentLength();
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean exists() {
+ ObjectMetadata meta = cosClient.getObjectMetadata(cosBucketName, filepath);
+ return meta != null;
+ }
+
+ @Override
+ public void createFile() {
+ if (!created) {
+ synchronized (this) {
+ if (!created) {
+ String bucketName = this.cosBucketName;
+ String key = filepath;
+ InputStream input = new ByteArrayInputStream(new byte[0]);
+ ObjectMetadata objectMetadata = new ObjectMetadata();
+ objectMetadata.setContentLength(0);
+ AppendObjectRequest putObjectRequest =
+ new AppendObjectRequest(bucketName, key, input, objectMetadata);
+ putObjectRequest.setPosition(0L);
+ AppendObjectResult putObjectResult = cosClient.appendObject(putObjectRequest);
+ created = true;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void destroyFile() {
+ if (exists()) {
+ cosClient.deleteObject(cosBucketName, filepath);
+ }
+ }
+
+ @Override
+ public CompletableFuture<ByteBuffer> read0(long position, int length) {
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ AttributesBuilder attributesBuilder = newAttributesBuilder()
+ .put(LABEL_OPERATION, OPERATION_POSIX_READ);
+
+ CompletableFuture<ByteBuffer> future = new CompletableFuture<>();
+ ByteBuffer byteBuffer = ByteBuffer.allocate(length);
+ try {
+ GetObjectRequest getObjectRequest = new GetObjectRequest(cosBucketName, filepath);
+ COSObject cosObject = cosClient.getObject(getObjectRequest);
+ int readed = cosObject.getObjectContent().read(byteBuffer.array(), (int) position, length);
+ if (readed != length) {
+ throw new IOException("read from cos failed,length is not matched");
+ }
+ byteBuffer.flip();
+
+ attributesBuilder.put(LABEL_SUCCESS, true);
+ long costTime = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+ TieredStoreMetricsManager.providerRpcLatency.record(costTime, attributesBuilder.build());
+
+ Attributes metricsAttributes = newAttributesBuilder()
+ .put(LABEL_OPERATION, OPERATION_POSIX_READ)
+ .build();
+ int downloadedBytes = byteBuffer.remaining();
+ TieredStoreMetricsManager.downloadBytes.record(downloadedBytes, metricsAttributes);
+
+ future.complete(byteBuffer);
+ } catch (IOException e) {
+ long costTime = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+ attributesBuilder.put(LABEL_SUCCESS, false);
+ TieredStoreMetricsManager.providerRpcLatency.record(costTime, attributesBuilder.build());
+ logger.error("CosFileSegment#read0: read file {} failed: position: {}, length: {}",
+ filepath, position, length, e);
+ future.completeExceptionally(e);
+ }
+ return future;
+ }
+
+ @Override
+ public CompletableFuture<Boolean> commit0(TieredFileSegmentInputStream inputStream, long position, int length,
+ boolean append) {
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ AttributesBuilder attributesBuilder = newAttributesBuilder()
+ .put(LABEL_OPERATION, OPERATION_POSIX_WRITE);
+
+ CompletableFuture<Boolean> future = new CompletableFuture<>();
+ try {
+ TieredStoreExecutor.commitExecutor.execute(() -> {
+ try {
+ byte[] byteArray = ByteStreams.toByteArray(inputStream);
+ if (byteArray.length != length) {
+ logger.error("CosFileSegment#commit0: append file {} failed: real data size: {}, is not equal to length: {}",
+ filepath, byteArray.length, length);
+ future.complete(false);
+ return;
+ }
+
+ ByteBuf buffer = Unpooled.copiedBuffer(byteArray);
+ ByteBufInputStream backedInputStream = new ByteBufInputStream(buffer);
+ AppendObjectRequest appendObjectRequest = new AppendObjectRequest(this.cosBucketName, filepath, backedInputStream);
+ appendObjectRequest.setPosition(position);
Review Comment:
I think it should use TieredStoreException here to tell the real position if append position is not equal to the file size.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #6788] support cos tired storage [rocketmq]
Posted by "leizhiyuan (via GitHub)" <gi...@apache.org>.
leizhiyuan closed pull request #6794: [ISSUE #6788] support cos tired storage
URL: https://github.com/apache/rocketmq/pull/6794
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org