Skip to content

Commit

Permalink
Bootstrap Performance Improvement[PR3] : Adding File Store And Relate…
Browse files Browse the repository at this point in the history
…d Interfaces (#2976)

* Add File Store Base Class And Storage Manager Interface Changes

* Updating Changes to Cloud Storage manager

* Making Review Comments

* Making Review Comments

* Making Review Comments
  • Loading branch information
aga9900 authored Dec 20, 2024
1 parent 1bc7fa0 commit faec92e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ambry-api/src/main/java/com/github/ambry/server/StoreManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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");
Expand Down
46 changes: 46 additions & 0 deletions ambry-store/src/main/java/com/github/ambry/store/FileStore.java
Original file line number Diff line number Diff line change
@@ -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<String, FileChannel> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}.
Expand Down

0 comments on commit faec92e

Please sign in to comment.