use of org.apache.bookkeeper.meta.MockLedgerManager in project bookkeeper by apache.
the class DataIntegrityCheckTest method testRecoverLimboManyLedgersErrorOnFirst.
@Test
public void testRecoverLimboManyLedgersErrorOnFirst() throws Exception {
MockLedgerManager lm = new MockLedgerManager();
ServerConfiguration conf = serverConf();
BookieId bookieId = BookieImpl.getBookieId(conf);
List<Long> cleared = new ArrayList<>();
MockLedgerStorage storage = spy(new MockLedgerStorage() {
@Override
public void clearLimboState(long ledgerId) {
// not using spy for this because it takes 10ms per ledger to verify
cleared.add(ledgerId);
}
});
final long numLedgers = 100;
long first = 1;
long last = first + numLedgers;
DataIntegrityCheckImpl impl = new DataIntegrityCheckImpl(bookieId, lm, storage, mock(EntryCopier.class), mock(BookKeeperAdmin.class), Schedulers.io()) {
@Override
Single<LedgerMetadata> recoverLedger(long ledgerId, String runId) {
if (ledgerId == first) {
return Single.error(new BKException.BKBookieHandleNotAvailableException());
} else {
return Single.just(newClosedMetadataWithEnsemble(ledgerId, -1, bookieId, bookie1).build());
}
}
};
Map<Long, LedgerMetadata> ledgers = new HashMap<>();
for (long i = first; i < last; i++) {
LedgerMetadata metadata = newMetadataWithEnsemble(i, bookieId, bookie1).build();
ledgers.put(i, metadata);
storage.setMasterKey(i, metadata.getPassword());
storage.setLimboState(i);
}
assertThat(ledgers.size(), equalTo((int) numLedgers));
Set<DataIntegrityCheckImpl.LedgerResult> results = impl.checkAndRecoverLedgers(ledgers, "test").get();
assertThat(results.size(), equalTo((int) numLedgers));
assertThat(results.stream().filter(r -> r.isOK()).count(), equalTo(numLedgers - 1));
assertThat(results.stream().filter(r -> r.isError()).count(), equalTo(1L));
assertThat(results.stream().filter(r -> r.isError()).map(r -> r.getLedgerId()).findFirst().get(), equalTo(first));
Set<Long> clearedSet = Sets.newHashSet(cleared);
assertThat(clearedSet.size(), equalTo(cleared.size()));
for (long l : LongStream.range(first, last).toArray()) {
if (l == first) {
assertThat(l, not(isIn(clearedSet)));
} else {
assertThat(l, isIn(clearedSet));
}
}
verify(storage, times((int) numLedgers - 1)).clearLimboState(anyLong());
}
use of org.apache.bookkeeper.meta.MockLedgerManager in project bookkeeper by apache.
the class DataIntegrityCheckTest method testRecoverLimboManyLedgers.
// TODO: what is this test?
// @Test
// public void testRecoverLimboFlushFailure() throws Exception {
// MockLedgerManager lm = new MockLedgerManager();
// ServerConfiguration conf = serverConf();
// BookieId bookieId = BookieImpl.getBookieId(conf);
// MockLedgerStorage storage = spy(new MockLedgerStorage() {
// @Override
// public void flush() throws IOException {
// throw new IOException("foobar");
// }
// });
// DataIntegrityCheckImpl impl = new DataIntegrityCheckImpl(bookieId, lm, storage,
// mock(EntryCopier.class),
// mock(BookKeeperAdmin.class),
// Schedulers.io()) {
// @Override
// CompletableFuture<Long> recoverLedgerIgnoreMissing(long ledgerId) {
// return CompletableFuture.completedFuture(ledgerId);
// }
// };
// Set<Long> ledgers = Sets.newHashSet(0xf00L, 0xdeadL);
//
// try {
// impl.recoverLedgersInLimbo(ledgers).get();
// Assert.fail("Shouldn't continue on an IOException");
// } catch (ExecutionException ee) {
// assertThat(ee.getCause(), instanceOf(IOException.class));
// }
// assertThat(results.stream().filter(r -> r.isOK()).count(), equalTo(1L));
// assertThat(results.stream().filter(r -> r.isOK()).map(r -> r.getLedgerId()).findFirst().get(),
// equalTo(0xdeadL));
// assertThat(results.stream().filter(r -> r.isError()).count(), equalTo(1L));
// assertThat(results.stream().filter(r -> r.isError()).map(r -> r.getLedgerId()).findFirst().get(),
// equalTo(0xf00L));
//
// verify(storage, times(1)).clearLimboState(0xf00L);
// verify(storage, times(1)).clearLimboState(0xdeadL);
// }
@Test
public void testRecoverLimboManyLedgers() throws Exception {
MockLedgerManager lm = new MockLedgerManager();
ServerConfiguration conf = serverConf();
BookieId bookieId = BookieImpl.getBookieId(conf);
List<Long> cleared = new ArrayList<>();
MockLedgerStorage storage = spy(new MockLedgerStorage() {
@Override
public void clearLimboState(long ledgerId) {
// not using spy for this because it takes 10ms per ledger to verify
cleared.add(ledgerId);
}
});
DataIntegrityCheckImpl impl = new DataIntegrityCheckImpl(bookieId, lm, storage, mock(EntryCopier.class), mock(BookKeeperAdmin.class), Schedulers.io()) {
@Override
Single<LedgerMetadata> recoverLedger(long ledgerId, String runId) {
return Single.just(newClosedMetadataWithEnsemble(ledgerId, -1, bookieId, bookie1).build());
}
};
final long numLedgers = 10000;
long first = 1;
long last = first + numLedgers;
Map<Long, LedgerMetadata> ledgers = new HashMap<>();
for (long i = first; i < last; i++) {
LedgerMetadata metadata = newMetadataWithEnsemble(i, bookieId, bookie1).build();
ledgers.put(i, metadata);
storage.setMasterKey(i, metadata.getPassword());
storage.setLimboState(i);
}
assertThat(ledgers.size(), equalTo((int) numLedgers));
Set<DataIntegrityCheckImpl.LedgerResult> results = impl.checkAndRecoverLedgers(ledgers, "test").get();
assertThat(results.size(), equalTo((int) numLedgers));
assertThat(results.stream().filter(r -> r.isOK()).count(), equalTo(numLedgers));
for (DataIntegrityCheckImpl.LedgerResult r : results) {
assertThat(r.isOK(), equalTo(true));
ledgers.remove(r.getLedgerId());
}
assertThat(ledgers.isEmpty(), equalTo(true));
Set<Long> clearedSet = Sets.newHashSet(cleared);
assertThat(clearedSet.size(), equalTo(cleared.size()));
for (long l : LongStream.range(first, last).toArray()) {
assertThat(l, isIn(clearedSet));
}
verify(storage, times(10000)).clearLimboState(anyLong());
}
use of org.apache.bookkeeper.meta.MockLedgerManager in project bookkeeper by apache.
the class DataIntegrityCheckTest method testFullCheckCacheLoadAndProcessSomeInLimbo.
@Test
public void testFullCheckCacheLoadAndProcessSomeInLimbo() throws Exception {
MockBookieClient bookieClient = spy(new MockBookieClient(executor));
MockLedgerManager lm = new MockLedgerManager();
ServerConfiguration conf = serverConf();
MockLedgerStorage storage = spy(new MockLedgerStorage());
EntryCopier copier = new EntryCopierImpl(bookie1, bookieClient, storage, new MockTicker());
long id1 = 0xdeadL;
long id2 = 0xbedeL;
long id3 = 0xbebeL;
LedgerMetadata metadata1 = newClosedMetadataWithEnsemble(id1, 1000, bookie1, bookie2).build();
LedgerMetadata metadata2 = newClosedMetadataWithEnsemble(id2, 1000, bookie1, bookie3).build();
LedgerMetadata metadata3 = newMetadataWithEnsemble(id3, bookie1, bookie3).build();
LedgerMetadata metadata3closed = newClosedMetadataWithEnsemble(id3, 1000, bookie1, bookie3).build();
DataIntegrityCheckImpl impl = new DataIntegrityCheckImpl(bookie1, lm, storage, copier, mock(BookKeeperAdmin.class), Schedulers.io()) {
@Override
Single<LedgerMetadata> recoverLedger(long ledgerId, String runId) {
return Single.just(metadata3closed);
}
};
bookieClient.getMockBookies().seedLedgerForBookie(bookie2, id1, metadata1);
bookieClient.getMockBookies().seedLedgerForBookie(bookie3, id2, metadata2);
bookieClient.getMockBookies().seedLedgerForBookie(bookie3, id3, metadata3closed);
lm.createLedgerMetadata(id1, metadata1).get();
lm.createLedgerMetadata(id2, metadata2).get();
lm.createLedgerMetadata(id3, metadata3).get();
assertThat(storage.ledgerExists(id1), equalTo(false));
assertThat(storage.ledgerExists(id2), equalTo(false));
assertThat(storage.ledgerExists(id3), equalTo(false));
storage.setMasterKey(id3, PASSWD);
storage.setLimboState(id3);
assertThat(storage.hasLimboState(id3), equalTo(true));
storage.setStorageStateFlag(StorageState.NEEDS_INTEGRITY_CHECK);
assertThat(StorageState.NEEDS_INTEGRITY_CHECK, isIn(storage.getStorageStateFlags()));
impl.runFullCheck().get();
assertThat(StorageState.NEEDS_INTEGRITY_CHECK, not(isIn(storage.getStorageStateFlags())));
assertThat(storage.ledgerExists(id1), equalTo(true));
assertThat(storage.ledgerExists(id2), equalTo(true));
assertThat(storage.ledgerExists(id3), equalTo(true));
assertThat(storage.hasLimboState(id3), equalTo(false));
}
use of org.apache.bookkeeper.meta.MockLedgerManager in project bookkeeper by apache.
the class DataIntegrityCheckTest method testFullCheckAllInLimboAndMissing.
@Test
public void testFullCheckAllInLimboAndMissing() throws Exception {
MockBookieClient bookieClient = spy(new MockBookieClient(executor));
MockLedgerManager lm = new MockLedgerManager();
ServerConfiguration conf = serverConf();
MockLedgerStorage storage = spy(new MockLedgerStorage());
EntryCopier copier = new EntryCopierImpl(bookie1, bookieClient, storage, new MockTicker());
long id1 = 0xdeadL;
long id2 = 0xbedeL;
long id3 = 0xbebeL;
LedgerMetadata metadata1 = newMetadataWithEnsemble(id1, bookie1, bookie2).build();
LedgerMetadata metadata2 = newMetadataWithEnsemble(id2, bookie1, bookie3).build();
LedgerMetadata metadata3 = newMetadataWithEnsemble(id3, bookie1, bookie3).build();
DataIntegrityCheckImpl impl = new DataIntegrityCheckImpl(bookie1, lm, storage, copier, mock(BookKeeperAdmin.class), Schedulers.io()) {
@Override
Single<LedgerMetadata> recoverLedger(long ledgerId, String runId) {
return Single.error(new BKException.BKNoSuchLedgerExistsOnMetadataServerException());
}
};
lm.createLedgerMetadata(id1, metadata1).get();
lm.createLedgerMetadata(id2, metadata2).get();
lm.createLedgerMetadata(id3, metadata3).get();
assertThat(storage.ledgerExists(id1), equalTo(false));
assertThat(storage.ledgerExists(id2), equalTo(false));
assertThat(storage.ledgerExists(id3), equalTo(false));
storage.setMasterKey(id1, PASSWD);
storage.setLimboState(id1);
storage.setMasterKey(id2, PASSWD);
storage.setLimboState(id2);
storage.setMasterKey(id3, PASSWD);
storage.setLimboState(id3);
assertThat(storage.hasLimboState(id1), equalTo(true));
assertThat(storage.hasLimboState(id2), equalTo(true));
assertThat(storage.hasLimboState(id3), equalTo(true));
storage.setStorageStateFlag(StorageState.NEEDS_INTEGRITY_CHECK);
assertThat(StorageState.NEEDS_INTEGRITY_CHECK, isIn(storage.getStorageStateFlags()));
impl.runFullCheck().get();
verify(storage, times(1)).flush();
assertThat(StorageState.NEEDS_INTEGRITY_CHECK, not(isIn(storage.getStorageStateFlags())));
}
use of org.apache.bookkeeper.meta.MockLedgerManager in project bookkeeper by apache.
the class DataIntegrityCheckTest method testPrebootClosedNotMarkedInLimbo.
@Test
public void testPrebootClosedNotMarkedInLimbo() throws Exception {
MockLedgerManager lm = new MockLedgerManager();
ServerConfiguration conf = serverConf();
BookieId bookieId = BookieImpl.getBookieId(conf);
lm.createLedgerMetadata(0xbeefL, newMetadataWithEnsemble(0xbeefL, BookieImpl.getBookieId(conf)).withClosedState().withLength(100).withLastEntryId(1).build()).get();
MockLedgerStorage storage = new MockLedgerStorage();
assertThat(storage.ledgerExists(0xbeefL), is(false));
DataIntegrityCheckImpl impl = new DataIntegrityCheckImpl(bookieId, lm, storage, mock(EntryCopier.class), mock(BookKeeperAdmin.class), Schedulers.io());
impl.runPreBootCheck("test").get();
assertThat(storage.hasLimboState(0xbeefL), is(false));
assertThat(storage.isFenced(0xbeefL), is(false));
}
Aggregations