Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap FC optimization: Interfaces for state build and state transition flows #2946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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