codingwangqi commented on a change in pull request #1640: Issue #1639: Etcd based metadata driver implementation URL: https://github.com/apache/bookkeeper/pull/1640#discussion_r218363035
########## File path: metadata-drivers/etcd/src/main/java/org/apache/bookkeeper/metadata/etcd/Etcd64bitIdGenerator.java ########## @@ -0,0 +1,141 @@ +/* + * 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.metadata.etcd; + +import static com.google.common.base.Preconditions.checkArgument; +import static org.apache.bookkeeper.metadata.etcd.EtcdConstants.EMPTY_BS; + +import com.coreos.jetcd.KV; +import com.coreos.jetcd.Txn; +import com.coreos.jetcd.data.ByteSequence; +import com.coreos.jetcd.data.KeyValue; +import com.coreos.jetcd.kv.GetResponse; +import com.coreos.jetcd.op.Cmp; +import com.coreos.jetcd.op.Cmp.Op; +import com.coreos.jetcd.op.CmpTarget; +import com.coreos.jetcd.options.GetOption; +import com.coreos.jetcd.options.PutOption; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +import lombok.extern.slf4j.Slf4j; +import org.apache.bookkeeper.client.BKException.Code; +import org.apache.bookkeeper.meta.LedgerIdGenerator; +import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback; + +/** + * Generate 64-bit ledger ids from a bucket. + * + * <p>The most significant 8 bits is used as bucket id. The remaining 56 bits are + * used as the id generated per bucket. + */ +@Slf4j +class Etcd64bitIdGenerator implements LedgerIdGenerator { + + static final long MAX_ID_PER_BUCKET = 0x00ffffffffffffffL; + static final long BUCKET_ID_MASK = 0xff00000000000000L; + static final int BUCKET_ID_SHIFT = 56; + static final int NUM_BUCKETS = 0x80; Review comment: I read the ledger manager implementation. I think current implementation excludes negative ledger id. so I am following the practice that other implementations are doing. ---------------------------------------------------------------- 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
