Skip to content

Commit

Permalink
Bootstrap FC optimization: Interfaces for state build and state trans…
Browse files Browse the repository at this point in the history
…ition flows (#2946)

* Changes for bootstrap improvement with statebuild

* Added initial changes for state build

* Changes for moving state build to FCM

* Changes for state build including FCM invocation

* reformatting changes

---------

Co-authored-by: Jai Balani <jbalani@jbalani-mn1.linkedin.biz>
  • Loading branch information
piyujai and Jai Balani authored Nov 29, 2024
1 parent d53dd22 commit 944356e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public interface StoreManager {
*/
boolean addBlobStore(ReplicaId replica);

/**
* Build state after filecopy is completed
* @param partitionName the partition id for which state is to be built..
*/
void buildStateForFileCopy(String partitionName);

/**
* Remove store from storage manager.
* @param id the {@link PartitionId} associated with store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public CloudStorageManager(VerifiableProperties properties, VcrMetrics vcrMetric
public boolean addBlobStore(ReplicaId replica) {
return createAndStartBlobStoreIfAbsent(replica.getPartitionId()) != null;
}
@Override
public void buildStateForFileCopy(String partitionName){
// no-op
}

@Override
public boolean shutdownBlobStore(PartitionId id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,8 @@ private DataNodeConfig getDataNodeConfig() {

@Override
public void onPartitionBecomeBootstrapFromOffline(String partitionName) {
// TODO: Prefilecopy steps: Handle scenarios for Filceopy -> filecopy, Replication->Filecopy,
// Filceopy -> replication and replication->replication rollout/rollback.
try {
// 1. take actions in storage manager (add new replica if necessary)
PartitionStateChangeListener storageManagerListener =
Expand All @@ -871,6 +873,17 @@ public void onPartitionBecomeBootstrapFromOffline(String partitionName) {
storageManagerListener.onPartitionBecomeBootstrapFromOffline(partitionName);
}

/**
* Should be invoked after storage manager listener to ensure that the replica is added to the store.
* Conditional execution based on requirement for File Copy.
*/
PartitionStateChangeListener fileCopyManagerListener =
partitionStateChangeListeners.get(StateModelListenerType.FileCopyManagerListener);
if(fileCopyManagerListener != null){
fileCopyManagerListener.onPartitionBecomeBootstrapFromOffline(partitionName);
replicaSyncUpManager.waitForFileCopyCompleted(partitionName);
}

// 2. take actions in replication manager (add new replica if necessary)
PartitionStateChangeListener replicationManagerListener =
partitionStateChangeListeners.get(StateModelListenerType.ReplicationManagerListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class PartitionStateChangeListenerImpl implements PartitionStateChangeListener {

@Override
public void onPartitionBecomeBootstrapFromOffline(String partitionName) {

// StateBuilding at the end of FCM's Offline->Bootstrap transition
storeManager.buildStateForFileCopy(partitionName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ public boolean addBlobStore(ReplicaId replica) {
logger.info("New store is successfully added into StorageManager");
return true;
}
@Override
public void buildStateForFileCopy(String partitionName){
// no-op
}

/**
* If a bootstrap replica fails, try to remove all the files and directories associated with it.
Expand Down Expand Up @@ -716,6 +720,8 @@ private class PartitionStateChangeListenerImpl implements PartitionStateChangeLi

@Override
public void onPartitionBecomeBootstrapFromOffline(String partitionName) {
// For Filecopy, 4 steps to be taken up here: Prefilecopy, Filecopy, State Build, Exception handling and cleanup

// check if partition exists on current node
ReplicaId replica = partitionNameToReplicaId.get(partitionName);
Store store;
Expand All @@ -737,6 +743,8 @@ public void onPartitionBecomeBootstrapFromOffline(String partitionName) {
// Attempt to add store into storage manager. If store already exists on disk (but not in clustermap), make
// sure old store of this replica is deleted (this store may be created in previous replica addition but failed
// at some point). Then a brand new store associated with this replica should be created and started.
// TODO: For Filecopy, we do not init the BlobStore since new log/index isn't required, the files will be directly
// copied from remote node.
if (!addBlobStore(replicaToAdd)) {
// We have decreased the available disk space in HelixClusterManager#getDiskForBootstrapReplica. Increase it
// back since addition of store failed.
Expand Down

0 comments on commit 944356e

Please sign in to comment.