Search in sources :

Example 1 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory 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 BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory 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);
}
Also used : lombok.val(lombok.val) ContainerConfig(io.pravega.segmentstore.server.containers.ContainerConfig) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) BookKeeperConfig(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin)

Example 3 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.

the class DataRecoveryTest method testBasicDurableLogRepairCommand.

@Test
public void testBasicDurableLogRepairCommand() throws Exception {
    int instanceId = 0;
    int bookieCount = 3;
    int containerCount = 1;
    @Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
    pravegaRunner.startBookKeeperRunner(instanceId);
    val bkConfig = BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort()).with(BookKeeperConfig.BK_LEDGER_PATH, pravegaRunner.getBookKeeperRunner().getLedgerPath()).with(BookKeeperConfig.ZK_METADATA_PATH, pravegaRunner.getBookKeeperRunner().getLogMetaNamespace()).with(BookKeeperConfig.BK_ENSEMBLE_SIZE, 1).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, 1).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, 1).build();
    this.factory = new BookKeeperLogFactory(bkConfig, pravegaRunner.getBookKeeperRunner().getZkClient().get(), this.executorService());
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory);
    String streamName = "testDataRecoveryCommand";
    TestUtils.createScopeStream(pravegaRunner.getControllerRunner().getController(), SCOPE, streamName, config);
    try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
        // Write events to the streams.
        TestUtils.writeEvents(streamName, clientRunner.getClientFactory());
    }
    // Shut down services, we assume that the cluster is in very bad shape in this test.
    pravegaRunner.shutDownControllerRunner();
    pravegaRunner.shutDownSegmentStoreRunner();
    // set Pravega properties for the test
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
    pravegaProperties.setProperty("pravegaservice.storage.layout", "ROLLING_STORAGE");
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort());
    pravegaProperties.setProperty("bookkeeper.ledger.path", pravegaRunner.getBookKeeperRunner().getLedgerPath());
    pravegaProperties.setProperty("bookkeeper.zk.metadata.path", pravegaRunner.getBookKeeperRunner().getLogMetaNamespace());
    pravegaProperties.setProperty("pravegaservice.clusterName", "pravega0");
    pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
    STATE.get().getConfigBuilder().include(pravegaProperties);
    // Execute basic command workflow for repairing DurableLog.
    CommandArgs args = new CommandArgs(List.of("0"), STATE.get());
    DurableDataLogRepairCommand command = Mockito.spy(new DurableDataLogRepairCommand(args));
    // First execution, just exit when asking to disable the original log.
    command.execute();
    // Disable Original Log first.
    System.setIn(new ByteArrayInputStream("yes".getBytes()));
    TestUtils.executeCommand("bk disable 0", STATE.get());
    // The test will exercise editing the Container 0 log with an operation of each type.
    Mockito.doReturn(true).doReturn(false).doReturn(false).doReturn(true).when(command).confirmContinue();
    Mockito.doReturn(900L).doReturn(901L).doReturn(902L).doReturn(1L).when(command).getLongUserInput(Mockito.any());
    Mockito.doReturn("delete").doReturn("add").doReturn("DeleteSegmentOperation").when(command).getStringUserInput(Mockito.any());
    command.execute();
    // Disable Original Log first.
    System.setIn(new ByteArrayInputStream("yes".getBytes()));
    TestUtils.executeCommand("bk disable 0", STATE.get());
    // Now, re-execute the command to exercise the case in which there is an existing backup log.
    Mockito.doReturn(1).when(command).getIntUserInput(Mockito.any());
    Mockito.doReturn(true).doReturn(false).doReturn(false).doReturn(true).when(command).confirmContinue();
    Mockito.doReturn(900L).doReturn(901L).doReturn(902L).doReturn(1L).when(command).getLongUserInput(Mockito.any());
    Mockito.doReturn("delete").doReturn("add").doReturn("DeleteSegmentOperation").when(command).getStringUserInput(Mockito.any());
    command.execute();
    // Disable Original Log first.
    System.setIn(new ByteArrayInputStream("yes".getBytes()));
    TestUtils.executeCommand("bk disable 0", STATE.get());
    // Re-execute, now adding a replace operation and not destroying previous backup log.
    Mockito.doReturn(2).when(command).getIntUserInput(Mockito.any());
    Mockito.doReturn(true).doReturn(false).doReturn(true).when(command).confirmContinue();
    Mockito.doReturn(900L).doReturn(1L).when(command).getLongUserInput(Mockito.any());
    Mockito.doReturn("replace").doReturn("StreamSegmentSealOperation").doReturn("replace").doReturn("StreamSegmentSealOperation").when(command).getStringUserInput(Mockito.any());
    command.execute();
    // Disable Original Log first.
    System.setIn(new ByteArrayInputStream("yes".getBytes()));
    TestUtils.executeCommand("bk disable 0", STATE.get());
    // Do nothing if we find an existing backup log.
    Mockito.doReturn(3).when(command).getIntUserInput(Mockito.any());
    command.execute();
    DurableDataLogRepairCommand.descriptor();
}
Also used : lombok.val(lombok.val) CommandArgs(io.pravega.cli.admin.CommandArgs) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) Properties(java.util.Properties) Cleanup(lombok.Cleanup) TestUtils(io.pravega.cli.admin.utils.TestUtils) ByteArrayInputStream(java.io.ByteArrayInputStream) AdminCommandState(io.pravega.cli.admin.AdminCommandState) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) Test(org.junit.Test)

