sijie commented on a change in pull request #1225: Issue #570: getting rid of 
unnecessary synchronization in InterleavedLedgerStorage
URL: https://github.com/apache/bookkeeper/pull/1225#discussion_r172304656
 
 

 ##########
 File path: 
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java
 ##########
 @@ -391,4 +400,137 @@ public void testGetEntryLogsSet() throws Exception {
 
         assertEquals(Sets.newHashSet(0L, 1L, 2L, 3L), 
logger.getEntryLogsSet());
     }
+
+    static class LedgerStorageWriteTask implements Callable<Boolean> {
+        long ledgerId;
+        int entryId;
+        LedgerStorage ledgerStorage;
+
+        LedgerStorageWriteTask(long ledgerId, int entryId, LedgerStorage 
ledgerStorage) {
+            this.ledgerId = ledgerId;
+            this.entryId = entryId;
+            this.ledgerStorage = ledgerStorage;
+        }
+
+        @Override
+        public Boolean call() {
+            try {
+                ledgerStorage.addEntry(generateEntry(ledgerId, entryId));
+            } catch (IOException e) {
+                LOG.error("Got Exception for AddEntry call. LedgerId: " + 
ledgerId + " entryId: " + entryId, e);
+                return false;
+            }
+            return true;
+        }
+    }
+
+    static class LedgerStorageReadTask implements Callable<Boolean> {
+        long ledgerId;
+        int entryId;
+        LedgerStorage ledgerStorage;
+
+        LedgerStorageReadTask(long ledgerId, int entryId, LedgerStorage 
ledgerStorage) {
+            this.ledgerId = ledgerId;
+            this.entryId = entryId;
+            this.ledgerStorage = ledgerStorage;
+        }
+
+        @Override
+        public Boolean call() {
+            try {
+                String expectedValue = generateDataString(ledgerId, entryId);
+                ByteBuf byteBuf = ledgerStorage.getEntry(ledgerId, entryId);
+                long actualLedgerId = byteBuf.readLong();
+                long actualEntryId = byteBuf.readLong();
+                byte[] data = new byte[byteBuf.readableBytes()];
+                byteBuf.readBytes(data);
+                if (ledgerId != actualLedgerId) {
+                    LOG.error("For ledgerId: {} entryId: {} readRequest, 
actual ledgerId: {}", ledgerId, entryId,
+                            actualLedgerId);
+                    return false;
+                }
+                if (entryId != actualEntryId) {
+                    LOG.error("For ledgerId: {} entryId: {} readRequest, 
actual entryId: {}", ledgerId, entryId,
+                            actualEntryId);
+                    return false;
+                }
+                if (!expectedValue.equals(new String(data))) {
+                    LOG.error("For ledgerId: {} entryId: {} readRequest, 
actual Data: {}", ledgerId, entryId,
+                            new String(data));
+                    return false;
+                }
+            } catch (IOException e) {
+                LOG.error("Got Exception for GetEntry call. LedgerId: " + 
ledgerId + " entryId: " + entryId, e);
+                return false;
+            }
+            return true;
+        }
+    }
+
+    /**
+     * test concurrent write operations and then concurrent read
+     * operations using InterleavedLedgerStorage.
+     */
+    @Test
+    public void testConcurrentWriteAndReadCallsOfInterleavedLedgerStorage() 
throws Exception {
 
 Review comment:
   > This change is in interleavedledgerstorage, which sortedledgerstorage 
derives from. It removes synchronization from processEntry, which 
sortedledgerstorage calls directly. It seems there's no other synchronization 
in sortedledgerstorage though, so it should be ok.
   
   this synchronization change only makes sense at InterleavedLedgerStorage, 
because there can be concurrent calls to `processEntry` when using 
InterleavedLedgerStorage. However this is not true in SortedLedgerStorage, 
because ledger storage flushes entries in a single-threaded executor. so I 
don't see why you need a test from SortedLedgerStorage. 
   
   The test case is testing concurrent reads and write on EntryLogTest, 
InterleavedLedgerStorage is the tool to use for testing. It is not testing 
concurrent reads and writes on ledger storage. 
   
   so 1) the testing object is EntryLog not ledger storage 2) concurrent reads 
and writes only make sense in interleaved ledger storage. so it is not right to 
add a duplicated test using sorted ledger storage.
   
   > which is exactly why we shouldn't be constructing a full bookie to test it.
   
   that's different. what I am talking here is you need to know what you are 
exactly _testing_. as I commented above, the testing subject is EntryLog not 
LedgerStorage.
   
   whether constructing a full bookie or constructing a ledger storage is just 
a tool to setup a test case for testing EntryLog. 
   
   the whole test suite is using Bookie already. for consistency, it is okay to 
use Bookie here. I don't see a strong reason to block this change just because 
of that.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to