atharvalade commented on code in PR #3103:
URL: https://github.com/apache/iggy/pull/3103#discussion_r3138642849


##########
core/connectors/sinks/s3_sink/src/sink.rs:
##########
@@ -0,0 +1,261 @@
+/*
+ * 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.
+ */
+
+use crate::buffer::FileBuffer;
+use crate::formatter;
+use crate::path::{PathContext, render_s3_key};
+use crate::{BufferKey, S3Sink};
+use async_trait::async_trait;
+use iggy_connector_sdk::{ConsumedMessage, Error, MessagesMetadata, Sink, 
TopicMetadata};
+use tracing::{debug, error, info, warn};
+
+#[async_trait]
+impl Sink for S3Sink {
+    async fn open(&mut self) -> Result<(), Error> {
+        info!("Opening S3 sink connector with ID: {}", self.id);
+
+        let bucket = crate::client::create_bucket(&self.config).await?;
+
+        info!(
+            "S3 sink ID: {} connected to bucket '{}' in region '{}'",
+            self.id, self.config.bucket, self.config.region
+        );
+
+        match crate::client::verify_bucket(&bucket).await {
+            Ok(()) => {
+                info!(
+                    "S3 sink ID: {} bucket '{}' connectivity verified",
+                    self.id, self.config.bucket
+                );
+            }
+            Err(e) => {
+                warn!(
+                    "S3 sink ID: {} bucket verification returned an error 
(non-fatal, \
+                     the bucket may still be accessible): {e}",
+                    self.id
+                );
+            }
+        }
+
+        self.bucket = Some(bucket);
+
+        info!(
+            "S3 sink ID: {} opened. format={}, rotation={}, max_file_size={}, 
template='{}'",
+            self.id,
+            self.config.output_format,
+            self.config.file_rotation,
+            self.config.max_file_size,
+            self.config.path_template,
+        );
+
+        Ok(())
+    }
+
+    async fn consume(
+        &self,
+        topic_metadata: &TopicMetadata,
+        messages_metadata: MessagesMetadata,
+        messages: Vec<ConsumedMessage>,
+    ) -> Result<(), Error> {
+        let bucket = self
+            .bucket
+            .as_ref()
+            .ok_or_else(|| Error::InitError("S3 client not 
initialized".to_string()))?;
+
+        let key = BufferKey {
+            stream: topic_metadata.stream.clone(),
+            topic: topic_metadata.topic.clone(),
+            partition_id: messages_metadata.partition_id,
+        };
+
+        let max_messages = 
self.config.max_messages_per_file.unwrap_or(u64::MAX);

Review Comment:
   I'll add a validation in `open()` that returns an error if file_rotation = 
"messages" but `max_messages_per_file` is not set. do you think this is a good 
approach?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to