dlg99 commented on a change in pull request #856: ISSUE #590 (@bug W-4556980@) Reduce excessive CPU usage on client side: add crc3? URL: https://github.com/apache/bookkeeper/pull/856#discussion_r157315333
########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java ########## @@ -0,0 +1,65 @@ +package org.apache.bookkeeper.client; + +/* +* 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. +*/ + +import com.scurrilous.circe.crc.Sse42Crc32C; +import io.netty.buffer.ByteBuf; +import org.apache.commons.lang3.mutable.MutableBoolean; +import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.pulsar.checksum.utils.Crc32cChecksum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class CRC32CDigestManager extends DigestManager { + static final Logger LOG = LoggerFactory.getLogger(CRC32CDigestManager.class); + + private final ThreadLocal<MutableInt> currentCrc = ThreadLocal + .withInitial(() -> new MutableInt(0)); + private final ThreadLocal<MutableBoolean> isNewCrc = ThreadLocal + .withInitial(() -> new MutableBoolean(true)); + + public CRC32CDigestManager(long ledgerId) { + super(ledgerId); + if (!Sse42Crc32C.isSupported()) { + LOG.error("Sse42Crc32C is not supported, will use less slower CRC32C implementation."); + } + } + + @Override + int getMacCodeLength() { + return 4; Review comment: @sijie Is there any guarantee that these will be interchangeable? i.e. jdk's one may use actual full long and pulsar's one will have int + another int (i.e. 0) as a filler. So we won't be able to upgrade bookie if it has ledgers created with one crc32c implementation and bookie just switched to another. Safer way would be to have yet another digest type (CRC32C_J) and set it explicitly. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
