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 2017/12/21 19:35:31 UTC

[GitHub] athanatos commented on a change in pull request #890: ISSUE #877: add verifier.BookkeeperVerifier

athanatos commented on a change in pull request #890: ISSUE #877: add verifier.BookkeeperVerifier
URL: https://github.com/apache/bookkeeper/pull/890#discussion_r158360777
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/verifier/BookkeeperVerifier.java
 ##########
 @@ -0,0 +1,692 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bookkeeper.verifier;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Random;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+import org.apache.bookkeeper.client.BKException;
+
+/**
+ * Encapsulates logic for playing and verifying operations against a bookkeeper-like
+ * interface. The test state consists of a set of ledgers in 1 of several states:
+ * 1) opening -- waiting for driver to complete open
+ * 2) open -- valid targets for reads and writes
+ * 3) live -- valid targets for reads
+ * 4) deleting
+ * Each ledger moves in sequence through these states.  See startWrite for the
+ * code driving the lifecycle.
+ */
+public class BookkeeperVerifier {
+    private Queue<Exception> errors = new LinkedList<>();
+
+    private synchronized boolean checkReturn(long ledgerID, Integer rc) {
+        if (rc != 0) {
+            String error = String.format("Got error %d on ledger %d", rc, ledgerID);
+            System.out.println(error);
+            propagateExceptionToMain(BKException.create(rc));
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private synchronized void propagateExceptionToMain(Exception e) {
+        errors.add(e);
+        this.notifyAll();
+    }
+
+    private synchronized void printThrowExceptions() throws Exception {
+        if (!errors.isEmpty()) {
+            for (Exception e: errors) {
+                System.out.format("Error found: %s%n", e.toString());
+                e.printStackTrace();
+            }
+            throw errors.poll();
+        }
+    }
+
+    /**
+     * Provides an interface for translating test operations into operations on a
+     * cluster.
+     */
+    public interface BookkeeperDriver {
+        void createLedger(
+                long ledgerID, int enSize, int writeQSize, int ackQSize,
+                Consumer<Integer> cb
+        );
+
+        void closeLedger(
+                long ledgerID,
+                Consumer<Integer> cb
+        );
+
+        void deleteLedger(
+                long ledgerID,
+                Consumer<Integer> cb
+        );
+
+        void writeEntry(
+                long ledgerID,
+                long entryID,
+                byte[] data,
+                Consumer<Integer> cb
+        );
+
+        /**
+         * Callback for reads.
+         */
+        interface ReadCallback {
+            void complete(
+                    long ledgerID,
+                    ArrayList<byte[]> results
+            );
+        }
+
+        void readEntries(
+                long ledgerID,
+                long firstEntryID,
+                long lastEntryID,
+                BiConsumer<Integer, ArrayList<byte[]>> cb);
+    }
+
+    private final BookkeeperDriver driver;
+
+    private final int ensembleSize;
+    private final int writeQuorum;
+    private final int ackQuorum;
+    private final int duration;
+    private final int drainTimeout;
+    private final int targetConcurrentLedgers;
+    private final int targetConcurrentWrites;
+    private final int targetWriteGroup;
+    private final int targetReadGroup;
+    private final int targetLedgers;
+    private final int targetEntrySize;
+    private final int targetConcurrentReads;
+    private final double coldToHotRatio;
+
+    private final long targetLedgerEntries;
+
+    BookkeeperVerifier(
+            BookkeeperDriver driver,
+            int ensembleSize,
+            int writeQuorum,
+            int ackQuorum,
+            int duration,
+            int drainTimeout,
+            int targetConcurrentLedgers,
+            int targetConcurrentWrites,
+            int targetWriteGroup,
+            int targetReadGroup,
+            int targetLedgers,
+            long targetLedgerSize,
+            int targetEntrySize,
+            int targetConcurrentReads,
+            double coldToHotRatio) {
+        this.driver = driver;
+        this.ensembleSize = ensembleSize;
+        this.writeQuorum = writeQuorum;
+        this.ackQuorum = ackQuorum;
+        this.duration = duration;
+        this.drainTimeout = drainTimeout;
+        this.targetConcurrentLedgers = targetConcurrentLedgers;
+        this.targetConcurrentWrites = targetConcurrentWrites;
+        this.targetWriteGroup = targetWriteGroup;
+        this.targetReadGroup = targetReadGroup;
+        this.targetLedgers = targetLedgers;
+        this.targetEntrySize = targetEntrySize;
+        this.targetConcurrentReads = targetConcurrentReads;
+        this.coldToHotRatio = coldToHotRatio;
+
+        this.targetLedgerEntries = targetLedgerSize / targetEntrySize;
+    }
+
+    private int outstandingWriteCount = 0;
+    private int outstandingReadCount = 0;
+    private long nextLedger = 0;
+    private long getNextLedgerID() {
+        return nextLedger++;
+    }
+
+    /**
+     * State required to regenerate an entry.
+     */
+    class EntryInfo {
 
 Review comment:
   Eh, it references targetEntrySize, not worth passing it in.

----------------------------------------------------------------
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