lordcheng10 commented on code in PR #3260:
URL: https://github.com/apache/bookkeeper/pull/3260#discussion_r911615444


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCacheContainer.java:
##########
@@ -0,0 +1,367 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.bookie.storage.ldb;
+
+import com.google.common.annotations.VisibleForTesting;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import java.io.IOException;
+import java.util.NoSuchElementException;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.StampedLock;
+import org.apache.bookkeeper.bookie.BookieCriticalThread;
+import org.apache.bookkeeper.bookie.CheckpointSource;
+import org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint;
+import org.apache.bookkeeper.bookie.storage.EntryLogger;
+import org.apache.bookkeeper.stats.Counter;
+import org.apache.bookkeeper.stats.OpStatsLogger;
+import org.apache.bookkeeper.util.MathUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Container for storing write cache blocks.
+ */
+public class WriteCacheContainer {
+    protected static final Logger LOG = 
LoggerFactory.getLogger(WriteCacheContainer.class);
+
+    private final LinkedBlockingQueue<WriteCache> freeBlockCaches = new 
LinkedBlockingQueue<>();
+
+    protected LinkedBlockingDeque<WriteCache> fulledBlockCaches = new 
LinkedBlockingDeque<>();
+
+    protected final ReentrantLock flushMutex = new ReentrantLock();
+
+    private CheckpointSource.Checkpoint lastCheckpoint = 
CheckpointSource.Checkpoint.MIN;
+
+    protected CheckpointSource checkpointSource = CheckpointSource.DEFAULT;
+
+    private EntryLogger entryLogger;
+
+    private LedgerMetadataIndex ledgerIndex;
+    private EntryLocationIndex entryLocationIndex;
+
+    private DbLedgerStorageStats dbLedgerStorageStats;
+
+    protected final Counter flushExecutorTime;
+
+    private final ScheduledExecutorService cleanupExecutor;
+
+    private FlushWriteCacheThread flushWriteCacheThread;
+
+    private final AtomicLong cacheSize = new AtomicLong(0);
+
+    private final LongAdder cacheCount = new LongAdder();
+
+    private final StampedLock rotationLock = new StampedLock();
+
+    private final AtomicBoolean disableFlushWriteCacheThread = new 
AtomicBoolean(false);
+
+
+    public WriteCacheContainer(EntryLogger entryLogger,
+                               LedgerMetadataIndex ledgerIndex,
+                               EntryLocationIndex entryLocationIndex,
+                               DbLedgerStorageStats dbLedgerStorageStats,
+                               ScheduledExecutorService cleanupExecutor,
+                               Counter flushExecutorTime,
+                               long writeCacheSize,
+                               long perDirectoryBlockWriteCacheSize,
+                               ByteBufAllocator allocator) {
+        this.entryLogger = entryLogger;
+        this.ledgerIndex = ledgerIndex;
+        this.entryLocationIndex = entryLocationIndex;
+        this.dbLedgerStorageStats = dbLedgerStorageStats;
+        this.cleanupExecutor = cleanupExecutor;
+        this.flushExecutorTime = flushExecutorTime;
+        for (int i = 0; i < writeCacheSize / perDirectoryBlockWriteCacheSize; 
i++) {
+            WriteCache writeCache = new WriteCache(allocator,
+                    perDirectoryBlockWriteCacheSize);
+            writeCache.isSingleDirectoryWriteCache(true);
+            freeBlockCaches.add(writeCache);
+        }
+        flushWriteCacheThread = new 
FlushWriteCacheThread("flush-write-cache-thread");
+        flushWriteCacheThread.start();
+    }
+
+    @VisibleForTesting
+    public void disableFlushWriteCacheThread() {

Review Comment:
   OK



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to