adam-christian-software commented on code in PR #2131:
URL: https://github.com/apache/polaris/pull/2131#discussion_r2216601495


##########
persistence/nosql/idgen/api/src/main/java/org/apache/polaris/ids/api/IdGenerator.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.ids.api;
+
+public interface IdGenerator {
+  /** Generate a new, unique ID. */
+  long generateId();
+
+  /** Generate the system ID for a node, solely used by/for node management 
purposes. */
+  long systemIdForNode(int nodeId);
+
+  default String describeId(long id) {
+    return Long.toString(id);
+  }
+
+  IdGenerator NONE =
+      new IdGenerator() {
+        @Override
+        public long generateId() {
+          throw new UnsupportedOperationException("NONE IdGenerator");

Review Comment:
   Updated.



##########
persistence/nosql/idgen/api/src/main/java/org/apache/polaris/ids/api/SnowflakeIdGenerator.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.ids.api;
+
+import jakarta.annotation.Nonnull;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.util.UUID;
+
+public interface SnowflakeIdGenerator extends IdGenerator {
+  /** Offset of the snowflake ID generator since the 1970-01-01T00:00:00Z 
epoch instant. */
+  Instant EPOCH_OFFSET =

Review Comment:
   @dimas-b  - At the risk of sounding too verbose, how about 
ID_GENERATOR_EPOCH? I'd like to distinguish this from Unix Epoch?
   
   And, I agree @adutra . I'll update.



##########
persistence/nosql/idgen/impl/src/main/java/org/apache/polaris/ids/impl/SnowflakeIdGeneratorFactory.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.ids.impl;
+
+import static 
org.apache.polaris.ids.impl.SnowflakeIdGeneratorImpl.validateArguments;
+
+import java.time.Instant;
+import java.util.Map;
+import java.util.function.LongSupplier;
+import org.apache.polaris.ids.api.SnowflakeIdGenerator;
+import org.apache.polaris.ids.spi.IdGeneratorFactory;
+import org.apache.polaris.ids.spi.IdGeneratorSource;
+
+public class SnowflakeIdGeneratorFactory implements 
IdGeneratorFactory<SnowflakeIdGenerator> {
+  @Override
+  public void validateParameters(Map<String, String> params, IdGeneratorSource 
idGeneratorSource) {
+    int timestampBits =
+        Integer.parseInt(
+            params.getOrDefault(
+                "timestamp-bits", "" + 
SnowflakeIdGenerator.DEFAULT_TIMESTAMP_BITS));
+    int nodeIdBits =
+        Integer.parseInt(
+            params.getOrDefault("node-id-bits", "" + 
SnowflakeIdGenerator.DEFAULT_NODE_ID_BITS));
+    int sequenceBits =
+        Integer.parseInt(
+            params.getOrDefault("sequence-bits", "" + 
SnowflakeIdGenerator.DEFAULT_SEQUENCE_BITS));
+    var offsetMillis = SnowflakeIdGenerator.EPOCH_OFFSET_MILLIS;
+    var offset = params.get("offset");
+    if (offset != null) {
+      offsetMillis = Instant.parse(offset).toEpochMilli();
+    }
+
+    validateArguments(timestampBits, sequenceBits, nodeIdBits, offsetMillis, 
idGeneratorSource);
+  }
+
+  @Override
+  public SnowflakeIdGenerator buildSystemIdGenerator(
+      Map<String, String> params, LongSupplier clockMillis) {
+    return buildIdGenerator(
+        params,
+        new IdGeneratorSource() {
+          @Override
+          public int nodeId() {
+            return 0;
+          }
+
+          @Override
+          public long currentTimeMillis() {
+            return SnowflakeIdGenerator.EPOCH_OFFSET_MILLIS;

Review Comment:
   So, I think that there are some special-casing that is happening and is 
leaking into our interfaces and implementation. See here as well: 
https://github.com/apache/polaris/pull/2131/files#r2214779625
   
   We need the Snowflake ID Generation for Commit IDs and Entity Object IDs.
   
   We need a Node ID. Node IDs cannot be Snowflake IDs because Snowflake IDs 
require a NodeID.
   
   So, I actually think that we need a NodeIdGenerator concept for Node IDs and 
the concepts presented here for the other IDs. Right now, we are blending them 
into one interface and I think that is making things a bit confusing.
   
   For example:
   1. IdGeneratorFactory#buildSystemIdGenerator
   2. IdGenerator#systemIdForNode
   
   I think that we probably need to separate these concepts.
   
   What do y'all think, @dimas-b & @snazy?



##########
persistence/nosql/idgen/api/src/main/java/org/apache/polaris/ids/api/IdGenerator.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.ids.api;
+
+public interface IdGenerator {
+  /** Generate a new, unique ID. */
+  long generateId();
+
+  /** Generate the system ID for a node, solely used by/for node management 
purposes. */
+  long systemIdForNode(int nodeId);

Review Comment:
   Actually, the more that I read about the node-id lease stuff. I don't know 
whether this should be in this module. Here's my thinking:
   1. It seems that NodeID generation is special and not a Snowflake ID 
generation. The implementation is only based upon the node id passed in and 
some system-wide variables such as SnowflakeIdGeneratorImpl#timestampMax, 
SnowflakeIdGeneratorImpl#timestampShift, & 
SnowflakeIdGeneratorImpl#sequenceBits. So, in practice, it's really just the 
Node ID passed in.
   2. So, given that, I think we could pull this out and just put it into the 
node leasing modules. That way, we can keep the IdGenerator clean for the cases 
that require the distributed id generation.
   
   What do y'all think?



##########
persistence/nosql/idgen/spi/src/main/java/org/apache/polaris/ids/spi/IdGeneratorFactory.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.ids.spi;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.function.LongSupplier;
+import org.apache.polaris.ids.api.IdGenerator;
+
+public interface IdGeneratorFactory<I extends IdGenerator> {
+  String name();
+
+  void validateParameters(Map<String, String> params, IdGeneratorSource 
idGeneratorSource);
+
+  I buildIdGenerator(Map<String, String> params, IdGeneratorSource 
idGeneratorSource);
+
+  I buildSystemIdGenerator(Map<String, String> params, LongSupplier 
clockMillis);

Review Comment:
   This is related to 
https://github.com/apache/polaris/pull/2131/files#r2215597303



##########
persistence/nosql/idgen/impl/src/main/java/org/apache/polaris/ids/impl/SnowflakeIdGeneratorFactory.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.ids.impl;
+
+import static 
org.apache.polaris.ids.impl.SnowflakeIdGeneratorImpl.validateArguments;
+
+import java.time.Instant;
+import java.util.Map;
+import java.util.function.LongSupplier;
+import org.apache.polaris.ids.api.SnowflakeIdGenerator;
+import org.apache.polaris.ids.spi.IdGeneratorFactory;
+import org.apache.polaris.ids.spi.IdGeneratorSource;
+
+public class SnowflakeIdGeneratorFactory implements 
IdGeneratorFactory<SnowflakeIdGenerator> {
+  @Override
+  public void validateParameters(Map<String, String> params, IdGeneratorSource 
idGeneratorSource) {
+    int timestampBits =
+        Integer.parseInt(
+            params.getOrDefault(
+                "timestamp-bits", "" + 
SnowflakeIdGenerator.DEFAULT_TIMESTAMP_BITS));
+    int nodeIdBits =
+        Integer.parseInt(
+            params.getOrDefault("node-id-bits", "" + 
SnowflakeIdGenerator.DEFAULT_NODE_ID_BITS));
+    int sequenceBits =
+        Integer.parseInt(
+            params.getOrDefault("sequence-bits", "" + 
SnowflakeIdGenerator.DEFAULT_SEQUENCE_BITS));
+    var offsetMillis = SnowflakeIdGenerator.EPOCH_OFFSET_MILLIS;
+    var offset = params.get("offset");
+    if (offset != null) {
+      offsetMillis = Instant.parse(offset).toEpochMilli();
+    }
+
+    validateArguments(timestampBits, sequenceBits, nodeIdBits, offsetMillis, 
idGeneratorSource);
+  }
+
+  @Override
+  public SnowflakeIdGenerator buildSystemIdGenerator(
+      Map<String, String> params, LongSupplier clockMillis) {

Review Comment:
   I don't believe so. Removing.



-- 
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