Search in sources :

Example 1 with EntryLocation

use of org.apache.bookkeeper.bookie.EntryLocation in project bookkeeper by apache.

the class EntryLocationIndex method updateLocations.

public void updateLocations(Iterable<EntryLocation> newLocations) throws IOException {
    if (log.isDebugEnabled()) {
        log.debug("Update locations -- {}", Iterables.size(newLocations));
    }
    Batch batch = newBatch();
    // Update all the ledger index pages with the new locations
    for (EntryLocation e : newLocations) {
        if (log.isDebugEnabled()) {
            log.debug("Update location - ledger: {} -- entry: {}", e.ledger, e.entry);
        }
        addLocation(batch, e.ledger, e.entry, e.location);
    }
    batch.flush();
    batch.close();
}
Also used : Batch(org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorage.Batch) EntryLocation(org.apache.bookkeeper.bookie.EntryLocation)

Example 2 with EntryLocation

use of org.apache.bookkeeper.bookie.EntryLocation in project bookkeeper by apache.

the class DbLedgerStorageTest method testBookieCompaction.

@Test
public void testBookieCompaction() throws Exception {
    storage.setMasterKey(4, "key".getBytes());
    ByteBuf entry3 = Unpooled.buffer(1024);
    // ledger id
    entry3.writeLong(4);
    // entry id
    entry3.writeLong(3);
    entry3.writeBytes("entry-3".getBytes());
    storage.addEntry(entry3);
    // Simulate bookie compaction
    EntryLogger entryLogger = ((DbLedgerStorage) storage).getEntryLogger();
    // Rewrite entry-3
    ByteBuf newEntry3 = Unpooled.buffer(1024);
    // ledger id
    newEntry3.writeLong(4);
    // entry id
    newEntry3.writeLong(3);
    newEntry3.writeBytes("new-entry-3".getBytes());
    long location = entryLogger.addEntry(4, newEntry3, false);
    List<EntryLocation> locations = Lists.newArrayList(new EntryLocation(4, 3, location));
    storage.updateEntriesLocations(locations);
    ByteBuf res = storage.getEntry(4, 3);
    System.out.println("res:       " + ByteBufUtil.hexDump(res));
    System.out.println("newEntry3: " + ByteBufUtil.hexDump(newEntry3));
    assertEquals(newEntry3, res);
}
Also used : EntryLocation(org.apache.bookkeeper.bookie.EntryLocation) EntryLogger(org.apache.bookkeeper.bookie.EntryLogger) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

EntryLocation (org.apache.bookkeeper.bookie.EntryLocation)2 ByteBuf (io.netty.buffer.ByteBuf)1 EntryLogger (org.apache.bookkeeper.bookie.EntryLogger)1 Batch (org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorage.Batch)1 Test (org.junit.Test)1