use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig in project pravega by pravega.
the class DurableDataLogRepairCommand method execute.
@Override
public void execute() throws Exception {
ensureArgCount(1);
int containerId = getIntArg(0);
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, getServiceConfig().getZkURL())).build().getConfig(BookKeeperConfig::builder);
@Cleanup val zkClient = createZKClient();
@Cleanup DurableDataLogFactory dataLogFactory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
dataLogFactory.initialize();
// Open the Original Log in read-only mode.
@Cleanup val originalDataLog = dataLogFactory.createDebugLogWrapper(containerId);
// Check if the Original Log is disabled.
if (originalDataLog.fetchMetadata().isEnabled()) {
output("Original DurableLog is enabled. Repairs can only be done on disabled logs, exiting.");
return;
}
// Make sure that the reserved id for Backup log is free before making any further progress.
boolean createNewBackupLog = true;
if (existsBackupLog(dataLogFactory)) {
output("We found data in the Backup log, probably from a previous repair operation (or someone else running the same command at the same time). " + "You have three options: 1) Delete existing Backup Log and start a new repair process, " + "2) Keep existing Backup Log and re-use it for the current repair (i.e., skip creating a new Backup Log), " + "3) Quit.");
switch(getIntUserInput("Select an option: [1|2|3]")) {
case 1:
// Delete everything related to the old Backup Log.
try (DebugDurableDataLogWrapper backupDataLogDebugLogWrapper = dataLogFactory.createDebugLogWrapper(dataLogFactory.getBackupLogId())) {
backupDataLogDebugLogWrapper.deleteDurableLogMetadata();
}
break;
case 2:
// Keeping existing Backup Log, so not creating a new one.
createNewBackupLog = false;
break;
default:
output("Not doing anything with existing Backup Log this time.");
return;
}
}
// Create a new Backup Log if there wasn't any or if we removed the existing one.
if (createNewBackupLog) {
createBackupLog(dataLogFactory, containerId, originalDataLog);
}
int backupLogReadOperations = validateBackupLog(dataLogFactory, containerId, originalDataLog, createNewBackupLog);
// Get user input of operations to skip, replace, or delete.
List<LogEditOperation> durableLogEdits = getDurableLogEditsFromUser();
// Show the edits to be committed to the original durable log so the user can confirm.
output("The following edits will be used to edit the Original Log:");
durableLogEdits.forEach(e -> output(e.toString()));
output("Original DurableLog has been backed up correctly. Ready to apply admin-provided changes to the Original Log.");
if (!confirmContinue()) {
output("Not editing Original DurableLog this time. A Backup Log has been left during the process and you " + "will find it the next time this command gets executed.");
return;
}
// Ensure that the Repair Log is going to start from a clean state.
output("Deleting existing medatadata from Repair Log (if any)");
try (val editedLogWrapper = dataLogFactory.createDebugLogWrapper(dataLogFactory.getRepairLogId())) {
editedLogWrapper.deleteDurableLogMetadata();
} catch (DurableDataLogException e) {
if (e.getCause() instanceof KeeperException.NoNodeException) {
output("Repair Log does not exist, so nothing to delete.");
} else {
outputError("Error happened while attempting to cleanup Repair Log metadata.");
outputException(e);
}
}
// that will write the edited contents into the Repair Log.
try (DurableDataLog editedDataLog = dataLogFactory.createDurableDataLog(dataLogFactory.getRepairLogId());
EditingLogProcessor logEditState = new EditingLogProcessor(editedDataLog, durableLogEdits, getCommandArgs().getState().getExecutor());
DurableDataLog backupDataLog = dataLogFactory.createDebugLogWrapper(dataLogFactory.getBackupLogId()).asReadOnly()) {
editedDataLog.initialize(TIMEOUT);
readDurableDataLogWithCustomCallback(logEditState, dataLogFactory.getBackupLogId(), backupDataLog);
Preconditions.checkState(!logEditState.isFailed);
// After the edition has completed, we need to disable it before the metadata overwrite.
editedDataLog.disable();
} catch (Exception ex) {
outputError("There have been errors while creating the edited version of the DurableLog.");
outputException(ex);
throw ex;
}
// Validate the contents of the newly created Repair Log.
int editedDurableLogOperations = validateRepairLog(dataLogFactory, backupLogReadOperations, durableLogEdits);
// Overwrite the original DurableLog metadata with the edited DurableLog metadata.
try (val editedLogWrapper = dataLogFactory.createDebugLogWrapper(dataLogFactory.getRepairLogId())) {
output("Original DurableLog Metadata: " + originalDataLog.fetchMetadata());
output("Edited DurableLog Metadata: " + editedLogWrapper.fetchMetadata());
originalDataLog.forceMetadataOverWrite(editedLogWrapper.fetchMetadata());
output("New Original DurableLog Metadata (after replacement): " + originalDataLog.fetchMetadata());
}
// Read the edited contents that are now reachable from the original log id.
try (val editedLogWrapper = dataLogFactory.createDebugLogWrapper(dataLogFactory.getRepairLogId())) {
int finalEditedLogReadOps = readDurableDataLogWithCustomCallback((op, list) -> output("Original Log Operations after repair: " + op), containerId, editedLogWrapper.asReadOnly());
output("Original DurableLog operations read (after editing): " + finalEditedLogReadOps);
Preconditions.checkState(editedDurableLogOperations == finalEditedLogReadOps, "Repair Log operations not matching before (" + editedDurableLogOperations + ") and after the metadata overwrite (" + finalEditedLogReadOps + ")");
} catch (Exception ex) {
outputError("Problem reading Original DurableLog after editing.");
outputException(ex);
}
output("Process completed successfully! (You still need to enable the Durable Log so Pravega can use it)");
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig in project pravega by pravega.
the class ContainerCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
@Override
public Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder);
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin((BookKeeper) factory.getBookKeeperClient());
return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin);
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig in project pravega by pravega.
the class BookkeeperCommandsTest method createLedgerInBookkeeperTestCluster.
private void createLedgerInBookkeeperTestCluster(int logId) throws Exception {
BookKeeperConfig bookKeeperConfig = BookKeeperConfig.builder().with(BookKeeperConfig.BK_ENSEMBLE_SIZE, 1).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, 1).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, 1).with(BookKeeperConfig.ZK_METADATA_PATH, "ledgers").with(BookKeeperConfig.BK_LEDGER_PATH, "/ledgers").with(BookKeeperConfig.ZK_ADDRESS, zkUtil.getZooKeeperConnectString()).build();
@Cleanup CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(zkUtil.getZooKeeperConnectString(), new RetryOneTime(5000));
curatorFramework.start();
@Cleanup("shutdownNow") ScheduledExecutorService executorService = ExecutorServiceHelpers.newScheduledThreadPool(1, "bk-test");
@Cleanup BookKeeperLogFactory bookKeeperLogFactory = new BookKeeperLogFactory(bookKeeperConfig, curatorFramework, executorService);
bookKeeperLogFactory.initialize();
@Cleanup DurableDataLog log = bookKeeperLogFactory.createDurableDataLog(logId);
log.initialize(Duration.ofSeconds(5));
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig in project pravega by pravega.
the class BookKeeperCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin);
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig in project pravega by pravega.
the class ContainerCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
@Override
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder);
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin);
}
Aggregations