Example 4 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.

the class DataRecoveryTest method testForceMetadataOverWrite.

@Test
public void testForceMetadataOverWrite() throws Exception {
    int instanceId = 0;
    int bookieCount = 3;
    int containerCount = 1;
    @Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
    pravegaRunner.startBookKeeperRunner(instanceId);
    val bkConfig = BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort()).with(BookKeeperConfig.BK_LEDGER_PATH, pravegaRunner.getBookKeeperRunner().getLedgerPath()).with(BookKeeperConfig.ZK_METADATA_PATH, pravegaRunner.getBookKeeperRunner().getLogMetaNamespace()).with(BookKeeperConfig.BK_ENSEMBLE_SIZE, 1).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, 1).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, 1).build();
    this.factory = new BookKeeperLogFactory(bkConfig, pravegaRunner.getBookKeeperRunner().getZkClient().get(), this.executorService());
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory);
    String streamName = "testDataRecoveryCommand";
    TestUtils.createScopeStream(pravegaRunner.getControllerRunner().getController(), SCOPE, streamName, config);
    try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
        // Write events to the streams.
        TestUtils.writeEvents(streamName, clientRunner.getClientFactory());
    }
    // Shut down services, we assume that the cluster is in very bad shape in this test.
    pravegaRunner.shutDownControllerRunner();
    pravegaRunner.shutDownSegmentStoreRunner();
    // set Pravega properties for the test
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
    pravegaProperties.setProperty("pravegaservice.storage.layout", "ROLLING_STORAGE");
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort());
    pravegaProperties.setProperty("bookkeeper.ledger.path", pravegaRunner.getBookKeeperRunner().getLedgerPath());
    pravegaProperties.setProperty("bookkeeper.zk.metadata.path", pravegaRunner.getBookKeeperRunner().getLogMetaNamespace());
    pravegaProperties.setProperty("pravegaservice.clusterName", "pravega0");
    pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
    STATE.get().getConfigBuilder().include(pravegaProperties);
    // Execute basic command workflow for repairing DurableLog.
    CommandArgs args = new CommandArgs(List.of("0"), STATE.get());
    DurableDataLogRepairCommand command = Mockito.spy(new DurableDataLogRepairCommand(args));
    // Test the DurableLogWrapper options to get, overwrite and destroy logs.
    @Cleanup val newFactory = new BookKeeperLogFactory(bkConfig, pravegaRunner.getBookKeeperRunner().getZkClient().get(), this.executorService());
    newFactory.initialize();
    @Cleanup DebugBookKeeperLogWrapper debugLogWrapper0 = newFactory.createDebugLogWrapper(0);
    int container0LogEntries = command.readDurableDataLogWithCustomCallback((a, b) -> {
    }, 0, debugLogWrapper0.asReadOnly());
    Assert.assertTrue(container0LogEntries > 0);
    ReadOnlyBookkeeperLogMetadata metadata0 = debugLogWrapper0.fetchMetadata();
    Assert.assertNotNull(metadata0);
    // Create a Repair log with some random content.
    @Cleanup DurableDataLog repairLog = newFactory.createDurableDataLog(this.factory.getRepairLogId());
    repairLog.initialize(TIMEOUT);
    repairLog.append(new CompositeByteArraySegment(new byte[0]), TIMEOUT).join();
    @Cleanup DebugBookKeeperLogWrapper debugLogWrapperRepair = newFactory.createDebugLogWrapper(0);
    // Overwrite metadata of repair container with metadata of container 0.
    debugLogWrapperRepair.forceMetadataOverWrite(metadata0);
    // Now the amount of log entries read should be equal to the ones of container 0.
    int newContainerRepairLogEntries = command.readDurableDataLogWithCustomCallback((a, b) -> {
    }, this.factory.getRepairLogId(), debugLogWrapperRepair.asReadOnly());
    ReadOnlyBookkeeperLogMetadata newMetadata1 = debugLogWrapperRepair.fetchMetadata();
    Assert.assertEquals(container0LogEntries, newContainerRepairLogEntries);
    Assert.assertEquals(metadata0.getLedgers(), newMetadata1.getLedgers());
    // Destroy contents of Container 0.
    debugLogWrapper0.deleteDurableLogMetadata();
    Assert.assertNull(debugLogWrapper0.fetchMetadata());
}
Also used : lombok.val(lombok.val) CommandArgs(io.pravega.cli.admin.CommandArgs) DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) ReadOnlyBookkeeperLogMetadata(io.pravega.segmentstore.storage.impl.bookkeeper.ReadOnlyBookkeeperLogMetadata) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) Properties(java.util.Properties) Cleanup(lombok.Cleanup) CompositeByteArraySegment(io.pravega.common.util.CompositeByteArraySegment) TestUtils(io.pravega.cli.admin.utils.TestUtils) DebugBookKeeperLogWrapper(io.pravega.segmentstore.storage.impl.bookkeeper.DebugBookKeeperLogWrapper) AdminCommandState(io.pravega.cli.admin.AdminCommandState) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) Test(org.junit.Test)

