You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/04/30 06:10:46 UTC

[GitHub] jvrao commented on a change in pull request #1375: BP14 - forceLedger bookie side implementation

jvrao commented on a change in pull request #1375: BP14 - forceLedger bookie side implementation
URL: https://github.com/apache/bookkeeper/pull/1375#discussion_r184915776
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
 ##########
 @@ -1141,6 +1145,40 @@ private void addEntryInternal(LedgerDescriptor handle, ByteBuf entry,
         getJournal(ledgerId).logAddEntry(entry, ackBeforeSync, cb, ctx);
     }
 
+    /**
+     * Force write on the journal assigned to the given ledger.
+     * It works like a regular addEntry with ackBeforeSync=false but without really
+     * writing to disk.
+     */
+    private void forceLedgerInternal(LedgerDescriptor handle,
+                                     WriteCallback cb, Object ctx, byte[] masterKey)
+            throws IOException, BookieException {
+        long ledgerId = handle.getLedgerId();
+
+
+        if (masterKeyCache.get(ledgerId) == null) {
+            // Force the load into masterKey cache
+            byte[] oldValue = masterKeyCache.putIfAbsent(ledgerId, masterKey);
+            if (oldValue == null) {
+                // new handle, we should add the key to journal ensure we can rebuild
+                ByteBuffer bb = ByteBuffer.allocate(8 + 8 + 4 + masterKey.length);
+                bb.putLong(ledgerId);
+                bb.putLong(METAENTRY_ID_LEDGER_KEY);
+                bb.putInt(masterKey.length);
+                bb.put(masterKey);
+                bb.flip();
+
+                getJournal(ledgerId).logAddEntry(bb, false /* ackBeforeSync */, new NopWriteCallback(), null);
 
 Review comment:
   Not sure how I missed, but 'sync' flag would have made standard here instead of ackBeforeSync.
   
   If sync == true -> sync to disk before ack
   if sync == false -> no need to sync before ack; 
   May be we can change it when we get a chance.
   @sijie ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services