ibessonov commented on code in PR #5670:
URL: https://github.com/apache/ignite-3/pull/5670#discussion_r2054575030


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/persistence/WriteBatchProtector.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.ignite.internal.metastorage.server.persistence;
+
+import java.util.Arrays;
+import org.apache.ignite.internal.util.HashUtils;
+
+/**
+ * Simple bloom-filter-based utility class to be used to cooperate compaction 
thread with an FSM thread. For a full explanation please
+ * consider reading comments in the {@link 
RocksDbKeyValueStorage#compact(long)} implementation.
+ */
+class WriteBatchProtector {
+    /**
+     * Signifies that there are 2^14 bits in this bloom filter, which is 
roughly equal to 16 thousand. This is a reasonably large value.
+     */
+    private static final int BLOOM_BITS = 14;
+    private static final int BLOOM_MASK = (1 << BLOOM_BITS) - 1;
+
+    // Constants for least significant bits (LSB) of hash values. These bits 
would point to individual bit positions in "long" values.
+    private static final int LSB_BITS = 
Integer.numberOfTrailingZeros(Long.SIZE);
+    private static final int LSB_MASK = Long.SIZE - 1;
+
+    /** Bit-set. */
+    private final long[] bloom = new long[1 << BLOOM_BITS >>> LSB_BITS];
+
+    /**
+     * Called when {@code key} is updated in the storage. Immediate 
consecutive call of {@code maybeUpdated(key)} will return {@code true}.
+     */
+    public void onUpdate(byte[] key) {
+        int h = hash(key);
+
+        int msb = h >>> LSB_BITS;
+        int lsb = h & LSB_MASK;
+        bloom[msb] |= 1L << lsb;

Review Comment:
   Sure



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to