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-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java b/ambry-cloud/src/main/java/com/github/ambry/cloud/CloudStorageManager.java index a33cf80c16..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 @@ -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,16 @@ 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 public boolean shutdownBlobStore(PartitionId id) { try { @@ -71,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 { @@ -84,6 +99,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"); 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..d3f36dee98 --- /dev/null +++ b/ambry-store/src/main/java/com/github/ambry/store/FileStore.java @@ -0,0 +1,46 @@ +/** + * 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; + + +/** + * 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. + */ +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() { + //TODO: 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..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 @@ -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,12 @@ public Store getStore(PartitionId id) { return getStore(id, false); } + @Override + public FileStore getFileStore(PartitionId id) { + //TODO: Implementation To Be added. + 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 +541,12 @@ public boolean addBlobStore(ReplicaId replica) { return true; } + @Override + public boolean addFileStore(ReplicaId replicaId) { + //TODO: Implementation To Be added. + 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}.