use of io.pravega.segmentstore.storage.impl.bookkeeper.DebugBookKeeperLogWrapper in project pravega by pravega.
the class BookKeeperCleanupCommand method checkForExtraLogs.
private void checkForExtraLogs(Context context) throws Exception {
val maxLogId = context.serviceConfig.getContainerCount() * 10;
for (int logId = context.serviceConfig.getContainerCount(); logId < maxLogId; logId++) {
@Cleanup DebugBookKeeperLogWrapper log = context.logFactory.createDebugLogWrapper(logId);
val m = log.fetchMetadata();
if (m != null) {
throw new Exception(String.format("Discovered BookKeeperLog %d which is beyond the maximum log id (%d) as specified in the configuration.", logId, context.serviceConfig.getContainerCount() - 1));
}
}
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.DebugBookKeeperLogWrapper 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());
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.DebugBookKeeperLogWrapper in project pravega by pravega.
the class BookKeeperCleanupCommand method collectAllReferencedLedgerIds.
private void collectAllReferencedLedgerIds(Collection<Long> referencedLedgerIds, Context context) throws Exception {
referencedLedgerIds.clear();
for (int logId = 0; logId < context.serviceConfig.getContainerCount(); logId++) {
@Cleanup DebugBookKeeperLogWrapper log = context.logFactory.createDebugLogWrapper(logId);
val m = log.fetchMetadata();
if (m == null) {
continue;
}
for (val lm : m.getLedgers()) {
referencedLedgerIds.add(lm.getLedgerId());
}
}
}
use of io.pravega.segmentstore.storage.impl.bookkeeper.DebugBookKeeperLogWrapper in project pravega by pravega.
the class BookKeeperListCommand method execute.
@Override
public void execute() throws Exception {
ensureArgCount(0);
// Loop through all known log ids and fetch their metadata.
@Cleanup val context = createContext();
for (int logId = 0; logId < context.serviceConfig.getContainerCount(); logId++) {
@Cleanup DebugBookKeeperLogWrapper log = context.logFactory.createDebugLogWrapper(logId);
val m = log.fetchMetadata();
outputLogSummary(logId, m);
}
}
Aggregations