From 9d6e69086bfed9465c11d92f47ada1e21c41b47a Mon Sep 17 00:00:00 2001 From: aga9900 Date: Fri, 20 Dec 2024 16:55:23 +0530 Subject: [PATCH 1/5] Add File Store Base Class And Storage Manager Interface Changes --- .../com/github/ambry/server/StoreManager.java | 17 ++++++++ .../com/github/ambry/store/FileStore.java | 41 +++++++++++++++++++ .../github/ambry/store/StorageManager.java | 11 +++++ 3 files changed, 69 insertions(+) create mode 100644 ambry-store/src/main/java/com/github/ambry/store/FileStore.java diff --git a/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java b/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java index c25fb82092..d170a1d29c 100644 --- a/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java +++ b/ambry-api/src/main/java/com/github/ambry/server/StoreManager.java @@ -18,6 +18,7 @@ import com.github.ambry.store.Store; import com.github.ambry.store.StoreException; import java.io.IOException; +import java.nio.file.FileStore; import java.util.Collection; import java.util.List; @@ -34,6 +35,13 @@ public interface StoreManager { */ boolean addBlobStore(ReplicaId replica); + /** + * Add a new FileStore with given {@link ReplicaId}. + * @param replicaId the {@link ReplicaId} of the {@link FileStore} which would be added. + * @return {@code true} if adding FileStore was successful. {@code false} if not. + */ + boolean addFileStore(ReplicaId replicaId); + /** * Remove store from storage manager. * @param id the {@link PartitionId} associated with store @@ -62,6 +70,15 @@ public interface StoreManager { */ Store getStore(PartitionId id); + + /** + * + * @param id the {@link PartitionId} to find the store for. + * @return the {@link FileStore} corresponding to the given {@link PartitionId}, or {@code null} if no store was found for + * that partition, or that store was not started. + */ + FileStore getFileStore(PartitionId id); + /** * Get replicaId on current node by partition name. (There should be at most one replica belonging to specific * partition on single node) diff --git a/ambry-store/src/main/java/com/github/ambry/store/FileStore.java b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java new file mode 100644 index 0000000000..3a95c39dd6 --- /dev/null +++ b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java @@ -0,0 +1,41 @@ +/** + * Copyright 2024 LinkedIn Corp. All rights reserved. + * + * Licensed 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. + */ +package com.github.ambry.store; + +import java.nio.channels.FileChannel; +import java.util.concurrent.ConcurrentHashMap; + +public class FileStore { + private boolean isRunning = false; + private ConcurrentHashMap fileNameToFileChannelMap; + + public FileStore(String dataDir){ + fileNameToFileChannelMap = new ConcurrentHashMap<>(); + isRunning = false; + } + + void start() { + if(!isRunning) { + //Start the FileStore + isRunning = true; + } + } + void stop() { + //Implement shutdown Hook. + isRunning = false; + } + boolean isRunning() { + return isRunning; + } +} diff --git a/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java b/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java index ea3db2f6ea..84676b0c46 100644 --- a/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java +++ b/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java @@ -38,6 +38,7 @@ import com.github.ambry.utils.Utils; import java.io.File; import java.io.IOException; +import java.nio.file.FileStore; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -353,6 +354,11 @@ public Store getStore(PartitionId id) { return getStore(id, false); } + @Override + public FileStore getFileStore(PartitionId id) { + return null; + } + /** * @param id the {@link PartitionId} to find the store for. * @param skipStateCheck whether to skip checking state of the store. if true, it also returns store that is not started yet. @@ -534,6 +540,11 @@ public boolean addBlobStore(ReplicaId replica) { return true; } + @Override + public boolean addFileStore(ReplicaId replicaId) { + return false; + } + /** * If a bootstrap replica fails, try to remove all the files and directories associated with it. * @param replica The failed bootstrap {@link ReplicaId}. From 6fed01bd38888e181a62435e30a984a1928139d2 Mon Sep 17 00:00:00 2001 From: aga9900 Date: Fri, 20 Dec 2024 17:10:26 +0530 Subject: [PATCH 2/5] Updating Changes to Cloud Storage manager --- .../com/github/ambry/cloud/CloudStorageManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java b/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java index a33cf80c16..1c407da9f8 100644 --- a/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java +++ b/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java @@ -20,6 +20,7 @@ import com.github.ambry.server.ServerErrorCode; import com.github.ambry.server.StoreManager; import com.github.ambry.store.Store; +import java.nio.file.FileStore; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -57,6 +58,11 @@ public boolean addBlobStore(ReplicaId replica) { return createAndStartBlobStoreIfAbsent(replica.getPartitionId()) != null; } + @Override + public boolean addFileStore(ReplicaId replicaId) { + return false; + } + @Override public boolean shutdownBlobStore(PartitionId id) { try { @@ -84,6 +90,11 @@ public Store getStore(PartitionId id) { return createAndStartBlobStoreIfAbsent(id); } + @Override + public FileStore getFileStore(PartitionId id) { + return null; + } + @Override public boolean scheduleNextForCompaction(PartitionId id) { throw new UnsupportedOperationException("Method not supported"); From dd92ef89be6861c933344914e48f1c27f955964e Mon Sep 17 00:00:00 2001 From: aga9900 Date: Fri, 20 Dec 2024 18:57:55 +0530 Subject: [PATCH 3/5] Making Review Comments --- .../java/com/github/ambry/cloud/CloudStorageManager.java | 9 +++++++++ .../src/main/java/com/github/ambry/store/FileStore.java | 5 +++++ .../main/java/com/github/ambry/store/StorageManager.java | 2 ++ 3 files changed, 16 insertions(+) diff --git a/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java b/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java index 1c407da9f8..41dd5d5ff5 100644 --- a/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java +++ b/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java @@ -58,9 +58,14 @@ public boolean addBlobStore(ReplicaId replica) { return createAndStartBlobStoreIfAbsent(replica.getPartitionId()) != null; } + /** + * Returning false because this will not be used as part of CloudStorageManager Implementation. + * Implementation will be added if needed. + */ @Override public boolean addFileStore(ReplicaId replicaId) { return false; + } @Override @@ -77,6 +82,10 @@ public boolean shutdownBlobStore(PartitionId id) { return false; } + /** + * Returning null because this will not be used as part of CloudStorageManager Implementation. + * Implementation will be added if needed. + */ @Override public Store getStore(PartitionId id) { try { diff --git a/ambry-store/src/main/java/com/github/ambry/store/FileStore.java b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java index 3a95c39dd6..11aa7eff4c 100644 --- a/ambry-store/src/main/java/com/github/ambry/store/FileStore.java +++ b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java @@ -16,6 +16,11 @@ import java.nio.channels.FileChannel; import java.util.concurrent.ConcurrentHashMap; + +/** + * This class is responsible for interactions with Disk as Part Of File Copy Protocol. + * It is responsible for reading and writing chunks and metadata to disk. + */ public class FileStore { private boolean isRunning = false; private ConcurrentHashMap fileNameToFileChannelMap; diff --git a/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java b/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java index 84676b0c46..9d48244934 100644 --- a/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java +++ b/ambry-store/src/main/java/com/github/ambry/store/StorageManager.java @@ -356,6 +356,7 @@ public Store getStore(PartitionId id) { @Override public FileStore getFileStore(PartitionId id) { + //TODO: Implementation To Be added. return null; } @@ -542,6 +543,7 @@ public boolean addBlobStore(ReplicaId replica) { @Override public boolean addFileStore(ReplicaId replicaId) { + //TODO: Implementation To Be added. return false; } From 34f092b869cf632985fee9083d6653088d677395 Mon Sep 17 00:00:00 2001 From: aga9900 Date: Fri, 20 Dec 2024 18:59:23 +0530 Subject: [PATCH 4/5] Making Review Comments --- ambry-store/src/main/java/com/github/ambry/store/FileStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambry-store/src/main/java/com/github/ambry/store/FileStore.java b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java index 11aa7eff4c..d15b2d2e02 100644 --- a/ambry-store/src/main/java/com/github/ambry/store/FileStore.java +++ b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java @@ -37,7 +37,7 @@ void start() { } } void stop() { - //Implement shutdown Hook. + //TODO: Implement shutdown Hook. isRunning = false; } boolean isRunning() { From 19617f2815a04b906424c2bb048d107d9e8e5c89 Mon Sep 17 00:00:00 2001 From: aga9900 Date: Fri, 20 Dec 2024 21:08:24 +0530 Subject: [PATCH 5/5] Making Review Comments --- ambry-store/src/main/java/com/github/ambry/store/FileStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambry-store/src/main/java/com/github/ambry/store/FileStore.java b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java index d15b2d2e02..d3f36dee98 100644 --- a/ambry-store/src/main/java/com/github/ambry/store/FileStore.java +++ b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java @@ -21,7 +21,7 @@ * This class is responsible for interactions with Disk as Part Of File Copy Protocol. * It is responsible for reading and writing chunks and metadata to disk. */ -public class FileStore { +class FileStore { private boolean isRunning = false; private ConcurrentHashMap fileNameToFileChannelMap;