Example 5 with BookKeeperLogFactory

use of io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory in project pravega by pravega.

the class DataRecoveryTest method testDurableLogRepairCommandExpectedLogOutput.

@Test
public void testDurableLogRepairCommandExpectedLogOutput() throws Exception {
    int instanceId = 0;
    int bookieCount = 3;
    int containerCount = 1;
    @Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
    pravegaRunner.startBookKeeperRunner(instanceId);
    val bkConfig = BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort()).with(BookKeeperConfig.BK_LEDGER_PATH, pravegaRunner.getBookKeeperRunner().getLedgerPath()).with(BookKeeperConfig.ZK_METADATA_PATH, pravegaRunner.getBookKeeperRunner().getLogMetaNamespace()).with(BookKeeperConfig.BK_ENSEMBLE_SIZE, 1).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, 1).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, 1).build();
    this.factory = new BookKeeperLogFactory(bkConfig, pravegaRunner.getBookKeeperRunner().getZkClient().get(), this.executorService());
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory);
    String streamName = "testDataRecoveryCommand";
    TestUtils.createScopeStream(pravegaRunner.getControllerRunner().getController(), SCOPE, streamName, config);
    try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
        // Write events to the streams.
        TestUtils.writeEvents(streamName, clientRunner.getClientFactory());
    }
    // Shut down services, we assume that the cluster is in very bad shape in this test.
    pravegaRunner.shutDownControllerRunner();
    pravegaRunner.shutDownSegmentStoreRunner();
    // set Pravega properties for the test
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
    pravegaProperties.setProperty("pravegaservice.storage.layout", "ROLLING_STORAGE");
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", "localhost:" + pravegaRunner.getBookKeeperRunner().getBkPort());
    pravegaProperties.setProperty("bookkeeper.ledger.path", pravegaRunner.getBookKeeperRunner().getLedgerPath());
    pravegaProperties.setProperty("bookkeeper.zk.metadata.path", pravegaRunner.getBookKeeperRunner().getLogMetaNamespace());
    pravegaProperties.setProperty("pravegaservice.clusterName", "pravega0");
    pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
    STATE.get().getConfigBuilder().include(pravegaProperties);
    // Execute basic command workflow for repairing DurableLog.
    CommandArgs args = new CommandArgs(List.of("0"), STATE.get());
    DurableDataLogRepairCommand command = Mockito.spy(new DurableDataLogRepairCommand(args));
    this.factory = new BookKeeperLogFactory(bkConfig, pravegaRunner.getBookKeeperRunner().getZkClient().get(), this.executorService());
    this.factory.initialize();
    // First, keep all the Operations of Container 0 in this list, so we can compare with the modified one.
    List<Operation> originalOperations = new ArrayList<>();
    @Cleanup DebugDurableDataLogWrapper wrapper = this.factory.createDebugLogWrapper(0);
    command.readDurableDataLogWithCustomCallback((op, entry) -> originalOperations.add(op), 0, wrapper.asReadOnly());
    // Disable Original Log first.
    System.setIn(new ByteArrayInputStream("yes".getBytes()));
    TestUtils.executeCommand("bk disable 0", STATE.get());
    // Second, add 2 operations, delete 1 operation, replace 1 operation.
    Mockito.doReturn(true).doReturn(true).doReturn(false).doReturn(true).doReturn(true).doReturn(false).doReturn(false).doReturn(true).when(command).confirmContinue();
    Mockito.doReturn(900L).doReturn(901L).doReturn(901L).doReturn(1L).doReturn(123L).doReturn(2L).doReturn(123L).doReturn(903L).doReturn(3L).doReturn(123L).doReturn(905L).doReturn(4L).doReturn(123L).when(command).getLongUserInput(Mockito.any());
    Mockito.doReturn("delete").doReturn("add").doReturn("DeleteSegmentOperation").doReturn("DeleteSegmentOperation").doReturn("replace").doReturn("DeleteSegmentOperation").doReturn("add").doReturn("StreamSegmentSealOperation").when(command).getStringUserInput(Mockito.any());
    command.execute();
    List<Operation> originalOperationsEdited = new ArrayList<>();
    @Cleanup DebugDurableDataLogWrapper wrapperEdited = this.factory.createDebugLogWrapper(0);
    command.readDurableDataLogWithCustomCallback((op, entry) -> originalOperationsEdited.add(op), 0, wrapperEdited.asReadOnly());
    // OP-905 (now 907)
    for (int i = 899; i < 910; i++) {
        // Sequence numbers will defer between the original and edited logs. To do equality comparisons between
        // Operations in both logs, reset the sequence numbers (other fields should be the same).
        originalOperations.get(i).resetSequenceNumber(0);
        originalOperationsEdited.get(i).resetSequenceNumber(0);
    }
    Assert.assertNotEquals(originalOperations.get(899), originalOperationsEdited.get(899));
    Assert.assertTrue(originalOperationsEdited.get(899) instanceof DeleteSegmentOperation);
    Assert.assertTrue(originalOperationsEdited.get(900) instanceof DeleteSegmentOperation);
    Assert.assertEquals(originalOperations.get(900).toString(), originalOperationsEdited.get(901).toString());
    Assert.assertEquals(originalOperations.get(901).toString(), originalOperationsEdited.get(902).toString());
    Assert.assertTrue(originalOperationsEdited.get(903) instanceof DeleteSegmentOperation);
    Assert.assertEquals(originalOperations.get(903).toString(), originalOperationsEdited.get(904).toString());
    Assert.assertTrue(originalOperationsEdited.get(905) instanceof StreamSegmentSealOperation);
    Assert.assertEquals(originalOperations.get(904).toString(), originalOperationsEdited.get(906).toString());
    this.factory.close();
}
Also used : lombok.val(lombok.val) CommandArgs(io.pravega.cli.admin.CommandArgs) StreamSegmentSealOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation) ArrayList(java.util.ArrayList) StorageMetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.StorageMetadataCheckpointOperation) MergeSegmentOperation(io.pravega.segmentstore.server.logs.operations.MergeSegmentOperation) Operation(io.pravega.segmentstore.server.logs.operations.Operation) StreamSegmentTruncateOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentTruncateOperation) StreamSegmentMapOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation) UpdateAttributesOperation(io.pravega.segmentstore.server.logs.operations.UpdateAttributesOperation) MetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) DeleteSegmentOperation(io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation) StreamSegmentSealOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) Properties(java.util.Properties) Cleanup(lombok.Cleanup) TestUtils(io.pravega.cli.admin.utils.TestUtils) DeleteSegmentOperation(io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation) DebugDurableDataLogWrapper(io.pravega.segmentstore.storage.DebugDurableDataLogWrapper) ByteArrayInputStream(java.io.ByteArrayInputStream) AdminCommandState(io.pravega.cli.admin.AdminCommandState) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) Test(org.junit.Test)

Aggregations

BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)16 lombok.val (lombok.val)11 BookKeeperConfig (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperConfig)9 Cleanup (lombok.Cleanup)8 AdminCommandState (io.pravega.cli.admin.AdminCommandState)5 TestUtils (io.pravega.cli.admin.utils.TestUtils)5 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)5 Properties (java.util.Properties)5 Test (org.junit.Test)5 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)4 BookKeeperAdmin (org.apache.bookkeeper.client.BookKeeperAdmin)4 CommandArgs (io.pravega.cli.admin.CommandArgs)3 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)3 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)3 ContainerConfig (io.pravega.segmentstore.server.containers.ContainerConfig)2 DebugDurableDataLogWrapper (io.pravega.segmentstore.storage.DebugDurableDataLogWrapper)2 Storage (io.pravega.segmentstore.storage.Storage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2