adnanhemani commented on code in PR #2602: URL: https://github.com/apache/polaris/pull/2602#discussion_r2383753226
########## runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdGenerator.java: ########## @@ -0,0 +1,53 @@ +/* + * 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.polaris.service.tracing; + +import com.google.common.annotations.VisibleForTesting; +import jakarta.enterprise.context.ApplicationScoped; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicLong; + +@ApplicationScoped +public class RequestIdGenerator { Review Comment: I'm in favor of the zero-padded counters, happy to make the change - but can you please explain what about the current implementation makes it faulty? I appreciate your alternative implementation, however, I think this is actually susceptible to a race condition as well. If two threads call `updateAndGet` at the same time, it is still entirely possible that (given `increment` returns back the same `State` object) both threads complete calling `updateAndGet` prior to calling `requestId()` and as a result return back the same counter value. If I'm reading the documentation correctly, `updateAndGet` only provide guarantees when the object is immutable or the the function is side-effect free - which I don't believe is the case with the `State` object. While I'm sure this sort of race condition is highly unlikely to happen, I think that we will not hit that in the implementation as it is written currently - which is why I'm curious as to what you spotted. -- 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]
