Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up the rebuildinding of RocksDB index #3458

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.Date;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.bookkeeper.bookie.BookieImpl;
import org.apache.bookkeeper.bookie.DefaultEntryLogger;
import org.apache.bookkeeper.bookie.LedgerDirsManager;
Expand All @@ -53,6 +55,8 @@ public LocationsIndexRebuildOp(ServerConfiguration conf) {
this.conf = conf;
}

private static final int BATCH_COMMIT_SIZE = 10_000;

public void initiate() throws IOException {
LOG.info("Starting locations index rebuilding");
File[] indexDirs = conf.getIndexDirs();
Expand Down Expand Up @@ -90,6 +94,8 @@ public void initiate() throws IOException {
int totalEntryLogs = entryLogs.size();
int completedEntryLogs = 0;
LOG.info("Scanning {} entry logs", totalEntryLogs);
AtomicReference<KeyValueStorage.Batch> batch = new AtomicReference<>(newIndex.newBatch());
AtomicInteger count = new AtomicInteger();

for (long entryLogId : entryLogs) {
entryLogger.scanEntryLog(entryLogId, new EntryLogScanner() {
Expand All @@ -108,7 +114,15 @@ public void process(long ledgerId, long offset, ByteBuf entry) throws IOExceptio
// Update the ledger index page
LongPairWrapper key = LongPairWrapper.get(ledgerId, entryId);
LongWrapper value = LongWrapper.get(location);
newIndex.put(key.array, value.array);
batch.get().put(key.array, value.array);

if (count.incrementAndGet() > BATCH_COMMIT_SIZE) {
batch.get().flush();
batch.get().close();

batch.set(newIndex.newBatch());
count.set(0);
}
}

@Override
Expand All @@ -122,6 +136,9 @@ public boolean accept(long ledgerId) {
completedEntryLogs, totalEntryLogs);
}

batch.get().flush();
batch.get().close();

newIndex.sync();
newIndex.close();
}
Expand Down