Search in sources :

Example 1 with DurableDataLogFactory

use of io.pravega.segmentstore.storage.DurableDataLogFactory 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)");
}
Also used : lombok.val(lombok.val) DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) DurableDataLogFactory(io.pravega.segmentstore.storage.DurableDataLogFactory) Cleanup(lombok.Cleanup) DataLogInitializationException(io.pravega.segmentstore.storage.DataLogInitializationException) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) DebugDurableDataLogWrapper(io.pravega.segmentstore.storage.DebugDurableDataLogWrapper) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with DurableDataLogFactory

use of io.pravega.segmentstore.storage.DurableDataLogFactory in project pravega by pravega.

the class DurableDataLogRepairCommand method validateRepairLog.

private int validateRepairLog(DurableDataLogFactory dataLogFactory, int backupLogReadOperations, List<LogEditOperation> durableLogEdits) throws Exception {
    @Cleanup DurableDataLog editedDebugDataLogReadOnly = dataLogFactory.createDebugLogWrapper(dataLogFactory.getRepairLogId()).asReadOnly();
    int editedDurableLogOperations = readDurableDataLogWithCustomCallback((op, list) -> output("Repair Log Operations: " + op), dataLogFactory.getRepairLogId(), editedDebugDataLogReadOnly);
    output("Edited DurableLog Operations read: " + editedDurableLogOperations);
    long expectedEditedLogOperations = backupLogReadOperations + durableLogEdits.stream().filter(edit -> edit.type.equals(LogEditType.ADD_OPERATION)).count() - durableLogEdits.stream().filter(edit -> edit.type.equals(LogEditType.DELETE_OPERATION)).map(edit -> edit.finalOperationId - edit.initialOperationId).reduce(Long::sum).orElse(0L);
    Preconditions.checkState(expectedEditedLogOperations == editedDurableLogOperations, "Expected (" + expectedEditedLogOperations + ") and actual (" + editedDurableLogOperations + ") operations in Edited Log do not match");
    return editedDurableLogOperations;
}
Also used : DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) OperationSerializer(io.pravega.segmentstore.server.logs.operations.OperationSerializer) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) StorageMetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.StorageMetadataCheckpointOperation) MergeSegmentOperation(io.pravega.segmentstore.server.logs.operations.MergeSegmentOperation) Cleanup(lombok.Cleanup) ImmutableDate(io.pravega.common.util.ImmutableDate) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) ContainerConfig(io.pravega.segmentstore.server.containers.ContainerConfig) Operation(io.pravega.segmentstore.server.logs.operations.Operation) DebugDurableDataLogWrapper(io.pravega.segmentstore.storage.DebugDurableDataLogWrapper) DebugBookKeeperLogWrapper(io.pravega.segmentstore.storage.impl.bookkeeper.DebugBookKeeperLogWrapper) StreamSegmentTruncateOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentTruncateOperation) CommandArgs(io.pravega.cli.admin.CommandArgs) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) Path(java.nio.file.Path) DebugRecoveryProcessor(io.pravega.segmentstore.server.logs.DebugRecoveryProcessor) NonNull(lombok.NonNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) List(java.util.List) ByteArraySegment(io.pravega.common.util.ByteArraySegment) DataFrameRecord(io.pravega.segmentstore.server.logs.DataFrameRecord) DurableDataLogFactory(io.pravega.segmentstore.storage.DurableDataLogFactory) Getter(lombok.Getter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) ArrayList(java.util.ArrayList) ReadIndexConfig(io.pravega.segmentstore.server.reading.ReadIndexConfig) DataLogInitializationException(io.pravega.segmentstore.storage.DataLogInitializationException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) StreamSegmentMapOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation) DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) KeeperException(org.apache.zookeeper.KeeperException) Files(java.nio.file.Files) UpdateAttributesOperation(io.pravega.segmentstore.server.logs.operations.UpdateAttributesOperation) AttributeId(io.pravega.segmentstore.contracts.AttributeId) lombok.val(lombok.val) MetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation) IOException(java.io.IOException) DataFrameBuilder(io.pravega.segmentstore.server.logs.DataFrameBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) Data(lombok.Data) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) DeleteSegmentOperation(io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation) StreamSegmentSealOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation) AtomicLong(java.util.concurrent.atomic.AtomicLong) Cleanup(lombok.Cleanup)

Example 3 with DurableDataLogFactory

use of io.pravega.segmentstore.storage.DurableDataLogFactory in project pravega by pravega.

the class ServiceBuilder method createOperationLogFactory.

protected OperationLogFactory createOperationLogFactory() {
    DurableDataLogFactory dataLogFactory = getSingleton(this.dataLogFactory, this.dataLogFactoryCreator);
    DurableLogConfig durableLogConfig = this.serviceBuilderConfig.getConfig(DurableLogConfig::builder);
    return new DurableLogFactory(durableLogConfig, dataLogFactory, this.coreExecutor);
}
Also used : DurableLogFactory(io.pravega.segmentstore.server.logs.DurableLogFactory) DurableLogConfig(io.pravega.segmentstore.server.logs.DurableLogConfig) InMemoryDurableDataLogFactory(io.pravega.segmentstore.storage.mocks.InMemoryDurableDataLogFactory) DurableDataLogFactory(io.pravega.segmentstore.storage.DurableDataLogFactory)

Aggregations

DurableDataLogFactory (io.pravega.segmentstore.storage.DurableDataLogFactory)3 DataLogInitializationException (io.pravega.segmentstore.storage.DataLogInitializationException)2 DebugDurableDataLogWrapper (io.pravega.segmentstore.storage.DebugDurableDataLogWrapper)2 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)2 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)2 BookKeeperConfig (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig)2 BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)2 IOException (java.io.IOException)2 Cleanup (lombok.Cleanup)2 lombok.val (lombok.val)2 KeeperException (org.apache.zookeeper.KeeperException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 CommandArgs (io.pravega.cli.admin.CommandArgs)1 ByteArraySegment (io.pravega.common.util.ByteArraySegment)1 ImmutableDate (io.pravega.common.util.ImmutableDate)1 AttributeId (io.pravega.segmentstore.contracts.AttributeId)1 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)1 AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)1 AttributeUpdateType (io.pravega.segmentstore.contracts.AttributeUpdateType)1