satishd commented on a change in pull request #10218:
URL: https://github.com/apache/kafka/pull/10218#discussion_r606253804



##########
File path: 
remote-storage/src/test/java/org/apache/kafka/server/log/remote/storage/InmemoryRemoteStorageManager.java
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.kafka.server.log.remote.storage;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * This class is an implementation of {@link RemoteStorageManager} backed by 
inmemory store.
+ */
+public class InmemoryRemoteStorageManager implements RemoteStorageManager {
+    private static final Logger log = 
LoggerFactory.getLogger(InmemoryRemoteStorageManager.class);
+
+    // map of key to log data, which can be segment or any of its indexes.
+    private Map<String, byte[]> keyToLogData = new ConcurrentHashMap<>();
+
+    public InmemoryRemoteStorageManager() {
+    }
+
+    static String generateKeyForSegment(RemoteLogSegmentMetadata 
remoteLogSegmentMetadata) {
+        return remoteLogSegmentMetadata.remoteLogSegmentId().id().toString() + 
".segment";
+    }
+
+    static String generateKeyForIndex(RemoteLogSegmentMetadata 
remoteLogSegmentMetadata,
+                                      IndexType indexType) {
+        return remoteLogSegmentMetadata.remoteLogSegmentId().id().toString() + 
"." + indexType.toString();
+    }
+
+    // visible for testing.
+    boolean containsKey(String key) {
+        return keyToLogData.containsKey(key);
+    }
+
+    @Override
+    public void copyLogSegmentData(RemoteLogSegmentMetadata 
remoteLogSegmentMetadata,
+                                   LogSegmentData logSegmentData)
+            throws RemoteStorageException {
+        log.debug("copying log segment and indexes for : {}", 
remoteLogSegmentMetadata);
+        Objects.requireNonNull(remoteLogSegmentMetadata, 
"remoteLogSegmentMetadata can not be null");
+        Objects.requireNonNull(logSegmentData, "logSegmentData can not be 
null");
+        try {
+            keyToLogData.put(generateKeyForSegment(remoteLogSegmentMetadata),

Review comment:
       We can add that. 




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to